Skip to content

Instantly share code, notes, and snippets.

@sunpietro
Created December 23, 2014 10:06
Show Gist options
  • Save sunpietro/462da31647b584102250 to your computer and use it in GitHub Desktop.
Save sunpietro/462da31647b584102250 to your computer and use it in GitHub Desktop.
An example of how to use eZ JS REST API to create a new content and get article user-friendly URL in the end.
var pageUrl = 'http://ez.local',
authAgent = new SessionAuthAgent({
login : 'admin',
password: 'admin'
}),
jsRestClient = new CAPI(pageUrl, authAgent),
contentService = jsRestClient.getContentTypeService(),
parentLocationId = '/api/ezp/v2/content/locations/1/2/102',
contentTypeId = '/api/ezp/v2/content/types/16',
locationStruct = contentService.newLocationStruct(parentLocationId),
contentCreateStruct = contentService.newContentCreateStruct(contentTypeId, locationStruct, callback);
contentService.createContent(contentCreateStruct, function (error, response) {
contentService.loadLocations(response.document.Content._href, function (error, response) {
contentService.listLocationAliases(response.document.LocationList.Location[0]._href, false, function (error, response) {
contentService.loadUrlAlias(response.document.UrlAliasRefList.UrlAlias[0]._href, function (error, response) {
console.log(response.document.UrlAlias.path);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment