T10 Postman · Lesson 3
Environments and variables
The same collection must ask a practice server and a real one, and the answer to one request is often the question of the next. Keep a server's values in an environment, know which scope wins when two hold the same name, pass an id from one request to the next, and run a request once for every row of a data file.
- keep a server's address and other values in an environment, and run the same collection against two servers by swapping it
- name the five scopes of a variable, global, collection, environment, data and local, and say which one wins when two hold the same name
- set a variable in one request's script and use it in the next, such as an id that a POST answers
- run a request once for every row of a JSON or CSV data file, and read the row with pm.iterationData
- say what the app's environment selector, Globals and data files do, and which Newman options do the same
- find a variable that came from the wrong scope by printing where each value comes from
The back cover
A box of questions that works for one yard should work for every yard. There is the practice copy down the street, and there is the real one. And some questions cannot be written in advance. They depend on what the last answer said.
These pages keep each server's values on a card of their own, called an environment. They show which of five places wins when two hold the same name. They pass a number from one answer to the next question. And they run one question once for every line of a list, a data file.
Before you start
The story: Two yards, one box
The Couriers' Yard has opened a practice yard down the street, a copy where new benches are tried before the real yard gets them. The clerks want to ask the same box of questions of both. But the address is written on the lid, and a lid can hold only one address.
Worse, some questions need the answer to the one before: the yard hands back a parcel number, and the next card must ask about that very parcel. Nobody knows the number until the yard says it.
Postmaster Meera Franking leaves the box alone. "Give each yard its own card of addresses and names," she says, "and let the runner carry whichever card I hand over. When the yard gives back a number, the runner writes it on the card, and the next question reads it there."
Lesson 02 kept the server's address in a collection variable, written once. That works while there is one server. Real teams have several: a server on your own machine, a shared test server, and the real one that customers use. The same collection should ask any of them, without a single edit to its requests.
This lesson adds the missing pieces. An environment is a named set of values, such as one server's address, kept outside the collection, so that swapping environments moves every request at once. Variables live in five scopes, and a short rule says which one wins. A script can pass a value from one request to the next, such as the id a POST answers. And a data file runs the same requests once for every row it holds.
It builds on these ideas. Each one has a tiny example, so you can check that you remember it.
| What you already know | A tiny example | Where it comes back |
|---|---|---|
| Collection variables. | variable: [{ key: "base", value: "..." }] | One of the five scopes. |
| Double curly braces. | {{base}}/gauges | Every variable, whatever its scope. |
| pm.collectionVariables. | pm.collectionVariables.set("n", 1) | pm.environment and pm.variables work the same way. |
| Iterations. | iterationCount: 3 | A data file sets the rounds, one per row. |
| A POST that answers what it stored. | res.status(201).json(...) | An id passed to the next request. |
| Route parameters. | /gauges/:id | A GET that uses the id. |
| JSON files. | [{ "name": "fan" }] | Environments and data files are JSON. |
| CSV. | name,value | A data file can be a spreadsheet's text. |
| The order of a run. | top to bottom | A value must be set before it is used. |
| The gauges server. | require("./server") | Every block's server, as before. |
By the end of this lesson you will be able to:
- keep a server's address and other values in an environment, and run the same collection against two servers by swapping it;
- name the five scopes of a variable, global, collection, environment, data and local, and say which one wins when two hold the same name;
- set a variable in one request's script and use it in the next, such as an id that a POST answers;
- run a request once for every row of a JSON or CSV data file, and read the row with pm.iterationData;
- say what the app's environment selector, Globals and data files do, and which Newman options do the same;
- find a variable that came from the wrong scope by printing where each value comes from.
How to follow this lesson
As before, every block is one program that starts a server, runs a collection with Newman's library, prints what happened and closes the server. It runs on the page with the small Newman, and it has also been run with the real Newman 6.2.3, where it prints the same.
The app's environment selector, its Globals and its data files are described in words from Postman's own documentation, each matched with the JSON it keeps and the Newman option that does the same job.
In one line
An environment holds one server's values outside the collection; variables live in five scopes, the narrowest wins; scripts pass values from one request to the next; and a data file runs the requests once for each of its rows.
Environments: one collection, many servers
At a glance
Teams have several servers that answer the same routes, and one collection should reach them all.
An environment is a named set of variables kept outside the collection: one server's address, its keys, its names. Give Newman an environment, as an object or a file, and every name in braces is filled from it. Give it another, and the same requests go to another server. Scripts use pm.environment, and Newman's envVar replaces a value for one run, without touching the file.
Take a guess: Can a variable's value hold another variable, and how deep can such nesting go?
A team rarely has one server. There is the copy on your own laptop, a shared practice server, and the real one that customers use. They answer the same routes at different addresses, with different keys. The collection should stay the same for all of them; only those few values should change.
An environment is a named set of variables kept outside the collection, such as practice yard or real yard, each holding that server's address and keys. You give Newman one environment for a run, and every {{name}} in the collection is filled from it. Change the environment, and the same requests go to another server.
Two yards, one collection
To stand for two servers, this lesson's server.js builds a yard: an Express app that answers GET /yard with its own name, keeps the gauges of the last lessons, and stores readings. Here two yards run side by side, the practice yard on port 3000 and the real yard on port 3001. One collection asks {{baseUrl}}/yard, and it runs twice, once with each environment:
server.js
const express = require("express");
module.exports = (yard) => {
const app = express();
app.use(express.json());
const gauges = { boiler: 95, pump: 40 };
const readings = [];
app.get("/yard", (req, res) => res.json({ yard }));
app.get("/gauges/:name", (req, res) => {
if (!(req.params.name in gauges)) return res.status(404).json({ error: "no such gauge" });
res.json({ name: req.params.name, value: gauges[req.params.name] });
});
app.post("/readings", (req, res) => {
const reading = { id: readings.length + 1, ...req.body };
readings.push(reading);
res.status(201).json(reading);
});
app.get("/readings/:id", (req, res) => {
const reading = readings.find((r) => r.id === Number(req.params.id));
if (!reading) return res.status(404).json({ error: "no such reading" });
res.json(reading);
});
return app;
};
app.js
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "which yard", request: "{{baseUrl}}/yard" }],
};
const practice = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const real = { name: "real yard", values: [{ key: "baseUrl", value: "http://localhost:3001" }] };
const a = yard("practice").listen(3000);
const b = yard("real").listen(3001, () => {
const ask = (environment, then) =>
newman.run({ collection, environment }, then)
.on("request", (err, args) => console.log(environment.name + ":", args.response.text()));
ask(practice, () => ask(real, () => { a.close(); b.close(); }));
});
Terminal: node app.js
practice yard: {"yard":"practice"}
real yard: {"yard":"real"}
The collection never changed; only the environment did. In the first run baseUrl was http://localhost:3000, so the practice yard answered. In the second it was http://localhost:3001, and the real yard answered. The second run starts from the first one's callback, so the two never overlap.
An environment is JSON of its own: a name and a values list of key and value pairs, the same shape as the collection's variable list. Each pair may also carry enabled, true or false; the mistakes section shows a surprise about it.
A card for each yard
The collection is a box of questions. An environment is a small card clipped to the box: the yard's address, its door number, its key. To ask another yard, you clip on another card. The questions in the box stay exactly as they were.
In the app
In Postman, environments are made from the sidebar, or from the environment selector at the top right of the workbench. Each environment is a table of variables: a name and a value on each row, saved as you type. Choosing an environment in the selector makes it the active one, and only one environment is active at a time. Exporting an environment gives the JSON file that Newman reads with -e.
Worked example 1
Keep the practice yard's values in a file, the way an exported environment is kept, and run the collection with it.
What we have: a file practice.postman_environment.json with two variables, host and baseUrl, where baseUrl itself uses {{host}}
What we need: the request's address and the answer
The plan: pass the file's path as the environment option, as -e does on the command line, and print the address as sent
practice.postman_environment.json
{
"name": "practice yard",
"values": [
{ "key": "host", "value": "localhost", "enabled": true },
{ "key": "baseUrl", "value": "http://{{host}}:3000", "enabled": true }
]
}
app.js (server.js builds a yard; it is shown in the environments section); the environment file is shown above
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "read the boiler", request: "{{baseUrl}}/gauges/boiler" }],
};
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment: "./practice.postman_environment.json" }, () => server.close())
.on("request", (err, args) => console.log(args.request.url.toString(), "|", args.response.text()));
});
Terminal: node app.js
http://localhost:3000/gauges/boiler | {"name":"boiler","value":95}
- Newman read the file itself, just as it reads a collection file.
- baseUrl was http://{{host}}:3000, a variable holding another variable. Newman filled in {{baseUrl}}, then the {{host}} it contained, so the address went out as http://localhost:3000/gauges/boiler.
The request went to http://localhost:3000/gauges/boiler, and the boiler's reading came back.
Check: The printed address has no braces left in it, so every name was found.
Another way: on the command line: newman run gauges.postman_collection.json -e practice.postman_environment.json.
A path that fails: writing the full address into each request instead of {{baseUrl}}. The environment file would then change nothing, and every request would still go to the old address.
Reading and changing it from a script
Scripts reach the active environment through pm.environment, with the same get, set, unset, has and toObject as pm.collectionVariables, and one more: pm.environment.name, the environment's name.
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "which yard",
request: "{{baseUrl}}/yard",
event: [{ listen: "test", script: { exec: [
'console.log("active:", pm.environment.name);',
'console.log("baseUrl:", pm.environment.get("baseUrl"));',
'pm.environment.set("lastYard", pm.response.json().yard);',
'console.log("now holds:", JSON.stringify(pm.environment.toObject()));',
] } }],
},
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("console", (err, args) => console.log(args.messages.join(" ")));
});
Terminal: node app.js
active: practice yard
baseUrl: http://localhost:3000
now holds: {"baseUrl":"http://localhost:3000","lastYard":"practice"}
The test read the environment's name and its baseUrl, then stored a new variable, lastYard, from the answer. toObject shows the environment as the run now holds it, with the new variable in it.
Worked example 2
Send the whole collection to the real yard without editing the practice environment.
What we have: the practice environment, whose baseUrl is http://localhost:3000, and the real yard listening on 3001
What we need: every request sent to port 3001 for this one run
The plan: use Newman's envVar option, which adds a value to the environment or replaces one, for this run only
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "which yard", request: "{{baseUrl}}/yard" }],
};
const practice = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const a = yard("practice").listen(3000);
const b = yard("real").listen(3001, () => {
newman.run({ collection, environment: practice, envVar: [{ key: "baseUrl", value: "http://localhost:3001" }] }, () => { a.close(); b.close(); })
.on("request", (err, args) => console.log(args.request.url.toString(), "|", args.response.text()));
});
Terminal: node app.js
http://localhost:3001/yard | {"yard":"real"}
- The environment still says 3000, but envVar replaced baseUrl for this run, so the request went to 3001.
- On the command line the same option is --env-var, given once for each pair: --env-var "baseUrl=http://localhost:3001".
The request reached the real yard, at http://localhost:3001/yard, and the environment's file was never touched.
Check: The answer names the real yard.
A path that fails: editing the practice environment to point at the real yard and forgetting to change it back. The next practice run would quietly go to the real server.
When you are stuck: The environment's values are not used
Was the environment given to the run at all? Without it, {{baseUrl}} stays as it was written, and Newman looks for a host called {{baseurl}}.
Is the variable's name exactly the same in the environment and in the request? Names are matched letter for letter.
Is another scope holding the same name? The next section shows which one wins.
Your turn
The practice environment has baseUrl http://localhost:3000, and the real one http://localhost:3001. Which server does {{baseUrl}}/yard reach when the real environment is given?Tap to reveal
- The request is filled from the environment given to the run.
The server on port 3001, the real yard.
In the app, where do you choose which environment is active?Tap to reveal
- It is near the top of the workbench.
In the environment selector, at the top right of the workbench.
cat > app.js <<'END'
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "read the pump", request: "{{baseUrl}}/gauges/{{gauge}}" }],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }, { key: "gauge", value: "pump" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.response.code, args.response.text()));
});
END
node app.js
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
200 {"name":"pump","value":40}
- Both variables come from the environment.
- The pump exists, so the yard answers 200 with its reading.
It prints 200 {"name":"pump","value":40}.
Did you know?
Nineteen layers deep
A variable's value may hold another variable, as a baseUrl of http://{{host}}:3000 does. Postman's collection library fills such values in passes, and its code sets a limit: the substitution repeats at most 19 times until all the names are resolved. So a chain of variables nested more than 19 deep would leave braces behind.
Why it fits here: It answers this topic's question: a variable may hold another, and Postman's library repeats the filling in at most 19 times.
A colour for each server
Picking the wrong environment can send a test to the real server. Postman lets you give each environment a colour, so that people can tell them apart and pick the right one at a glance. Its documentation adds that the colour stays with an environment when it is copied, forked or moved into another workspace.
Why it fits here: It meets this topic's danger: a colour per environment helps people tell the practice server from the real one.
Source: Postman Docs: Organize your workspace environments with colors
In one line
An environment is a named set of variables kept outside the collection; give Newman a different environment, as an object or a file, and the same requests go to a different server.
Five scopes, and who wins
At a glance
When the same name lives in two places, one rule decides which value a request gets.
Postman keeps variables in five scopes. From the broadest to the narrowest, they are global, collection, environment, data and local. When two scopes hold the same name, the narrowest wins. pm.variables.get looks through them in that order, narrowest first. pm.variables.set writes a local value. That value wins over every other scope for the rest of the run, which is handy and also a trap.
Take a guess: When you change a variable's value in the app, does Postman send that value to its cloud?
You have now met three places a variable can live: the collection's variable list, an environment, and, through pm.variables.set, a script. Postman has five such places, called scopes. Each one suits a different kind of value, and when two scopes hold the same name, a short rule decides which value is used.
| Scope | Where it lives | What it suits | In Newman |
|---|---|---|---|
| global | the workspace, for every collection | quick trials | globals, or -g |
| collection | the collection's variable list | values every server shares, such as a path | inside the collection |
| environment | the active environment | one server's address and keys | environment, or -e |
| data | the row of a data file for this round | a value that changes each round | iterationData, or -d |
| local | set by a script, for this run only | a value that must win for a while | pm.variables.set |
Postman's documentation lists them from the broadest to the narrowest: global, collection, environment, data, local. The rule is: when two scopes hold the same name, the narrowest wins. A local value beats a data value, which beats the environment's, which beats the collection's, which beats a global.
Rules at school
The school has a rule for every class; your class has its own rules; today's lesson may have one more. When two rules disagree, the one closest to you wins: today's lesson over the class, the class over the school. Variables work the same way, with the local scope closest of all.
Watching the rule work
This block puts a variable called who into three scopes at once: the globals, the collection and the environment. The second request's pre-request script then sets a local value. Every request prints the value it sees:
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const say = 'console.log(pm.info.requestName + ": who is", pm.variables.get("who"));';
const collection = {
info: { name: "Engine Hall gauges" },
variable: [{ key: "who", value: "the collection" }],
item: [
{ name: "first", request: "http://localhost:3000/yard", event: [{ listen: "test", script: { exec: [say] } }] },
{
name: "second",
request: "http://localhost:3000/yard",
event: [{ listen: "prerequest", script: { exec: ['pm.variables.set("who", "a local value");'] } }, { listen: "test", script: { exec: [say] } }],
},
{ name: "third", request: "http://localhost:3000/yard", event: [{ listen: "test", script: { exec: [say] } }] },
],
};
const environment = { name: "practice yard", values: [{ key: "who", value: "the environment" }] };
const globals = { name: "globals", values: [{ key: "who", value: "the globals" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment, globals }, () => server.close())
.on("console", (err, args) => console.log(args.messages.join(" ")));
});
Terminal: node app.js
first: who is the environment
second: who is a local value
third: who is a local value
The first request saw the environment's value: it beat the collection's and the globals'. The second request set a local value, and the local scope beat them all. The third request set nothing, yet it still saw the local value. A local value, once set, lasts for the rest of the run, so it kept winning. That is useful, and it is also a trap, as the mistakes section shows.
In a script, pm.variables.get looks through the scopes in that same order, the narrowest first, and gives the first value it finds. pm.variables.set always writes a local value. To change a value in one scope on purpose, use that scope's own object: pm.environment, pm.collectionVariables or pm.globals.
Worked example 3
A request uses {{baseUrl}} from the environment and {{gauge}} from the collection. Which gauge does it read?
What we have: baseUrl only in the environment, and gauge only in the collection
What we need: the address that goes out
The plan: look each name up in every scope; with only one scope holding each name, there is no contest
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
variable: [{ key: "gauge", value: "pump" }],
item: [{ name: "read a gauge", request: "{{baseUrl}}/gauges/{{gauge}}" }],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.request.url.toString(), "|", args.response.text()));
});
Terminal: node app.js
http://localhost:3000/gauges/pump | {"name":"pump","value":40}
- Each name was found in exactly one scope, so each came from there: the address from the environment, pump from the collection.
- Scopes mix freely: one request can take each of its variables from a different scope.
It reads the pump, at http://localhost:3000/gauges/pump.
Check: No braces are left in the address, so both names were found.
A path that fails: thinking a request must take all its variables from one scope. Each name is looked up on its own.
Worked example 4
Now the environment also holds gauge, set to boiler, while the collection still says pump. Which gauge does the request read?
What we have: gauge in two scopes: boiler in the environment, pump in the collection
What we need: the value that wins, and so the address
The plan: apply the rule: the narrower scope wins, and the environment is narrower than the collection
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
variable: [{ key: "gauge", value: "pump" }],
item: [{ name: "read a gauge", request: "{{baseUrl}}/gauges/{{gauge}}" }],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }, { key: "gauge", value: "boiler" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.request.url.toString(), "|", args.response.text()));
});
Terminal: node app.js
http://localhost:3000/gauges/boiler | {"name":"boiler","value":95}
- The environment's boiler beat the collection's pump, as the rule says.
- The collection's value is not lost: give a run an environment without gauge, and pump is used again.
It reads the boiler: the environment beats the collection.
Check: The printed address ends in /boiler, and the boiler's reading came back.
A path that fails: expecting the value that was written first, or the one written in the request's own collection, to win. Only the scope decides.
When you are stuck: A variable has the wrong value
Print pm.variables.get("name") in a pre-request script: it is the value the request will use.
Then print the name from each scope: pm.environment.get, pm.collectionVariables.get and pm.globals.get. The narrowest one holding it is the winner.
Did an earlier request set a local value with pm.variables.set? It wins for the rest of the run.
Your turn
Name the five scopes from the broadest to the narrowest.Tap to reveal
- The broadest covers a whole workspace.
- The narrowest is set by a script.
global, collection, environment, data, local.
baseUrl is in the globals as http://localhost:4000 and in the environment as http://localhost:3000. Which one does a request use?Tap to reveal
- The narrower scope wins.
http://localhost:3000, the environment's: the environment is narrower than the globals.
cat > app.js <<'END'
const newman = require("newman");
const yard = require("./server");
const say = 'console.log(pm.info.requestName + ": who is", pm.variables.get("who"));';
const collection = {
info: { name: "Engine Hall gauges" },
variable: [{ key: "who", value: "the collection" }],
item: [
{ name: "first", request: "http://localhost:3000/yard", event: [{ listen: "test", script: { exec: [say] } }] },
{
name: "second",
request: "http://localhost:3000/yard",
event: [{ listen: "prerequest", script: { exec: ['pm.variables.set("who", "a local value");'] } }, { listen: "test", script: { exec: [say] } }],
},
{ name: "third", request: "http://localhost:3000/yard", event: [{ listen: "test", script: { exec: [say] } }] },
],
};
const environment = { name: "practice yard", values: [{ key: "place", value: "the hall" }] };
const globals = { name: "globals", values: [{ key: "who", value: "the globals" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment, globals }, () => server.close())
.on("console", (err, args) => console.log(args.messages.join(" ")));
});
END
node app.js
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
first: who is the collection
second: who is a local value
third: who is a local value
- The environment no longer holds who, so the first request finds the collection's value.
- The second request sets a local value, which lasts for the rest of the run.
It prints the collection for the first request, then a local value for the second and third.
Did you know?
Your values stay on your machine
By default, a variable's value in Postman stays on your machine. The documentation says that collection, environment and global values are only available locally, in your own instance of Postman, and are not synced to the Postman Cloud. A value you choose to share is synced, and features that run in the cloud, such as monitors and the Postman CLI, use that shared value.
Why it fits here: It answers this topic's question: values you type stay local unless you share them, and cloud features use the shared value.
Source: Postman Docs: Store and reuse values using variables
A vault for secrets
Keys and passwords have a safer home than any scope: Postman Vault, which keeps them as vault secrets in encrypted storage. In the Local Vault, the documentation says, only you can reach your secrets, and they are not synced to the Postman Cloud. A request can use a secret without the secret ever being written into a collection or an environment.
Why it fits here: It adds a safer place beside this topic's scopes: secrets kept encrypted in a vault, on your own machine.
In one line
Variables live in five scopes, global, collection, environment, data and local; when two hold the same name the narrowest wins, and a local value set by pm.variables.set wins for the rest of the run.
Passing a value to the next request
At a glance
Some values do not exist until the server makes them, so a request cannot know them in advance.
To chain requests, a test catches a value from one answer, such as the id a POST returns, and keeps it in a variable with set. The next request uses it in braces, and the server is asked about the very thing it just made. The request that sets the value must run before the one that uses it, and exportEnvironment keeps what the run changed.
Take a guess: Could anyone count how many readings a server holds, just from the ids it hands out?
Many APIs give you a value you could not know in advance. A POST stores a reading and answers with its new id; the next request must ask for that very id. You cannot write the id into the collection, because the server chooses it during the run. A script can catch it from one answer and hand it to the next request. Passing values along like this is called chaining requests.
Catch it, keep it, use it
The recipe has three steps. The POST's test script reads the id from the answer. It keeps it in a variable, here in the environment with pm.environment.set. The next request uses {{readingId}} like any other variable:
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "store a reading",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "boiler", "value": 96 }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
{ name: "read it back", request: "{{baseUrl}}/readings/{{readingId}}" },
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.item.name, "|", args.request.url.toString(), "|", args.response.code, args.response.text()));
});
Terminal: node app.js
store a reading | http://localhost:3000/readings | 201 {"id":1,"gauge":"boiler","value":96}
read it back | http://localhost:3000/readings/1 | 200 {"id":1,"gauge":"boiler","value":96}
The yard gave the new reading the id 1. The test stored it as readingId, and when the second request was built, {{readingId}} was filled in, so it asked for /readings/1. Nothing about the id was written in the collection: it travelled from the first answer to the second question during the run.
A ticket at the counter
At a bank counter you hand in a form, and the clerk hands back a token with a number. You cannot know the number before you arrive. Later you show that token to collect your work. The test script is your hand taking the token; the variable is your pocket; the next request shows it at the counter.
Where to keep it
Any scope with a set method can carry the value. The environment, as here, is a common choice: Postman's documentation suggests environments for values that change with the server, and an id belongs to the server that made it. A collection variable also works. A local value, pm.variables.set, is enough for a value that matters only during this run, and it wins over every other scope while the run lasts.
Worked example 5
Store two readings, then read back the first by its fixed id and the latest by the id the run caught.
What we have: two POSTs, each saving its id as readingId, then two GETs
What we need: which reading each GET returns
The plan: follow readingId: each POST overwrites it, so after both it holds the second id
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "store a reading",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "boiler", "value": 96 }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
{
name: "store another",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "pump", "value": 41 }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
{ name: "read the first", request: "{{baseUrl}}/readings/1" },
{ name: "read the latest", request: "{{baseUrl}}/readings/{{readingId}}" },
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.item.name, "|", args.response.code, args.response.text()));
});
Terminal: node app.js
store a reading | 201 {"id":1,"gauge":"boiler","value":96}
store another | 201 {"id":2,"gauge":"pump","value":41}
read the first | 200 {"id":1,"gauge":"boiler","value":96}
read the latest | 200 {"id":2,"gauge":"pump","value":41}
- The first POST stored the boiler as id 1, and set readingId to 1.
- The second POST stored the pump as id 2, and set readingId to 2, replacing the 1.
- read the first asks for /readings/1, written in the request, so it gets the boiler. read the latest uses {{readingId}}, which now holds 2, so it gets the pump.
read the first returns the boiler, id 1; read the latest returns the pump, id 2.
Check: The ids printed by the GETs match the ids the POSTs answered.
Another way: keep each id under its own name, such as boilerId and pumpId, when later requests need both.
A path that fails: using one variable for two things at once. Each set replaces the last value, so only the latest id survives.
Worked example 6
The read comes first in this collection, before the POST that sets readingId. What happens?
What we have: a GET using {{readingId}}, then the POST whose test sets it
What we need: the address the GET sends, and its status
The plan: remember that a value exists only after the script that sets it has run
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{ name: "read it back", request: "{{baseUrl}}/readings/{{readingId}}" },
{
name: "store a reading",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "boiler", "value": 96 }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.item.name, "|", args.request.url.toString(), "|", args.response.code));
});
Terminal: node app.js
read it back | http://localhost:3000/readings/%7B%7BreadingId%7D%7D | 404
store a reading | http://localhost:3000/readings | 201
- When the GET ran, no scope held readingId, so its braces stayed, written as %7B%7B and %7D%7D in the path.
- The yard had no reading with that strange id and answered 404. The POST ran afterwards and set the id too late to help.
The GET goes to /readings/%7B%7BreadingId%7D%7D and gets a 404: the id was set after it was needed.
Check: Swap the two items, and the GET gets the reading, as in the first block.
A path that fails: fixing the 404 on the server. The server was right: the request asked for a reading that does not exist.
What survives the run
A value set during a run lives in Newman's memory, not in your files. To keep an environment as the run left it, Newman's exportEnvironment option, --export-environment on the command line, writes it to a file at the end:
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const fs = require("fs");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "store a reading",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "boiler", "value": 96 }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment, exportEnvironment: "./after.json" }, () => {
const after = JSON.parse(fs.readFileSync("after.json", "utf8"));
console.log(after.name, JSON.stringify(after.values.map((v) => [v.key, v.value])));
fs.rmSync("after.json");
server.close();
});
});
Terminal: node app.js
practice yard [["baseUrl","http://localhost:3000"],["readingId",1]]
The block deletes after.json at the end, with fs.rmSync, so that it leaves the folder as it found it; the file itself also carries the time of the export. The saved environment holds readingId, which the run added. Measured with Newman, this is a difference worth remembering: an exported environment keeps what the run changed, while an exported collection, as lesson 02 found, keeps the values the run started with.
When you are stuck: The next request does not get the value
Is the request that sets the value above the one that uses it? Values exist only after their script runs.
Is the name the same in pm.environment.set("readingId", ...) and in {{readingId}}? Letter for letter.
Did the answer hold what you read? Print pm.response.json() in the test before setting the variable.
Your turn
A POST answers {"id": 7, ...}. Which line in its test keeps the id in the environment as readingId?Tap to reveal
- Read the answer's JSON, then use the environment's set method.
pm.environment.set("readingId", pm.response.json().id);
Why can the id not be written into the collection before the run?Tap to reveal
- Who chooses the id, and when?
Because the server chooses it during the run, when the POST stores the reading.
cat > app.js <<'END'
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "store a reading",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "boiler", "value": 99 }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
{ name: "read it back", request: "{{baseUrl}}/readings/{{readingId}}" },
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment }, () => server.close())
.on("request", (err, args) => console.log(args.response.code, args.response.json().value));
});
END
node app.js
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
201 99
200 99
- The POST stores the reading with value 99 and answers it.
- The GET reads it back by the caught id.
It prints 201 99, then 200 99.
Did you know?
Serial numbers that told a secret
Ids that count up, 1, 2, 3, tell anyone how many things exist. In the Second World War, Allied statisticians estimated German tank production from the serial numbers on captured tanks. The Guardian reported that they estimated 246 tanks a month, while ordinary intelligence believed around 1,400; German records later showed 245. Statisticians still call it the German tank problem.
Why it fits here: It answers this topic's question: ids that count up reveal how many there are, which is why many servers prefer random ids.
Sources: Wikipedia: German tank problem; The Guardian: Gavyn Davies does the maths
The address of the new thing
A server can hand over more than an id. RFC 9110, the standard for HTTP's meaning, says a 201 Created answer identifies the new resource by a Location header, or, when there is none, by the address the request was sent to. A client can then follow Location, instead of building the next address from an id itself.
Why it fits here: It shows a standard way to chain: a 201's Location header names the address of the thing just made.
Source: RFC 9110: HTTP Semantics
In one line
To chain requests, a test catches a value from one answer, keeps it in a variable with set, and the next request uses it in braces; the setter must run before the user, and exportEnvironment saves what the run changed.
A data file: one round per row
At a glance
When each round should use different values, a list does the work of many requests.
A data file holds rows, as JSON or as CSV with a header line. Newman runs one round per row, unless iterationCount says otherwise. Each row's values become data variables, used in braces and read with pm.iterationData. Numbers in a CSV become numbers. Past the last row, the last row is used again. And when a data variable and an environment variable share a name, data wins.
Take a guess: Was CSV, the oldest of these formats, ever written down as a standard?
Lesson 02 ran a collection several rounds, each the same. Often you want each round to be a little different: store a list of readings, one per round, or check many gauges, each against the value it should have. Writing a request for each would be slow. A data file keeps the changing values in rows, and Newman runs the collection once per row.
Each row's values become data variables for that round: the scope between the environment and the local scope. In requests they are used with braces like any variable; in scripts they are read with pm.iterationData.get. Newman's iterationData option takes the rows themselves, or the path of a JSON or CSV file; on the command line it is -d.
A CSV file
A CSV file, short for comma-separated values, is the plain text of a spreadsheet: the first line names the columns, and each line after it is a row. Here is one with three readings, and a collection that stores {{gauge}} and {{value}} in each round:
readings.csv
gauge,value
boiler,96
pump,41
fan,12
app.js (server.js builds a yard; it is shown in the environments section); the data file is shown above
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "store a reading",
request: {
method: "POST",
url: "http://localhost:3000/readings",
body: { mode: "raw", raw: '{ "gauge": "{{gauge}}", "value": {{value}} }', options: { raw: { language: "json" } } },
},
},
],
};
const server = yard("practice").listen(3000, () => {
newman.run({ collection, iterationData: "./readings.csv" }, (err, summary) => {
console.log("rounds:", summary.run.stats.iterations.total);
server.close();
}).on("request", (err, args) => console.log(args.response.text()));
});
Terminal: node app.js
{"id":1,"gauge":"boiler","value":96}
{"id":2,"gauge":"pump","value":41}
{"id":3,"gauge":"fan","value":12}
rounds: 3
Three rows made three rounds, and each round's POST took that row's values. Newman read the header line as the names of the variables. It also turned 96, 41 and 12 into numbers, which is why the body, "value": {{value}}, went out as valid JSON numbers.
Filling in one form many times
Think of a printed form and a list of names to send it to. You fill in the same form once for each line of the list. The collection is the form, the data file is the list, and each round is one filled-in copy.
A JSON file, and checks against it
A data file can also be JSON: a list of objects, one per row. Newman tries the file as JSON first, and reads it as CSV only if that fails. Rows are a natural place for the answer you expect, so that one test checks many cases:
Worked example 7
Check three gauges against the readings they should have, with one request and one test.
What we have: a file expected.json with three rows, each a gauge and the value it should read; the chimney does not exist
What we need: a passed or failed test for each row
The plan: use {{gauge}} in the URL, and compare the answer's value with pm.iterationData.get("expected") in the test; name each test after its row
expected.json
[
{ "gauge": "boiler", "expected": 95 },
{ "gauge": "pump", "expected": 40 },
{ "gauge": "chimney", "expected": 0 }
]
app.js (server.js builds a yard; it is shown in the environments section); the data file is shown above
const newman = require("newman");
const yard = require("./server");
const test = [
'const gauge = pm.iterationData.get("gauge"), expected = pm.iterationData.get("expected");',
'pm.test(gauge + " reads " + expected, () => pm.expect(pm.response.json().value).to.equal(expected));',
];
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "read a gauge", request: "http://localhost:3000/gauges/{{gauge}}", event: [{ listen: "test", script: { exec: test } }] }],
};
const server = yard("practice").listen(3000, () => {
newman.run({ collection, iterationData: "./expected.json" }, () => server.close())
.on("assertion", (err, args) => console.log(args.assertion, "|", err ? err.message : "passed"));
});
Terminal: node app.js
boiler reads 95 | passed
pump reads 40 | passed
chimney reads 0 | expected undefined to equal +0
- The boiler and the pump read what their rows expected.
- The chimney has no reading. The yard answered 404 with an error, so the answer's value was undefined, and the test failed with Chai's message: expected undefined to equal +0. Chai writes the number 0 with a plus sign in its messages.
boiler and pump pass; chimney fails, because the yard has no such gauge.
Check: Three rows, three rounds, three named results.
Another way: add a row to the file to check a fourth gauge; the collection does not change at all.
A path that fails: writing three requests with the values typed in. It works for three; the data file stays one request for three hundred.
Rounds and rows
By default there is one round per row. If you also give iterationCount, Newman runs that many rounds; when the rounds outnumber the rows, the last row is used again:
Worked example 8
Two rows and three rounds: which gauge does each round read?
What we have: rows boiler and pump, and iterationCount: 3
What we need: the gauge read in rounds 0, 1 and 2
The plan: rounds take rows in order; past the last row, the last row repeats
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "read a gauge",
request: "http://localhost:3000/gauges/{{gauge}}",
event: [{ listen: "test", script: { exec: ['console.log("round", pm.info.iteration, "reads", pm.iterationData.get("gauge"));'] } }],
},
],
};
const data = [{ gauge: "boiler" }, { gauge: "pump" }];
const server = yard("practice").listen(3000, () => {
newman.run({ collection, iterationData: data, iterationCount: 3 }, () => server.close())
.on("console", (err, args) => console.log(args.messages.join(" ")));
});
Terminal: node app.js
round 0 reads boiler
round 1 reads pump
round 2 reads pump
- Round 0 took the first row, and round 1 the second.
- Round 2 found no third row, so it used the last one again, pump.
boiler, then pump, then pump again.
Check: Three rounds printed, with the last row repeated once.
A path that fails: expecting Newman to wrap round to the first row. It repeats the last row instead.
In the app
In the Collection Runner, the Iteration data setting takes a CSV or JSON file from your computer, previews it, and runs one round per row. Postman's documentation notes that custom data files are a feature of its paid plans; Newman's -d reads the same files in any plan.
When you are stuck: A data variable is empty or wrong
Is the column's name in the file's first line exactly the name in the braces?
Does an environment or local value of the same name hide it? A local value wins over data; data wins over the environment.
Is the file read as you think? Print JSON.stringify(pm.iterationData.toObject()) in a script to see the whole row.
Your turn
A CSV file has a header line and five rows. With no iterationCount, how many rounds run?Tap to reveal
- One round per row; the header line names the columns.
5.
In a script, how do you read the value of the column gauge for this round?Tap to reveal
- Data variables have their own object in pm.
pm.iterationData.get("gauge").
cat > app.js <<'END'
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "read a gauge", request: "http://localhost:3000/gauges/{{gauge}}" }],
};
const data = [{ gauge: "pump" }, { gauge: "boiler" }];
const server = yard("practice").listen(3000, () => {
newman.run({ collection, iterationData: data }, () => server.close())
.on("request", (err, args) => console.log(args.response.json().value));
});
END
node app.js
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
40
95
- Two rows, so two rounds, in order.
- The pump reads 40 and the boiler 95.
It prints 40, then 95.
Did you know?
Common for decades, written down in 2005
CSV is older than its standard. RFC 4180, of October 2005, says the format had been used to exchange and convert data between spreadsheet programs for quite some time, and then adds: surprisingly, while this format is very common, it has never been formally documented. That RFC finally wrote down a common form, with a header line and quotes around fields that hold commas.
Why it fits here: It answers this topic's question: CSV was in use for years before RFC 4180 wrote it down in 2005.
Source: RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files
A cell that runs a formula
A CSV file can be dangerous to open. OWASP, the web security project, describes CSV Injection, also called Formula Injection: when a spreadsheet program such as Microsoft Excel or LibreOffice Calc opens a CSV, any cell starting with = is read as a formula. A site that writes untrusted text into a CSV can hand its users a file that runs someone else's formula.
Why it fits here: It warns about this topic's files: a CSV opened in a spreadsheet treats a cell starting with = as a formula.
Source: OWASP: CSV Injection
In one line
A data file, JSON or CSV, gives each round one row of values as data variables; Newman runs one round per row, pm.iterationData reads the row, and past the last row the last row repeats.
Where it is used
Every team that tests an API against more than one server uses these ideas daily. Here is where each one does its work.
| What you learned | Where it is used | A real example |
|---|---|---|
| environments | one collection for every server | local, staging and production environments for the same API |
| envVar and -e | build servers choosing a server | a pipeline that runs the collection against staging with -e staging.json |
| the five scopes | keeping values where they belong | the address in the environment, a shared path in the collection |
| chaining | APIs that create things | create an order, then read, update and delete it by the id it was given |
| data files | many cases, one request | checking a hundred products against their expected prices |
| exportEnvironment | carrying values to the next run | saving a login token that the next run reuses |
Keys and passwords belong in environments, not in collections, so that a collection can be shared without them. Postman's documentation also marks some environment values as secret and keeps them out of shared copies; the idea is the same as keeping your .env file out of git.
In the Testing House, an environment is the card clipped to the box, chaining is the parcel number written on the card, and a data file is the stack of slips the runner works through.
Mistakes and debugging
These are the mistakes people make most with environments and variables, each with the way to see it and the fix.
1. Running without the environment
A collection written with {{baseUrl}} needs an environment that holds it. Forget to give one, and the braces stay where the host should be:
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "which yard", request: "{{baseUrl}}/yard" }],
};
const server = yard("practice").listen(3000, () => {
newman.run({ collection }, () => server.close())
.on("request", (err, args) => console.log(args.request.url.toString(), "|", err ? err.message : args.response.code));
});
Terminal: node app.js
http://{{baseurl}}/yard | getaddrinfo ENOTFOUND {{baseurl}}
Newman looked for a machine called {{baseurl}}, in small letters, because the names of machines on a network do not care about capitals, and found none. Give the run its environment: the environment option, or -e on the command line.
2. A switched-off value that Newman still uses
In the app, clearing the checkbox beside an environment variable makes it unavailable. In an environment's JSON that box is enabled. Measured with Newman 6.2.3, a value marked enabled: false is still used:
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [{ name: "which yard", request: "{{baseUrl}}/yard" }],
};
const environment = {
name: "real yard",
values: [{ key: "baseUrl", value: "http://localhost:3001", enabled: false }],
};
const a = yard("practice").listen(3000);
const b = yard("real").listen(3001, () => {
newman.run({ collection, environment }, () => { a.close(); b.close(); })
.on("request", (err, args) => console.log(args.request.url.toString(), "|", args.response.text()));
});
Terminal: node app.js
http://localhost:3001/yard | {"yard":"real"}
The value was switched off, yet the request went to the real yard. Do not rely on enabled: false to keep a value out of a Newman run: remove the value from the environment, or give the run a different environment.
3. A local value that hides the environment
A value set with pm.variables.set is local, and it wins over every other scope for the rest of the run. Set baseUrl locally in one request, and every later request goes there, whatever the environment says. Use pm.environment.set when you mean the environment.
4. Using a value before it is set
A variable exists only after the script that sets it has run. A request that uses {{readingId}} above the POST that sets it sends the braces, percent-encoded, and gets a 404. Keep the setter above the user.
5. Expecting the file to change
pm.environment.set changes the environment in Newman's memory, for this run. The file on disk stays as it was, unless the run exports it with exportEnvironment, or --export-environment.
6. Two scopes with one name
A data file's column and an environment variable with the same name: the data value wins, because data is the narrower scope. Give values that mean different things different names.
The debugging corner: ask each scope
When a value surprises you, print it from every scope in a pre-request script: pm.variables.get("name") for the winner, then pm.iterationData.get, pm.environment.get, pm.collectionVariables.get and pm.globals.get. The first one that holds it, narrowest first, is where the value came from.
In the app, the variables pane, opened with Variables at the top right of the workbench, shows the variables a request uses and their values.
Quick card
The whole lesson on one card. Come back to it whenever you need a reminder.
app.js (server.js builds a yard; it is shown in the environments section)
const newman = require("newman");
const yard = require("./server");
const collection = {
info: { name: "Engine Hall gauges" },
item: [
{
name: "store a reading",
request: {
method: "POST",
url: "{{baseUrl}}/readings",
body: { mode: "raw", raw: '{ "gauge": "{{gauge}}", "value": {{value}} }', options: { raw: { language: "json" } } },
},
event: [{ listen: "test", script: { exec: ['pm.environment.set("readingId", pm.response.json().id);'] } }],
},
{
name: "read it back",
request: "{{baseUrl}}/readings/{{readingId}}",
event: [{ listen: "test", script: { exec: [
'const r = pm.response.json();',
'console.log("round " + pm.info.iteration + ": reading " + r.id + " is the " + r.gauge + " at " + r.value);',
] } }],
},
],
};
const environment = { name: "practice yard", values: [{ key: "baseUrl", value: "http://localhost:3000" }] };
const data = [{ gauge: "boiler", value: 96 }, { gauge: "pump", value: 41 }];
const server = yard("practice").listen(3000, () => {
newman.run({ collection, environment, iterationData: data }, () => server.close())
.on("console", (err, args) => console.log(args.messages.join(" ")));
});
Terminal: node app.js
round 0: reading 1 is the boiler at 96
round 1: reading 2 is the pump at 41
| When you see | It means | Do |
|---|---|---|
| getaddrinfo ENOTFOUND {{baseurl}} | the run has no environment holding baseUrl | give the environment, or -e |
| a request to a server you switched off | enabled: false is still used by Newman | remove the value, or use another environment |
| the wrong value everywhere after one request | a local value set by pm.variables.set wins | set the scope you mean, such as pm.environment |
| %7B%7BreadingId%7D%7D and a 404 | the value was used before it was set | put the request that sets it first |
| the environment file unchanged after a run | a run's changes live in memory | exportEnvironment, or --export-environment |
| a data value beating the environment | data is the narrower scope | use different names |
| the last data row used twice | more rounds than rows | add rows, or leave out iterationCount |
The story: A card for each yard
Two cards now hang beside the box, one for the practice yard and one for the real yard, each with its own address. The runner takes one, and every question in the box goes to that yard. When the yard answers with a parcel number, the runner writes it on the card, and the next question asks about that parcel.
A stack of slips lets the runner ask the same question once for each line, and a short rule settles any argument: when two cards disagree, the nearer one wins.
The Postmaster reads the reports from both yards. "Tomorrow," she says, "we check what the answers say, not just that they came back."
Reagents gathered: environment, global, iteration data, scope, precedence, chaining.
Sources
- Newman's README (its command line options, library API, run events and reporters) (Apache-2.0 (the package's LICENSE.md, read 2026-11-20); facts and ideas only)
- Postman Learning Center (Postman's documentation of its app, collections, variables and scripts) (Not stated as open: Postman's own documentation (read 2026-11-20); facts and ideas only)
- The Express documentation (CC BY-SA 3.0 US (the site's footer, read 2026-11-15); facts and ideas only)