The request is well-formed but contains semantically invalid data.
422 Unprocessable Content (formerly Unprocessable Entity) is the validation-error code. The request was syntactically valid (parseable JSON, all required fields present), but failed business-rule validation: email already exists, age must be positive, cross-field constraint violated. Many APIs use 400 for everything client-side wrong, but 422 is more specific and lets clients distinguish "your JSON is broken" (400) from "your data is logically invalid" (422).
When servers should return it: Return 422 when the request parsed successfully but failed validation. Include detailed per-field errors in the response body.
curl -i -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","age":-5}'
HTTP/2 422
content-type: application/json
{
"error":"validation failed",
"details":[
{"field":"email","reason":"already taken"},
{"field":"age","reason":"must be positive"}
]
}
For a one-page reference of all HTTP status codes, see the HTTP cheat sheet. For testing API responses, try the API Tester tool. For inspecting responses on the command line, the curl cheat sheet covers the most common flags.