Class: ContentManagementClient

Class: ContentManagementClient

ContentManagementClient

Client object to interact with draft content in Oracle Content Management:
  • Authenticated connection to the Content Server.
  • Read content types.
  • Read draft content items.
  • Render draft content using named content layouts.
The content management client SDK object uses the "/management/" Content REST API calls. This requires the user to be logged in to the system.

Constructor

new ContentManagementClient(args) → {ContentManagementClient}

Parameters:
Name Type Description
args ClientParameters A JavaScript object containing the parameters to create the content management client instance.
Returns:
Type
ContentManagementClient

Extends

Methods

expandMacros(fieldValue) → {string}

Expand Content Macros.
Content item fields can contain macros that reference other content items. For example, a Rich Text field can have links to digital assets.
If a field that you want to render can contain macros, you can use this utility function to expand the macros. Expand macros are supported in Large Text fields, which work with rich text, but not in Text fields, which contain plain text. This method supports expanding the macro CEC_DIGITAL_ASSET into a rendition URL for a digital asset. If the asset GUID is followed by ",true" then the URL will be a download URL.

Parameters:
Name Type Description
fieldValue string A field value that may contain macros.
Overrides:
Returns:
The "fieldValue" string with all macros expanded.
Type
string
Examples
// embed an image asset:
contentClient.expandMacros(
'<img src="[!--$CEC_DIGITAL_ASSET--]CONTABC123[/!--$CEC_DIGITAL_ASSET--]"/>');
// A download link:
contentClient.expandMacros(
'<a href="[!--$CEC_DIGITAL_ASSET--]CONTABC123,true[/!--$CEC_DIGITAL_ASSET--]">Download</a>');

getInfo() → {ContentInfo}

Retrieves the values stored as part of the client object and used on each call.
Once created, these values are immutable for the client instance.
Overrides:
Returns:
The information the SDK is using to retrieve content from Oracle Content Management.
Type
ContentInfo
Example
// get the information on the server and the state used by calls to this client
console.log(contentClient.getInfo());

getItem(args) → {Promise}

Get a single item given its ID or SLUG.
The ID can be found in the search results.
Parameters:
Name Type Description
args object A JavaScript object containing the "getItem" parameters.
Properties
Name Type Attributes Description
id string <optional>
The ID of the content item to return.
The ID or SLUG must be specified.
slug string <optional>
The SLUG of the content item to return, used instead of id.
The ID or SLUG must be specified.
language string <optional>
The language locale variant of the content item to return.
version string <optional>
The version of the asset to return. Should only be used when calling getItem in a preview, not a delivery context. Ignored if language is specified
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
Overrides:
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// Getting item by ID
contentPromise = contentClient.getItem({
    'id': contentId
});


// Getting item by SLUG
contentPromise = contentClient.getItem({
    'slug': contentSlug
});

// handle the result
contentPromise.then(
    function (result) {
        console.log(result);
    },
    function (error) {
        console.log(error);
    }
);

getItems(args) → {Promise}

Get a list of items based on their IDs.
Parameters:
Name Type Description
args object A JavaScript object containing the "getItems" parameters.
Properties
Name Type Attributes Default Description
ids array <optional>
[] Restrict results to the list of requested items.
language string The language locale variant of the content items to return.
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
fields string <optional>
'ALL' Any additional properties in the "args" object will be added to the query string parameters; for example, "fields".
Overrides:
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Examples
// get all items
contentClient.getItems().then(function (items) {
    console.log(items);
});
// get all items and order by type and name
contentClient.getItems().then(function (data) {
    // sort by type and then by name
    console.log(data.items.sort(function (a, b) {
        if (a.type.localeCompare(b.type) !== 0) {
            return a.type.localeCompare(b.type);
        } else {
            return a.name.localeCompare(b.name);
        }
    }));
});

getLayoutInfo(args) → {Promise}

Retrieve metadata information about the content layout.
Note: This method isn't supported if the Content Delivery SDK is used in NodeJS.
Parameters:
Name Type Description
args object A JavaScript object containing the "getLayoutInfo" parameters.
Properties
Name Type Description
layout string Name of the layout in the component catalog for Oracle Content Management.
Overrides:
Returns:
JavaScript Promise object that is resolved when the metadata for the layout is retrieved.
Type
Promise
Example
// get the Content REST API versions supported by the content layout
contentClient.getLayoutInfo({
    'layout': contentLayout
}).then(
    function (layoutInfo) {
        // determine the content versions supported by the layout
        console.log('Content versions supported: ' + layoutInfo.contentVersion)
    },
    function (error) {
        console.log('Error getting data: ' + error);
    }
);

getRenditionURL(args) → {string}

Get the native URL to render an image asset.
Parameters:
Name Type Description
args object A JavaScript object containing the "getRenditionURL" parameters.
Properties
Name Type Attributes Default Description
id string The ID of the image asset. One of 'id' or 'slug' must be provided for the function to return a URL.
slug string The slug of the image asset. One of 'id' or 'slug' must be provided for the function to return a URL.
type string <optional>
'native' The name of the desired rendition
format string <optional>
The desired format. Required for non-native renditions but ignored for native. For image assets the value should be 'jpg' or 'webp'.
download boolean <optional>
Pass true to add &download=true or false for &download=false. This flag will force a content-disposition of 'attachment' or 'inline'. If unspecified, the content server will choose a disposition based on the type of asset.
Overrides:
Returns:
A fully qualified URL to the published image asset.
Type
string
Examples
//get the native rendition URL for this client
contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1'
});
 
