# How to set the environment /global variables file updated for each request in the single collection?

**URL:** <https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054>\
**Category:** Help Hub\
**Tags:** newman-project, variables, collections, authentication\
**Created:** [September 20, 2020, 3:40pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054 "2020-09-20T15:40:08Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 20, 2020, 3:40pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/1 "2020-09-20T15:40:08Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-help-category/38) before creating a new topic.**

Hello Helpers,

I am trying to execute my collection from newman (I also have the same configured in Jenkins).

AuthToken is not being sent to the request when running from newman and it works in POSTMAN.

Collection - Logout

1 Request - Login, getting the authcode and saving it as env variable  
2 Request - Generate Token - Saving the generated token as env variable.  
3 Request - Logout - using the authcode which is generated in the 2nd request (setting this headers and passing the same in script as well)

Since I am running the collection from newman, I am downloading the JSONs and executing the collection.

**Problem: The Logout request is not taking the updated authtoken from environment variable.**

**Can you please help?**

---

<div class="post-metadata">

**Author:** ![Seluj78](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/seluj78/32/5646_2.png) [@Seluj78](https://community.postman.com/u/Seluj78)\
**Post date:** [September 21, 2020, 8:12am UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/2 "2020-09-21T08:12:10Z")

</div>

Hi !

Are your variables set in the environment or the collections ? Can you send us the command you run for newman ?

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 8:24am UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/3 "2020-09-21T08:24:48Z")

</div>

Yes, I am setting my variables in the environment only.  
below is the command that I am using…  
newman run xx.postman\_collection.json -g xx.postman\_globals.json -e xx.postman\_environment.json

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 11:11am UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/4 "2020-09-21T11:11:38Z")

</div>

@danny-dainton, can you please look into this ticket in case if this falls under your scope…

---

<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 21, 2020, 11:23am UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/5 "2020-09-21T11:23:59Z")

</div>

Are the variables getting set as the initial or current value? If the variables are getting set as the current value only, the exported files wouldn’t contain that information.

Have you tried logging out those environment variables to ensure that they are actually getting set in those stages? How are you confirming it’s _just_ the Logout request?

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 12:27pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/7 "2020-09-21T12:27:26Z")

</div>

I am setting them as current values by using pm.environment.set method. I have fetched the values and printed them on the console and to my surprise, the correct value is being passed to the logout request but I am getting the “code”: “INVALID\_AUTHORIZATION\_HEADER”, in the response.

getting the token as Bearer even after setting it as “oAuth 2.0”

![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/6/f6b61c8583e6049d7baec448046dc156ff773ebb.png)

 ![Oauth](https://us1.discourse-cdn.com/getpostman/original/3X/4/f/4fe5da45c4a7e6a34edc052d73b87288e713895e.png)

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 2:22pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/8 "2020-09-21T14:22:17Z")

</div>

Eagerly waiting for a reply on this. Here it is showing “OAuth” but in the report it is showing as “Bearer”.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/e/de6d63a6eb0ad1237b361635ca318a4640647942.png)  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/5/25483cba1df2072ea012ada8ca7287c51c4bb28f.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:** [September 21, 2020, 2:49pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/9 "2020-09-21T14:49:27Z")

</div>

The reporter is only presenting what information Newman is telling it, it’s not changing anything.

This flag we show you what information the reporter is told about the environment data using `--reporter-htmlextra-showEnvironmentData`

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 3:04pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/10 "2020-09-21T15:04:02Z")

</div>

Hmm… What can be done now? Do you suggest anything?

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 3:13pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/11 "2020-09-21T15:13:46Z")

</div>

I am thinking it is same as [https://github.com/postmanlabs/newman/issues/1513](https://github.com/postmanlabs/newman/issues/1513) even though oauth is set as2.0 i think it is still taking as bearer token in 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:** [September 21, 2020, 3:21pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/12 "2020-09-21T15:21:42Z")

</div>

Have you tried to add it without using the helper?

Putting that to ‘No Auth’ and manually adding the request header with the value.

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 5:19pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/13 "2020-09-21T17:19:13Z")

</div>

Yes, the above-mentioned scenario is working fine.

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 21, 2020, 5:48pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/14 "2020-09-21T17:48:46Z")

</div>

When I print the header value from the logout request it is showing Bearer , so Instead of oAuth , bearer token is coming.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/4/a/4a20a3f50f55df0a53af974e9ad3061c7aae8062.png)

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 22, 2020, 12:54am UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/15 "2020-09-22T00:54:21Z")

</div>

For time being, I have the put the following code in the pre-requests script and it works fine. But we need to see why we are getting Bearer instead of OAuth…

var headervalue = 'OAuth ’ + pm.environment.get(“oAuthToken”);  
pm.request.headers.add({key: ‘Authorization’, value: headervalue });

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 25, 2020, 6:17am UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/16 "2020-09-25T06:17:52Z")

</div>

@ [dannydainton](https://community.postman.com/u/dannydainton) , waiting for your reply on this 🙂

---

<div class="post-metadata">

**Author:** ![michal.robaszewski.j](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michal.robaszewski.j/32/5378_2.png) [@michal.robaszewski.j](https://community.postman.com/u/michal.robaszewski.j)\
**Post date:** [September 25, 2020, 12:43pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/17 "2020-09-25T12:43:19Z")

</div>

Hi,  
OAuth 2.0 is general approach and on of the subcategory is Bearer

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/f/afde36e1208e08bc3e2d6ac47efe9e011e3e64a2.png)  
If you go with oAuth 2.0 and your token type is Bearer Header prefix should be Bearer.  
As you said your prefix is `OAuth` so type it in Header Prefix.

You can provide Auth per Request or on Collection scope or any directory inside that collection.  
Check if all of that places are set correctly.  
Then Export collection again just to be sure that your Newman have fresh and up to date file.

---

<div class="post-metadata">

**Author:** ![bhargavikongara](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bhargavikongara](https://community.postman.com/u/bhargavikongara)\
**Post date:** [September 26, 2020, 1:13pm UTC](https://community.postman.com/t/how-to-set-the-environment-global-variables-file-updated-for-each-request-in-the-single-collection/16054/18 "2020-09-26T13:13:07Z")

</div>

Hello Michal,

Thanks for the reply. If you can see the screenshots above I am sending ‘OAuth’ as a header.  
Still, it is showing the ‘Bearer’ only. Kindly see all the screenshots.

Can we not declare Auth token as an environment variable?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/9/b9b84824edbf1cb512e2215e320de590e6b12984.png)
