Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,997
Community Members
 
Community Events
168
Community Groups

authenticating into GraphQL API via CLI

I'm rather enjoying exploring the GraphQL capabilities in the browser-based explorer that each subdomain has.  For me, its https://hv-eng.atlassian.net/gateway/api/graphql

I'd like to take that to the next level and incorporate it into some Bash shell scripts.  However, I'm unable to figure out how to properly auth from curl.

The docs at https://developer.atlassian.com/platform/atlassian-graphql-api/graphql/#authentication suggest there are (2) options for authenticating via CLI: OAUTH and API TOKEN.  No further explanation or examples regarding expected headers are given for either scenario.  Searches on OAUTH lead to https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/ and the development of an app using Node.js and Docker as described in https://developer.atlassian.com/platform/forge/getting-started/, which is way beyond the scope of a simple curl.

That leaves the API TOKEN scenario.  What I'm able to do in the browser explorer though, I'm unable to do via curl:

$ curl -s -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "Authorization: Basic $MY_API_TOKEN" \
-d "{ query cloudid { \
tenantContexts(hostNames:['hv-eng.atlassian.net']) { \
cloudId \
} \
} \
}" \
"https://hv-eng.atlassian.net/gateway/api/graphql" | jq '.'

{
"code": 401,
"message": "Unauthorized"
}

 This post suggests using https://atlassian.net/gateway/api/graphql, contrary to the documentation, but that doesn't work either.

1 answer

1 accepted

0 votes
Answer accepted

I finally found https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/  and was able to properly auth using the output of this in place of $MY_API_TOKEN:


echo -n <MY_EMAIL>:<MY_API_TOKEN> | base64

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events