This is the official JavaScript library for accessing live and preview content from your Agility CMS instance.
You can use this in both node and browser based JS apps.
- Queries the high-availability, CDN backed Agility Fetch REST API
- Get a sitemap for a given channel
- Get a page, including its content zones, modules, and their content
- Get a content item
- Query a content list
In order to use this sdk, you'll need to install the script and you'll also need to authenticate your requests.
You must have access to an Agility instance to retrieve the instanceID and generate your apiKey. Or, you must have these values provided to you.
Install it using npm (recommended):
npm install @agility/content-fetch
If necessary, you can also reference a standalone package that can be used in a browser using a traditional script tag. In this case, the sdk can be accessed using a global variable by name of agility:
<!-- Use a specific version (i.e. 0.1.4) -->
<script type="text/javascript" src="https://unpkg.com/@agility/content-fetch@0.1.4/dist/agility-content-fetch.browser.js"></script>
<!-- Or, Use the latest version -->
<script type="text/javascript" src="https://unpkg.com/@agility/content-fetch@latest/dist/agility-content-fetch.browser.js"></script>import agility from '@agility/content-fetch'
//initialize the api client
const api = agility.getApi({
instanceID: '1234-1234',
accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
languageCode: 'en-us'
});
//make the request: get a content item with the ID '22'
api.getContentItem({
contentID: 22
})
.then(function(contentItem) {
//on success
console.log(contentItem);
})
.catch(function(error) {
//on error
console.log(error);
});Full documentation for this sdk can be found in our Agility Fetch JS SDK Reference Doc.
Coming soon...