💡 If you like this website, please share it with your friends and network! 🚀
Back to All Questions
Question 22 of 100
Basic API Testing
Beginner

Q22: How Do You Verify API Responses in Postman?

🎯Core Concept

How Do You Verify API Responses in Postman?

Key Takeaways & Architecture Summary

  • Use the "Tests" tab to write custom JavaScript validation assertions.
  • Leverage the built-in pm.test() library and Chai assertion utilities.
  • Confirm status codes, response times, headers, and exact payload values.

Direct Answer Summary

To verify responses in Postman, you write assertions in the "Tests" tab of the request. Using the `pm.test` wrapper and `pm.expect` library, you can programmatically validate that the status code is correct, response latency meets SLAs, headers are secure, and JSON properties contain correct values.

⚠️ Senior Engineering Warning (Red Flag)

Never verify payloads using loose substring searches (e.g. responseText.includes("success")). If "success" appears in a failure message like "transaction was not a success", your test will pass falsely.

💡 STAR Architectural Explanation & Pro Tip

These verification scripts run automatically in the Postman runner sandbox. Any assertion failure marks the test run as failed, enabling quick integration checks in deployment pipelines.

RestAssuredTest.java
Rest-Assured + Java
// Postman script: Multi-layered response validation
pm.test("Status is 200 and role is Admin", function () {
    pm.response.to.have.status(200);
    
    const data = pm.response.json();
    pm.expect(data.id).to.equal(1024);
    pm.expect(data.role).to.equal("admin");
});