Search code examples
authenticationgithubgoogle-apps-scriptbasic-authenticationgithub-api

GAS: How to use UrlFetchApp to search private repo via GitHub API, with authentication?


Am trying to scrape data from a private repo by using GitHub's API via the Google Apps Script (GAS).

I have an accessToken that seems to work for normal things, but when it comes to doing searches for issues, the accessToken is not accepted.

https://api.github.com/search/issues?q=repo:esaruoho/ztracker_mac+state:open (+aT)

I'm trying to access a private repo (not the one I linked here, which is public, and the link works) and attach the

?access_token=token

at the end, but for some reason this simply does not seem to work. Is there some other way of authentication?

I'm trying to figure out how I could modify the UrlFetchApp.fetch to also input the required headers that authenticate, but I'm not figuring out what kind of stuff GitHub authenticates with


Solution

  • Here's what you are trying to do:

    https://api.github.com/search/issues?q=repo:esaruoho/ztracker_mac+state:open?access_token=yourToken
    

    Notice how you already have a question mark (?) in the URL, you can't put two in, you have to change the question mark to an ampersand (&)

    https://api.github.com/search/issues?q=repo:esaruoho/ztracker_mac+state:open&access_token=yourToken