Search code examples
calendarms-officemicrosoft-graph-api

MSGraph request with $Filter returning Invalid Filter Clause


I am trying to use a filter on a MSGraph CalendarView request.

The request works perfectly until I add the filter to the URL. After adding the filter I receive the error:

"code":"BadRequest","message":"Invalid filter clause"

The URL I am using for the quest is:

https://graph.microsoft.com/v1.0/users/{userEmail}/calendar/calendarView?$filter=subject contains 'twilight'&$top=1000&startDateTime=2022-04-25T00:00:00-04:00&endDate=2022-04-30T00:00:00-04:00

I am trying to get any events with twilight in the subject between the date range.

Any ideas as I'm not sure what I'm missing.


Solution

  • The contains method should be used this way:

    contains(subject, 'twilight')

    Instead endDate there should be endDateTime

    https://graph.microsoft.com/v1.0/users/{userEmail}/calendar/calendarView? 
    $filter=contains(subject,'twilight')&$top=1000
    &startDateTime=2022-04-25T00:00:00-04:00&endDateTime=2022-04-30T00:00:00-04:00