I am trying to use a pre-request to create an object then I will store an Id from that response and I will use in my main request but I am getting a status code 401 related to authentication but I added that header in the pre-request. could someone please help me?
Here is my script :
var options = {
'method': 'POST',
'url': 'https://www.pivotaltracker.com/services/v5/projects',
'headers': {
'X-TrackerToken': '12345647897',
'Accept': ['application/json', 'application/json']
},
body: JSON.stringify({"name":"Asia"})
};
pm.sendRequest(options, function (error, response) {
const data = response.json();
pm.variables.set("project_id", data.id);
console.log('project id: '+ data.id);
});
attached image:
console log:
POST https://www.pivotaltracker.com/services/v5/projects401820 ms
POST /services/v5/projects HTTP/1.1
Content-Type: text/plain
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Postman-Token: ee62474c-ff9c-4de8-95f9-20de17983a3d
Host: www.pivotaltracker.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 15
{"name":"Asia"}
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Status: 401 Unauthorized
Cache-Control: no-cache
X-Request-Id: ac3fc051-c4f3-4fd6-9bc8-2ee99966f16b
X-Runtime: 0.008757
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
Date: Wed, 13 May 2020 03:57:08 GMT
X-Powered-By: Phusion Passenger
Server: nginx + Phusion Passenger
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: false
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is
X-Tracker-Client-Pinger-Interval: 20
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-XSS-Protection: 1; mode=block
Via: 1.1 google
Alt-Svc: clear
{"code":"unauthenticated","kind":"error","error":"Needs authentication credentials.","possible_fix":"Try basic auth, or include header X-TrackerToken.","general_problem":"User authentication required but not provided."}
Show pretty log
project id: undefined