How can I filter documents returned via the REST automation API?
I'm attempting to retrieve a selection of documents from a Nuxeo server using the REST automation APIs (from C++ using libCURL). I'm new to Nuxeo, so I'm trying to 'prototype' the calls using CURL from the command line. We've defined some custom document metadata called a Plate which has a manufacturer field.
The following works in the shell, returning two plates named 1 and 2 from a collection; query “SELECT * FROM Document WHERE plate:manufacturer = 'Oxoid'” /default-domain/workspaces/testing/collection/1 /default-domain/workspaces/testing/collection/2
But if I execute this inside a CURL request, it gets confused; curl -H 'Content-Type:application/json+nxrequest' -X POST -d '{“params”:{“query”:“SELECT * FROM Document WHERE plate:manufacturer = 'Oxoid'“},“context”:{}}' -u Administrator:Administrator http://localhost:8080/nuxeo/site/automation/Document.Query
This fails with a page of java exception, but ultimately says “No such property: Oxoid”
Looks like it maybe a simple quote escaping issue.
curl -H 'Content-Type:application/json+nxrequest' -X POST -d '{“params”:{“query”:“SELECT * FROM Document WHERE plate:manufacturer = 'Oxoid'“},“context”:{}}' -u Administrator:Administrator http://localhost:8080/nuxeo/site/automation/Document.Query
{"entity-type":"exception","type":"org.nuxeo.ecm.automation.TraceException","status":500,"message":"Failed to execute operation: Document.Query","stack":"org.nuxeo.ecm.automation.TraceException: \n\n chain \nName: operation\nException: OperationException\nCaught error: Failed to invoke operation Document.Query\nCaused by: org.nuxeo.ecm.core.api.ClientException: Failed to execute query: No such property: Oxoid\n
Ah well I figured it out eventually - well, I'm using a different command that works:
curl –trace-ascii dump.txt -H 'Content-Type:application/json+nxrequest' -X POST -d '{“params”:{“property”:“plate:manufacturer”,“values”:“Oxoid”},“context”:{}}' -u Administrator:Administrator http://localhost:8080/nuxeo/site/automation/Document.FetchByProperty
…does the trick. Not sure why, but Document.FetchByProperty just seems to work better than Document.Query.