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?

Have you tried using impersonation?

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