Agility Content Management JS SDK
This is the official JavaScript library for inserting, updating, managing and importing content, pages and media in your Agility CMS instance.
Don't have an Agility CMS instance? Sign up for Free (forever) today!
Features
Programmatically manage content via JavaScript API client
Agility Instance Management | Content Management | Media Management | URL Redirections | WebHooks |
---|
Get API | Approve Content | Get Media | Delete URL Redirection | Delete WebHook |
| Decline Content | Upload Media | Save URL Redirection | Save WebHook |
| Delete Content | | Save URL Redirection Test | |
| Publish Content | | | |
| Request Approval | | | |
| Save Content Item | | | |
| Unpublish Content | | | |
| Get Content Item | | | |
Getting Started
Installation
Install it using npm (recommended):
npm install @agility/content-management
Making a Request
Create an instance of API client for Agility Content Management REST API
Get API
import agilityMgmt from "@agility/content-management";
const mgmtApi = agilityMgmt.getApi({
location: "USA",
websiteName: "MyWebsiteName",
securityKey: "xyz123",
});
Content Management
Get Content Item
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.getContentItem({
contentID,
languageCode,
})
.then(function (item) {
})
.catch(function (error) {
});
Approve Content
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.approveContent({
contentID,
languageCode,
})
.then(function (contentID) {
})
.catch(function (error) {
});
Decline Content
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.declineContent({
contentID,
languageCode,
})
.then(function (contentID) {
})
.catch(function (error) {
});
Delete Content
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.deleteContent({
contentID,
languageCode,
})
.then(function (contentID) {
})
.catch(function (error) {
});
Publish Content
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.publishContent({
contentID,
languageCode,
})
.then(function (contentID) {
})
.catch(function (error) {
});
Request Approval
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.requestApproval({
contentID,
languageCode,
})
.then(function (contentID) {
})
.catch(function (error) {
});
Save Content Item
let contentItem = {
contentID: -1,
fields: {
Title: "Test Title",
Image: {
mediaID: 123,
label: "Test Image",
},
},
};
let languageCode = "en-us";
let referenceName = "MyReferenceName";
api
.saveContentItem({
contentItem,
languageCode,
referenceName,
})
.then(function (contentID) {
contentIDToWorkOn = contentID;
})
.catch(function (error) {
});
Unpublish Content
let contentID = contentIDToWorkOn;
let languageCode = "en-us";
api
.unpublishContent({
contentID,
languageCode,
})
.then(function (contentID) {
})
.catch(function (error) {
});
Media Management
Get Media
let path = "test.png";
api
.getMediaID({
path,
})
.then(function (mediaObj) {
})
.catch(function (error) {
});
Upload Media
let blob = fs.createReadStream("./test/sample/logo.png");
let filename = `test-${new Date()
.toISOString()
.replace(/\./g, "")
.replace(/:/g, "")}.png`;
api
.uploadMedia({
fileName: filename,
fileContent: blob,
})
.then(function (mediaObj) {
})
.catch(function (error) {
});
URL Redirections
Delete URL Redirection
api
.deleteUrlRedirection({
urlRedirectionID: urlRedirectionIDToDelete,
})
.then(function () {
console.log("deleted");
})
.catch(function (error) {
});
Save URL Redirection
api
.saveUrlRedirection({
originUrl: "/from/link",
destinationUrl: "/to/link",
})
.then(function (urlRedirectionID) {
console.log("saved ", urlRedirectionID);
})
.catch(function (error) {
});
Save URL Redirection Test
api
.saveUrlRedirectionTest({
urlRedirectionID: urlRedirectionIDtoUpdate,
passed: true,
testResult: "- 301 to /dest-url",
})
.then(function () {
console.log("updated test");
})
.catch(function (error) {
});
WebHooks
Delete WebHook
const urlToWorkOn = `http://test.url.com`;
api
.deleteWebHook({ url: urlToWorkOn })
.then(function () {
console.log("deleted");
})
.catch(function (error) {
});
Save WebHook
const name = `Test WebHook`;
const urlToWorkOn = `http://test.url.com`;
api
.saveWebHook({
url: urlToWorkOn,
name,
publishEvents: false,
saveEvents: true,
workflowEvents: false,
})
.then(function () {
})
.catch(function (error) {
});
Documentation
Full documentation for this SDK can be found in our Agility Management JS SDK Reference Doc
For docs & help around Agility CMS, please see Agility CMS Documentation
Tutorials
Calling the Content Management API using the JavaScript SDK
Contributing
If you would like to contribute to this SDK, you can fork the repository and submit a pull request. We'd love to include your updates.
Running the Tests
An essential part of contributing to this SDK is adding and running unit tests to ensure the stability of the project.
> npm run test