# The header configured on pre request script is not added

**URL:** <https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602>\
**Category:** Help Hub\
**Tags:** pmsendrequest, pre-request-script\
**Created:** [May 13, 2020, 4:03am UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602 "2020-05-13T04:03:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuri.vayne](https://avatars.discourse-cdn.com/v4/letter/y/aeb1de/32.png) [@yuri.vayne](https://community.postman.com/u/yuri.vayne)\
**Post date:** [May 13, 2020, 4:03am UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/1 "2020-05-13T04:03:01Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/0/20ceed94f2b052e139427c6e612e0bfb5d70b8b5.png)

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

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 13, 2020, 5:09am UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/2 "2020-05-13T05:09:30Z")

</div>

Hey @yuri.vayne,

Welcome to the community!! 🚀

The `key` for adding Request Headers is `header` and not `headers`:

```
'header': {
	'X-TrackerToken': '12345647897',
	'Accept': 'application/json'
}

```

Could you give that a go and so if that helps out? 😁

---

<div class="post-metadata">

**Author:** ![yuri.vayne](https://avatars.discourse-cdn.com/v4/letter/y/aeb1de/32.png) [@yuri.vayne](https://community.postman.com/u/yuri.vayne)\
**Post date:** [May 13, 2020, 1:44pm UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/3 "2020-05-13T13:44:51Z")

</div>

Hi @dannydainton, thanks ,it works the header was added in the request, but I am getting another problem related to body in the same request, could you please help me with this, not sure if that is the correct way to set the body :  
body: JSON.stringify({“name”:“Kaylee”})

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/e/e751fcd614ddbb5952688480edf11ac5271f7935.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 13, 2020, 4:45pm UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/4 "2020-05-13T16:45:22Z")

</div>

Is this the same if you add the `'Content-Type': 'application/json'` header?

Looks like the docs say that it’s needed:

[https://www.pivotaltracker.com/help/api/rest/v5#Projects](https://www.pivotaltracker.com/help/api/rest/v5#Projects)

---

<div class="post-metadata">

**Author:** ![yuri.vayne](https://avatars.discourse-cdn.com/v4/letter/y/aeb1de/32.png) [@yuri.vayne](https://community.postman.com/u/yuri.vayne)\
**Post date:** [May 13, 2020, 5:34pm UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/5 "2020-05-13T17:34:39Z")

</div>

You are right, thanks @danny-dainton ,now its working well.

---

<div class="post-metadata">

**Author:** ![fptmark](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/fptmark/32/11925_2.png) [@fptmark](https://community.postman.com/u/fptmark)\
**Post date:** [May 6, 2022, 10:21pm UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/6 "2022-05-06T22:21:29Z")

</div>

Wow! “Header” vs “Headers” ??? I sure hope there is a good reason for 2 different keys because I spent hours debugging this one.  
Thanks!!!

---

<div class="post-metadata">

**Author:** ![alfianrehanusa](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@alfianrehanusa](https://community.postman.com/u/alfianrehanusa)\
**Post date:** [April 28, 2023, 2:14am UTC](https://community.postman.com/t/the-header-configured-on-pre-request-script-is-not-added/12602/7 "2023-04-28T02:14:26Z")

</div>

agreed, the autocomplete it say ‘Headers’ only
