A Javascript client for the Integration API provided by the Optimizely CMS. It wraps the Optimizely CMS SaaS Core REST API.
This package is provides as part of one of the mono-repo style demo sites. Install this package by using a mono-repo style structure for your project and copying this package into your mono-repo.
This package works across browser and modern Node.JS environments, which provide an implementation for the Fetch API. The library has been tested with the Fetch API implementation in Node.JS v18 and above.
// Import the Client
import createClient, { ContentRoots } from '@remkoj/optimizely-cms-integration-api'
// Create an instance of the client
const client = createClient({
base: "https://example.com",
clientId: "apiClientID",
clientSecret: "apiClientSecret"
});
// Start using client
client.content.contentListItems(ContentRoots.SystemRoot).then(response => {
const items = response.items
items?.map(item => {
// Do something with the item
})
})
The configuration object for the createClient()
method is optional, if it is omitted, the configuration will be read from the environment variables.
The following configuration options are available for
Environment variable | Configuration key | Required | Usage |
---|---|---|---|
OPTIMIZELY_CMS_URL | base | yes | The URL where the CMS is available |
OPTIMIZELY_CMS_CLIENT_ID | clientId | yes | The API Client ID, as configured within the CMS |
OPTIMIZELY_CMS_CLIENT_SECRET | clientSecret | yes | The API Client Secret as generated by the CMS when creating the client |
OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
OPTIMIZELY_CMS_SCHEMA | cmsVersion | no | Override the target Optimizely CMS Version:OPTI-CMS-12 : Optimizely CMS 12, With CMS Service Preview 1 installed and working.OPTI-CMS-13 : Optimizely SaaS CMS / CMS 13Default: SaaS CMS / CMS 13 |