Hi,
I had a scripts to run every month to help me fetching some data from ZenHub and generate some reports for me.
However, when I try to run the same scripts by using GraphQL API to fetch GitHub workspace repos, it returns error.
The query content
query Viewer {
viewer {
zenhubOrganizations(query: "{QUERY}") {
nodes {
id
workspaces {
totalCount
nodes {
repositories {
ghId
id
name
}
}
}
}
}
}
}
and I got erros like below
{
"errors": [
{
"message": "GitHub error. Message: Bad credentials",
"locations": [
{
"line": 9,
"column": 25
}
],
"path": [
"viewer",
"zenhubOrganizations",
"nodes",
0,
"workspaces",
"nodes",
0,
"repositories"
],
"extensions": {}
},
...
I am sure my API key is valid, and my ZenHub UI works fine and can be integrated with GitHub properly. I am not sure what happen here, it feels like an issue from ZenHub side.
Could anyone confirm is this a bug?
More info, I thought maybe the schema changes, and I used the wrong query.
So I use the official postman to check the schema, and they are all valid.
I got the same error from postman as well.
Hi @timmylin,
First thing to narrow down is the authentication, bad credentials sounds like a token problem. Do you get the same error if you try a basic query like this?
viewer {
id
}
I am focusing on what you said here: “when I try to run the same scripts by using GraphQL API”
We do have different tokens for our REST and GraphQL APIs, are you able to try and generate a new GraphQL token on this page and try again?
Thanks!
Will
Hi @WillDonohoe ,
Thank you for responding so quickly!
I mentioned that I was running the same scripts to emphasize that I had already automated the GraphQL API, and neither the code nor the query method has been changed. For the past year, these queries have worked without any issues.
I’ve already tried generating a new ZenHub API key and testing it, but the result is the same.
In fact, if the token had expired or invalid, I would be seeing a 401 error instead of this GitHub error.
I noticed that if I remove the repositories, the error disappears, which means some parts of the query are functioning correctly.
Got it, thanks @timmylin, repositories
is deprecated. Would you mind trying repositoriesConnection
instead. You’ll need to modify the query a little to include nodes:
query Viewer {
viewer {
zenhubOrganizations(query: "{QUERY}") {
nodes {
workspaces {
totalCount
nodes {
repositoriesConnection {
nodes {
ghId
id
name
}
}
}
}
}
}
}
}
Hi @WillDonohoe,
I tried your queries, but it’s still got GitHub error.
Did you try this? Is this working for you but not for me only?
query Viewer {
viewer {
zenhubOrganizations(query: "{QUERY}") {
nodes {
workspaces(first: 10) {
nodes {
repositoriesConnection(first: 10) {
nodes {
ghId
id
name
}
}
}
}
}
}
}
}
Response
{
"errors": [
{
"message": "GitHub error. Message: Bad credentials",
"locations": [
{
"line": 7,
"column": 13
}
],
"path": [
"viewer",
"zenhubOrganizations",
"nodes",
0,
"workspaces",
"nodes",
0,
"repositoriesConnection"
],
"extensions": {}
},
Hi @timmylin,
I can reproduce on my side now. I’'m asking the team and I’ll get back to you shortly.
Thanks!
Will
Hi @timmylin,
When requesting repositoriesConnection
we’ll check your permissions in GitHub. It’s possible that the GitHub token is expired or invalid. Could you try this: Logout of Zenhub and log back in using the “Login with GitHub” method. After that, generate a new API key via this page. That should fix the issue for you (it resolved the issue for me).
Thank you
Will
Hi @WillDonohoe,
Great, this solves the issue for me as well!
I’ve already changed the way of fetching workspace repo info on Monday to bypass the GitHub Error. As I originally thought there was no solution, so I’m glad we eventually found the root cause.
Thanks for your help in this thread!