Search code examples
node.jsnode-libcurl

nodejs node-libcurl HTTP Authorisation - problems with Bearer Auth Token


I'm coding a nodejs app to retrieve a transcript file from a site via the API.
If I use a curl command line everything works fine but I'm getting an

"Authoristaion Required"

status code back from my nodejs code.

I'm using the "node-libcurl" library and I'm trying to pass the Authorisation code by:

const curl = new Curl();
.....
curl.setopt(Curl.option.XOAUTH2_BEARER, "xxxxxxxxxxxxxxxxx");
.....

where xxxxxxxxxxxxxxxx is the Bearer authorization code. Is this syntax incorrect?


Solution

  • You have to set the same headers as in your working call from the cli. According to the docs this should do the trick

    curl.setOpt(Curl.option.HTTPHEADER, ['Authorization: Bearer xxxxx'])