Using the Pivotal API in javascript

90 Views Asked by At

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.

1

There are 1 best solutions below

0
Aran Mulholland On

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
}