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

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines 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?

Hi !

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

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

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

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?

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

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


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

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

I am thinking it is same as 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

Have you tried to add it without using the helper?

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

Yes, the above-mentioned scenario is working fine.

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

image

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 });

@ dannydainton , waiting for your reply on this :slight_smile:

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


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.

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?