Time Zone Conversion Issue When Creating Events via Microsoft Graph API

Stephen Ignatius 20 Reputation points
2024-05-15T21:21:05.9733333+00:00

Question:

I am currently integrating the Microsoft Graph API for calendar event management within my application. When creating events using the API, I specify the start and end times in the local time zone (America/New_York), but I've noticed that the response from the API shows the event times in UTC. Here are the details of my implementation:

Controller (Request Body):

{

  "title": "American Event",

  "startTime": "2024-05-15T22:00:00Z",

  "endTime": "2024-05-15T22:30:00Z",

  "timeZone": "America/New_York",

  "participants": [

    {

      "email": "stephenignatiusbiz@gmail.com",

      "isOrganizer": false,

      "status": "needsAction"

    }

  ]

}

Controller (Formatted Request):

`javascript

const formattedRequest = {

  subject: 'American Event',

  start: { dateTime: '2024-05-15T22:00:00Z', timeZone: 'America/New_York' },

  end: { dateTime: '2024-05-15T22:30:00Z', timeZone: 'America/New_York' },

  attendees: [

    {

      emailAddress: {

        address: 'stephenignatiusbiz@gmail.com',

        name: ''

      },

      type: 'required'

    }

  ]

};

Service (Graph API Call):

const eventsResponse = await axios.post(

  `https://graph.microsoft.com/v1.0/me/calendars/${calendarId}/events`,

  eventsData,

  {

    headers: {

      Authorization: `Bearer ${accessToken}`

    }

  }

);

Received Response (Partial):

{

  "id": "AAMkADk5ZTYxMTBiLTI0N2ItNDkxNy04NDQ1LTU4NTM2NDUwZWJjNABGAAAAAADPDz1yPyCcQY6PeLRiiFj4BwB-un6eMt9nSr8XjQvbqJVBAAAAAAENAAB-un6eMt9nSr8XjQvbqJVBAACgoOtOAAA=",

  "start": { "dateTime": "2024-05-15T22:00:00.0000000", "timeZone": "UTC" },

  "end": { "dateTime": "2024-05-15T22:30:00.0000000", "timeZone": "UTC" },

  ...

}

Issue:

Despite specifying the timeZone as America/New_York in the request, the response returns event times in UTC (dateTime fields). I expected the response to reflect the specified time zone (America/New_York) for easier interpretation and display on the client side.

Question:

  1. Is there a specific reason why the event times are returned in UTC instead of the specified time zone?
  2. What is the recommended approach to handle time zone conversions when displaying event details to end users?
  3. Is there a way to configure the API request to receive event times directly in the specified time zone (America/New_York)?

Any guidance or insight on this matter would be greatly appreciated. Thank you!

Outlook
Outlook
A family of Microsoft email and calendar products.
4,169 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,540 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CharanyaB-MSFT 1,891 Reputation points Microsoft Vendor
    2024-05-16T19:12:55.5766667+00:00

    Hello @STEPHEN IGNATIUS,

    Thanks for reaching Microsoft.

    Use the Prefer: outlook.timezone request header to specify the time zone for the start and end times in the response. Please use the header as example: Prefer: outlook.timezone="Pacific Standard Time". Also specify the timezone property in the request body with respective timezone.

    Please refer the example from below documentation to create an event in the specified time zone:

    https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http#example-1-create-an-event-in-the-specified-time-zone-and-assign-the-event-an-optional-transactionid-value

    Hope this helps.

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.