I am using a 3rd party REST API in my node server. The 3rd party API provider as given me an API key and an example in cURL as follows:
$ curl -u APIKey@https://xyzsite.com/api/v1/users
I am not sure how I do it in node js. I have tried following but no luck. I get
var options = {
host: "xyzsite.com",
path: "/api/v1/users",
headers: {
"Authorization": "Basic " + myAPIKey
}
};
https.get(options, function(res, error) {
var body = "";
res.on('data', function(data) {
body += data;
});
res.on('end', function() {
console.log(body);
});
res.on('error', function(e) {
console.log(e.message);
});
});
Console message
{
"message": "No authentication credentials provided."
}