What HTTP status should I use for when I'm missing a parameter in POST?


I have a form that will be submitted to the server via ajax, using a plugin for that. When the form is not filled correctly (in the case when a mandatory parameter is missing), I want to return a JSON with an error message and an error status, so that in javascript, the plugin enters the error callback instead of success.

I know it must be one of the 4xx family, but I don't know which one.

There doesn't seem to be any of these:

  • 400 – Bad request: the request worked, so much so that I returned a JSON

  • 404 – Not found: the resource exists, so much so that I can POST it

  • 403 – Forbidden: I don't think so either

What status should I return?


The 422 is the closest to that (I'll talk more about it already).

In the 400 , " bad syntax " is talked about, but this is not the case (syntax error).

In 412 , it is talked about " preconditions that the requester put on the request ", that is, whoever contacted the server had a precondition. But that's not the case either, because it's the server (not the requester ) who will actually do the validation. Although, of course, it is possible to have some validation on the form/client side as well.

At 422 , he talks about semantic errors. In other words, there is no syntax error, but some information is missing. It seems to be the most convenient.

Scroll to Top