# Issues with Variables When Running Newman

**URL:** <https://community.postman.com/t/issues-with-variables-when-running-newman/70583>\
**Category:** Help Hub\
**Tags:** newman-project, tests, variables, authentication\
**Created:** [October 29, 2024, 5:16pm UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583 "2024-10-29T17:16:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottqa3t](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@scottqa3t](https://community.postman.com/u/scottqa3t)\
**Post date:** [October 29, 2024, 5:16pm UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583/1 "2024-10-29T17:16:27Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

Hello everyone,

I’m encountering an issue when running my Postman collection via Newman, alongside some Playwright tests, from the command line. I’m a QA engineer, setting up basic CRUD tests using both Newman and Playwright to validate API functionality and its frontend representation.

### Collection Structure

Here’s the structure of my Postman collection, where I save variables to use across different requests:

**Postman Collection (QA)**

- **Create Item (Folder)**
  - **POST Get Bearer Token** : Retrieves an authentication token.
  - **POST Create Item** : Creates an item, and the `id` from this response is saved as a variable.

- **Update Item (Folder)**
  - **PATCH Update Item** : Uses the previously saved `id` variable in the URL to update the item.

- **Delete Item (Folder)**
  - **DELETE Delete Item** : Deletes the item using the `id` variable saved from the Create request.

### Execution Flow

I export this collection and run it from a batch script, which includes Playwright tests to validate frontend actions between each request. The batch script mirrors the collection structure, running Playwright tests after each API call to check frontend accuracy.

### Issue

When I run this setup via Newman, the `id` variable saved during the “Create Item” step does not seem to be retained by the time it’s used in the “Update Item” request. This works perfectly when running the collection in Postman manually but fails when run via Newman.

Any insights on why the `id` variable might not be persisting across requests in Newman, or tips on troubleshooting this setup, would be greatly appreciated!

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:** [November 4, 2024, 3:33pm UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583/2 "2024-11-04T15:33:23Z")

</div>

Hey @scottqa3t 👋

Welcome to the Postman Community! :postman:

At which scope are you saving the `id` as a variable?

How are you getting and setting the Bearer Token, with an Auth Helper/Pre-request Script?

Are there are request errors that you can share for the sequence? The output on the Newman CLI reporter?

---

<div class="post-metadata">

**Author:** ![scottqa3t](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@scottqa3t](https://community.postman.com/u/scottqa3t)\
**Post date:** [November 5, 2024, 10:54am UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583/3 "2024-11-05T10:54:52Z")

</div>

> [@danny-dainton](#):
>
> At which scope are you saving the `id` as a variable?
> 
> How are you getting and setting the Bearer Token, with an Auth Helper/Pre-request Script?
> 
> Are there are request errors that you can share for the sequence? The output on the Newman CLI reporter?

Hi Danny,

Thanks for your response!

I am saving the `id` as a environment variable after the `Create Item` request, as it needs to be reused in subsequent `Update` and `Delete` requests within separate folders.

The Bearer Token is set in a `Get Bearer Token` request, and I’m using a Pre-request Script to retrieve it.  
The token is stored in an environment variable, accessible throughout the collection.  
It’s in the `Create Item` request folder and runs before the `Create Item`

When running the collection in Newman, I’m seeing errors related to the `Update Item` request. Here’s an example output:

```auto

Error: Authorization header cannot be empty (hashed with SHA-256 and encoded with Base64): '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='.

```

However this is a strange one to me because the `update` & `delete` calls both have authorisation in the `Header` when the collection is extracted from Postman.

Additionally, the `id` variable doesn’t seem to be recognized across folders, leading to a failure in the `Update` and `Delete` requests when trying to use this ID.

---

<div class="post-metadata">

**Author:** ![harshika.dhamankar](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@harshika.dhamankar](https://community.postman.com/u/harshika.dhamankar)\
**Post date:** [November 22, 2024, 7:40am UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583/4 "2024-11-22T07:40:46Z")

</div>

is this resolved? I m facing the same issue.  
Is there any way to run collection file along with the environment

---

<div class="post-metadata">

**Author:** ![scottqa3t](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@scottqa3t](https://community.postman.com/u/scottqa3t)\
**Post date:** [November 28, 2024, 8:30am UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583/5 "2024-11-28T08:30:49Z")

</div>

Sadly not, i haven’t been able to get this working

---

<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:** [December 28, 2024, 8:31am UTC](https://community.postman.com/t/issues-with-variables-when-running-newman/70583/6 "2024-12-28T08:31:34Z")

</div>

Closed on December 28, 2024, 8:31am UTC

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