Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Difference between API token for REST and GRAPHQL

Edited

Hi guys!! I've created an api token to use with REST API. I pass it by header Authentication and everything works fine:

curl 'https://myspace.atlassian.net/rest/api/3/users/search?maxResults=1000' \
-H 'Connection: keep-alive' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"' \
-H 'Accept: */*' \
-H 'Authorization: Basic base64<user:token>' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36' \
-H 'Origin: http://localhost:3000' \
-H 'Sec-Fetch-Site: same-site' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: http://localhost:3000/' \
-H 'Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7' \
-H 'x-elastica_gw: 3.116.0' \
--compressed

But when I try to call an GRAPHQL endpoint I receive a forbidden error.

I thought the token was the same for both APIs, isn't it?

 

If it is not, where can I create a token for GRAPHQL API?

 

Here is my curl for GRAPHQL

curl 'https://myspace.atlassian.net/gateway/api/directory/graphql?q=UserDetails' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"' \
-H 'Accept: */*' \
-H 'Referer: http://localhost:3000/' \
-H 'Authorization: Basic base64<user:token>' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36' \
-H 'Content-Type: application/json' \
--data-raw $'{"operationName":"UserDetails","variables":{"userId":"1234","cloudId":"1234"},"query":"query UserDetails($userId: String\u0021, $cloudId: String\u0021) {\\n CloudUser(userId: $userId, cloudId: $cloudId) {\\n id\\n fullName\\n isCurrentUser\\n title\\n department\\n companyName\\n location\\n timezone\\n email\\n phoneNumber\\n remoteWeekdayIndex: localTime(format: \\"d\\")\\n remoteWeekdayString: localTime(format: \\"ddd\\")\\n remoteTimeString: localTime(format: \\"h:mma ([GMT]Z)\\")\\n __typename\\n }\\n}\\n"}' \
--compressed 

 

1 answer

1 accepted

0 votes
Answer accepted
Andy Heinzer Atlassian Team Dec 16, 2021

Hi Danilo,

If I understand the question here, you are looking to use the Basic Authentication when accessing the Graphql API.  This is still possible to do with curl, but it looks like there is a problem with your request.

First, your request in this case is not made directly to your Cloud site URL of example.atlassian.net, but rather directly to https://atlassian.net/gateway/api/graphql

Here is my example call

curl --request POST \
--url "https://atlassian.net/gateway/api/graphql" \
--header "Content-Type: application/json" \
--header "Authorization: Basic myREDACTEDencodedstring" \
--data '{"query": "query example {me {user { ... on AtlassianAccountUser {accountId \n accountStatus \n name \n picture}}}}"}'

When I made this specific call, I was able to get back a json response that showed me the expected information about the account I used to create my API token.

However I did have to adjust from the examples given over in https://developer.atlassian.com/platform/atlassian-graphql-api/graphql/#examples in order to get them to work in curl.  It appears that the multiple lines shown within the payloads of the examples aren't really working well in curl, thus the need to use a \n for a new line in my payload.  I also found from playing with this that if the payload contains any quotes, those too have to be escaped with a \ character before the request can be successful in curl.

Try this and let me know if that helps.

Andy

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

111 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you