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.
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
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”
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…
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.
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?