Category: Forms and APIs

HTTP 422 Unprocessable Content Despite Valid JSON

Read this guide in Polish

POST is syntaxally correct, but endpoint returns 422 and does not create a record. The server understands the request format, but data values do not meet business validation rules.

How to determine the source of the error

Check the body of the validation response and indicate the specific field and the condition of rejection.

Compare the client and server diagram, especially the enum, dates, fields and numbers required.

What to do step by step

1. Improve field mapping and check the data before sending without weakening server rules. For multi-step forms, compare also the data after moving between steps, because the customer may lose hidden fields.

2 . Show the user an error with the appropriate field and keep the entered data to correct.

How to check the score

The correct data creates a record, and the incorrect get a understandable 422 without partial recording.

What to do

Do not turn every 422 into a general ‘no connection’ message. The client should keep the fields of the form in order not to require re-entering of all data.