Search code examples
eventsmicrosoft-graph-apicategories

Filtering calendar view request in Microsoft Graph API by categories


I need get from Graph API events without any category or havn't specific category So, when I send:

https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2024-01-05T12:32:50.095Z&endDateTime=2024-01-31T12:32:50.095Z&$filter=not (categories/any(x:x eq 'MySyncJob'))

I get response

{
    "error": {
        "code": "ErrorInternalServerError",
        "message": "An internal server error occurred. The operation failed."
    }
}

But request:

https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2024-01-05T12:32:50.095Z&endDateTime=2024-01-31T12:32:50.095Z&$filter=categories/any(x:x eq 'MySyncJob')

and

https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2024-01-05T12:32:50.095Z&endDateTime=2024-01-31T12:32:50.095Z&$filter=categories/any(x:x ne 'MySyncJob')

working well...

What I do wrong?


Solution

  • The calendarView endpoint supports only filtering by one category

    /v1.0/me/calendarView?startDateTime=2024-01-05T12:32:50.095Z&endDateTime=2024-01-31T12:32:50.095Z&$filter=categories/any(x:x eq 'MySyncJob')
    

    Based on OData specification, you should be able to get events without categories by either

    /v1.0/me/calendarView?startDateTime=2024-01-05T12:32:50.095Z&endDateTime=2024-01-31T12:32:50.095Z&$filter=not(categories/any())
    

    or

    /v1.0/me/calendarView?startDateTime=2024-01-05T12:32:50.095Z&endDateTime=2024-01-31T12:32:50.095Z&$filter=categories/$count eq 0
    

    But it's not supported and I don't expect that they will improve/fix it.

    For now, only solution is to get all event from the range and filter them on the client side.