|
||
In this topic, you can find examples of REST requests that can be used to manipulate document or object data in a Kentico CMS instance using the REST service. The URLs in this topic are listed as relative, so e.g. if your instance is running at http://localhost/KenticoCMS, you would perform a request listed as ~/rest in format http://localhost/KenticoCMS/rest.
|
Validation of inserted or updated data
Please note that when inserting or updating object data via the REST service, no validation is performed on the side of Kentico CMS. You therefore need to ensure appropriate validation on the side of your application to prevent unwanted behavior.
|
The following URLs can be requested by the respective type of request in order to manipulate Kentico CMS documents. You can update, delete and insert documents (respectively) using these Http methods. Both XML and JSON formats are supported when performing these requests.
•Creates new document in the given culture, website and alias path location:
•~/rest/content/site/<sitename>/<culture>/document/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/document/news
•~/rest/content/currentsite/<culture>/document/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/document/news
•Updates the specified document:
•~/rest/content/site/<sitename>/<culture>/document/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/document/news
•~/rest/content/currentsite/<culture>/document/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/document/news
•Publishes the specified document:
•~/rest/content/site/<sitename>/<culture>/publish/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/publish/news/mynewsitem
•~/rest/content/currentsite/<culture>/publish/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/publish/news/mynewsitem
•Performs check-out of the specified document:
•~/rest/content/site/<sitename>/<culture>/checkout/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/checkout/news/mynewsitem
•~/rest/content/currentsite/<culture>/checkout/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/checkout/news/mynewsitem
•Performs check-in of the specified document:
•~/rest/content/site/<sitename>/<culture>/checkin/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/checkin/news/mynewsitem
•~/rest/content/currentsite/<culture>/checkin/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/checkin/news/mynewsitem
•Archives the specified document:
•~/rest/content/site/<sitename>/<culture>/archive/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/archive/news/mynewsitem
•~/rest/content/currentsite/<culture>/archive/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/archive/news/mynewsitem
•Moves the specified document to the next workflow step:
•~/rest/content/site/<sitename>/<culture>/movetonextstep/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/movetonextstep/news/mynewsitem
•~/rest/content/currentsite/<culture>/movetonextstep/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/movetonextstep/news/mynewsitem
•Moves the specified document to the previous workflow step:
•~/rest/content/site/<sitename>/<culture>/movetopreviousstep/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/movetopreviousstep/news/mynewsitem
•~/rest/content/currentsite/<culture>/movetopreviousstep/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/movetopreviousstep/news/mynewsitem
•Deletes the specified document:
•~/rest/content/site/<sitename>/<culture>/document/<aliaspath>, e.g. ~/rest/content/site/corporatesite/en-us/document/news
•~/rest/content/currentsite/<culture>/document/<aliaspath>, e.g. ~/rest/content/currentsite/en-us/document/news
|
Please note
If you specify a NodeID and a DocumentID is not specified, the operation is considered as new culture version creation. If you want to create a linked document, you have to specify a NodeLinkedNodeID in the request.
|
Below, you can find examples of document manipulation requests. For testing purposes, you can use Fiddler to send the requests to your web application and see the results.
The following example creates a sample document in the content tree.
POST http://localhost/CMS/rest/content/site/CorporateSite/en-us/document/Home HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: text\xml Content-Length:165
<CMS_MenuItem> <NodeClassID><enter class ID here></NodeClassID> <DocumentName>Services</DocumentName> <DocumentPageTemplateID><enter template ID here></DocumentPageTemplateID> </CMS_MenuItem> |
The following example updates the sample document created by the example above.
PUT http://localhost/CMS/rest/content/site/CorporateSite/en-us/document/Home/Services HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: text\xml Content-Length:81
<CMS_MenuItem> <DocumentName>Services MODIFIED</DocumentName> </CMS_MenuItem> |
The following example creates a new language version of the document created by the first example in this section.
POST http://localhost/CMS/rest/content/site/CorporateSite/cs-cz/document/Home/Services HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: text\xml Content-Length:103
<CMS_MenuItem> <NodeID>51939</NodeID> <DocumentName>Services CZ</DocumentName> </CMS_MenuItem> |
Object data manipulation methods
The following URLs can be requested by the respective type of request in order to manipulate Kentico CMS objects. You can update, delete and insert objects (respectively) using these Http methods. Both XML and JSON formats are supported when performing these requests.
Creates a new object of the specified type.
•~/rest/<objectType>, e.g. ~/rest/cms.user
Creates a new object of the specified type and assigns it to the current website.
•~/rest/<objectType>/currentsite, e.g. ~/rest/cms.user/currentsite
Creates a new object of the specified type and assigns it to the specified website.
•~/rest/<objectType>/site/<sitename>, e.g. ~/rest/cms.user/site/corporatesite
Updates the object of the specified type with the specified ID.
•~/rest/<objectType>/<id>, e.g. ~/rest/cms.user/53
Updates the object of the specified type with the specified code name and assigns it to the specified site.
•~/rest/<objectType>/site/<sitename>/<objectcodename>, e.g. ~/rest/cms.user/site/corporatesite/administrator
Updates the object of the specified type with the specified code name and assigns it to the current website.
•~/rest/<objectType>/<currentsite>/<objectcodename>, e.g. ~/rest/cms.user/currentsite/administrator
Updates the global object of the specified type with the specified code name.
•~/rest/<objectType>/global/<objectcodename>, e.g. ~/rest/cms.user/global/administrator
Deletes the object of the specified type with the specified ID.
•~/rest/<objectType>/<id>, e.g. ~/rest/cms.user/53
Deletes the object of the specified type with the specified code name assigned to the specified website.
•~/rest/<objectType>/site/<sitename>/<objectcodename>, e.g. ~/rest/cms.user/site/corporatesite/administrator
Deletes the object of the specified type with the specified code name assigned to the current website.
•~/rest/<objectType>/<currentsite>/<objectcodename>, e.g. ~/rest/cms.user/currentsite/administrator
Deletes the globlal object of the specified type with the specified code name.
•~/rest/<objectType>/global/<objectcodename>, e.g. ~/rest/cms.user/global/administrator
Below, you can find examples of object data manipulation requests. For testing purposes, you can use e.g. Fiddler to send the requests to your web application and see the results in the UI.
The following request creates a sample cms.country object based on the provided XML definition.
POST http://localhost/CMS/rest/cms.country HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: text\xml Content-Length: 271
<data><cms_country><CountryDisplayName>Test Country REST</CountryDisplayName><CountryName>TestCountryREST</CountryName></cms_country><CMS_State><StateDisplayName>Test State 1</StateDisplayName><StateName>TestState1</StateName><StateCode>TST</StateCode></CMS_State></data> |
The following example updates the sample cms.country object created by the example above based on the provided XML data.
PUT http://localhost/CMS/rest/cms.country/TestCountryREST HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: text\xml Content-Length: 102
<data><cms_country><CountryDisplayName>Test Country MODIFIED</CountryDisplayName></cms_country></data> |
The following request creates a sample cms.country object based on the provided JSON definition.
POST http://localhost/CMS/rest/cms.country?format=json HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: application/json Content-Length:161
{ "CountryDisplayName":"Test JSON","CountryName":"TestJSON","cms.state": [{"StateCode":"TST","StateName":"TestStateJSON","StateDisplayName":"Test State JSON"}] } |
The following example updates the sample cms.country object created by the example above based on the provided JSON data.
PUT http://localhost/CMS/rest/cms.country/TestJSON HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: application/json Content-Length:45
{ "CountryDisplayName":"Test JSON MODIFIED" } |
The following example deletes the sample cms.country object created by either of the examples above.
DELETE http://localhost/CMS/rest/cms.country/TestCountryREST HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost |
In case that you need to specify an empty value in a data manipulation request, you can use the ##null## macro instead of an actual value. This is particularly useful for non-string fields (e.g. typically foreign keys) where an empty string value would not produce the desired results.
The following example updates the Home page of the sample Corporate Site and ensures that it will not have any user specified in the Document created by field.
PUT http://localhost/CMS/rest/content/currentsite/en-us/document/home HTTP/1.1 User-Agent: Fiddler Authorization: Basic <enter Base64-encoded <username>:<password> here> Host: localhost Content-Type: text\xml Content-Length: 271
<CMS_File><DocumentCreatedByUserID>##null##</DocumentCreatedByUserID></CMS_File> |