How to complete the challenge PUT /api/todos/{id} (422)
Issue a PUT request to /api/todos/{id} using an id that does not exist.
This API does not allow creating todos with a caller-selected auto-generated id, so the valid JSON reaches the write use case but is rejected as unprocessable.
If you do not know which todo ids already exist, first send:
GET /api/todos?_sortBy=-id
This lists the todos from highest id to lowest id. If you are using the public site, the URL is:
https://apichallenges.eviltester.com/api/todos?_sortBy=-id
GET /api/todos?_sortBy=-id to identify an id that does not exist
Choose an id higher than the highest returned id, then use that same missing id in the PUT URL and in the request body.
The response should be 422 Unprocessable Content with this message:
{
"errorMessages": [
"Cannot create todo with PUT due to Auto fields id"
]
}
Try it now
PUT /api/todos/{id} with a matching body id to attempt creating a todo and trigger 422
Lessons Learned
PUT /api/todos/{id}can be used for create-or-replace in some APIs, but this API rejects caller-selected auto ids.422 Unprocessable Contenthere comes from a business rule after the request shape is understood.- Idempotent method semantics do not override resource-specific validation rules.
Suggested Experiments
- Try a missing
idwith and without a matching bodyidand compare validation messages. - Create the resource another way first, then repeat
PUT /api/todos/{id}against that existingid.