What is a good way to handle multiple response codes for an API?

advertisements

Consider a call to a REST API:

POST /employees
[{ "name":"joe", "job":"dev",
 { "name":"bob" }]

For each array element an employee would be created. However, job is a required field, so the second element is invalid and the employee cannot be created.

What is a good response for this? 201 or 422?

I saw 207, but it seems to require an XML response, and the API does not use XML. It seems strange to return XML only for this case.

For this particular use case, I am thinking that all valid elements would be used to create resources. But I'm not sure what a good response would be.


We use 400 for any field validation errors (including missing required fields), be it on a single resource, or an entire collection.