//get the Thumbnail rendition URL for an image in JPEG format
contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1',
    type: 'Thumbnail',
    format: 'jpg'
});
 
//get the native rendition URL, to be rendered inline
contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1',
    download: false
});
 
//get the native rendition URL by slug, to be rendered inline
contentClient.getRenditionURL({
    slug: 'pageBanner,
    download: false
});

getTaxonomies(params) → {Promise}

Get taxonomies for the channel.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
params object A JavaScript object containing the "getTaxonomies" parameters.
Overrides:
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all taxonomies
client.getTaxonomies().then(function (topLevelItem) {
     console.log(topLevelItem);
     return topLevelItem;
}, function (xhr, status, error) {
     console.log(xhr.responseText);
});

getType(args) → {Promise}

Get a single item type given it's name.
The name can be found from the search results.
Parameters:
Name Type Description
args object A JavaScript object containing the "getType" parameters.
Properties
Name Type Description
typeName string The name of the content type to return.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed
Type
Promise
Example
contentClient.getType({
    'typeName': 'Customer'
}).then(
    function (data) {
        console.log(data);
    }).catch(function (error) {
        console.log(error);
    });

getTypes(args) → {Promise}

Get a list of item types based on the search criteria.
Parameters:
Name Type Description
args object A JavaScript object containing the "getTypes" parameters. If empty, it will return all content types.
Properties
Name Type Attributes Description
limit number <optional>
Limit the number of content types returned.
offset number <optional>
Return results starting at this number in the results.
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Examples
contentClient.getTypes().then(
    function (data) {
        console.log(data);
    }).catch(function (error) {
        console.log(error);
    });
contentClient.getTypes({
    limit: 10
}).then(
    function (data) {
        console.log(data);
    }).catch(function (error) {
        console.log(error);
    });

loadContentLayout(args) → {Promise}

Require in the requested content layout Note: This method isn't supported if the Content Delivery SDK is used in NodeJS.
Parameters:
Name Type Description
args object A JavaScript object containing the "renderItem" parameters.
Properties
Name Type Description
layout string Name of the layout to use to render the component.
Overrides:
Returns:
JavaScript Promise object that is resolved when the layout JavaScript is loaded
Type
Promise

queryItems(args) → {Promise}

Get a list of items based on SCIM search criteria.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
args object A JavaScript object containing the "queryItems" parameters.
Properties
Name Type Attributes Default Description
q string <optional>
'' An SCIM query string to restrict results.
fields string <optional>
'' A list of fields to include for each item returned.
offset number <optional>
Return results starting at this number in the results.
limit number <optional>
Limit the number of items returned.
orderBy array | string <optional>
[] The order by which results should be returned.
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
Overrides:
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all items and order by type and name
contentClient.queryItems({
    'q': '(type eq "' + contentType + '")',
    'fields': 'ALL'
}).then(function (items) {
    console.log(items);
});

queryTaxonomies(params) → {Promise}

Get taxonomies for the channel.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
params object A JavaScript object containing the "queryTaxonomies" parameters.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all taxonomies in draft status
client.queryTaxonomies({
     'q': '(status eq "' + draft + '")',
}).then(function (topLevelItem) {
     return topLevelItem;
}, function (xhr, status, error) {
     console.log(xhr.responseText);
});

queryTaxonomyCategories(args) → {Promise}

Get categories for the specified taxonomy.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
args object A JavaScript object containing the "queryTaxonomyCategories" parameters.
Properties
Name Type Description
id string The ID of the taxonomy.
Overrides:
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all categories for a taxonomy
client.queryTaxonomyCategories({
     'id': taxonomyId,
     'q': '(name eq "' + categoryName + '")',
}).then(function (topLevelItem) {
     console.log(topLevelItem);
     return topLevelItem;
});

renderItem(args) → {Promise}

Render the given data or content item using the named layout in the given container.
Note: This method isn't supported if the Content Delivery SDK is used in NodeJS.
Parameters:
Name Type Description
args object A JavaScript object containing the "renderItem" parameters.
Properties
Name Type Description
data object JSON data to use to render.
layout string Name of the layout to use to render the component.
container DOMElement Container DOMElement to append to.
Overrides:
Returns:
JavaScript Promise object that is resolved when the layout is loaded and rendered into the container.
Type
Promise
Examples
// render the item into the DOM element with a custom content layout expecting data
compatible with Oracle Content Management Sites
contentClient.getItem({
    'id': contentId
}).then(
    function (contentItemData) {
        // now the data is retrieved, render the layout
        contentClient.renderItem({
            'data': {
                contentItemData: contentItemData,
                scsData {
                    contentClient: contentClient
                }
            },
            'layout': contentLayout,
            'container': document.getElementById(containerDivId)
        }).then(
            function () {
                // render complete
                console.log('layout added to the page');
            },
            function (error) {
                console.log('error rendering layout onto the page: ' + JSON.stringify(error));
            }
        );
    },
    function (error) {
        console.log('Error getting data: ' + error);
    }
);
// render the item into the DOM element with a custom content layout expecting custom data
contentClient.getItem({
    'id': contentId
}).then(
    function (data) {
        // now the data is retrieved, render the layout
        contentClient.renderItem({
            'data': data,
            'layout': contentLayout,
            'container': document.getElementById(containerDivId)
        }).then(
            function () {
                // render complete
                console.log('layout added to the page');
            },
            function (error) {
                console.log('error rendering layout onto the page: ' + JSON.stringify(error));
            }
        );
    },
    function (error) {
        console.log('Error getting data: ' + error);
    }
);