Get time zone for a user in Graph
With the current SDK for .NET you cannot directly get the time zone for a user. But you could work around this.
The problem
Last week I showed how to create an event in Microsoft Graph. That example used a hard coded time zone. Of course, it would be better if we could get this directly from Graph.
The solution
To my understanding, there is no time zone setting in the userโs profile.
Instead, the time zone for the mailbox settings are used to solve this. The URL
for this setting is
https://graph.microsoft.com/v1.0/me/mailboxsettings/timeZone
. Try this
yourself in the Graph
Explorer. I get
this response:
Read more about this in the documentation.
Unfortunately, this value cannot be directly downloaded from the current SDK. But it is not that hard to work around this. In the SDK documentation there is some information how to create custom request. I am using this in the code below.
Note that the permission MailboxSettings.Read
needs to be set both
appsettings.json and the API permission in your application settings in Azure
App Registrations.
Summary
This was a bit more complicated than I was hope for. But being able to work around limitations in the SDK, with a relatively small amounts of code, is a useful skill.