What's the proper error code to return when a POST request has an invalid parameter? Say: a form takes data for an event, but the date provided is in the past; or a form takes data for a user registration, but the name provided is a number or any invalid person name.
-
2possible duplicate of [REST response code for invalid data](http://stackoverflow.com/questions/6123425/rest-response-code-for-invalid-data) – Adrien Plisson Oct 20 '11 at 11:55
2 Answers
11.2. 422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server
understands the content type of the request entity (hence a
415(Unsupported Media Type) status code is inappropriate), and the
syntax of the request entity is correct (thus a 400 (Bad Request)
status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML
request body contains well-formed (i.e., syntactically correct), but
semantically erroneous, XML instructions.
(From RFC 4918)
i would personally opt for: 400 Bad Request
the error should be in the 4xx range which represents client errors, because it is the responsibility of the client to transmit valid data.
anyway, you can have a look at a list of standard HTTP response codes and chose one that seems to fit your need.

- 22,486
- 6
- 42
- 73
-
1Isn't 400 reserved for bad syntax? An invalid parameter may be invalid but syntactically correct. – Maurício C Antunes Oct 20 '11 at 11:03
-
the rfc says: "The request could not be understood by the server due to malformed syntax", but sending a number instead of a date is a bad syntax, although the client can send the request. specifically, the query parameters can be considered as a part of the request, and can thus trigger some errors. error "409 Conflict" is such a good example. – Adrien Plisson Oct 20 '11 at 11:08
-
Sending a number instead of a date is bad syntax, but sending an invalid date in the place of a date is not. What should I use then? – Maurício C Antunes Oct 20 '11 at 11:22
-
We've tried to clarify this in httpbis, see https://svn.tools.ietf.org/svn/wg/httpbis/draft-ietf-httpbis/latest/p2-semantics.html#status.400 – Mark Nottingham May 17 '12 at 06:57