MS GRaph API - /users/{user AAID}/calendarView - fetching all day event for one day with - time range (23:59), give wrong results due expanding range for next day

Dariusz Niedzialek 1 Reputation point
2022-08-23T10:13:06.72+00:00

There are 2 all-day events
1st. 2022-08-06
2nd. 2022-08-07

I'm preparing solution to get events from one day:
the problem is with time range, I don't understand why when I use hour 23:59:59 (endDateTime=2022-08-06T23:59:59) - the returned results contains 2nd day events too. It's look like timerange is corelated with user's timezone.
So when I change endDateTime to: 2022-08-06T21:59:59 the results are correct and contain only 1 event from requested day (1st day). The user's timezone is Eastern Standard Time (EST).

I'm still confused because changing user timezone (in outlook settings) doesn't impact on results.
How to get correct results?

Used query:
https://graph.microsoft.com/v1.0/users/099392bd-26d7-47ef-887d-46ef5332d774/calendarView?startDateTime=2022-08-06T00:00:00&endDateTime=2022-08-06T23:59:59&$top=100&$skip=0&$select=categories,start,end,subject,isCancelled

RESULTS (shortened):
1st day task start end datetimes
"start": {
"dateTime": "2022-08-06T00:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2022-08-07T00:00:00.0000000",
"timeZone": "UTC"
}

2nd day task start end datetimes

        "start": {  
            "dateTime": "2022-08-07T00:00:00.0000000",  
            "timeZone": "UTC"  
        },  
        "end": {  
            "dateTime": "2022-08-08T00:00:00.0000000",  
            "timeZone": "UTC"  
        }
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,124 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shivam Dhiman 5,951 Reputation points
    2022-08-24T16:57:59.813+00:00

    Hi @Dariusz Niedzialek

    To address your issue I have created 2 All day event in my test tenant. My outlook time zone is Eastern time. As per this documentation you have to use offset time to get the right result.
    234602-docfinal.png

    You can use this https://graph.microsoft.com/v1.0/users/Shivam1@***.onmicrosoft.com/calendarview?startDateTime=2022-09-06T00:00:01-04:00&endDateTime=2022-09-07T00:00:00-04:00 Graph API.

    As you can see I am able to get both the events
    234509-sep5a.png

    234529-sep6a.png

    Hope this helps.

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

    0 comments No comments