# Temporary Header Values

**URL:** <https://community.postman.com/t/temporary-header-values/8069>\
**Category:** Help Hub\
**Tags:** authentication\
**Created:** [September 30, 2019, 7:05am UTC](https://community.postman.com/t/temporary-header-values/8069 "2019-09-30T07:05:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![enadocganith](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@enadocganith](https://community.postman.com/u/enadocganith)\
**Post date:** [September 30, 2019, 7:05am UTC](https://community.postman.com/t/temporary-header-values/8069/1 "2019-09-30T07:05:40Z")

</div>

Hey, i need to catch some values which are generated as temporary header values. i need to catch the oauth code which is generated as temporary header value to get the access token.is there anyway to save thad oauth code to variable.

---

<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:** [September 30, 2019, 9:38am UTC](https://community.postman.com/t/temporary-header-values/8069/2 "2019-09-30T09:38:01Z")

</div>

Hey @enadocganith,

Welcome to the Postman Community 🚀

You could use the `pm.request.headers.get()` function to capture the value of the header.

For example, adding this to the `Tests` tab would set the `Authorization` header, as the `token` environment variable.

`pm.environment.set('token', pm.request.headers.get('Authorization'))`

Is this what you were looking to do?

---

<div class="post-metadata">

**Author:** ![enadocganith](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@enadocganith](https://community.postman.com/u/enadocganith)\
**Post date:** [October 1, 2019, 7:45am UTC](https://community.postman.com/t/temporary-header-values/8069/3 "2019-10-01T07:45:06Z")

</div>

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

@danny-dainton Thank you for the solution and the fast replying.it’s very appreciated. it really helped me.but i need to know how to catch these values which i have numbered on the image that i have attached.

1. code (inside the Request Body).
2. access\_token (inside Response Body).

---

<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:** [October 1, 2019, 8:10am UTC](https://community.postman.com/t/temporary-header-values/8069/4 "2019-10-01T08:10:48Z")

</div>

You’re welcome. 🏆

This question seems to have now morphed into wanting to get the values from the `Headers` to you wanting to get the values from a `Request` and a `Response`.

At this point, it would probably be really helpful to take a look through the [learning centre](https://learning.getpostman.com/) to get up to speed with the way that the [Postman sandbox](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/) works and features available within it.

We also have an in-app [Bootcamp](https://blog.getpostman.com/2019/01/11/in-app-postman-lessons/) which is packed full of interactive lessons, it will guide you through some of the application’s awesome features.

For your particular problem, you _could_ use something like this, in the `Tests` sandbox, to log the values to the Postman Console:

```
console.log(JSON.parse(pm.request.body.raw).code)
console.log(pm.response.json().access_code)

```

Once you’re happy with the values, you will be able to set them as variables using the syntax as previously mentioned.

---

<div class="post-metadata">

**Author:** ![hvirdi92](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hvirdi92](https://community.postman.com/u/hvirdi92)\
**Post date:** [December 5, 2019, 4:49pm UTC](https://community.postman.com/t/temporary-header-values/8069/5 "2019-12-05T16:49:51Z")

</div>

@danny-dainton

If I may ask here. I am sending a POST request to

`https://login.xyz.com/oauth2/v2.0/authorize`

Request Header: `content-type = application/x-www-form-urlencoded`

Request body contains: `response type`, `client id`, `redirect uri`, `grant type = implicit`, `scope`.

I am able to fetch the access token from a temporary header - ‘Referer’ and pass it on to next requests successfully in POSTMAN manual run or using Collection Runner . BUT - When I run it using Newman CLI in cmd, Temp Header value is not stored in variable . Variable is NULL.

This makes sense as well as POSTMAN UI shows an info that Temporary Headers are generated by Postman and are not saved during the process of request, so may be these headers are not picked by Newman.

Could you please confirm if we can pick values from Temporary Headers using Newman ?

---

<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:** [December 6, 2019, 12:35pm UTC](https://community.postman.com/t/temporary-header-values/8069/6 "2019-12-06T12:35:08Z")

</div>

Hey @hvirdi92,

Could you share the code in the `Tests` tab that you’re using to get the `Referer` header, please?

This doesn’t sound like it would have anything to do with the `Temporary Headers` but more about a `redirect` issue.

Have you tried using the Newman command with the `--ignore-redirects` flag? The way these are handled in the app are slightly different.

---

<div class="post-metadata">

**Author:** ![hvirdi92](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hvirdi92](https://community.postman.com/u/hvirdi92)\
**Post date:** [December 6, 2019, 1:10pm UTC](https://community.postman.com/t/temporary-header-values/8069/7 "2019-12-06T13:10:23Z")

</div>

Thanks for the response !

Code in Tests -

> postman.setEnvironmentVariable(“refererHeader”, pm.request.headers.get(‘Referer’));

I am putting environment variable in a variable just to see what I get in console when I run the script - using Postman (prints the variable value ) and Newman (prints [null] in cmd)

Code in Tests -

> var x = pm.environment.get(“refererHeader”);  
> console.log(x);

When ran in postman collection runner it is working fine but when run via newman run command it is not,  
Newman command -

> newman run collection.json -e environments.json  
> Also, tried

> newman run collection.json -e environments.json --export-environment environments.json

( after the run environment file is exported but it has null variable value )

Tried

> newman run collection.json -e environments.json -e environments.json --ignore-redirects

and with

> –export-environment environments.json

. It didn’t work ☹

---

<div class="post-metadata">

**Author:** ![nahy](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@nahy](https://community.postman.com/u/nahy)\
**Post date:** [April 1, 2020, 6:37pm UTC](https://community.postman.com/t/temporary-header-values/8069/8 "2020-04-01T18:37:31Z")

</div>

Hi @hvirdi92,

I `ve got the same problem!

Did you fix it?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![GrapeQA2](https://avatars.discourse-cdn.com/v4/letter/g/b19c9b/32.png) [@GrapeQA2](https://community.postman.com/u/GrapeQA2)\
**Post date:** [May 7, 2020, 11:11am UTC](https://community.postman.com/t/temporary-header-values/8069/9 "2020-05-07T11:11:45Z")

</div>

Hey @danny-dainton ,  
I have ran into the same issue as @hvirdi92 , but couldn’t find a solution.  
If I run the test from Postman, everything works fine, I can access the required value from the header with `pm.request.headers.get("Referer")`.  
But when I use Newman to run the collection, this value will be undefined. Tried with the `--ignore-redirects` flag, got the same result.

I’m trying to get OAuth 2.0 token from Google to access Gmail API using the following request:  
`curl --location --request POST 'https://accounts.google.com/o/oauth2/v2/auth?client_id=<clientID>&redirect_uri=https://www.getpostman.com/oauth2/callback&response_type=code&scope=https://www.googleapis.com/auth/gmail.readonly&access_type=offline`

After the request, `pm.request.headers.get("Referer")` contains the redirect URL with the authorization code:  
`https://www.postman.com/oauth2/callback?code=<authorization_code>&scope=https://www.googleapis.com/auth/gmail.readonly`

Using Newman to run this request will result in the request header being undefined. Is there another way to access this value?
