Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What 422 Means

The request is well formed: the JSON parses, the content type is right, the method is allowed. The server still cannot act on it because the content breaks a rule. Think of a form that was delivered correctly but filled in wrong.

The code was first defined for WebDAV as "Unprocessable Entity". RFC 9110, the current HTTP specification, moved it into core HTTP and renamed it "Unprocessable Content". Both names refer to the same 422.

Typical Causes

  • Missing required field: a name, a password, or an ID left out.
  • Wrong type: the string "10" where the API expects the number 10.
  • Wrong format: a date written as 31/12/2026 where ISO format is expected, or an invalid e-mail address.
  • Value out of range: a quantity of zero, a text longer than allowed.
  • Business rules: a user name that is taken, a start date after the end date.

Where You Meet It

Many web frameworks return 422 when validation fails. Laravel does so for JSON requests that fail its validator, FastAPI for requests that do not match the declared model, and Ruby on Rails applications commonly use it when a record cannot be saved. Many public APIs follow the same convention.

Read the Response Body

The status code says that something failed; the body says what. Fetch it with headers:

curl -i -X POST https://api.example.com/v1/users \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"name":"","age":"ten"}'

A typical answer lists the fields:

HTTP/1.1 422 Unprocessable Content
Content-Type: application/json

{"message":"Validation failed","errors":{"name":["This field is required."],"age":["Must be a number."]}}

The exact shape depends on the framework, but the field names are almost always there. For a larger body, keep it in a file and send it with -d @./data.json; more examples are in curl POST request.

422 Compared with 400

CodeProblemExample
400Cannot be readBroken JSON
415Wrong format typeForm data, not JSON
422Read, but invalidEmpty name

Some APIs use 400 for both cases. Read their documentation; the fix is the same. The other two codes are covered in 400 Bad Request and 415 Unsupported Media Type.

How to Fix It as a Client

  1. Read the field names in the response body.
  2. Compare your request with the API's documentation for that endpoint: required fields, types, formats.
  3. Send the corrected request. A 422 does not change by retrying the same data.

When Your Own Application Returns 422

The web server only passes the code through, so its logs show the status and nothing more. Look in the application log, and make sure the response body names the failing fields: a bare 422 with no body leaves the client guessing. Log validation failures at a low level, so a sudden rise is visible without filling the disk.

If a form on a website fails with 422 only after it has been open for a while, an expired session or security token can be the reason in some frameworks, such as Ruby on Rails; reloading the page gives the form a new one.

Was this answer helpful?
Loading...