Social API
The Social API allows for the manipulation and retrieval of social data for a content item, library item, or page. Social data is defined as likes, comments, and views. This data persists across versions and, if applicable, revisions of the item. In addition to aggregate data, an individual user's social activity in relation to the item can also be stored and retrieved.
SocialAPIRequest
A Social API request is made up of the following properties. Requirements may differ depending on the API method used:
socialRequest.parameters (Map<String, String>)
- limit: (Optional; default: 500), The maximum number of items to retrieve.
- type: (Optional; default: Content), The type of item to get social data for. This must be the type of the IDs. Options are: Content, Media or Page.
socialRequest.listParameters (List<String>)
- originIds: List of origin IDs of items to get social data for. The IDs must all be of the same type.
socialRequest.requestFlags (Map<String, Boolean>)
- noData: (Optional; default: true), Whether to return the responseObject as part of the API request.
like
Creates a record of the item being liked by the running user. This also increments the aggregate number of likes on the item.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.listParameters.put('originIds', new List<String>{'a00000000000000000'});
socialRequest.parameters.put('type', 'Content');
socialRequest.requestFlags.put('noData', false);
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'like');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'Map<String,SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and Map<String,SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {
originIds: ['a00000000000000000']
},
parameters: {
type: 'Content'
},
requestFlags: {
noData: false
}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'like',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // like Request
unlike
Removes the record of the item being liked by the running user. This also decrements the aggregate number of likes on the item.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.listParameters.put('originIds', new List<String>{'a00000000000000000'});
socialRequest.parameters.put('type', 'Content');
socialRequest.requestFlags.put('noData', false);
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'unlike');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'Map<String,SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and Map<String,SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {
originIds: ['a00000000000000000']
},
parameters: {
type: 'Content'
},
requestFlags: {
noData: false
}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'unlike',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // unlike Request
view
Creates a record of the item being viewed by the running user. This also increments the aggregate number of views on the item.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.listParameters.put('originIds', new List<String>{'a00000000000000000'});
socialRequest.parameters.put('type', 'Content');
socialRequest.requestFlags.put('noData', false);
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'view');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'Map<String,SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and Map<String,SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {
originIds: ['a00000000000000000']
},
parameters: {
type: 'Content'
},
requestFlags: {
noData: false
}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'view',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // unlike Request
getSocialData
Retrieves social data for any number of items.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.listParameters.put('originIds', new List<String>{'a00000000000000000'});
socialRequest.parameters.put('type', 'Content');
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'getSocialData');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'Map<String,SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and Map<String,SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {
originIds: ['a00000000000000000']
},
parameters: {
type: 'Content'
},
requestFlags: {}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'getSocialData',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // getSocialData Request
getMySocialData
Retrieves social data for items the running user has recently liked or viewed. Data is returned in descending order by the date the user last interacted with the item. An interaction is defined as liking or viewing the item.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.parameters.put('type', 'Content');
socialRequest.parameters.put('limit', '10');
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'getMySocialData');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'List<SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and List<SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {},
parameters: {
type: 'Content',
limit: '10',
},
requestFlags: {}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'getMySocialData',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // getMySocialData Request
getLikedByMe
Retrieves social data for items the running user has recently liked. Data is returned in descending order by the date the user last liked the item.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.parameters.put('type', 'Content');
socialRequest.parameters.put('limit', '10');
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'getLikedByMe');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'List<SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and List<SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {},
parameters: {
type: 'Content',
limit: '10',
},
requestFlags: {}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'getLikedByMe',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // getLikedByMe Request
getViewedByMe
Retrieves social data for items the running user has recently viewed. Data is returned in descending order by the date the user last viewed the item.
Apex Request
SocialAPIRequest socialRequest = new SocialAPIRequest();
socialRequest.parameters.put('type', 'Content');
socialRequest.parameters.put('limit', '10');
Map<String, String> parameters = new Map<String, String>();
parameters.put('service', 'SocialAPI');
parameters.put('action', 'getViewedByMe');
parameters.put('request', json.serialize(socialRequest));
parameters.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
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('Unable to get social data.');
}
if (apiResponse.type != 'List<SocialBundle>') {
throw new APIException('Unexpected result from Social API.');
}
System.Debug(response); // Outputs response and List<SocialBundle>
System.Debug(apiResponse.message); // Outputs no message on success
JavaScript Request
var apiRequest = {
listParameters: {
originIds: ['a00000000000000000']
},
parameters: {
type: 'Content'
},
requestFlags: {
noData: false
}
};
var response = '';
var data = {
service: 'SocialAPI',
action: 'view',
request: JSON.stringify(apiRequest),
apiVersion: '5.0'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {
var jsonResponse = JSON.parse(json);
console.log(jsonResponse);
}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options); // unlike Request
JSON-Serialized Response Examples
List<SocialBundle> Example
{
"type": "List<SocialBundle>",
"transactionId": null,
"timeNow": "2017-06-26T00:00:00.000Z",
"responseObject": [{
"views": 1,
"socialID": "a00000000000000000",
"socialActivity": {
"viewedDate": "2017-06-26T00:00:00.000Z",
"viewedByMe": true,
"likedDate": "2017-06-26T00:00:00.000Z",
"likedByMe": true
},
"originId": "a01000000000000000",
"likes": 1
}],
"moreResults": false,
"message": "getMySocialData results",
"isSuccess": true,
"error": null
}
Map<String,SocialBundle> Example
{
"type": "Map<String,SocialBundle>",
"transactionId": null,
"timeNow": "2017-06-26T00:00:00.000Z",
"responseObject": {
"a01000000000000000": {
"views": 1,
"socialID": "a00000000000000000",
"socialActivity": {
"viewedDate": "2018-02-01T00:01:38.059Z",
"viewedByMe": true,
"likedDate": "2018-01-31T23:35:04.000Z",
"likedByMe": true
},
"originId": "a01000000000000000",
"likes": 1
}
},
"moreResults": false,
"message": "Viewed",
"isSuccess": true,
"error": null
}