Verify GET API response using Postman
Preconditions (2)
✅ Expected Result: Response status code is 200 and response body contains expected data
pm.test('Status code is 200', function () { pm.response.to.have.status(200); }); pm.test('Response has expected key', function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('data'); });
The first test checks that the API response status code is 200, which means success.
The second test parses the JSON response body and verifies it contains a key named 'data'.
These simple tests ensure the API is reachable and returns expected data.
Using Postman's built-in JavaScript test framework makes it easy to write and run these checks right after sending the request.
Now add tests to verify the API returns correct data for 3 different user IDs using Postman environment variables and pre-request scripts.
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});pm.test("Response has userId", function () {
pm.expect(pm.response.json().userId).to.exist;
});Pass the test and this pattern moves unknown