Example: Retrieving all operation records for all existing and deleted objects in a directory
Here’s a sample metadata query API request that retrieves operation records for all objects currently in or deleted from the sales namespace owned by the midwest tenant. The query uses an XML request body and requests results in JSON format.
The verbose
entry is set to true to request detailed information for all operation records in the result set.
The response body includes records for all create, delete, and purge operations that occurred since the namespace was created up to one minute before the request was made at March 14, 2013 at 14:59:37 EST.
Request body in the XML file named AllSales.xml
<queryRequest> <operation> <count>-1</count> <systemMetadata> <namespaces> <namespace>sales.midwest</namespace> </namespaces> </systemMetadata> <verbose>true</verbose> </operation> </queryRequest>
Request with cURL command line
curl -i -k -H "Authorization: HCP bXl1c2Vy:3f3c6784e97531774380db177774ac8d" -H "Content-Type: application/xml" -H "Accept: application/json" -d @AllSales.xml "https://midwest.hcp.example.com/query?prettyprint"
Request in Python using PycURL
import pycurl import os curl = pycurl.Curl() # Set the URL, command, and headers curl.setopt(pycurl.URL, "https://midwest.hcp.example.com/" + "query?prettyprint") curl.setopt(pycurl.SSL_VERIFYPEER, 0) curl.setopt(pycurl.SSL_VERIFYHOST, 0) curl.setopt(pycurl.POST, 1) curl.setopt(pycurl.HTTPHEADER, ["Authorization: HCP bXl1c2Vy:3f3c6784e97531774380db177774ac8d", "Content-Type: application/xml", "Accept: application/json"]) # Set the request body from an XML file filehandle = open("AllSales.xml", 'rb') curl.setopt(pycurl.UPLOAD, 1) curl.setopt(pycurl.CUSTOMREQUEST, "POST") curl.setopt(pycurl.INFILESIZE, os.path.getsize("AllSales.xml")) curl.setopt(pycurl.READFUNCTION, filehandle.read) curl.perform() print curl.getinfo(pycurl.RESPONSE_CODE) curl.close() filehandle.close()
Request headers
POST /query HTTP/1.1 Host: finance.hcp.example.com Authorization: HCP bXl1c2Vy:3f3c6784e97531774380db177774ac8d Content-Type: application/xml Accept: application/json Content-Length: 258
Response headers
HTTP/1.1 200 OK Transfer-Encoding: chunked
JSON response body
To limit the example size, the JSON below shows only one object
entry in the response body.
{"queryResult": {"query":{"start":0,"end":1331751577658}, "resultSet":[ {"version":81787144560449 "utf8Name":"C346527", "urlName":"https://sales.midwest.hcp.example.com/rest/ customers/widgetco/orders/C346527", "updateTimeString":"2012-03-10T14:55:33-0500" "updateTime":1331409333, "uid":0, "type":"object", "size":4985, "shred":false, "retentionString":"Deletion Allowed", "retentionClass":"", "retention":"0", "replicated":true, "permissions":"256" "owner":"USER,midwest,rblack" "operation":"CREATED", "namespace":"sales.midwest", "ingestTimeString":"2012-03-10T14:55:33-0500", "ingestTime":1331409333, "index":true, "hold":false, "hashScheme":"SHA-256", "hash":"SHA-256 C67EF26C0E5EDB102A2DEF74EF02A8DF5A4F16BF4D...", "gid":0, "objectPath":"/customers/widgetco/orders/C346527", "dpl":2, "customMetadata":false, "changeTimeString":"2012-03-10T14:55:33-0500", "changeTimeMilliseconds":"1331409333948.00", "accessTimeString":"2012-03-10T14:55:33-0500", "accessTime":1331409333, "acl":false}, . . . ], "status":{"results":7,"message":"","code":"COMPLETE"} } }