Introduction
We check the status code to make sure the server responded correctly. It tells us if our request worked or if there was a problem.
Jump into concepts and practice - no test required
We check the status code to make sure the server responded correctly. It tells us if our request worked or if there was a problem.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); });
The number 200 means OK or success.
You can change 200 to other codes like 404 (Not Found) or 500 (Server Error).
pm.test("Status code is 404", function () { pm.response.to.have.status(404); });
pm.test("Status code is 201", function () { pm.response.to.have.status(201); });
pm.test("Status code is 500", function () { pm.response.to.have.status(500); });
This test checks if the server responded with status code 200, meaning success.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); });
Always check the status code before checking the response body.
Common status codes: 200 (OK), 201 (Created), 400 (Bad Request), 401 (Unauthorized), 404 (Not Found), 500 (Server Error).
Status code tells if the request worked or failed.
Use pm.response.to.have.status(code) to check it in Postman tests.
Checking status code helps catch errors early.
200 usually mean in a Postman response?pm.response.to.have.status(code).pm.response.to.have.status() [OK]pm.test('Check status', () => {
pm.response.to.have.status(201);
});pm.test('Status is 200', () => {
pm.response.to.have.status = 200;
});= which assigns a value instead of calling status(200) as a function.pm.response.to.have.status(200); to assert status code.status().pm.expect with a boolean expression checking if code is 200 or 201, which is correct.