1

So, I'm attempting to make an HTTP request to github to return a list of all the issues on a particular github repository. I'm using coffeescript in my code below but it should be fairly self explanatory for any JS developer. my confusion is that if I enter "https://api.github.com/repos/username/repo-name/issues" into my browser I can retrieve all of the info that I'm looking for. I get an error saying "Missing or invalid User Agent string" when I try to make the request through my application with the request node library. Please let me know if you know how to properly structure a URL to actually retrieve information from the github API.

githubUrl = "https://api.github.com/repos/#{username}/#{repoName}/issues?state=open"

    request githubUrl, (error, response, body) ->

        console.log body
Will Piers
  • 421
  • 2
  • 8
  • 13

1 Answers1

5

You need to pass a user agent string like it says :) I just pulled one from chrome:

require( 'https' )
    .get({
         hostname : 'api.github.com'
        ,    path :'/repos/cwolves/jquery-imask/issues'
        , headers : {
            'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'
        }
    }, function(res){
        res.on('data',function(data){
            console.log(data+'');
    });
});
  • You shouldn't lie its request was fired from browser. Instead, User-Agent header should be you login id; as https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required mentions. – user-id-14900042 May 11 '22 at 20:40