Issue using Microsoft Graph SDK filter clause in an Calendar/Events query.

John Pike 25 Reputation points
2023-03-23T14:40:12.4133333+00:00

Issue using Microsoft Graph SDK filter clause in an Calendar/Events query. Here is the actual c# code that I am having the problem with: var results = await eventServiceClient.Users[users[i].Id].Calendar.Events.Request().Top(999).Select("Start,End,Body,BodyPreview,Subject,CreatedDateTime,LastModifiedDateTime,Type").Filter("startDateTime ge 2023-03-20T08:00:00").GetAsync();

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,857 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 41,286 Reputation points
    2023-03-24T03:23:12.42+00:00

    Hi @John Pike

    Please try to upgrade your Microsoft Graph package to version 5.0 or above:

    dotnet add package Microsoft.Graph --version 5.2.0
    

    Note that the Microsoft Graph .NET SDK v5 has removed the Request() method.

    using Azure.Identity;
    using Microsoft.Graph;
    using Newtonsoft.Json;
     
    var scopes = new[] { "https://graph.microsoft.com/.default" };
     
    var tenantId = "{tenant id}";
     
    // Values from app registration
    var clientId = "{client id}";
    var clientSecret = "{client secret}";
     
    // using Azure.Identity;
    var options = new TokenCredentialOptions
    {
          AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
    };
     
    // https://docs.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
    var clientSecretCredential = new ClientSecretCredential(
          tenantId, clientId, clientSecret, options);
     
    GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
     
    var result = await graphServiceClient.Users["{user id}"].Calendar.Events.GetAsync((requestConfiguration) =>
     
    {
     
          requestConfiguration.QueryParameters.Select = new string[] { "start", "end", "bodyPreview", "body", "subject", "createdDateTime", "lastModifiedDateTime", "type" };
     
          requestConfiguration.QueryParameters.Filter = "start/dateTime ge '2023-03-20T08:00:00'";
     
          requestConfiguration.QueryParameters.Top = 999;
     
    });
      
    Console.WriteLine(JsonConvert.SerializeObject(result));
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Siddharth Gautam 860 Reputation points
    2023-03-23T22:33:57.1533333+00:00

    Hello John Pike,

    Thanks for reaching out.

    As per my testing, you are not using the $filter query parameter on startDate Time property in right way. The correct way to write startDate Time is 'start/dateTime'.

    Please refer the below snippet for same:

    var result = await graphClient.Users["{user-id}"].Calendar.Events.GetAsync((requestConfiguration) =>
    {
        requestConfiguration.QueryParameters.Filter = " start/dateTime ge '2023-03-20T08:00:00Z'";
        requestConfiguration.QueryParameters.Select = new string []{ "Start","End","Body","BodyPreview","Subject","CreatedDateTime","LastModifiedDateTime","Type"};
    
    });
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

  2. John Pike 25 Reputation points
    2023-03-24T17:05:14.6+00:00

    Now that I have upgraded to version 5.3, how do I get the next page in multiple page results.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.