20Postman Deep-Dive
What you will master here
- Every configuration option in a Postman request
- Authentication: API key, Basic, Bearer/JWT, Digest, AWS, NTLM, OAuth1 vs OAuth2
- JWT internals — header.payload.signature
- OAuth 1.0a vs OAuth 2.0 — the actual difference
- Collections, environments, variables, scopes
- Pre-request scripts, test scripts (the "Tests" tab)
- Collection runner, data-driven runs, Newman (CLI), CI integration
- Mock servers, monitors, public workspaces
20.1 Anatomy of a Postman request
| Tab | What lives here |
|---|---|
| Params | URL query string (?key=value), URL path variables (:id) |
| Authorization | Auth type + credentials (see 17.2) |
| Headers | Request headers (Content-Type, custom) |
| Body | JSON / form-data / x-www-form-urlencoded / raw / binary / GraphQL |
| Pre-request Script | JS that runs before sending — set variables, compute signatures |
| Tests | JS that runs after response arrives — assertions, capture variables |
| Settings | Per-request: SSL verify, automatic redirect, timeout, cookies |
20.2 Authorization types — exhaustive
| Type | What it sends | When to use |
|---|---|---|
| No auth | Nothing | Public endpoints |
| API Key | Key passed as header or query param (configurable) | Simple API key auth (Stripe, Twilio) |
| Bearer Token | Authorization: Bearer <token> | JWT, OAuth2 access tokens |
| Basic Auth | Authorization: Basic base64(user:pass) | Legacy admin endpoints, internal tools |
| Digest Auth | Challenge-response, MD5 hashed | Old enterprise systems |
| OAuth 1.0 | Header with nonce, timestamp, signature, etc. | Legacy (Twitter v1, old APIs) |
| OAuth 2.0 | Access token obtained via grant flow; sent as Bearer | Modern OAuth (Google, GitHub, almost all) |
| Hawk Auth | HMAC-based, similar to OAuth1 | Mozilla / Atlassian internal |
| AWS Signature | AWS Sig v4 calculated automatically | AWS API calls (S3, DynamoDB, etc.) |
| NTLM | Windows-domain challenge auth | On-prem Microsoft systems |
| Akamai EdgeGrid | Custom Akamai header set | Akamai's APIs |
| ASAP | Atlassian Service Auth Protocol | Atlassian internal |
| Inherit auth from parent | Use folder/collection's auth | Apply once at collection, inherit in every request |
20.3 JWT — what's inside that token
A JWT (JSON Web Token) is just three base64-url chunks joined by dots:
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0Iiwicm9sZSI6ImFkbWluIn0.4Adcj3UFYzPUVaVF43FmMab6RlaQD8A9V8wFzzht-KQ └──── header ────┘ └──────── payload ────────┘ └────────── signature ──────────┘
| Part | What it holds | Decoded example |
|---|---|---|
| Header | Algorithm + token type | { "alg": "HS256", "typ": "JWT" } |
| Payload | Claims about the user / token | { "sub": "1234", "role": "admin", "exp": 1735689600 } |
| Signature | HMAC of header.payload using a secret | Binary, base64url |
Standard claims (RFC 7519)
iss— issuersub— subject (usually user id)aud— audience (intended recipient)exp— expiry (unix seconds)nbf— not beforeiat— issued atjti— token id (for revocation)
CriticalThe signature ONLY proves the token wasn't tampered with — it does NOT encrypt. Anyone with the token can decode it:
echo "eyJzdWIi..." | base64 -d. Never put secrets in JWT payload.Using a JWT in Postman
- POST to
/auth/loginwith credentials - In the Tests tab:
pm.collectionVariables.set('token', pm.response.json().access_token) - On other requests, Authorization → Bearer Token →
{{token}}
20.4 OAuth 1.0a vs OAuth 2.0 — the real difference
OAuth 1.0a (legacy)
- Stateless signing on every request
- Client signs each request with a consumer secret using HMAC-SHA1
- No reliance on TLS — built to work over plain HTTP
- Header contains: nonce, timestamp, signature, signature_method, consumer_key, token, version
- Complex — hard to implement correctly
- Used by old Twitter API, some legacy systems
OAuth 2.0 (modern)
- Token-based — get an access token, send it on every request
- Relies on TLS for transport security; tokens are bearer tokens
- Multiple grant flows: authorization code, client credentials, device code, refresh token, (deprecated) password, (deprecated) implicit
- Much simpler client implementation
- De facto standard for modern APIs
OAuth 2.0 grant flows (Postman supports all)
| Flow | Used for | How it works |
|---|---|---|
| Authorization Code | User-facing web apps | User logs in on the provider, returns a code, client exchanges code for token |
| Authorization Code + PKCE | Mobile / SPA | Same + Proof Key for Code Exchange — protects public clients (no secret) |
| Client Credentials | Server-to-server | Service uses its own client_id + secret to get a token — no user involved |
| Refresh Token | Renewal | Exchange long-lived refresh for short-lived access |
| Device Code | TVs / CLI tools | Display code, user visits URL on phone, then token issued |
| Resource Owner Password | Legacy / trusted | Deprecated — pass username+password directly. Avoid. |
| Implicit | Old SPA | Deprecated — replaced by Auth Code + PKCE |
Interview one-liner"OAuth1 signs every request with HMAC; OAuth2 obtains an access token once and sends it as a Bearer header per request. OAuth2 wins on simplicity but depends on TLS for security."
20.5 Variables & scopes
| Scope | Lifetime | Use for |
|---|---|---|
| Global | Workspace-wide | Truly cross-collection constants (rare) |
| Collection | One collection | baseUrl, apiVersion, shared tokens |
| Environment | Per environment (dev/stg/prod) | URLs, credentials per env |
| Data | Per row in a CSV/JSON data file (during run) | Data-driven iteration |
| Local | Single request | Captured response values used by chained next request |
Reference: {{baseUrl}}/users/{{userId}}. Resolution order: data → local → environment → collection → global.
20.6 Pre-request & Tests scripts
Pre-request — runs BEFORE sending
// Compute a signed HMAC header
const ts = Date.now();
const body = pm.request.body.raw || '';
const sig = CryptoJS.HmacSHA256(ts + body, pm.environment.get('signingKey')).toString();
pm.request.headers.add({ key: 'X-Timestamp', value: ts });
pm.request.headers.add({ key: 'X-Signature', value: sig });
Tests — runs AFTER response (assertions + capture)
// Status assertion
pm.test('status 200', () => pm.response.to.have.status(200));
// JSON schema assertion
pm.test('response has user', () => {
const body = pm.response.json();
pm.expect(body).to.have.property('id');
pm.expect(body.email).to.match(/@/);
});
// Capture value for next request
const token = pm.response.json().access_token;
pm.collectionVariables.set('token', token);
// Conditional next request
postman.setNextRequest('Verify Token'); // skip to a specific request in the run
// postman.setNextRequest(null); // stop the runner
20.7 Collections, folders, runner
- Collection — a group of related requests with optional collection-level auth and variables
- Folder — nested grouping inside a collection (e.g. "Users", "Orders")
- Collection Runner — runs requests sequentially with delay, iterations, data file. Outputs per-request results.
Data-driven runs
Upload a CSV / JSON file. Postman runs the collection once per row, with each row's columns available as {{column}}.
// users.csv email,role alice@test.com,admin bob@test.com,user carol@test.com,viewer
Request body becomes {"email": "{{email}}", "role": "{{role}}"}. Three iterations run automatically.
20.8 Newman — Postman in CI
Newman is Postman's CLI. Export the collection JSON, commit it, and run on CI.
npm i -g newman newman run my-collection.json -e staging.postman_environment.json \ --iteration-data users.csv \ --reporters cli,htmlextra,junit \ --reporter-junit-export results/junit.xml
# GitHub Actions
- uses: actions/setup-node@v4
with: { node-version: '20' }
- run: npm i -g newman newman-reporter-htmlextra
- run: newman run my-collection.json -e prod.json --reporters cli,htmlextra
- uses: actions/upload-artifact@v4
if: always()
with: { name: newman-report, path: newman/ }
20.9 Mock servers and monitors
- Mock server — Postman hosts a fake endpoint that returns saved example responses. Useful for parallel front-end development.
- Monitor — schedule a collection to run on Postman's cloud (every N minutes). Sends alerts on failures. Lightweight uptime/synthetic monitoring.
20.10 When to use Postman vs Playwright API vs REST Assured
| Use Postman when | Use Playwright/REST Assured when |
|---|---|
| Exploring an API manually | Automated regression in CI |
| Non-engineers need to test | Tests live alongside app code |
| Demo / share via public workspace | Tight integration with UI tests |
| Light scheduled monitoring | Heavy load, parallel suites |
| Quick ad-hoc data-driven runs | Type-safe, reviewable test code |
Module 17 — Postman interview Q&A bank
What are the auth types available in Postman?
No auth, API Key, Bearer Token, Basic, Digest, OAuth 1.0, OAuth 2.0, Hawk, AWS Signature, NTLM, Akamai EdgeGrid, ASAP, and Inherit-from-parent. Choose based on what the API expects.
What is a JWT?
JSON Web Token — base64-url-encoded header + payload + signature, joined by dots. The signature uses a secret + algorithm (e.g. HS256) to sign header+payload, proving tampering hasn't happened. Payload is readable to anyone — never put secrets in it.
What are the standard JWT claims?
iss (issuer), sub (subject), aud (audience), exp (expiry), nbf (not before), iat (issued at), jti (token id). Defined by RFC 7519.
What's the difference between OAuth 1.0 and OAuth 2.0?
OAuth1 signs every request with HMAC using a consumer secret — no TLS dependency, but the signing is complex. OAuth2 obtains an access token via one of several grant flows and sends it as a Bearer header per request — simpler, but depends on TLS for transport security. Modern APIs use OAuth2.
What's the OAuth2 Authorization Code flow?
User clicks "Sign in with X", redirected to provider, logs in, redirected back to your app with a one-time code, your server exchanges the code (using its client secret) for an access token. Used for web apps with a server backend.
What is PKCE and why does it exist?
Proof Key for Code Exchange. Public clients (mobile apps, SPAs) can't keep a client secret. PKCE replaces the secret with a per-request code_verifier the client generates, hashes (code_challenge) and sends with the auth request, then proves at token exchange. Prevents intercepted auth codes from being usable.
What's a Bearer token?
A credential passed in the
Authorization header as Bearer <token>. Whoever holds the token can use it — there's no other proof of identity. Hence "bearer". Standard for OAuth2 access tokens.How do you chain requests in Postman?
In the Tests tab of request 1, capture a value:
pm.collectionVariables.set('userId', pm.response.json().id). In request 2's URL or body, reference {{userId}}. Run via Collection Runner so they execute in order.Difference between pre-request and tests scripts?
Pre-request runs before sending — generate signatures, set headers, compute timestamps. Tests runs after the response — assertions and capturing variables for next requests.
What is Newman?
Postman's command-line runner. Reads exported collection + environment JSON, runs them headlessly, supports iteration data, multiple reporters (CLI, HTML, JUnit). Used to run Postman tests in CI without a desktop GUI.
Variable resolution order?
Data > Local > Environment > Collection > Global. Data file variables (during a runner iteration) override everything else; globals are fallback.
How do you do data-driven testing in Postman?
Provide a CSV or JSON file to Collection Runner. Each row becomes a set of variables; the collection runs once per row. Reference
{{columnName}} in URL/body/headers.What is a Postman mock server?
A cloud-hosted endpoint that returns saved example responses. Pin examples to specific URLs/methods; calls to the mock match and return them. Useful for parallel frontend development before a real API exists.
What is a Postman monitor?
A scheduled cloud run of a collection. Pings endpoints on a cadence (every 5 min/hour). Sends alerts on failure — lightweight uptime / contract monitoring.
When would you NOT use Postman?
When you want full code-review on tests, run them alongside UI tests, share fixtures between API and UI suites, or need a typed test language. Use Playwright's
request fixture or REST Assured in those cases.How do you keep secrets out of Postman exports?
Mark variables as "secret" type and store in a local environment (not synced) or external vault. For Newman in CI, pass via
--env-var "TOKEN=$TOKEN" using CI secrets. Never commit environment JSON containing real tokens.What's the difference between collection auth and request auth?
Collection-level auth applies to every request that inherits ("Inherit auth from parent"). Override at folder or request level when an endpoint needs different auth. Set common auth once, override exceptions.
How would you script Newman to fail CI when tests fail?
Newman exits non-zero on test failures by default — CI step fails automatically. Use
--bail to stop on first failure, or --suppress-exit-code only if you want CI to continue (rare).