422 Unprocessable Entity

HTTP response status code 422 Unprocessable Entity is a client error that is returned by the server to indicate that it understands the content type, and the syntax is correct, but it is unable to process the instructions specified by the request.

Usage

When the 422 Unprocessable Entity error message is sent, the server is indicating that it cannot process the instructions contained in the request. The content type is understood, otherwise, a 415 Unsupported Media Type error will have been sent. Additionally, the syntax is valid, otherwise, a 400 Bad Request error will be more explanatory.

An error of this type can be generated if the request includes an XML instruction block as the message body, which is not only correctly formed but understood by the server, yet contains errors in logic that result in a server-side error.

Note

Search engines like Google will not index a URL with 422 Unprocessable Entity response status, and consequently, URLs that have been indexed in the past but are now returning this HTTP status code will be removed from the search results.

Example

In the example, the client uses an XML document to request that task #100 be started. The XML document is recognized and accepted by the server, and it is syntactically correct. For instance, it does not have an error such as an unmatched tag, nor does it contain a properly matched but unrecognized tag. However, the server does not have a record of a task with id=100. Therefore, the request cannot be processed.

Request

POST /requests HTTP/1.1
Host: www.example.re
Content-Type: application/xml
Content-Length: 101

<?xml version="1.0" encoding="utf-8"?>
<request>
   <id>100</id>
   <action>start</action>
</request>

Response

HTTP/1.1 422 Unprocessable Entity
Content-Type: text/html
Content-Length: 150

<html>
  <head>
    <title>Request Failed</title>
  </head>
  <body>
   <p>Task #100 is not recognized and cannot be started.</p>
  </body>
</html>

Code references

.NET

HttpStatusCode.UnprocessableEntity

Rust

http::StatusCode::UNPROCESSABLE_ENTITY

Rails

:unprocessable_entity

Go

http.StatusUnprocessableEntity

Symfony

Response::HTTP_UNPROCESSABLE_ENTITY

Python3.5+

http.HTTPStatus.UNPROCESSABLE_ENTITY

Apache HttpComponents Core

org.apache.hc.core5.http.HttpStatus.SC_UNPROCESSABLE_ENTITY

Angular

@angular/common/http/HttpStatusCode.UnprocessableEntity

Takeaway

The 422 Unprocessable Entity status code is a client error that is sent by the server to indicate that the request is syntactically correct and understood by the server, but semantically invalid.

See also

Last updated: August 2, 2023