How do you work in Postman?
In Postman, requests are grouped into collections and whatever changes between runs (environment address, token, IDs) moves into variables. Pre-request scripts prepare data; Post-response scripts write assertions and save values for later requests. Nothing is hard-coded, and assertions describe the contract, not just the status. Secrets stay out of the shared value (formerly initial value), which syncs to the cloud, and go to the local value or Vault.
QA Fundamentals · Manual API testing
A 40-request collection works for you and is red on CI. What went wrong?
A colleague sends a Postman collection and everything is red for you: requests go to someone else's environment, the token is expired, request 12 has an empty ID that was "supposed to remain" from request 11. Each cause is easy to fix separately, but together they show that the collection was built as a set of separate requests, not as a test. This lesson is about what working in Postman consists of, how variables and scripts work there and what turns a collection from a notebook into a repeatable test.
How it works and why. Postman keeps requests in collections (with folders) and moves whatever changes between runs into variables: the environment address, the token, the ID of a created resource. Variables exist in several scopes, and on a name clash the narrower one wins: local over data, data over environment, environment over collection, collection over global. Thanks to this a collection does not depend on the environment: {{baseUrl}} is taken from the selected environment, and switching dev to staging changes one place instead of forty requests.
Variable scope and precedence
Two things people often mix up. First, a variable has a shared value (formerly initial value; synced to the cloud and visible to those you share the collection with) and a local value (formerly current value; stays local). Secrets such as a token are kept in the local value, and better still in a secret variable type or a vault. Second, scripts come in two kinds: the Scripts tab has Pre-request (runs before sending: prepare data, compute a signature) and Post-response (after the response: assertions, saving values). The latter used to be called the Tests tab. Scripts can be attached to a collection or a folder, and then they run for every request inside (the collection first, then the folder, then the request itself).
Example: from a notebook collection to a chain. Before: every request has the full address and the token written in, and there is a single check, "status is not 4xx"; the ID of a resource for the next request was copied by hand. After: the address is in {{baseUrl}}, authorisation (Bearer {{token}}) is configured once at the collection level, and the requests are linked by variables:
A chain of requests in a collection
The script in the "Create transfer" request turns it from "sent and looked" into a check:
// Scripts → Post-response of the "Create transfer" request
pm.test('201 Created', () => pm.response.to.have.status(201));
const ct = pm.response.headers.get('Content-Type');
pm.test('JSON', () => pm.expect(ct).to.include('application/json'));
const body = pm.response.json();
pm.test('amount is stored', () => pm.expect(body.amount).to.eql(100.5));
pm.test('fast enough', () => pm.expect(pm.response.responseTime).to.be.below(800));
// for the next requests: GET /transfers/{{transferId}}
pm.collectionVariables.set('transferId', body.id);
What matters here. The assertions describe the contract (status, content type, value), not "something came back". The response time is compared with a threshold that has a justification (an SLO), and 800 is only an example. Saving transferId makes the next requests independent of a human: Get and Delete take the ID from the variable. The Login request puts the token into the environment, and the collection on CI gets it the same way, without copying. For a table of input values (different amounts and currencies) use Collection Runner with a CSV or JSON file: each row is one iteration, and the values are available as data variables.
Limits and alternatives. Postman is good for exploring an API, manual checks and quick regression sets, but it has limits. A collection is a big JSON that compares poorly in code review, and scripts live in a sandbox with a limited set of libraries. For CI Postman recommends Postman CLI; Newman is still found in existing pipelines, but new ones should take the CLI. When there are many tests, they need complex data or code shared with the rest of the automation, teams move to code in a repository: Playwright or REST Assured. Postman then stays for exploration and reproducing bugs. Secrets are a separate matter: a collection that is exported or published must not contain real tokens and passwords in the shared value.
Common mistakes.
- Hard-coding the address and the token in requests: the collection is tied to one environment, and the token expires and ends up in an export.
- Asserting only the status: the test does not see wrong values and types in the body.
- Depending on manual copying of IDs between requests: the collection cannot be re-run, nor run on CI.
- Keeping secrets in the shared value: they sync to the cloud and become visible to those you share the collection with.
- Creating data and not cleaning up: after twenty runs the environment holds hundreds of "test" records. Add a DELETE at the end of the chain.
- Mixing up variable scope: a local value "overrides" the environment, and the request goes somewhere unexpected.
Check yourself
The Login request puts the token into the variable token, yet Create transfer still answers 401. Name two causes related to variables.
Answer
The variable was written in one scope (say, collection), while the request reads another one with the same name that has higher precedence (an environment with a stale token). Or the token did not reach the Authorization header (the request has No Auth set or does not inherit the collection authorisation), or the variable is named differently (letter case in the name matters).
Why use Collection Runner with a data file instead of copying a request ten times?
Answer
One request with different inputs is a table-driven test: each row of CSV or JSON gives an iteration with its own variables. Changes are made in one place, new cases are added as a row in the file, and the report shows exactly which iteration failed.