Validation
Getting it right second time round
Summary
In this guide, we'll take a look at the validation error responses that are returned by the API. Specifically what they look like and what they are trying to tell you.
Validation Error Structure
As a validation problem is just a specific type of error, it follows the same convention and structure as all error responses but with a few additional conventions.
{ "error": { "code": "YM1000", "reference": "https://developer.youmanage.co.uk/api/errors/ym1000", "target": "Validation", "message": "Validation failed", "details": [ { "code": "YM1002", "reference": "https://developer.youmanage.co.uk/api/errors/ym1002", "target": "Name", "message": "Validation failed for a specific property", "details": [ { "code": "YM1006", "reference": "https://developer.youmanage.co.uk/api/errors/ym1006", "target": "Name", "message": "'Name' must not be empty.", "details": null } ] } ] } }
The root object for a validation error will always have an error code of YM1000 (Validation Failed).
Within that error will normally be a collection of error objects detailing the properties that have failed validation. These objects will always have an error code of YM1002 (Property Validation Summary) and can be used to identify the properties that have failed validation.
Finally, within the Property Validation Summary errors is a collection of error objects detailing each specific problem with the data given for the property. Each property validation summary can have a number of reasons for failure and might not only have one problem. The error messages given in property validation errors are designed to be user-friendly and as such can be displayed to users.
If an error is not linked to a specific property, for example, the error is to do with the entity as a whole, then it will not appear wrapped in a Property Validation Summary error.
We've now covered most of the topics that you'll need in order to get up and running with the API, however, if you'd like to know more the next topic is how we plan to version the API and what that will mean for you.