Issues with Variables When Running Newman

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!

Hey @scottqa3t :wave:

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?

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:


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.

1 Like

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

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

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