3

I am trying to get data of below url using sync-request module.

https://api.github.com/repos/rethinkdb/rethinkdb/stargazers

I get the data when i call it in browser or through postman.
But i am getting 403 forbidden error when calling it using sync-request in my node api.

My code looks like this.

 var request = require("sync-request");

 var response = request('GET', 'https://api.github.com/repos/rethinkdb/rethinkdb/stargazers', {
                headers: {},
                json: true
            });

I am able to fetch data of many other api's but not this one. Please help.

2 Answers 2

1

Response body already contains the explanation:

Request forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.

It will work like:

var response = request('GET', 'https://api.github.com/repos/rethinkdb/rethinkdb/stargazers', {
    headers: { 'User-Agent': 'Request' },
    json: true
});

The use of sync-request is strongly discouraged because synchronousness is achieved via a hack and may block the process for a long time.

For sequential execution request-promise can be used together with async..await.

Sign up to request clarification or add additional context in comments.

Comments

1

Try to use an access token along with the GitHub API call like this

[https://api.github.com/repos/rethinkdb/rethinkdb/stargazers?access_token=f33d1f112b7883456c990028539a22143243aea9]

As you say the API works in the browser it should not be an issue.

When you use too many calls through the GitHub API they they give the following message

{ "message": "API rate limit exceeded for 192.248.24.50. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", "documentation_url": "https://developer.github.com/v3/#rate-limiting" }

To overcome this issue you can use an access token using an access token you can to access the private repositories in your account as well . Here is the link for to get an access token [https://github.com/settings/developers]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.