Postman: variables, scripts and running a collection from the command line
Make one collection work for many servers and many sets of data. Learn variable scopes, pre-request and test scripts, the collection runner and Newman.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a radio with presets. A radio has buttons for your stations. Press one and it tunes in at once. Change the preset and the same button plays a new station.
You do not rebuild the radio.
Variables are the presets. Tom, the tester at Daily List, a to-do list app, changes one setting and the same requests run on a new server. The goal is one collection that works on any server, with any data, without editing each request.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A radio with preset buttons.
- Set
- Run
- Report
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The preset buttons | Variables |
| Changing a preset | Switching the environment |
| A song list for the evening | A data file |
| The radio itself | The collection |
WHERE THIS PICTURE STOPS
- A radio has a few presets, but a collection can hold hundreds of values.
- A preset is chosen by hand, but a script can set a value.
- A radio plays one station, but a runner plays every request.
HOOK
Presets, a song list, one press.
TELL A FRIEND
A radio with presets: change the button, not the radio.
OFTEN MIXED UP WITH Postman: a first collection of API checks. That topic builds the first collection. This one makes it reusable and runs it from a pipeline.
PRACTISE AND KEEP
Sources for this topic — 5 sources
- Market practice
Store and reuse values using variables (Postman docs) ↗ — Postman · Postman docs: variable scopes run from global through collection, environment and data to local, and the narrowest scope wins when a name appears twice (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Verification supplement, 6 November 2026: Actual current v12 page opened: global/collection/environment/data/local scope precedence; local variable value distinct from local scope; shared values used by some cloud features. V27 supplement, 6 November 2026: relevant primary page sections actually opened; implementation-specific current product guidance, not universal standard. See full V27 audit for version and access scope.
- Market practice
Write pre-request scripts to add dynamic behavior (Postman docs) ↗ — Postman · Postman docs: a pre-request script runs before a request is sent, for example to set variable values, and a collection-level script runs before every request in it (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Write scripts to test API response data (Postman docs) ↗ — Postman · Postman docs: test scripts run after the response arrives and check things such as status, structure and field values (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Newman CLI Overview — Postman documentation Latest (v12) ↗ — Postman · Latest(v12)NewmanCLIOverview:legacycollectionv2.1JSON,no further updates/fixes,currentPostmanCLI supportsv3;record runner/collection versions (relevant primary passages opened6November2026).
Opened relevant primary passages on6November2026 via normal web search and document view. Current vendor page opened: Newman supports collectionv2.1 JSON, not current collectionv3; no further updates or fixes. Postman CLI handles v3. Legacy exercises explicitly retain compatible v2.1 files.
- Market practice
Store and reuse values using variables (Postman docs) ↗ — Postman · Postman current v12 variables: scope precedence global→collection→environment→data→local; local value differs from temporary local scope (actual relevant primary passages opened 6 November 2026).
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Verification supplement, 6 November 2026: Actual current v12 page opened: global/collection/environment/data/local scope precedence; local variable value distinct from local scope; shared values used by some cloud features. V27 supplement, 6 November 2026: relevant primary page sections actually opened; implementation-specific current product guidance, not universal standard. See full V27 audit for version and access scope.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.