Test Overview
This test checks how chaining API requests in Postman simulates real user workflows by passing data from one request to the next and verifying the final result.
This test checks how chaining API requests in Postman simulates real user workflows by passing data from one request to the next and verifying the final result.
pm.test("Chained API workflow test", function () { // Step 1: Send first request to create a user pm.sendRequest({ url: 'https://api.example.com/users', method: 'POST', header: { 'Content-Type': 'application/json' }, body: { mode: 'raw', raw: JSON.stringify({ name: 'Alice', role: 'tester' }) } }, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('code', 201); const userId = res.json().id; // Step 2: Use userId from first response to get user details pm.sendRequest({ url: `https://api.example.com/users/${userId}`, method: 'GET' }, function (err2, res2) { pm.expect(err2).to.be.null; pm.expect(res2).to.have.property('code', 200); pm.expect(res2.json()).to.have.property('name', 'Alice'); // Step 3: Update user role pm.sendRequest({ url: `https://api.example.com/users/${userId}`, method: 'PUT', header: { 'Content-Type': 'application/json' }, body: { mode: 'raw', raw: JSON.stringify({ role: 'admin' }) } }, function (err3, res3) { pm.expect(err3).to.be.null; pm.expect(res3).to.have.property('code', 200); // Step 4: Verify updated role pm.sendRequest({ url: `https://api.example.com/users/${userId}`, method: 'GET' }, function (err4, res4) { pm.expect(err4).to.be.null; pm.expect(res4).to.have.property('code', 200); pm.expect(res4.json()).to.have.property('role', 'admin'); }); }); }); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send POST request to create a new user with name 'Alice' and role 'tester' | API server receives user creation request | Response code is 201 Created | PASS |
| 2 | Extract userId from response and send GET request to fetch user details | API server returns user details for userId | Response code is 200 OK and user name is 'Alice' | PASS |
| 3 | Send PUT request to update user's role to 'admin' using userId | API server updates user role | Response code is 200 OK | PASS |
| 4 | Send GET request to verify user's updated role | API server returns updated user details | Response code is 200 OK and role is 'admin' | PASS |