Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

Does exceeding GitHub api rate limit cause Bad Credentials/401 error?

I had no problem issuing the same query all afternoon.

const query = `{
      repository(
        owner: "org"
        name: "publicRepo"
      ) {
        name
        forkCount
        forks(
          first: 2
        ) {
          totalCount
          nodes {
            name
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }`;
    
    var success = false;
    var makefileName = "";
    await fetch('https://api.github.com/graphql', {
      method: 'POST',
      body: JSON.stringify({query: query}),
      headers: {
        'Authorization': `Bearer ${accessToken}`,
      },
    }).then(res => res.text())
      .then(body => {
        try {
          var obj = JSON.parse(body); // this is how you parse a string into JSON 
     
          obj.data.repository.forks.nodes.forEach((item, index) => {
            //do things.....
        });
        } catch (ex) {
          console.error(ex);
        }
      })
      .catch(error => console.error(error));
    console.log("\n\n\n");
  }

This is an org I am a part of and a public repo - I don't even think I should have to get an auth token because all of the forks of this repo are public as well? But that's not the issue. 

 

The issue is that the query worked all afternoon. I got the list of fork names. Then, seemingly out of nowhere, I am getting the following in terminal:

{  message: 'Bad credentials',  documentation_url: 'https://developer.github.com/v4'
}

And when I run in an online javascript interpreter, I get 

POST https://api.github.com/graphql 401 (Unauthorized)

 

Do I need to regenerate the oauth token? I'm using an oauth token generated for a github bot

1 Reply
Community Manager
Message 2 of 2

Re: Does exceeding GitHub api rate limit cause Bad Credentials/401 error?

If you want to check to see if you're running up against rate limits, you can use a simple query like is mentioned in our rate limit documentation. To my knowledge though, no, it shouldn't give you a 401 Unauthorized error when you're running into rate limits.

 

I hope that helps!