I am trying to access ‘https://zenhub.ibm.com/api/v1/graphql’ url by using api_key generating from account management.
With this api_key also i am getting api key ‘401 error with “message”:“missing authentication token in headers”’.
So how can i generate the access_token to pass in the header ?.
I got back to trying to using API today, and I keep getting 401 with a newly generated token.
It is very strange that no one is responding to many questions asked on this forum. I understand when open source projects do not have the capacity to respond, but Zenhub is not a free open source project. Very strange…
Hey @fedorov
Can you share some details around the request you are trying to make and your request body?
You can also take a look at our getting started guide which has a few example requests to try out.
@Joseph.from.Zenhub thanks for responding!
I am following the documentation, and specifically the link to the Explorer: Explorer | Zenhub Developers. I generated the token as described in the documentation.
When I enter that token in the Explorer page and run the auto-generated example, I am getting this:
Also, the link https://developers.zenhub.com/explorer/graphql-api-docs/getting-started#authentication from the Explorer page is broken.
Do you mind double checking that you have correctly copied your token, and the query you are trying to run? Please also be sure to replace the “WORKSPACE_NAME” with the workspace you are looking for.
I was able to get the same query working using the explorer.
@Joseph.from.Zenhub thank you for your help!
As it turns out, I was using incorrect token. Instead of generating the API key in the " GraphQL Personal API Key" section, I created one using " REST API Token" section. This problem is resolved, I appreciate the quick response!
Hi,
Did you correctly included API Key in your request headers?
You can consider this-
curl -X POST https://zenhub.ibm.com/api/v1/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{ "query": "{ yourGraphQLQueryHere }" }'
using Python with requests
:
import requests
url = "https://zenhub.ibm.com/api/v1/graphql"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
query = {
"query": "{ yourGraphQLQueryHere }"
}
response = requests.post(url, headers=headers, json=query)
print(response.status_code)
print(response.json())
using JavaScript with fetch
:
const url = "https://zenhub.ibm.com/api/v1/graphql";
const headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
};
const query = JSON.stringify({ query: "{ yourGraphQLQueryHere }" });
fetch(url, {
method: "POST",
headers: headers,
body: query
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));