Postman Monitors vs Newman CLI: Persisting Environment Variables During Scheduled Runs
0 reputation · 21 Mar 2021, 19:09 UTC
0 reputation · 21 Mar 2021, 19:09 UTC
When a collection writes a timestamp or token to an environment variable during a scheduled run, the next execution must see the updated value. Postman Monitors provide a UI‑driven scheduler with automatic email alerts, while Newman offers fine‑grained control via cron or CI/CD pipelines. Both tools support environment variables, but the current behavior of Monitors is unclear: do they snapshot the environment before each run or allow changes to survive into the next cycle?
Key constraints include:
Unresolved behavior: does Postman enforce a read‑only snapshot for each monitor execution, or can it preserve variable changes across runs?
Specific questions:
35345 reputation · 22 Mar 2021, 04:54 UTC
1. Monitors do not persist changes. When a monitor starts, Postman takes a snapshot of the selected environment. Any variable updates made during the run are written to the in‑memory copy only and discarded when the run finishes. The next scheduled run starts again with the original values stored in the Postman account.
2. No built‑in persistence. Because the snapshot is immutable, there is no documented way for a monitor to automatically carry forward updated values. Workarounds rely on external storage or manual steps.
3. Newman can keep the environment in sync. Running the collection with --environment test.env.json --save-environment updated.env.json writes the modified variables back to updated.env.json. That file can then be uploaded to Postman via the API (POST /environments or PUT /environments/{id}) or used as the environment for a new monitor.
--save-environment flag writes any runtime changes to a JSON file.newman run collection.json \
--environment test.env.json \
--save-environment updated.env.json
curl -X PUT \
-H "X-Api-Key: YOUR_POSTMAN_API_KEY" \
-H "Content-Type: application/json" \
-d @updated.env.json \
https://api.getpostman.com/environments/:environment_id
pre-request script to read a value from an external key‑value store (e.g., Postman’s own environment via the API, a database, or a file served over HTTP) and set it in the environment before each request.
To tailor the recommendation further, could you confirm whether the environment you use for monitors is a personal or a team/shared environment? The API endpoints differ slightly, and rate limits apply to shared environments.
| Component |
|---|
| Monitor Snapshot |
| Environment Persistence |
| Newman Save‑Environment |
| Postman API Sync |
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.