Postman Runner and Newman Failures: Diagnose Environment Variables and Pre-Request Scripts
Requests work manually but fail in Collection Runner or Newman. Diagnose environment variables, current values, and pre-request script errors with this targeted guide.
17 Mar 2026, 08:58 UTC

Problem and Takeaway
A request works when you click Send in Postman, but the same request fails in Collection Runner or Newman with a 401 Unauthorized, 404 Not Found, or a script ReferenceError. The useful takeaway is that the failure is usually caused by variable resolution or script behavior, not by the API endpoint. Collection Runner and Newman execute the collection with a specific environment and a different script runtime than the manual request builder, so a missing variable value or an unsupported API call surfaces only there.
Recognizable Condition
You see one or more of the following:
- Manual request returns success; Collection Runner or Newman returns 401 or 404.
- Newman exits with a non-zero exit code and the report shows script errors.
- A pre-request script works in the Postman app but throws ReferenceError in Newman.
- A variable such as {{baseUrl}} or {{token}} resolves manually but appears empty in runner logs.
Cause and Diagnostic Table
| Observed failure | Likely cause | Where to check |
|---|---|---|
| 401 or 404 only in Runner/Newman | Wrong environment selected, or variable current value is empty | Runner environment dropdown; Newman -e argument; environment editor |
| ReferenceError in pre-request script | Script references undefined variable or uses Postman-app-only globals | Postman Console; Newman CLI reporter output |
| Variable resolves manually but not in runner | Current value differs from initial value; current values are local only | Environment editor Current value column |
| Non-zero Newman exit code | Test assertions or script exceptions failed during collection run | Newman exit code and JSON report |
Ordered Checks
- Confirm the active environment. In Postman, open Collection Runner and verify the environment dropdown matches the one used for manual requests. In Newman, confirm you passed the environment file with
-e environment.jsonand that the file path is correct relative to where you run the command. - Compare current and initial values. Open the environment editor in Postman. Initial values sync to Postman Cloud; current values are stored locally and are not synced by default. If current value is blank while initial value has data, the runner may use the empty current value depending on scope and precedence.
- Capture script and network details. Open Postman Console (
Ctrl+Alt+CorCmd+Alt+C) before running the collection. In Newman, run with--reporters cli,jsonso exceptions and request details appear in the terminal and a JSON report. - Inspect pre-request scripts. Look for
pm.collectionVariables.get("token")when you meantpm.environment.get("token"), references to variables not defined in the active environment, or globals that exist only in the Postman app UI.
Fixes Tied to Findings
- Wrong environment: Select the correct environment in the Runner dropdown, or rerun Newman with the matching file:
newman run collection.json -e environment.json. - Empty current value: Enter the missing value in the Current value column of the environment editor, or export the environment and update
environment.jsonbefore running Newman. - Wrong variable scope: Replace
pm.collectionVariables.get("token")withpm.environment.get("token")if the variable lives in the active environment, not the collection. - Unsupported script API: Remove Postman-app-only globals or rewrite the script to use Newman-compatible APIs. Test the script in Newman, not only in the Postman app.
- Secrets: Do not store tokens or passwords in collection variables or plain environment files. Use environment variables, Postman Vault where supported, or a secret store, and inject values at runtime.
Concrete Example: Collection, Environment, and Newman Command
Suppose a collection request uses {{baseUrl}}/users/{{userId}} and a pre-request script reads pm.environment.get("apiToken").
Environment file (environment.json):
{
"name": "development",
"values": [
{ "key": "baseUrl", "value": "https://api.example.com", "enabled": true },
{ "key": "userId", "value": "123", "enabled": true },
{ "key": "apiToken", "value": "REPLACE_WITH_REAL_TOKEN", "enabled": true }
]
}
Newman command run in a terminal:
newman run collection.json -e environment.json --reporters cli,json
Where to run: a terminal or command prompt with Newman installed. Required permissions: read access to collection.json and environment.json; no administrator privileges are required unless the files are in a protected directory.
Expected checks: Newman exits with code 0, the CLI reporter shows each request and test result, and the JSON report contains an executions array with no error entries for the pre-request script. If the exit code is non-zero, inspect the reporter output for the failing assertion or exception.
Relevant risks: Editing environment.json changes the local configuration. Keep a backup before replacing values. Never commit real tokens to version control; use a placeholder and inject secrets through a secure mechanism.
Limitations
Newman may behave differently from the Postman app for scripts that depend on Postman-specific UI globals or a particular Postman runtime version. Environment current values are local and do not sync to Postman Cloud by default. Behavior is version-sensitive: Newman releases have Node.js support policies and may change exit codes or the script API surface. This guide covers variable and script diagnostics; it does not address network proxies, certificates, or Postman Cloud outages.
Practical Verification
- Run the collection in Postman App Collection Runner with the suspect environment selected and compare results to manual execution.
- Run
newman run collection.json -e environment.json --reporters cliand inspect the exit code, console output, and any generated JSON report. - Open Postman Console before running to capture script exceptions and network traffic.
- Compare
newman --versionwith the Postman app version and test on the Node.js LTS version supported by that Newman release.
Escalation Criteria
Escalate when the failure reproduces in Postman App, Newman, and Postman Web after you verify the environment, variable values, and pre-request scripts. At that point, suspect collection synchronization problems, expired API keys or tokens, or a Postman Cloud service issue rather than a local configuration mistake.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.