How to complete the challenge QUERY /todos JSONPath (200)
QUERY is a safe read method that can send query content in the request body. For this challenge, use a JSONPath expression to request todos where doneStatus=true.
QUERY /todos JSONPath (200)
Issue a QUERY request on the
/todosend point with JSONPath query content to get only todos which are done. There must exist both done and not done todos to pass this challenge.
- Use the
QUERYmethod with/todos. - Add
Content-Type: application/jsonpath. - Add
Accept: application/jsonso you can inspect the response. - Send
$.todos[?(@.doneStatus == true)]in the request body. - Make sure your challenger data has at least one todo with
"doneStatus": trueand at least one with"doneStatus": false.
Basic Instructions
- Issue a
QUERYrequest to:https://apichallenges.com/todos
- The request should have an
X-CHALLENGERheader so the challenge is tracked. - The request body should be a JSONPath expression:
$.todos[?(@.doneStatus == true)]
Try it now
If you need fixture data, create one done todo and one not-done todo first. See the solution.
POST /todos to create a done todo fixture
POST /todos to create a not-done comparison todo
Issue the QUERY request with the JSONPath filter in the body:
QUERY /todos with a JSONPath doneStatus filter
Example Request
> QUERY /todos HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/jsonpath
> Accept: application/json
>
> $.todos[?(@.doneStatus == true)]
Example Response
< HTTP/1.1 200 OK
< Content-Type: application/json
< Accept-Query: application/x-www-form-urlencoded, application/jsonpath
< X-Challenger: x-challenger-guid
Returned body:
{
"todos": [
{
"id": 42,
"title": "done todo for JSONPath query",
"doneStatus": true,
"description": "created for query challenge"
}
]
}
Lessons Learned
QUERY /todoscan useContent-Type: application/jsonpathwhen the request body is aJSONPathexpression.JSONPathstarts from$, uses@for the current item in a filter, and can select matching objects from the collection.- API Challenges expects the
JSONPathexpression to select complete todo objects, not isolated fields such as titles. - The
Accept-Queryresponse header lists both supportedQUERYbody media types.
Suggested Experiments
- Send
$.todosto return every todo and compare it withGET /todos. - Send
$.todos[?(@.doneStatus == false)]to return todos that are not done. - Send
$.todos[?(@.description != '')]after creating a todo with a description. - Try
$.todos[*].titleand observe that selecting only field values is rejected. - Use the method reference for extra
QUERYexperiments and details onapplication/jsonpath.