0

I am new to using API's that have authentications, on the pivotal website they have commands using curl commands that look like this

export TOKEN='your Pivotal Tracker API token'

curl -X GET -H "X-TrackerToken: $TOKEN" "https://www.pivotaltracker.com/services/v5/projects/99"

I was wondering how I can convert this to JavaScript by making a request, the problem is I don't know where to put the token when making the request to an API.

So far in JavaScript I have this

 function reqListener () {
      console.log(this.responseText);
    }

    var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
    var oReq = new XMLHttpRequest();
    oReq.addEventListener("load", reqListener);

    oReq.open("GET", "https://www.pivotaltracker.com/services/v5/projects/99?fields=version");
    oReq.setRequestHeader(header, 'Pivotal token');
    oReq.send();

Also i dont know what to in place of header.

none
  • 1
  • 1
  • Look into the docs for `curl` then. `-X` specifies a HTTP method, `-H` denotes a request header to add. Find out how to do that in Javascript with for example the Fetch API. – nbokmans Feb 26 '19 at 14:23
  • I edited it now , what should I put in place of header – none Feb 26 '19 at 17:24

1 Answers1

0

When you set up your http request put the access token in the headers using the key "X-TrackerToken". I have been using the following headers when making a request:

{
    "Content-Type": "application/json",
    "X-TrackerToken": apiToken
}
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228