Flow creation helps you automate a series of API requests and checks in Postman. It saves time and ensures your APIs work as expected step-by-step.
Flow creation in Postman
1. Create a new collection in Postman. 2. Add requests in the order you want them to run. 3. Use 'Tests' tab in each request to write JavaScript code for checks. 4. Use 'Pre-request Script' tab to set variables or prepare data. 5. Run the collection using the Collection Runner or Monitor.
Each request can pass data to the next using environment or collection variables.
Tests use JavaScript and Postman API like pm.test() and pm.response.
// In Tests tab of first request pm.test('Status is 200', () => { pm.response.to.have.status(200); }); // Save token for next request const jsonData = pm.response.json(); pm.environment.set('token', jsonData.token);
// In Pre-request Script of second request
pm.request.headers.add({key: 'Authorization', value: `Bearer ${pm.environment.get('token')}`});This flow logs in first, saves the token, then uses it to get the user profile and checks the response.
// Collection with two requests // Request 1: Login API // Tests tab: pm.test('Login success', () => { pm.response.to.have.status(200); const data = pm.response.json(); pm.environment.set('authToken', data.token); }); // Request 2: Get user profile // Pre-request Script: pm.request.headers.add({key: 'Authorization', value: `Bearer ${pm.environment.get('authToken')}`}); // Tests tab: pm.test('Profile fetched', () => { pm.response.to.have.status(200); pm.expect(pm.response.json()).to.have.property('username'); });
Always clear or reset environment variables before running flows to avoid stale data.
Use descriptive test names to understand results easily in reports.
Flows help catch errors early by testing APIs in real usage order.
Flow creation automates API tests in Postman by chaining requests.
Use Tests and Pre-request Scripts to pass data and check responses.
Run flows with Collection Runner to see step-by-step results.
Practice
Solution
Step 1: Understand flow creation in Postman
Flow creation means linking API requests so they run one after another automatically.Step 2: Identify the purpose of chaining requests
Chaining helps automate tests by passing data between requests and checking responses.Final Answer:
To automate API tests by chaining multiple requests -> Option AQuick Check:
Flow creation = automate chained API tests [OK]
- Confusing flow creation with UI design
- Thinking flow creates database backups
- Assuming flow writes SQL queries
Solution
Step 1: Identify where to save data after a request
The Tests script runs after a request and can save response data to variables.Step 2: Understand data passing in flows
Saved variables from Tests can be used in the next request's Pre-request Script or URL.Final Answer:
Tests -> Option CQuick Check:
Data passing happens in Tests script [OK]
- Using Body to pass data between requests
- Confusing Pre-request Script as data saver
- Trying to pass data via Headers
pm.environment.set('token', pm.response.json().access_token);What will be the value of
token after this runs if the response JSON is {"access_token": "abc123"}?Solution
Step 1: Extract value from response JSON
The code accesses the 'access_token' key from the JSON response, which is "abc123".Step 2: Store value in environment variable
pm.environment.set saves "abc123" as the value of 'token'.Final Answer:
"abc123" -> Option BQuick Check:
token = "abc123" after set [OK]
- Assuming token becomes undefined
- Confusing the whole JSON with the value
- Expecting null instead of actual token
pm.request.headers.add({key: 'Authorization', value: 'Bearer ' + pm.environment.get('token')});But the API returns 401 Unauthorized. What is the likely error?
Solution
Step 1: Check if token variable exists
If 'token' is missing or empty, the Authorization header will be invalid.Step 2: Verify header syntax and casing
Header keys are case-insensitive, and 'Bearer' is case-sensitive but usually uppercase works fine.Step 3: Confirm method usage
pm.request.headers.add is valid to add headers dynamically.Final Answer:
The token variable is not set or is empty -> Option DQuick Check:
Missing token causes 401 Unauthorized [OK]
- Changing header key case unnecessarily
- Lowercasing 'Bearer' keyword
- Thinking pm.request.headers.add is invalid
Solution
Step 1: Save token after login request
Use Tests script in first request to extract token from response and save it to environment variables.Step 2: Use token before second request
In second request's Pre-request Script, read the saved token and add it to the Authorization header.Final Answer:
In first request Tests, save token to environment; in second request Pre-request Script, add Authorization header using saved token -> Option AQuick Check:
Save token in Tests, use in Pre-request Script [OK]
- Trying to save token in Body or Headers
- Adding header in Tests instead of Pre-request Script
- Saving token before request runs
Ready to prove it?
Pass the test and this pattern moves unknown
