Ultimate Postman Cheat Sheet
Ultimate Postman Cheat Sheet
A reference for API testing, automation scripts, and Newman CLI.
1. Variables & Scope
Access and modify variables within the "Pre-request Script" or "Tests" tabs.
Get Variables
Set Variables
Remove Variables
2. Scripting & Parsing
Handling responses and debugging logic.
Parse JSON Response
Convert the response body into a JavaScript object.
Parse XML Response
Logging
Open the Postman Console (Ctrl+Alt+C) to view these logs.
3. Assertions (pm.test)
Writing tests to validate API behavior.
Status Code Check
Response Time Check
Check JSON Body Content
Check Headers
4. Dynamic Variables
Postman can generate random data inside the Request Builder using {{...}} syntax.
| Variable | Output |
|---|---|
{{$guid}} | v4 unique identifier |
{{$timestamp}} | Current UNIX timestamp |
{{$randomInt}} | Random integer (0-1000) |
{{$randomEmail}} | Random fake email |
{{$randomFirstName}} | Random first name |
{{$randomCity}} | Random city name |
5. Workflows (Chaining Requests)
Control the order of execution in the Collection Runner.
Set Next Request
Jump to a specific request by name.
Stop Execution
Stop the runner immediately.
In a "Login" request test, check if login failed. If yes, use setNextRequest(null) to stop the tests so you don't run 50 failed requests.
6. Newman CLI
Run Postman collections from the command line (CI/CD pipelines).
Installation
Run Collection
Run with Environment
Load environment variables file.
Generate Report (HTML)
Requires newman-reporter-html.
Bail on Failure
Stop the pipeline immediately if a test fails.
Post a Comment