Test Overview
This test sends two API requests in Postman. It verifies that data from the first response is correctly used in the second request, ensuring chaining of request data works.
This test sends two API requests in Postman. It verifies that data from the first response is correctly used in the second request, ensuring chaining of request data works.
pm.test("Chaining request data test", function () { // First request: Get user info pm.sendRequest("https://jsonplaceholder.typicode.com/users/1", function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('status', 200); const userId = res.json().id; pm.expect(userId).to.eql(1); // Second request: Get posts by userId from first response pm.sendRequest({ url: `https://jsonplaceholder.typicode.com/posts?userId=${userId}`, method: 'GET' }, function (err2, res2) { pm.expect(err2).to.be.null; pm.expect(res2).to.have.property('status', 200); const posts = res2.json(); pm.expect(posts.length).to.be.greaterThan(0); // Check that all posts belong to userId posts.forEach(post => { pm.expect(post.userId).to.eql(userId); }); }); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test runner is ready to execute the test script | - | PASS |
| 2 | Send first GET request to https://jsonplaceholder.typicode.com/users/1 | Browser/Postman sends HTTP GET request to user API endpoint | Check response status code is 200 | PASS |
| 3 | Parse JSON response and extract userId | Response body contains user data with id=1 | Verify userId equals 1 | PASS |
| 4 | Send second GET request to https://jsonplaceholder.typicode.com/posts?userId=1 using extracted userId | Postman sends HTTP GET request to posts API with userId query parameter | Check response status code is 200 | PASS |
| 5 | Parse JSON response and verify posts belong to userId=1 | Response body contains array of posts with userId=1 | Verify posts array length > 0 and each post.userId equals 1 | PASS |
| 6 | Test ends successfully | All assertions passed, test completes | - | PASS |