How to use REST with versions | HCL Digital Experience
Item versions can be listed and read by using the REST service.
Note: New with HCL Digital Experience 9.5 CF_173 and CF18 higher releases: the Restore version
API supports restoring content versions to a previous level. This option is available to
8.5 and 9.0 CF18 users.
Retrieving a list of versions
To retrieve
a list of versions, you use a GET request to the following URI:
/item/item-uuid/versionsA feed is returned containing the identifying information of each version, along with a relation "versioned-item" that links to the specified version.
- Version link relations
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="wcm/namespace"> ... <link rel="versions" href="/wps/mycontenthandler/!ut/p/wcmrest/item/0d678334-69ae-4d3a-a525-91bb551e5a18/versions"/> ... </entry>
- Versions feed
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="wcm/namespace"> <entry> <link rel="versioned-item" href="/wps/mycontenthandler/!ut/p/wcmrest/item/0d678334-69ae-4d3a-a525-91bb551e5a18/version/2"/> <content> <wcm:versionContent> <wcm:versionName>2</wcm:versionName> <wcm:versionDate>2011-05-30T04:38:49.540Z</wcm:versionDate> </wcm:versionContent> </content> </entry> <entry> <link rel="versioned-item" href="/wps/mycontenthandler/!ut/p/wcmrest/item/0d678334-69ae-4d3a-a525-91bb551e5a18/version/1"/> <content> <wcm:versionContent> <wcm:versionName>1</wcm:versionName> <wcm:versionDate>2011-05-30T04:33:40.677Z</wcm:versionDate> </wcm:versionContent> </content> </entry> </feed>
Viewing the details of a version
To view the details of a specified version, you use a GET request in the following
format:
/item/item-uuid/version/version-name
For example:
GET HTTP/1.0
/wps/mycontenthandler/wcmrest/item/8f055ba2-1bc3-4d21-8443-86274e14dd2c/version/1
Host: www.example.com
Accept: application/atom+xml
HTTP/1.0 200 OK
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="wcm/namespace">
<id>0d678334-69ae-4d3a-a525-91bb551e5a181</id>
<title>SampleNumericComponentTitle</title>
<link rel="edit" href="/wps/mycontenthandler/!ut/p/wcmrest/LibraryNumericComponent/0d678334-69ae-4d3a-a525-91bb551e5a181"/>
<link rel="edit-media" type="text/plain" href="/wps/mycontenthandler/!ut/p/wcmrest/LibraryNumericComponent/0d678334-69ae-4d3a-a525-91bb551e5a181"/>
<link rel="library" href="/wps/mycontenthandler/!ut/p/wcmrest/item/c98d11e1-7f2a-480e-9aac-40eb1949cbda"/>
<link rel="create-draft" href="/wps/mycontenthandler/!ut/p/wcmrest/item/0d678334-69ae-4d3a-a525-91bb551e5a181/create-draft"/>
<link rel="change-to-draft" href="/wps/mycontenthandler/!ut/p/wcmrest/item/0d678334-69ae-4d3a-a525-91bb551e5a181/change-to-draft"/>
<link rel="versions" href="/wps/mycontenthandler/!ut/p/wcmrest/item/0d678334-69ae-4d3a-a525-91bb551e5a181/versions"/>
<updated>2011-05-30T06:42:10.244Z</updated>
<author>
<wcm:distinguishedName>uid=wpsadmin,o=defaultWIMFileBasedRealm</wcm:distinguishedName>
<uri>/wps/mycontenthandler/!ut/p/digest!6GVkh5Ul75Ln7DdEgvHm_g/um/users/profiles/Z9eAeH1C2JG561RC6JM47H9E4MMG6PHO6JM4C5JD0JMOC6BEEJS464JDG3I56K1</uri>
<email></email>
<name>wpsadmin</name>
</author>
<wcm:owner>
<wcm:distinguishedName>uid=wpsadmin,o=defaultWIMFileBasedRealm</wcm:distinguishedName>
<uri>/wps/mycontenthandler/!ut/p/digest!6GVkh5Ul75Ln7DdEgvHm_g/um/users/profiles/Z9eAeH1C2JG561RC6JM47H9E4MMG6PHO6JM4C5JD0JMOC6BEEJS464JDG3I56K1</uri>
<email></email>
<name>wpsadmin</name>
</wcm:owner>
<wcm:name>SampleNumericComponentNameUpdated</wcm:name>
<wcm:description>SampleNumericComponentDescription</wcm:description>
<wcm:type>LibraryNumericComponent</wcm:type>
<wcm:state>PUBLISHED</wcm:state>
<versionContent>
<wcm:versionName>1</wcm:versionName>
<wcm:versionDate>2011-05-30T04:33:40.677Z</wcm:versionDate>
</versionContent>
</entry>
- Restore version API:
- This new API supports capability to restore a version of content to a previous one.
Using the Restore Version API
To restore a previous content version, you use a PUT request in the following format:
- Endpoint
- PUT request to:
http://host:port/wps/mycontenthandler/!ut/p/digest!KG7Oo8qSOni4fLuinAp3sA/ wcmrest/item/<UUID of the content>/versions? setVersion=<versionName>&restoreAsPublished=<true|false>
- Expected Body
- The Body can have the basic WCM structure:
<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="http://www.ibm.com/xmlns/wcm/8.0"> </feed>
- Expected Headers
- LTPA token of the user.
- Return body
- The list of versions. Results are the same as when calling the wcmrest/item//versions/ structure.