What Is a 422 Status Code?
A 422 Unprocessable Entity error means the server understood the request, but could not process it due to semantic issues. The structure is valid, but something about the data does not meet requirements.
Common causes include:
- Missing required fields
- Malformed input (e.g., an email missing the
@
) - Business rule violations (e.g., trying to book a past date)
422 Code References
- Rails:
:unprocessable_entity
- Symfony:
Response::HTTP_UNPROCESSABLE_ENTITY
- .NET:
HttpStatusCode.UnprocessableEntity
- Rust:
http::StatusCode::UNPROCESSABLE_ENTITY
- Go:
http.StatusUnprocessableEntity
- Python 3.5+:
http.HTTPStatus.UNPROCESSABLE_ENTITY
- Apache HC:
org.apache.hc.core5.http.HttpStatus.SC_UNPROCESSABLE_ENTITY
- Angular:
@angular/common/http/HttpStatusCode.UnprocessableEntity
422 Status Code Example
Here is a typical request and response scenario that triggers a 422 error:
Request
POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
{
"name": "",
"email": "example.com"
}
Response
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{
"error": "Unprocessable Entity",
"message": "Validation failed",
"details": [
{
"field": "name",
"message": "Name is required"
},
{
"field": "email",
"message": "Invalid email address"
}
]
}
This error occurs because the submitted JSON payload does not meet validation rules. The server returns a 422 with helpful messages so the client can fix and resubmit the request.
What Causes a 422 Status Code?
- Validation errors: Input fails validation rules, such as a required field being empty or incorrectly formatted.
- Business logic errors: The request violates a rule, such as using a duplicate email or an invalid state transition.
- Authorization issues: The action may not be permitted for the current user, depending on the endpoint logic.
- Data conflicts: The request may conflict with existing data or application constraints.
How to Fix a 422 Status Code
- Review the request payload: Confirm it includes all required fields and that data is well-formed.
- Validate on both client and server: Use front-end validation where possible and ensure robust server-side validation.
- Return clear error messages: Help users and developers identify what went wrong and how to fix it.
- Use debugging tools: Logs, dev tools, and HTTP interceptors can help trace bad requests.
Additional Resources
- Web development resources
- SEO insights from WebFX
- Web development services
- SEO services
- MDN Web Docs
- W3Schools HTTP Status Reference
Marketing Tips for Niche Industries
- Turn Clicks into Contracts with High-ROI PPC for Manufacturers
- Urgent Care Marketing Ideas: 5 High-ROI Tactics
- Vision Care Industry Statistics
- WebFX: Your Education Digital Marketing Agency
- What is Patient Acquisition Cost & How Do You Calculate It?
- Why Auto Part Retailers Need Digital Marketing
- Why Digital Marketing is Essential for Auctioneers
- Your 2025 Guide to Digital Marketing for Home Security Companies
- Your Guide to Digital Marketing for Exercise Equipment Companies