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.
0
0
Flow creation in Postman
Introduction
You want to test a login API, then use the token in the next request automatically.
You need to check if creating a user works before updating that user.
You want to run multiple API calls in order and verify each response.
You want to automate repetitive API tests without manual clicks.
Syntax
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.
Examples
This example checks the response status and saves a token to use later.
Postman
// 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);
This adds the saved token as an Authorization header before the second request runs.
Postman
// In Pre-request Script of second request
pm.request.headers.add({key: 'Authorization', value: `Bearer ${pm.environment.get('token')}`});Sample Program
This flow logs in first, saves the token, then uses it to get the user profile and checks the response.
Postman
// 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'); });
OutputSuccess
Important Notes
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.
Summary
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.