Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting data of GITHUB api using npm module sync-request

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.

like image 600
Sagar Chaudhary Avatar asked Apr 19 '26 10:04

Sagar Chaudhary


1 Answers

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.

like image 185
Estus Flask Avatar answered Apr 22 '26 02:04

Estus Flask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!