How to filter calendar events

Ahmed Magdi 0 Reputation points
2023-10-03T20:51:51.45+00:00

I have been trying to filter calendar events on specific dates, so I wrote the following codes

List<Microsoft.Graph.QueryOption> options = new(); ;

options.Add(new Microsoft.Graph.QueryOption("$filter",$"start ge {startDate.ToDateTimeTimeZone()} and end le {endDate.ToDateTimeTimeZone()}"));

and

var eventResponse = await this.graphServiceClient.Me.Calendars[calendarId].Events.Request().Select("start").Filter($"start ge {startDate.ToDateTimeTimeZone()}").GetAsync();

but none of them seemed to work, I bounced between a lot of errors the last one was

Message: Invalid filter clause: Encountered invalid type cast. 'microsoft.graph.dateTimeTimeZone' is not assignable from 'microsoft.graph.event'.

I would really appreciate some , thanks in advance

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

1 answer

Sort by: Most helpful
  1. AsithwMSFT 1,435 Reputation points Microsoft Vendor
    2023-12-04T01:38:30.03+00:00

    @ahmed magdi

    are you looking this kind of solutions?

    var graphClient = new GraphServiceClient(requestAdapter);
    
    var result = await graphClient.Me.Calendar.Events.GetAsync((requestConfiguration) =>
    {
    	requestConfiguration.QueryParameters.Filter = "start/dateTime eq '2022-07-14T12:30:00Z' and subject eq 'Testing'";
    });
    
    0 comments No comments

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.