My question:
I got âtoken âUâ at 1:1 Unauthorized requestâ when I use Newman to run my collection.
JSONError Unexpected token âUâ at 1:1
Unauthorized request
^ Details (like screenshots):
This may not completely resolve the issue but if you are going to use the âlong notationâ I think you are missing a - from âenvironmentâ.
Should be either -e or --environment (Note the 2x - for the latter)
More info here;
Iâm not 100% sure if you can call variables from a file you are also trying to load at the same time⌠but if you try the dash thing above first and report back, I will look into this further if needed.
Thank you for the response!
Yes, I did use --environment in the command. I didnât call variables from a file. I just set the environment variables and got the environment URI from: https://api.getpostman.com/environments?apikey=$apiKey.
I canât really see how that would work and set any global value that the second run could use here. Those are both independent runs.
Within the app, youâre doing all this in a Workspace and those variables are stored at the global level in the current value (If thatâs set via a script). Even if the Globals were exported, those current values wouldnât be in that exported JSON file.
Itâs worth opening up those exported files in a text editor to check the contents.
What variables are actually used during the Collection Run?
You should be able to see that in the report when using the --reporter-htmlextra-showEnvironmentData and --reporter-htmlextra-showGlobalData flags.
Yes, I tried --reporter-htmlextra-showEnvironmentData and --reporter-htmlextra-showGlobalData flags and found second collection is not taking Globals set runtime from first collection.
I have requirement where there are multiple collections and each collection has its own csv as an input. First collection generates access token, some other parameters and all other collections should take those globals set i.e. âaccess tokenâ, other parametersâ as an input to generate their respective results.
I even tried below in Newman:
newman run "FirstAuth.json" -e "Environment.postman_environment" -d "First.csv" --export-environment "Path for Enviroment.json" -r htmlextra --reporter-htmlextra-showEnvironmentData --reporter-htmlextra-showGlobalData --reporter-htmlextra-export "Path for HTMLReport"
In above command I have exported environment and in below command have take exported environment as an input
newman run "Second.json" -e "Exported Environment Json" -d "Second.csv" -r htmlextra --reporter-htmlextra-showEnvironmentData --reporter-htmlextra-showGlobalData --reporter-htmlextra-export "Path for HTMLReport"
Report generated for second command shows environment variable generated from first command.
Still I am getting same Json Error.
Any suggestion what needs to be done to resolve this.
What does the request data (Request Params/Request Headers/Request Body) look like for those failed ones - Are the values from the environment file actually getting set correctly?
Do you still have references to getting those values from the global scope in the Collection?
Without more information and seeing what you have in place, itâs difficult to know whatâs going on here. Just looking at those commands doesnât really give you the full picture.