Content

AgilityFetch.Client. Content

Agility Fetch API JS SDK for retrieving content from the Agility CMS

Source:

Methods

(static) getContentItem(requestParams) → {Promise.<AgilityFetch.Types.ContentItem>}

Gets the details of a content item by their Content ID.

Source:
Parameters:
Name Type Description
requestParams Object

The paramters for the API request.

Name Type Attributes Description
contentID number

The contentID of the requested item in this language.

languageCode string

The language code of the content you want to retrieve.

contentLinkDepth number <optional>

The depth, representing the levels in which you want linked content auto-resolved. Default is 1.

Returns:
Type:
Promise.<AgilityFetch.Types.ContentItem>
  • Returns a content item object.
Example
import agility from '@agility/content-fetch'

const api = agility.getApi({
  guid: 'ade6cf3c',
  apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
});

api.getContentItem({
    contentID: 22,
    languageCode: 'en-us'
})
.then(function(contentItem) {
    console.log(contentItem);
})
.catch(function(error) {
    console.log(error);
});

(static) getContentList(requestParams) → {Promise.<AgilityFetch.Types.ContentList>}

Retrieves a list of content items by reference name.

Source:
Parameters:
Name Type Description
requestParams Object

The parameters for the API request.

Name Type Attributes Description
referenceName string

The unique reference name of the content list you wish to retrieve in the specified language.

languageCode string

The language code of the content you want to retrieve.

contentLinkDepth number <optional>

The depth, representing the levels in which you want linked content auto-resolved. Default is 1.

take number <optional>

The maximum number of items to retrieve in this request. Default is 10. Maximum allowed is 50.

skip number <optional>

The number of items to skip from the list. Default is 0. Used for implementing pagination.

sort string <optional>

The field to sort the results by. Example fields.title or properties.modified.

direction AgilityFetch.Types.SortDirection <optional>

The direction to sort the results by.

filters Array.<AgilityFetch.Types.Filter> <optional>

The collection of filters to filter the results by.

filtersLogicOperator AgilityFetch.Types.FilterLogicOperator <optional>

The logic operator to combine multiple filters.

Returns:
Type:
Promise.<AgilityFetch.Types.ContentList>
  • Returns a list of content items.
Example
import agility from '@agility/content-fetch'

const api = agility.getApi({
  guid: 'ade6cf3c',
  apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
});

api.getContentList({
    referenceName: 'posts',
    languageCode: 'en-us',
    take: 50,
    skip: 0,
    sort: 'properties.modified',
    direction: api.types.SortDirections.ASC
})
.then(function(contentList) {
    console.log(contentList);
})
.catch(function(error) {
    console.log(error);
});

api.getContentList({
    referenceName: 'posts',
    languageCode: 'en-us',
    take: 50,
    skip: 0,
    filters: [
     {property: 'fields.title', operator: api.types.FilterOperators.EQUAL_TO, value: '"How this site works"'},
     {property: 'fields.details', operator: api.types.FilterOperators.LIKE, value: '"Lorem ipsum dolar"'}
    ],
    filtersLogicOperator: api.types.FilterLogicOperators.OR
})
.then(function(contentList) {
    console.log(contentList);
})
.catch(function(error) {
    console.log(error);
});