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

**URL:** <https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249>\
**Category:** Help Hub\
**Tags:** authentication\
**Created:** [December 31, 2024, 8:57am UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249 "2024-12-31T08:57:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcolmer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pcolmer/32/31170_2.png) [@pcolmer](https://community.postman.com/u/pcolmer)\
**Post date:** [December 31, 2024, 8:57am UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249/1 "2024-12-31T08:57:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pcolmer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pcolmer/32/31170_2.png) [@pcolmer](https://community.postman.com/u/pcolmer)\
**Post date:** [December 31, 2024, 9:46am UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249/2 "2024-12-31T09:46:16Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 3, 2025, 7:37pm UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249/3 "2025-01-03T19:37:35Z")

</div>

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.❤

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.

---

<div class="post-metadata">

**Author:** ![pcolmer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pcolmer/32/31170_2.png) [@pcolmer](https://community.postman.com/u/pcolmer)\
**Post date:** [January 6, 2025, 9:21am UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249/4 "2025-01-06T09:21:10Z")

</div>

> [@danny-dainton](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 6, 2025, 9:47am UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249/5 "2025-01-06T09:47:50Z")

</div>

That’s a recommendation that I would agree with! 🏆

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!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [January 13, 2025, 9:48am UTC](https://community.postman.com/t/running-in-postman-works-running-with-postman-cli-doesnt-but-used-to/73249/6 "2025-01-13T09:48:08Z")

</div>

Closed on January 13, 2025, 9:48am UTC

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