Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

API token generated from OAuth2 is returning 401

Ashrafuzzaman A_K_M
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 11, 2021

I generated API token and refresh token using OAuth2.

Here is my information about the scopes,

    scope: ['offline_access''read:me''read:account''read:jira-work''read:jira-user'],
    custom_params: { prompt: 'consent'audience: 'api.atlassian.com' },
I did get access_token and refresh_token successfully.

I am using the token to make the following API.
curl -X GET -H "Authorization: Bearer $API_TOKEN" \
-H "Accept: application/json" \
https://<company-subdomain>.atlassian.net/rest/api/2/issue/API-***
But I am getting 401. Am I doing something wrong?

1 answer

1 accepted

0 votes
Answer accepted
Andy Heinzer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2021

Hi Ashrafuzzaman,
It appears that you are trying to call the Cloud site directly by its URL.  However the guide in OAuth 2.0 (3LO) apps explains that first you have to get the Cloudid of the site,

curl --request GET \
--url https://api.atlassian.com/oauth/token/accessible-resources \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Accept: application/json'

Once you have the id, you can then Construct the request URL, from that point your call will look more closely related to this one:

curl --request GET \
  --url https://api.atlassian.com/ex/jira/11223344-a1b2-3b33-c444-def123456789/rest/api/2/project \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Accept: application/json'

Try this and see if that helps.

Andy

Ashrafuzzaman A_K_M
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 13, 2021

That was it. Thanks for helping

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events