Running in Postman works, running with Postman CLI doesn't - but used to

I’m trying to use the Contract Testing Generator. If I run the generator in Postman then the run proceeds (but ultimately fails but that isn’t the reason for this post).

If, however, I try to run it with Postman CLI, the run fails because calls to some Postman APIs are rejected with 401 Unauthorized.

I’ve copied/pasted the commands from Postman where it provides the Postman CLI commands to use.

postman login --with-api-key shows “Logged in successfully”.

This was working a couple of days ago so I’m unsure as to why the API calls are now unauthorised. Unfortunately, I can’t see the request headers when I run it with Postman CLI because the headers are not persisted, and I cannot find a way to get them to be persisted when using Postman CLI

Have now discovered that I can run Postman CLI with -r json and the details of the run are preserved in a JSON file.

Not sure if that has helped, though, as the failing call to a Postman API is showing that X-Api-Key is empty, but there is a value provided for Postman-Token.

There is also a html reporter in the latest version of the Postman CLI. I also believe that you can use the --verbose flag with the CLI reporter in the terminal.:heart:

Is the API Key in only the current value of your Environment file?

If if only in that field, it isn’t synced and when run with the Postman CLI it would be resolved due to it only being know to your current session in the UI.

Yes - I had removed it from the “Initial value” column because Postman was advising against sharing sensitive values with team members.

Passing it via --env-var solves the challenge.

Thank you.

1 Like

That’s a recommendation that I would agree with! :trophy:

Using the --env-var flag is a great shout and something that is probably not used enough with passing sensitive data into a Collection from the CLI. Also, it works really well with the various CI/CD tools syntax to use their Environment Variables in your requests!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.