GraphQL Authorization still leads to anonymous access

KB March 15, 2024

Hi,

I want to lookup some issues through the graphql API and managed to put together the components in GraphQL explorer.

Now trying this in a node app, I get the error:

Invalid JQL: Field 'type' does not exist or this field cannot be viewed by anonymous users.

This is how I put together the request:

I also copy the token from https://id.atlassian.com/manage-profile/security/api-tokens

async function fetchIssueIds() {
  const response = await fetch('https://MYINSTANCE.atlassian.net/gateway/api/graphql', {
    method: 'POST',
    headers: {
      'Authorization':"MYTOKEN-copied-from-https://id.atlassian.com/manage-profile/security/api-tokens",
      'Content-Type': 'application/json',
      "X-ExperimentalApi":"JiraIssueSearch"
    },
    body: JSON.stringify({
      query: `query example {
                jira {
                  issueSearchStable(cloudId: "MYCLOUDID", issueSearchInput: {jql: "type = 'Idea'"}) {
                    edges {
                      node {
                        id
                      }
                    }
                  }
                }
              }`
    }),
  });
  const responseBody = await response.json();
  return responseBody.data.jira.issueSearchStable.edges.map(edge => edge.node.id);
}

Not sure about the Token format, but from what I found this would be it.

I appreachiate any help!

1 answer

1 accepted

0 votes
Answer accepted
KB March 26, 2024

Unfortunately the documentation is really bad for this. With the help from the support team i figured the resolution:

 

First, the domain you use does not matter.

Second the authorization:

'Authorization':"Basic InserTokenHere"
and the token needs to be created by this string in  base64 encoding:
your@emailaddress.com:MYTOKEN-copied-from-https://id.atlassian.com/manage-profile/security/api-tokens

Suggest an answer

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

Atlassian Community Events