Thursday 20 April 2017

NodeJS Request Bearer

I can't seem to get a proper response using the request package with node. I have tried several different placements according to the documentation on npm but keep getting the same result.

"Invalid Access Token 401"

I've asked around the forums and they ensure me that the token I'm using is correct. Any help would be greatly appreciated!

const restify = require('restify');
const request = require('request');

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
   console.log('%s listening to %s', server.name, server.url);
});


var options = {
  url: 'https://css.api.hp.com/productWarranty/v1/queries',
  json: true,
  method: 'POST',
  Authorization: 'Bearer MYAUTHORIZATIONKEY',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'text/plain',
  }
};

var callback = (error, response, body) => {
  console.log(body);
  console.log(response.statusCode);
}

request(options, callback);



via Parakoopa

No comments:

Post a Comment