Content API
The Content API allows content to be created, edited, versioned, published and expired. Tree based content such as menus are excluded. Content API calls will not work unless the user making the call has appropriate permissions in OrchestraCMS. JavaScript calls may work from a browser console during a live preview, but may not work on the live site (with the exception of Intranets).
ContentAPIRequest
A Content API request is made up of the following options. Availability may differ depending on the API method used:
contentRequest.requestFlags (Map<String, Boolean>)
- allData: (optional; default: false), Retrieve all data on the content including attributes, versions and content data.
- attributes: (optional, default: true), Content layout attribute only retrieved if layouts are set to true.
- layouts: (optional, default: true), Retrieve ContentLayoutInstance data.
- lock: (optional, default: false), Return the content in a lock or unlocked state. If true the content is locked, if false the content is unlocked.
- noData: (optional, default: false), Returns only a success response with an associated Message object.
- targets: (optional, default: false), Return targets on content.
- taxonomy: (optional, default: false), Return tag paths on content.
- versions: (optional, default: false), Retrieve content data and the list of content versions.
contentRequest.parameters (Map<String, String>)
- name, The content name.
- comment: (optional), A comment to be submitted with the approval request.
- contentTypeName, The content type name the content will be is associate with.
- description: (optional), The content description.
- priority: (optional, default: Normal), The priority of the approval request. Options are: Normal, Low, High.
- publishedEndDate: (optional), The publish end date of the content.
- publishedStartDate: (optional), The publish start date of the content.
- versionId: (optional), The ID of the requested version.
- versionNumber: (optional), The version number of the requested content.
contentRequest.listParameters (Map<String, List<String>>)
- contentLayoutNames: (optional only if ‘Auto Create’ on layouts for the requested type is set), List of layouts to add to content.
- contentTypes: (optional, default: all content types), The content types to be included.
- languages: (optional), Contains list of languages to be added to the content. If not specified a default language will be added.
addLayoutToContent
This method allows for the addition of a set of Content Layouts to unpublished Content.
Parameters
- objectId: String, Set to the Origin ID of the content to add a new Content Layout to. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content to add a new Content Layout to. If this is used, objectId is not required to be set.
- listParameters.contentLayoutNames: List<String>, The list of Content Layouts by Name wanting to be added.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
List<String> contentLayouts = new List<String> {'PlainText'};
contentRequest.listParameters.put('contentLayoutNames', contentLayouts);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'addLayoutToContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Added template to content' on success
JavaScript Request Example
var listparams = {
contentLayoutNames: ['PlainText']
};
var contentRequest = {
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
},
listParameters: listparams
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'addLayoutToContent',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
- The Content is published or sent for approval
- The user doesn’t have edit Content permission.
- The user doesn’t have a lock on the Content.
- The contentLayoutNames parameter doesn’t contain list of Content Layout Names.
createContent
This method provides the required data to create a new Content version 1.0. The Content will be created with any provided list of Content Layouts as well as layouts specified as Auto Create in the OrchestraCMS setup for that Content Type.
The data for the new Content can be sent in a ContentBundle or a combination of parameters and listParameters.
Parameters
When using parameters and listParameters to create Content, the following fields are available.
- parameters.name: String, Set to the Name of the Content to create.
- parameters.description: String (optional), The Content description.
- parameters.publishedStartDate: DateTime (optional), The Publish Start Date of the Content.
- parameters.publishedEndDate: DateTime (optional), The Publish End Date of the Content.
- parameters.contentTypeName: String, The Content Type name the Content will be associated with.
- listParameters.contentLayoutNames: List<String> (optional only if Auto Create is set), The Content Layout Names the Content will be associated with.
- listParameters.languages: List<String> (optional; default site language), A list of languages to be added to the Content.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
When using a ContentBundle to create Content, the following fields are available.
- bundle.contentMetaAttributes: Map<String, List<AttributeBundle.ContentAttribute>>, Set to the Name of the Content to create.
- bundle.contentType.Name: String, The Content Type name the Content will be associated with.
- bundle.contentLayouts: Map<String, ContentLayoutBundle> (optional only if Auto Create is set), The Content Layout Names the Content will be associated with.
- bundle.publishedStartDate: DateTime (optional), The Publish Start Date of the Content.
- bundle.publishedEndDate: DateTime (optional), The Publish End Date of the Content.
- listParameters.languageStatuses: Map<String, ContentLanguageStatus> (optional; default site language), A list of languages to be added to the Content. languageStatus.isAddedToContent has to be set true for each language to be added to Content.
- bundle.contentAttributes: Map<String, List<AttributeBundle.ContentAttribute>> (optional), A map to a list of attributes to be created with the Content.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.parameters.put('name', 'API Test Content');
contentRequest.parameters.put('description', 'Test Content description');
contentRequest.parameters.put('contentTypeName', 'Text');
List<String> contentLayouts = new List<String> {'DocumentStyle1'};
contentRequest.listParameters.put('contentLayoutNames', contentLayouts);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'createContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Retrieve content' on success
JavaScript Request Example
var params = {
'name': 'API Test Content',
'description': 'Test Content description',
'contentTypeName': 'Text'
};
var listparams = {
contentLayoutNames: ['DocumentStyle1']
};
var contentRequest = {
parameters: params,
listParameters: listparams
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'createContent',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
deleteContent
This method deletes the content. It checks the user permission and content status.
Parameters
- objectId: String, Set to the ID of the content that will be deleted. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the ID of the content that will be deleted. If this is used, objectId is not required to be set.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'deleteContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'Message') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Saved content' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'deleteContent',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- It’s published or sent for approval in a production org.
- The user doesn’t have edit content permission.
- The content is locked by another user.
expireContent
This method expires a piece of Content based on the provided Content ID and unlocks the Content.
Parameters
- objectId: String, Set to the ID of the content that will be expired. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the ID of the content that will be expired. If this is used, objectId is not required to be set.
- publishedEndDate: String (optional; default: current time), The published end date of the content.
requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API except lock are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'expireContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'expireContent',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- The Content is not published.
- The user doesn’t have the publish content permission.
- If an approval process is being used and the user account that submits the request does not have the ability to publish outside of the approval process, the expire call will fail.
getContent
This method retrieves the latest version of the Content based on Content Origin ID or any specific version of the content based on either the combination of Origin ID and version number, or solely the version ID. The content can be returned in the lock state if requested. The amount of data returned is controlled by the requestFlags. The following table outlines the required and optional parameters for each of the four methods.
To request a specific content version, the ‘versionNumber’ field in parameters has to be set to the requested version and the Origin ID must be passed, or these parameters can be omitted and the versionId parameter can be passed instead.
Parameters
- objectId: String, Set to the Origin ID of the content to retrieve. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content to retrieve. If this is used, objectId is not required to be set.
- versionNumber: String (optional), Request specific content version.revision, set to the requested version number in a decimal format (e.g. ‘3.0’ or '3.1').
- versionId: String (optional), Set to ID of the requested version, this parameter does not require an Origin ID or version number parameter to be provided.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content origin ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'getContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Retrieve content' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'getContent',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- If requestFlags contains lock set to true, the system will attempt to lock the content. The content is successfully locked if the contentBundle.lockedByMe flag is set to true.
- If the content can’t be locked it will be returned in the read only state (ie contentBundle.readonly=true).
- The API client must check the readonly status to confirm edibility.
- User does not have access to the content.
- Invalid objectId is specified.
- Invalid versionNumber or versionId is specified.
getContentTypes
This method returns a list of ContentTypeBundles based on a provided list of Content Type IDs.
Parameters
- listParameters.contentTypes: List<String> (optional; default: all core and custom Content Types), The list of Content Types by ID wanting to be returned.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
List<String> contentTypes = new List<String>{'Article', 'Text'};
contentRequest.listParameters.put('contentTypes', contentTypes);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'getContentTypes');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentTypeBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentTypeBundle
System.Debug(apiResponse.message); // Outputs 'Retrieve Content Types' on success
JavaScript Request Example
var response = '';
var data = {
service: 'ContentAPI',
action: 'getContentTypes',
contentRequest: JSON.stringify({})
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
getContentTypesByName
This method returns a list of ContentTypeBundles based on a provided list of Content Type names.
Parameters
- listParameters.contentTypes: List<String>, The list of Content Types by Name wanting to be returned.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
List<String> contentTypes = new List<String> {'Taxonomy', 'Text'};
contentRequest.listParameters.put('contentTypes', contentTypes);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'getContentTypesByName');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentTypeBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentTypeBundle
System.Debug(apiResponse.message); // Outputs 'Retrieve Content Templates' on success
JavaScript Request Example
var listparams = {
contentTypes: ['Taxonomy', 'Text']
};
var contentRequest = {
listParameters: listparams
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'getContentTypesByName',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
getContentLayoutsByTypeId
This method returns a list of ContentLayoutBundles based on a provided list of Content Type IDs.
Parameters
- listParameters.contentTypes: List<String>, The list of Content Types by ID wanting to be returned.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
List<String> contentTypes = new List<String> {'a00000000000000000'};
contentRequest.listParameters.put('contentTypes', contentTypes);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'getContentLayoutsByTypeID');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentLayoutBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentLayoutBundle
System.Debug(apiResponse.message); // Outputs 'Retrieve Content Templates' on success
JavaScript Request Example
var listparams = {
contentTypes: ['a00000000000000000']
};
var contentRequest = {
listParameters: listparams
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'getContentLayoutsByTypeID',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
getContentLayoutsByTypeName
This method returns a list of ContentLayoutBundles based on a provided list of Content Type names.
Parameters
- listParameters.contentTypes: List<String>, The list of Content Types by Name wanting to be returned.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
List<String> contentTypes = new List<String> {'Text'};
contentRequest.listParameters.put('contentTypes', contentTypes);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'getContentLayoutsByTypeName');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentLayoutBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentLayoutBundle
System.Debug(apiResponse.message); // Outputs 'Retrieve Content Types' on success
JavaScript Request Example
var listparams = {
contentTypes: ['Text']
};
var contentRequest = {
listParameters: listparams
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'getContentLayoutsByTypeName',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
newContentRevision
This method creates a new Content revision based on objectId or ContentBundle. The request for new revision needs to respect timeline restrictions. If there is a future published content version, OrchestraCMS will adjust the EndDate or throw an exception if it can’t be done.
Parameters
- objectId: String, Set to the Origin ID of the content that a new revision will be created from. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content that a new revision will be created from. If this is used, objectId is not required to be set.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'newContentRevision');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Created New Content version' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'newContentRevision',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- The user has no edit content permission.
- ContentBundle with modified attribute data was provided and user has no translate permission for that language.
- The requested revision violates the timeline and can not be created. Scenarios violating the timeline could include attempting to set the published end date before the published start date or setting the published start date past the published start date of a subsequent published version (ex. creating a revision 2.1 with a published start date of January 1st, 2018 while a version 3.0 exists with a published start date of December 1, 2017).
newContentVersion
This method creates a new Content version based on the objectId or ContentBundle.
Parameters
- objectId: String, Set to the Origin ID of the content that a new version will be created from. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content that a new version will be created from. If this is used, objectId is not required to be set.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'newContentVersion');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Created New Content version' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'newContentVersion',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- The user has no edit content permission.
- ContentBundle with modified attribute data was provided and user has no translate permission for that language.
- There is currently an unpublished version of that content.
publishContent
This method publishes content based on content ID and unlocks the content.
Parameters
- objectId: String, Set to the Origin ID of the content to be published. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content to be published. If this is used, objectId is not required to be set.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API except lock are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'publishContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Content published' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'publishContent',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- The Content is published/expired or already sent for approval.
- The user doesn’t have the publish content permission.
- The Content is locked by another user.
releaseLock
Releases the lock based on objectId or ContentBundle.contentId. In order to successfully unlock content, you must be the user who locked the content in order to release it.
Parameters
- objectId: String, Set to the ID of the content of the content the lock will be released from. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the ID of the content to the lock will be released from. If this is used, objectId is not required to be set.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API except lock are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'releaseLock');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Content unlocked' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'releaseLock',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
removeLayoutFromContent
This method allows for the removal of a set of Content Layouts from unpublished Content.
Parameters
- objectId: String, Set to the Origin ID of the content to remove the layout from. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content to remove the layout from. If this is used, objectId is not required to be set.
- listParameters.contentLayoutNames : List<String>, The list of Content Layouts by Name wanting to be removed.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
List<String> contentLayouts = new List<String> {'PlainText'};
contentRequest.listParameters.put('contentLayoutNames', contentLayouts);
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'removeLayoutFromContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Removed layout(s) from content' on success
JavaScript Request Example
var listparams = {
contentLayoutNames: ['PlainText']
};
var contentRequest = {
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
},
listParameters: listparams
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'removeLayoutFromContent',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
- The Content is published or sent for approval.
- The user doesn’t have edit Content permission.
- The user doesn’t have a lock on the Content.
- The contentLayoutNames parameter doesn’t contain list of Content Layout Names.
- The Content with the requested layouts are already on a Page.
requestLock
Locks the content based on objectId or ContentBundle.contentId. It can either return success message or ContentBundle based on requestFlags.
Parameters
- objectId: String, Set to the ID of the content to lock. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the ID of the content to lock. If this is used, objectId is not required to be set.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API except lock are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'requestLock');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Content locked' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'requestLock',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- It’s published or sent for approval and the current user is not the approver with edit permissions.
- The user doesn’t have edit or translate content permissions.
- Content is locked by someone else.
saveContent
This method saves an updated ContentBundle. OrchestraCMS checks the user permission and content status, including the user lock. A user must have obtained a lock on a piece of content before they can use the saveContent method (see requestLock). You must request that the lock be maintained in the requestFlags; otherwise the lock will be released upon saving.
Parameters
- objectId: String, Set to the ID of the content to saved. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the ID of the content to saved. If this is used, objectId is not required to be set.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
contentRequest.requestFlags = new Map<String, Boolean>{'lock' => true};
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'saveContent');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Saved content' on success
JavaScript Request Example
var contentrequest = {
parameters: {},
requestFlags: {lock: true},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response = '';
var data = {
service: 'ContentAPI',
action: 'saveContent',
contentRequest: JSON.stringify(contentrequest)
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus) {}, // Handle response on complete
readonly: true // Whether it is a read only call
};
doServiceRequest(data, options);
- The user has no edit content or translate content permissions for the content type.
- The content is published or sent for approval.
- The content is locked by another user.
- The user is trying to save attributes on a language they do not have access to (i.e. they are not in the translation group for that language).
submitForApproval
This method submits content for approval. In addition to having publish permissions, if an approval process is enabled for the site, it will need to be overridden by selecting “Allow users with this profile to publish independently of the approval process”. The data for submitting content for approval is to be sent in the ContentAPIRequest parameters list. There must be an active approval process in place in the org to utilize the submitForApproval method. See the OrchestraCMS documentation Manage a Publish Approval Process for more information on setting an approval process up. Users with the "Allow users with this profile to publish independently of the Approval Process" profile setting will also bypass an approval process when using the API.
Parameters
- objectId: String, Set to the Origin ID of the content to submit for approval. If this is used, bundle.contentId is not required to be set.
- bundle.contentId: String, Set to the Origin ID of the content to submit for approval. If this is used, objectId is not required to be set.
- parameters.priority: String (optional; default: 'Normal'), The priority of the content approval request. Accepted String values are:
- Normal
- Low
- High
- parameters.comment: String (optional), A field to allow for a comment by the content author as part of the approval request.
- requestFlags: Map<String, Boolean> (optional), All standard request flags available in the Content API are supported with this method.
Apex Request Example
ContentAPIRequest contentRequest = new ContentAPIRequest();
contentRequest.objectId = 'a00000000000000000'; // Replace objectId with the content version ID
contentRequest.parameters = new Map<String, String>{'priority' => 'High', 'comment' => 'Test approval'};
Map<String, String> parameters = new Map<String, String>();
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
parameters.put('service', 'ContentAPI');
parameters.put('action', 'submitForApproval');
parameters.put('contentRequest', json.serialize(contentRequest));
parameters.put('apiVersion', '5.0');
String response = cms.ServiceEndpoint.doActionApex(parameters);
JSONMessage.APIResponse apiResponse = (JSONMessage.APIResponse) json.deserialize(response, JSONMessage.APIResponse.class);
if (!apiResponse.isSuccess) {
throw new APIException('Could not retrieve information from the Content API');
}
if (apiResponse.type != 'ContentBundle') {
throw new APIException('Unexpected result from Content API');
}
System.Debug(response); // Outputs response and ContentBundle
System.Debug(apiResponse.message); // Outputs 'Removed layout(s) from content' on success
JavaScript Request Example
var contentRequest = {
parameters: {'priority': 'High', 'comment': 'Test approval'},
bundle: {
contentId: 'a00000000000000000' // Replace objectId with the content version ID
}
};
var response; // Used to get the JSON Object Response from action
var data = {
service: 'ContentAPI',
action: 'submitForApproval',
contentRequest: JSON.stringify(contentRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function (json, Success) {
console.log(json);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){},
readonly: false
};
doServiceRequest(data, options);
- The Content is published or already sent for approval.
- The user doesn’t have the edit content permission.
- The user doesn’t have a lock on the Content.
- The Content is locked by another user.
JSON-Serialized Response Examples
Response messages and other fields may differ depending on the API method used and the requestFlags supplied.
ContentBundle Example
{
"type": "ContentBundle",
"transactionId": null,
"timeNow": "2017-06-26T00:00:00.000Z",
"responseObject": {
"versionsAndRevisions": [],
"version": 1,
"siteName": "site_name",
"siteId": "a00000000000000000",
"sentForApproval": false,
"revision": 0,
"readonly": false,
"publishedStartDate": "2017-06-26T00:00:00.000Z",
"published": false,
"originId": "a01000000000000000",
"lockedByMe": false,
"lockedBy": "",
"locked": false,
"lastModifiedDate": "2017-06-26T00:00:00.000Z",
"lastModifiedBy": "John Smith",
"languageStatuses": {
"en_US": {
"languageCode": "en_US",
"isTranslated": true,
"isAddedToContent": true,
"isActive": true,
"canTranslate": true
}
},
"expired": false,
"excludeFromSearch": false,
"createdDate": "2017-06-26T00:00:00.000Z",
"contentType": {
"type": "Core",
"name": "Text",
"label": "Text",
"contentTypeId": "a02000000000000000"
},
"contentMetaAttributes": {
"en_US": {
"languageCode": "en_US",
"metaContentName": "Test Content"
}
},
"contentLayouts": {
"a03000000000000000": {
"name": "TextBlock",
"label": "Text Block",
"contentLayoutId": "a04000000000000000"
}
},
"contentId": "a00000000000000000",
"contentAttributes": {
"en_US": [{
"simple": false,
"languageCode": "en_US",
"valueType": "Rich Text",
"value": "<p>API Example</p>",
"name": "HTMLContent"
}]
},
"allowVersioning": false,
"allowTarget": false,
"allowSendForApproval": false,
"allowRevisioning": false,
"allowPublish": true,
"allowExpire": false,
"allowEdit": true,
"allowDelete": true,
"allowClone": true
},
"moreResults": false,
"message": "Retrieve content",
"isSuccess": true,
"error": null
}
ContentLayoutBundle Example
{
"type": "ContentLayoutBundle",
"transactionId": null,
"timeNow": "2017-06-26T00:00:00.000Z",
"responseObject": {
"Text": [{
"name": "DocumentStyle1",
"label": "Document Style 1",
"contentLayoutId": "a01000000000000000"
}, {
"name": "Listable",
"label": "Listable",
"contentLayoutId": "a01000000000000001"
}, {
"name": "ListableWithImage",
"label": "Listable With Image",
"contentLayoutId": "a01000000000000002"
}, {
"name": "PlainText",
"label": "Plain Text",
"contentLayoutId": "a01000000000000003"
}, {
"name": "SmallBlock",
"label": "Small Block",
"contentLayoutId": "a01000000000000004"
}, {
"name": "SmallBlockWithImage",
"label": "Small Block With Image",
"contentLayoutId": "a01000000000000005"
}, {
"name": "TextBlock",
"label": "Text Block",
"contentLayoutId": "a01000000000000006"
}]
},
"moreResults": false,
"message": "Retrieve Content Templates",
"isSuccess": true,
"error": null
}
ContentTypeBundle Example
{
"type": "ContentTypeBundle",
"transactionId": null,
"timeNow": "2017-06-26T00:00:00.000Z",
"responseObject": [{
"type": "Core",
"name": "Carousel",
"label": "Carousel",
"contentTypeId": "a00000000000000000"
}, {
"type": "Core",
"name": "Data",
"label": "Data",
"contentTypeId": "a00000000000000001"
}, {
"type": "Core",
"name": "Form",
"label": "Form",
"contentTypeId": "a00000000000000002"
}, {
"type": "Core",
"name": "List (Dynamic)",
"label": "List (Dynamic)",
"contentTypeId": "a00000000000000003"
}, {
"type": "Core",
"name": "List (Fixed)",
"label": "List (Fixed)",
"contentTypeId": "a00000000000000004"
}, {
"type": "Core",
"name": "Media",
"label": "Media",
"contentTypeId": "a00000000000000005"
}, {
"type": "Core",
"name": "Menu",
"label": "Menu",
"contentTypeId": "a00000000000000006"
}, {
"type": "Core",
"name": "Portal",
"label": "Portal",
"contentTypeId": "a00000000000000007"
}, {
"type": "Core",
"name": "Search",
"label": "Search",
"contentTypeId": "a00000000000000008"
}, {
"type": "Core",
"name": "SiteMap",
"label": "Site Map",
"contentTypeId": "a00000000000000009"
}, {
"type": "Core",
"name": "Taxonomy",
"label": "Taxonomy",
"contentTypeId": "a00000000000000010"
}, {
"type": "Core",
"name": "Text",
"label": "Text",
"contentTypeId": "a00000000000000011"
}, {
"type": "Core",
"name": "Utility",
"label": "Utility",
"contentTypeId": "a00000000000000012"
}],
"moreResults": false,
"message": "Retrieve Content Types",
"isSuccess": true,
"error": null
}