How to Validate OTP API Responses in Postman

Postman lets you write automated assertions in the Tests section of a request.

For example, to verify the HTTP status code:

pm.test("Status code is 200", () => {
    pm.response.to.have.status(200);
});

Use the status code specified in your API documentation. A successful verification endpoint might return 200, while an endpoint that creates a resource may return 201. Other valid designs are possible.

To validate the response body:

pm.test("OTP verification is successful", () => {
    const response = pm.response.json();

    pm.expect(response.verified).to.eql(true);
});

This assertion is suitable for the illustrative success response shown earlier.

You can also validate the response time:

pm.test("Response time is within the limit", () => {
    pm.expect(pm.response.responseTime).to.be.below(2000);
});

This example checks whether the response arrives in less than two seconds. Choose a performance threshold based on your application’s requirements and test environment.

Important: Response-time checks in Postman measure the observed request duration. They do not replace proper load testing.

Pages: 1 2 3 4 5 6 7 8 9

Leave a Reply

Your email address will not be published. Required fields are marked *