Example: Retrieving metadata for changed objects

Content Platform Tenant Management Help

Version
9.7.x
File Size
4269 KB
Audience
anonymous
Part Number
MK-95HCPH002-19

Here’s a sample metadata query API request that uses a JSON body specified directly in the cURL command line and Python code to retrieve operation records for objects that:

  • Are in the finance namespace, which is owned by the europe tenant
  • Were modified during 2019

The start entry specifies 12:00:00.00 a.m. on January 1, 2019, and the end entry specifies 12:00:00.00 a.m. on January 1, 2020.

The response body is XML. The information returned for each operation record that meets the query criteria consists of the object URL, version ID, operation, and change time.

Request with cURL command line

curl -k -H "Authorization: HCP bXl1c2Vy:3f3c6784e97531774380db177774ac8d"
         -H "Content-Type: application/json" -H "Accept: application/xml"
         -d '{"operation":{"systemMetadata":{"changeTime":
         {"start":1293840000000,"end":1325376000000},"namespaces":
         {"namespace":["finance.europe"]}}}}'
         "https://europe.hcp.example.com/query?prettyprint"

Request in Python using PycURL

import pycurl
curl = pycurl.Curl()

# Set the URL, command, and headers
curl.setopt(pycurl.URL, "https://europe.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/json", "Accept: application/xml"])

# Set the request body
theFields = '{"operation":{"systemMetadata":{"changeTime": \
  {"start":1293840000000,"end":1325376000000},"namespaces": \
  {"namespace":["finance.europe"]}}}}'
curl.setopt(pycurl.POSTFIELDS, theFields)

curl.perform()
print curl.getinfo(pycurl.RESPONSE_CODE)
curl.close()

Request headers

POST /query HTTP/1.1
Host: europe.hcp.example.com
Authorization: HCP bXl1c2Vy:3f3c6784e97531774380db177774ac8d
Content-Type: application/json
Accept: application/xml
Content-Length: 81

Response headers

HTTP/1.1 200 OK
Transfer-Encoding: chunked

Response body

To limit the example size, the XML below shows only two object entries in the response body.

<?xml version='1.0' encoding='UTF-8'?>
<queryResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="/static/xsd/query-result-7.0.xsd">
    <query start="1293840000000" end="1325376000000" />
    <resultSet>
         <object
             version="81787101672577"
            urlName="https://finance.europe.hcp.example.com/rest/
                Presentations/Q2_2019.ppt"
            operation="CREATED"
            changeTimeMilliseconds="1310392057456.00" />
        <object
            version="81787102472129"
            urlName="https://finance.europe.hcp.example.com/rest/
                Presentations/Images/thankYou.jpg"
            operation="CREATED"
            changeTimeMilliseconds="1310392336286.00" />
         .
         .
         .
    </resultSet>
    <status results="11" message="" code="COMPLETE" />
</queryResult>