I am trying to access an API using "request" npm. This API requires header "content-type" and a basic authentication. here is what I've done so far.
var request = require('request');
var options = {
url: 'https://XXX/index.php?/api/V2/get_case/2',
headers: {
'content-type': 'application/json'
},
};
request.get(options, function(error, response, body){
console.log(body);
}
).auth("dummyemail@abc.com","password",false);
upon executing this using Node , I am getting an error that says invalid username and password. I've validated the same API, authentication and header using CURL with the command below and it gave an expected HTTP response.
curl -X GET -H "content-type: application/json" -u dummyemail@abc.com:password "https://XXX/index.php?/api/V2/get_case/2"
Please suggest the right way to code request with auth and header.
Aucun commentaire:
Enregistrer un commentaire