Which API to use to get user timezone?

:wave:

For one of our apps we need to use the user’ timezone, and we noticed that there are two APIs that provide this information:

GET /rest/api/3/user
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-get

This retrieves the entire user object, which includes timeZone property. However, it is unclear if this property is actually retrieved from the Atlassian ID account preference, or if this is the system timezone.

The reason why this is unclear is because apparently there is also a User Management API which I assume actually holds the most up-to-date information of the Atlassian ID account information, including locale and timezone.

GET /users/{account_id}/manage/profile
https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-profile/

This includes the zoneinfo property.

Is there a preference from Atlassian with regard to which API we should use, and which API is the most up-to-date?

Cheers,

Remie

I don’t think a normal connect app has access to the user management api’s…

The documentation says you can generate an API key for it, I was assuming that would work? I mean, I’d rather do it within the context of the Connect app, but if this is the right API to get timezone information, I can add the API key to my environment variables.

You’d need to get the end user to put in their api key…

Oh shit, is that API only available to the current user, even though it asks for account ID? What is the point of having an API key for that user, and asking to provide an account ID in the path?

Oh well… ok, that won’t work. Let’s hope that the Jira.User timeZone property is accurate :crossed_fingers:

Well if you have the “right” accountID - then it’s probably usable:

Use this REST API to administer and edit the managed accounts in your organization by account

So you would need to get hold of an org admin’s API key…

Hi @remie ,

This retrieves the entire user object, which includes timeZone property. However, it is unclear if this property is actually retrieved from the Atlassian ID account preference, or if this is the system timezone.

I did a little test by updating my time zone at https://id.atlassian.com/manage-profile/account-preferences and then querying https://my-test-instance.atlassian.net/rest/api/3/user?accountId=my-atlassian-account-id. The test indicated that GET /rest/api/3/user returns the time zone from the user’s Atlassian ID account preference.

Is there a preference from Atlassian with regard to which API we should use, and which API is the most up-to-date?

I don’t think there is a preference per se, but as @danielwester inferred, apps will probably want to call GET /rest/api/3/user. My test was manual, but the time zone preference was updated quickly.

Regards,
Dugald

1 Like

Hello @dmorrow ,

It seems, when call is made from Connect app, it returns system time zone unless user has set time zone privacy setting to “Anyone”.
Is there any way to work around this for use cases when actual time zone information is critical for end user experience?

1 Like

Have you tried using impersonation?

Yes, there’s no difference, even myself endpoint with impersonation returns system time zone.

Does anyone from Atlassian have any thoughts?
@dmorrow

We have found only the frontend method on the AP.user API: User. It obviously wont work in all use cases - ie backend processing only or something - but if your requests are all coming from your own frontend - then it does work well.

Reliably gets correct timezone (actually it completely ignores user privacy setting)>

Please be aware that this field is under profile visibility controls and that a user may intend to hide this field from the public. Because this API will provide unrestricted access to the current user’s timezone you should only use this API to establish context for the user. You should not present the user’s timezone in a way that can be seen by other users viewing the application.