Reputation: 887
Here is a basic code:
const superagent = require('superagent');
superagent.get('https://api.arabam.com/pp/step')
.query({ apikey: '_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA==' })
.end((err, res) => {
if (err) { return console.log(err); }
console.log(res.body.url);
console.log(res.body.explanation);
});
But apikey is header rather than query. How do I send it as a header?
Edit:
I have tried using request module and it simply says that I'm unable to access it
var request = require("request");
request({
uri: "https://api.arabam.com/pp/step",
method: "GET",
'Content-Type' : "application/json",
apikey: "_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA=="
}, function(error, response, body) {
console.log(body);
});
It says unauthorized to access
Upvotes: 1
Views: 8991
Reputation: 102447
From the Setting header fields doc, you should use
request.set('apikey', '_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA==')
to set the header field.
Upvotes: 1