I'm trying to filter the results I'm getting from the Users/Calendar/List Events endpoint of the MS Graph API. While trying to figure out what's going on I've been using the Graph Explorer. If I make a request with a filter as follows:
https://graph.microsoft.com/v1.0/users/{redactedUPN}/events?$filter=start/dateTime ge '2022-05-03T00:00:00.0000000Z'
I get back a bunch of results, one of which is this all day event (I've removed most of the response's body for clarity):
{
"subject": "Annual leave",
"start": {
"dateTime": "2022-05-04T00:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2022-05-05T00:00:00.0000000",
"timeZone": "UTC"
}
},
As you can see, this event starts at midnight (UTC) on 4th May 2022. If I now modify my request to filter for events a day later, thus:
https://graph.microsoft.com/v1.0/users/{redactedUPN}/events?$filter=start/dateTime ge '2022-05-04T00:00:00.0000000Z'
This same event is not included in the results. I would expect it to be included because I'm using the ge
predicate, meaning "greater than or equal to" according to the docs, and my missing event's start datetime is identical to the date I've passed in my filter. Just to prove the point, if I change the predicate and use eq
(equals) instead:
https://graph.microsoft.com/v1.0/users/{redactedUPN}/events?$filter=start/dateTime eq '2022-05-04T00:00:00.0000000Z'
I get no events at all in my response. Even if I copy and paste the value from the response to the first request into the filter for the subsequent requests, the event doesn't get returned. What gives? Is this a time zone thing? I hoped that by including the Z
in my time filter I was being specific enough (note that it doesn't work without the Z
either).
As a side note, the documentation for the Graph API isn't great. The only way I learned to use the format start/dateTime
to reference the nested property was by coming across it in an issue posted by a user on GitHub. I can't see it anywhere in the docs.
Update
I've just tried another request, using the eq
predicate and setting the time filter to an hour earlier than I'm expecting (my time zone is UTC+1), like this:
https://graph.microsoft.com/v1.0/users/{redactedUPN}/events?$filter=start/dateTime eq '2022-05-03T23:00:00.0000000Z'
That query does return the event in question, although the response is the same as the one posted above, with the time showing as midnight on the 4th May and the time zone as UTC. So it definitely looks like a time zone issue, but surely if my filter matches the response's value exactly that should work?!