Authorization error in newman html report generation while running postman collection though bearertoken have been passed as an environment variable

Hi,
I am trying to generate test report for my collections in postman using newman cli,htmlextra reporter. I am able to run my authentication request successfully and generate report. In Postman, I have passed the bearertoken to all my other requests for authorization.

Everything is working in postman. On trying to execute the collection, am facing 401 Unauthorized error in newman though I have passed the required environment and global variables.
The following is the command I have used in the command line

newman run “D:\xxx\API backup\Control Branch Master Latest.postman_collection.json” -e “D:\xxx\API backup\Azure.postman_environment.json” -g “D:\xxx\API backup\xxx.postman_globals.json” --reporters=cli,htmlextra --insecure

The below is the screenshot the error in cmdline

image

Also the bearer value is not getting passed when I check it in the html report due to which my requests are failing thereby causing failure in the tests

Though all the required details have been passed in newman commandline, unable to get the expected report which is working fine in postman. Can someone please suggest me how to resolve the authorization issue in newman and Is there any specific way to pass the bearertoken here?

1 Like

Hey @saisubhashini :wave:

To troubleshoot further, can you include --reporter-json-export output.json --reporters cli,json and check if bearer token in the request is correctly set (you can search for "key": "Authorization" to find out the token value)?

Another check you can try is to include console.log(pm.environment.get(bearertoken)) in your pre-request/test scripts to validate the value.

Hope this helps!
Let me know if you have further questions :slightly_smiling_face:

1 Like

Hi @taehoshino ,

Thanks for your reply. Your inputs were really useful. The bearer token is being set correctly when the Authentication request and my other requests are put in same collection and also the test report is being generated successfully. I tried with few requests and checked. This might not be possible in all cases. When I put the Authentication request and all my other API requests in different collections I get the Authorization error and also bearer token value is not retrieved on adding console.log(pm.environment.get(“bearertoken”)) in the prerequest script.

Thanks for your response @saisubhashini!

As I understand it, you are facing the issue only when you save the authentication request from which you retrieve a bearer token in a different collection than the collection you run with newman, is that correct?

How are you passing the bearer token to the collection that you run with newman?
If you are passing the bearer token value to the environment and then use that environment to run newman, please make sure that you first update the environment, save the environment, export it before passing to newman command.

Im new in Collection Run.
I am testing some websites for research. I found cookies like: XSRF-TOKEN,_aid, _rid, and these cookies change periodically.
When I tried running for an extended period, like 2-3 min, the above-mentioned cookies were changed, but cookies were not synced to Collection Runner as I’m using Postman-Interceptor to sync cookies(Cookies works fine if it is run in a single instance or by clicking send-request) while running. If I want to sync, I could do so by stopping it and rerunning it.
I want to sync dynamic cookies with requests while running Collection Runner without stopping and rerunning it. I found that is act as SandBox.
Thank you…

Did we get the issue solved?

I am facing similar issue .
In Postman, I see my collection is passing. But when I am executing in Newman, I am getting 401 -Unauthorized error.
I see the Bearer Token is rightly passed too.