HTTP status codes every API tester should know

There are dozens of HTTP status codes. In API testing you'll see about fifteen of them over and over. Knowing what each one usually means in practice, not just its name, makes debugging a lot faster. This is that list, with the mix-ups that cost people the most time.

2xx: it worked

CodeNameWhat it usually means
200OKThe request worked and there's a body
201CreatedA POST created something. Often with a Location header pointing at it
202AcceptedQueued for later. The work isn't done yet, so don't assert on the result
204No ContentWorked, and there's deliberately no body. Common for DELETE and some PUTs
JavaScript
pm.test('creates the order', () => {
  pm.expect(pm.response.code).to.equal(201);
});

3xx: look elsewhere

CodeNameWhat it usually means
301 / 308Moved Permanently / Permanent RedirectUpdate the URL in your collection
302 / 307Found / Temporary RedirectOften a login redirect: you're not authenticated
304Not ModifiedYour cached copy is still good (you sent If-None-Match or If-Modified-Since)

An API that answers a JSON request with a 302 to a login page is telling you your session or token isn't being accepted. Whether redirects are followed is a per-request setting in the request's Settings tab.

4xx: you sent something wrong

CodeNameWhat it usually means
400Bad RequestMalformed JSON, a missing required field, a wrong type
401UnauthorizedNo credentials, or invalid ones. Despite the name, it's about authentication
403ForbiddenValid credentials, not allowed to do this
404Not FoundWrong path, or the resource doesn't exist. Some APIs also use it to hide resources you can't see
405Method Not AllowedThe path exists, the method doesn't. POST where only GET works
409ConflictDuplicate, or the resource changed since you read it
415Unsupported Media TypeMissing or wrong Content-Type, usually not application/json
422Unprocessable ContentThe JSON is valid but the values aren't: validation errors
429Too Many RequestsRate limited. Check the Retry-After header

Test the 4xx responses on purpose. A good API test suite has as many tests for bad input as for good:

JavaScript
pm.test('rejects a negative quantity with a clear error', () => {
  pm.expect(pm.response.code).to.equal(422);
  pm.expect(pm.response.json().errors[0].field).to.equal('qty');
});

5xx: the server failed

CodeNameWhat it usually means
500Internal Server ErrorA bug. Unhandled exception, nil pointer, failed query
502Bad GatewayA proxy or load balancer couldn't get a valid answer from the service behind it, often during a restart
503Service UnavailableOverloaded, in maintenance, or not ready yet
504Gateway TimeoutThe service behind the proxy took too long

The distinction that matters for CI: 502, 503 and 504 are often transient: a deploy, a restart, a cold start. A 500 is almost always a real bug. That's why the Requestarium CLI's --retries option retries 502, 503 and 504 (and connection errors), but never a 500:

Terminal
requestarium run-collection "Orders API" --env Staging --retries 2

More in How to deal with flaky API tests.

A safety net for every request

Add one rule to a whole collection so no request can silently return a 5xx: in the collection's Tests tab, add Status code, less than, 500. It applies to every request inside, on top of their own checks. See API assertions without writing code.

And in the CLI's JUnit report, a request with no tests at all still gets a test case that checks its status is below 400, so nothing slips through.