Postman Cheatsheet - API Debugging Tool Reference

A single curl proves nothing about auth edge cases or response shapes across environments. Postman turns requests into an environment-aware, scriptable workflow. This reference covers building requests, environment and global variables, test assertions with pm.test, pre-request scripts and dynamic data, plus running whole collections and spinning up Mock servers. Use it when you need repeatable tests for many endpoints, not one-off probes. After reading you automate assertions and re-run suites across dev/staging/prod.

Dev Tools·35 commands·Last updated 2026-07-21

Request Building 7

GET {{base_url}}/api/users
GET request
POST {{base_url}}/api/users
POST request
PUT {{base_url}}/api/users/1
PUT request
DELETE {{base_url}}/api/users/1
DELETE request
Headers: Content-Type: application/json
Set a request header
Body → raw → JSON
JSON request body
Authorization: Bearer {{token}}
Bearer Token auth

Environment Variables 6

{{base_url}}
Reference an environment variable
pm.environment.set("token", "xxx")
Set an environment variable
pm.environment.get("token")
Get an environment variable
pm.environment.unset("token")
Unset an environment variable
pm.globals.set("key", "value")
Set a global variable
pm.variables.get("key")
Get a variable (env/global)

Test Scripts 6

pm.test("Status is 200", () => { pm.response.to.have.status(200) })
Status code test
pm.expect(pm.response.json().name).to.eql("Alice")
JSON field test
pm.response.to.be.json
Response is JSON
pm.response.to.have.header("Content-Type")
Response header test
pm.expect(pm.response.responseTime).to.be.below(500)
Response time test
const json = pm.response.json()
Parse response JSON

Pre-request Scripts 4

pm.request.headers.add({key: "X-Token", value: "xxx"})
Dynamically add a request header
pm.request.body.update("new body")
Modify the request body
const timestamp = Date.now(); pm.environment.set("ts", timestamp)
Generate a timestamp
pm.request.url.addQueryParams({page: 1})
Add a query parameter

Collections & Runner 7

Collection Runner
Run a collection in batch
New Runner
New runner
Set Data File (CSV/JSON)
Data-driven testing
Delay: 1000ms
Request interval
Iterations: 10
Iteration count
Export Collection
Export collection
Import from cURL / OpenAPI
Import from cURL / OpenAPI

Mock & Docs 5

Mock Server
Create a Mock server
Example Responses
Save example responses
Documentation
Generate API docs
Publish Documentation
Publish docs
Monitor
Monitor

Command Examples

Layered assertions: status, field, and response time

pm.test("Status is 200", () => { pm.response.to.have.status(200) }) pm.response.to.be.json pm.expect(pm.response.json().name).to.eql("Alice") pm.expect(pm.response.responseTime).to.be.below(500)

The first confirms the channel, the second that the body parses, and the last two the contract and the timing budget. The response-time assertion catches slow regressions that the status check can never see.

Injecting a dynamic value in the pre-request script and using it in the test

const timestamp = Date.now(); pm.environment.set("ts", timestamp) pm.request.headers.add({key: "X-Token", value: "xxx"}) pm.request.url.addQueryParams({page: 1})

All three take effect before the request goes out: setting an environment variable, adding a header, appending query parameters. Adding headers this way suits values generated per call, such as caller identifiers, and is more controllable than typing them into the UI.

Building requests: variable-driven URLs and methods

GET {{base_url}}/api/users POST {{base_url}}/api/users PUT {{base_url}}/api/users/1 DELETE {{base_url}}/api/users/1

Pulling the host into base_url is what makes environment switching possible: the same collection runs against dev, staging and prod by changing that one value, with the requests untouched.

Data-driven runs: CSV rows determine real iteration count

Set Data File (CSV/JSON) Iterations: 10 Delay: 1000ms

In data-driven mode the effective count is the smaller of iterations and data rows, and leftover rows never run. Delay is not optional insurance: create, update and delete requests with real ordering dependencies read state that the previous step has not yet committed.

Common Pitfalls

  • Values written with pm.globals.set are shared by every environment, so an address or credential set for one easily leaks into another. Keep sensitive values in the Environment and exclude it from version control.
  • Body rewrites in a pre-request script happen before sending and override anything typed into the Body tab, which produces the confusing situation where the payload looks filled in but never arrives.
  • Setting Delay to 0 makes dependent requests fail intermittently, and flaky red builds are far harder to diagnose than deterministic ones. Any collection with state transitions needs a gap.
  • Mock Server returns exactly the example responses you saved. If the backend’s real shape changes and the examples are not updated, the frontend keeps developing against a contract that no longer exists.
  • Credentials hard-coded into a request travel with Export Collection and end up in version control. Inject them from environment variables instead.

Tips

  • Variables come in Environment (current) and Global; put secrets in Environment.
  • Collection Runner plus a CSV data file enables data-driven testing.
  • Mock Server suits parallel frontend dev when the backend isn't ready yet.

FAQ

How should I split environment variables from global variables?

Split them by scope and sensitivity. Values tied to one environment — base URLs, credentials — belong in the Environment, because switching between dev, staging and prod replaces them wholesale without disturbing the others. Anything needed across every environment goes in Global, such as formatting conventions or backend-agnostic defaults. Sensitive values belong only in the Environment, and that environment must stay out of version control. On the read side pm.variables.get is usually easier since it resolves across environment and global by precedence; on the write side, use pm.environment.set or pm.globals.set to be explicit about the destination.

What makes an assertion actually worth having?

It must separate "the endpoint is broken" from "the data changed". Asserting a 200 status alone is close to worthless, since an empty object also returns 200. The useful shape is layered: assert the status code to confirm the channel, then assert a field with pm.expect(pm.response.json().name).to.eql("Alice") to confirm the contract, and add a response-time assertion to catch performance regressions. Pick fields that are stable in business terms — an id type, an enum-valued status — not display text that changes on every run.

When do pre-request scripts run compared with test scripts?

They sit at opposite ends of the request lifecycle. Pre-request scripts run before the request is sent and exist to prepare dynamic content: generate a timestamp, add a header, rewrite the body, append query parameters. Test scripts run once the response is back and read that response to assert. A variable produced by a pre-request script is therefore available to the test script, but never the reverse. Passing a token or a unique key forward this way is how chained flows authenticate automatically after login.

How do I turn a collection into a repeatable regression suite?

The key is putting assertions inside the collection instead of eyeballing responses. Run it in bulk with Collection Runner and feed inputs through Set Data File so the same assertions apply across CSV/JSON data rows. Iterations controls repetition and Delay controls the gap between requests — workflows with dependencies need that gap, or the second request reads before the first has written. Exporting the collection then gives you both documentation and a shared assertion suite for the team.

How can frontend work proceed in parallel before the backend exists?

Use Mock Server together with Example Responses. Define each endpoint’s method, path and response shape from the contract first and save those as example responses; the mock server then serves that contract so the frontend integrates normally. Contract-first has a bonus: when the backend is finally implemented, both sides already agree on field names and types, which cuts rework. Save separate examples for success, authentication failure and validation error so the frontend also gets the error states it needs to design against.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us