Do the timezone and time change in the in the result of msgraph-sdk calendar_view.get() ?

Shaun Yang (Medalsoft) 0 Reputation points
2024-05-14T09:14:27.6033333+00:00

I am using python msgraph sdk to query calendar views. Below is my request:

params = {"start_date_time": "2024-05-15T00:00:00+08:00", "end_date_time": "2024-05-15T23:59:59+08:00"}
query_params = CVRBuilder.CalendarViewRequestBuilderGetQueryParameters(
        **params
)
config.query_parameters = query_params

events = asyncio.run(client.users.by_user_id("myid").calendar.calendar_view.get(
        config
))

However, the event.start.date_time for each event in the events changed when I run my code on my desktop in UTC-8 timezone, and a server in US East. The difference of the time is actually the time zone difference. I did not get a chance to print out the event.start.time_zone because when I update my code and restart my server, the issue was gone.

Is there anyone facing the same issue?

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

1 answer

Sort by: Most helpful
  1. awijekoon 1,335 Reputation points Microsoft Vendor
    2024-05-18T03:17:44.32+00:00

    Hi Shaun,

    You could use the Prefer: outlook.timezone header to retrieve events in a specific time zone. This will ensure that the event times are retrieved in the time zone you prefer.

    request_configuration.headers.add("Prefer", "outlook.timezone=\"Pacific Standard Time\"")
    

    https://learn.microsoft.com/en-us/graph/api/event-get?view=graph-rest-1.0&tabs=python

    0 comments No comments