Home > database >  Microsoft Graph C# SDK, Date Range
Microsoft Graph C# SDK, Date Range

Time:01-11

Just started having to learn Microsoft.Graph SDK C#. I am getting it to work however I am running in to an issue and cant seem to find the correct documentation for using this in C#

I am trying to get a week worth of event date.

 var filterString = $"start ge 2023-01-09& lt eq 2023-01-16";
        var events = await graphServiceClient.Me.Calendar.Events
            .Request().Filter(filterString)
            .GetAsync();
        ResultText.Text = "";
        foreach (var response in events)
        {
            ResultText.Text  = response.Subject;
            ResultText.Text  = Environment.NewLine;




        }

However, I am receiving the following in Chrome and trying to figure out what I am doing wrong. Perhaps I could not locate the correct documentation for this. Most is for the Rest API and no the C# SDK I have tried using the rest $filter and to no avail.

Code: BadRequest Message: Invalid filter clause Inner error: AdditionalData: date: 2023-01-09T19:50:50 request-id: 427f24b9-62ab-4541-bc4e-a49e02bcc508 client-request-id: 427f24b9-62ab-4541-bc4e-a49e02bcc508 ClientRequestId: 427f24b9-62ab-4541-bc4e-a49e02bcc508

CodePudding user response:

start property is of type dateTimeTimeZone with the property dateTime of type string.

You need to filter by start/dateTime

// filter events between 2023-01-09 and 2023-01-16
var filterString = "start/dateTime ge '2023-01-09T08:00' and start/dateTime le '2023-01-16T08:00'";
var events = await graphClient.Me.Calendar.Events
    .Request()
    .Filter(filterString)
    .GetAsync();

Supported operators for dateTime are less than (lt), greater than (gt), less than or equal to (le) and greater than or equal to (ge).

Documentation:

$filter query operator

  • Related