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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.