Use REST with elements
We can use the Web Content Manager REST service to create, read, update and delete some types of elements stored in site areas and content items.
The following element types can be used with the Web Content Manager REST service.
Element API type Text element TextComponent Short text element ShortTextComponent Rich text element RichTextComponent HTML element HTMLComponent Number element NumericComponent Date and time element DateComponent Image element ImageComponent File resource element FileComponent Style sheet element StyleSheetComponent
Create
An element can be created by sending a POST request to the following URI with an atom entry representing the title of the element:
/[Content|SiteArea]/<parent-uuid>/elementsThe type of the element to be created must be specified in the type field of the entry that is posted. For example:
POST /wps/mycontenthandler/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements HTTP/1.0 Content-type: application/atom+xml <entry xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="namespace"> <title>numericComponentTitle</title> <wcm:name>numericComponentName</wcm:name> <wcm:type>NumericComponent</wcm:type> </entry> HTTP/1.0 201 Created Content-type: application/atom+xml; type=entry Content-location: /wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName <entry xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="namespace"> <title>numericComponentTitle</title> <link rel="edit-media" type="text/plain" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName"/> <link rel="edit" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName"/> <wcm:name>numericComponentName</wcm:name> <wcm:type>NumericComponent</wcm:type> </entry>
Update
An element can be updated by sending a PUT request to the following URI with an atom entry including the name and title of the element.
/[Content|SiteArea]/<parentuuid>/elements/<element-name-encoded>For example:PUT /wps/mycontenthandler/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName HTTP/1.0 Content-type: application/atom+xml <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wcm="namespace"> <title>numericComponentTitleUpdated</title> <wcm:name>numericComponentNameUpdated</wcm:name> </atom:entry> HTTP/1.0 200 OK Content-type: application/atom+xml; type=entry <entry xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="namespace"> <title>numericComponentTitleUpdated</title> <link rel="edit-media" type="text/plain" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName"/> <link rel="edit" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName"/> <wcm:name>numericComponentNameUpdated</wcm:name> <wcm:type>NumericComponent</wcm:type> </entry>
Read
An element can be read by sending a GET request to the following URI :
/[Content|SiteArea]/<parentuuid>/elements/<element-name-encoded>For example:GET /wps/mycontenthandler/wcmrest/Content/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName HTTP/1.0 HTTP/1.0 200 OK Content-type: application/atom+xml; type=entry <entry xmlns="http://www.w3.org/2005/Atom" xmlns:wcm="namespace"> <title>numericComponentTitleUpdated</title> <link rel="edit-media" type="application/vnd.ibm.wcm+xml" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName"/> <link rel="edit" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/numericComponentName"/> <wcm:name>numericComponentNameUpdated</wcm:name> <wcm:type>NumericComponent</wcm:type> </entry>
Delete
An element can be deleted by sending a DELETE request to the following URI:
/[Content|SiteArea]/<parentuuid>/elements/<element-name-encoded>For example:
- DELETE
HTTP/1.1 DELETE http://host:port/wps/mycontenthandler/wcmrest/Content/<parentuuid>/elements/<element-name-encoded>
- Response
Status Code :200 Status Message : OK
Work with raw data
The content of an element is accessed from the media resource specified in the HREF attribute of the edit-media link. The link will also contain a TYPE attribute which contains the accepted media type of the content. For example:
<link rel="edit-media" type="text/html" href="/wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/heading"/>The media types for supported elements are:
Media type Component types text/plain
- Text
application/vnd.ibm.wcm+xml
- Number
- Date and Time
- Image
- Stylesheet
text/html
- HTML
- Rich text
text/css
- Stylesheet
image/*
- Image
application/octet-stream
- File
To update content of an element PUT content in an accepted media type to the edit-media URL. For example:
PUT /wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/heading HTTP/1.0 Content-type: text/html <h1>Heading Text</h1> HTTP/1.0 200 OKTo retrieve content from a library component GET content from the edit-media URL. For example:
GET /wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/heading HTTP/1.0 Accept: text/html HTTP/1.0 200 OK Content-type: text/plain <h1>Heading Text</h1>An alternative to specifying the media type in the HTTP accept header, is to use the request parameter mime-type. You must URL encode the value. For example:GET /wps/mycontenthandler/!ut/p/wcmrest/SiteArea/c6b00ee6-d628-4cbd-9e65-15c90f2093a6/elements/heading?mime-type=text%2Fhtml HTTP/1.0 HTTP/1.0 200 OK Content-type: text/plain <h1>Heading Text</h1>