Get server info from OAuth2 token

I’d like to link to an issue from my app, which uses OAuth2. To do this, I think I need the base URL.
Per the docs, the API does not return the base URL, but says the following:

To get the base URL of the site, call Get Jira instance info using the access token.

When I call that with an access token, I get the following:

{
    "errorMessages": [
        "OAuth 2.0 is not enabled for this method."
    ]
}

All I want to do is let folks click a link in my app to go directly to the issue in Jira. How can I accomplish this?

The endpoint /rest/api/3/serverInfo does not need any auth/token (example). What hostname are you trying to make that call against?

That example uses the base url that I’m trying to get :slightly_smiling_face: How can I get that endpoint using OAuth2? Per the docs:

Requests that use OAuth 2.0 authorization code grants are made via api.atlassian.com (not https://your-domain.atlassian.net ). Construct your request URL using the following structure:
https://api.atlassian.com/ex/jira/{cloudid}/{api}

The accessible resources returns a name field, but per the docs:

Note that the name property in the response does not always correspond to the base URL of the site, even though it looks similar. It is only suitable for display to users.

Given the api.atlassian.com hostname, is there a way to get the baseUrl?

Hi @matt1!

Apologies, the error message “OAuth 2.0 is not enabled for this method.” isn’t super useful. You can also make unauthenticated requests via https://api.atlassian.com, so to get the serverInfo for @nmansilla’s site (which has a cloud id of 4ce3c724-3201-4adf-b441-be21797af3a5), you could use:

https://api.atlassian.com/ex/jira/4ce3c724-3201-4adf-b441-be21797af3a5/rest/api/3/serverInfo

Without an Authorization header (supplying one triggers the OAuth2 error you saw). Simply substitute 4ce3c724-3201-4adf-b441-be21797af3a5 with the Cloud ID of the site you’re trying to determine the base url of.

cheers,
Tim

3 Likes