Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ContentClient

Amplience Content Delivery API client.

This client is intended to be used by end user applications to fetch content so that it can be displayed to users.

You must provide some configuration options in order to create an instance of ContentClient. Example:

const client = new ContentClient({
   account: 'test'
});

You may override other settings when constructing the client but if no additional configuration is provided sensible defaults will be used.

Hierarchy

  • ContentClient

Implements

Index

Constructors

constructor

  • new ContentClient(config: ContentClientConfigOptions): ContentClient
  • Creates a Delivery API Client instance. You must provide a configuration object with the required details for the particular service you wish to fetch content from.

    Parameters

    • config: ContentClientConfigOptions

      Client configuration options

    Returns ContentClient

Properties

Private Readonly config

config: ContentClientConfigOptions

Client configuration options

Private Readonly contentClient

contentClient: AxiosInstance

Private Readonly contentMapper

contentMapper: ContentMapper

Methods

fetchContentItems

  • This function will help construct requests for fetching multiple Content Items or Slots by delivery key or ID. Wraps /content/fetch endpoint. Additional documentation

    Type parameters

    • Body

      The type of content returned. This is optional and by default the content returned is assumed to be “any”.

    Parameters

    • body: FetchRequest

      The request body. Can include per item parameters as well as global parameters

    Returns Promise<FetchResponse<Body>>

    Promise<FetchResponse<Body>>

filterBy

  • filterBy<Body, Value>(path: string, value: Value): FilterBy<Body>
  • This function will help construct requests for filtering Content Items or Slots

    Type parameters

    • Body

    • Value

    Parameters

    • path: string

      json path to property you wish to filter by e.g /_meta/schema

    • value: Value

      value you want to return matches for

    Returns FilterBy<Body>

    FilterBy<Body>

filterByContentType

  • filterByContentType<Body>(contentTypeUri: string): FilterBy<Body>
  • This function will help construct requests for filtering Content Items or Slots

    equivalent to:

     client.filterBy('/_meta/schema', contentTypeUri)

    Type parameters

    • Body

    Parameters

    • contentTypeUri: string

      Content Type Uri you want to filter

    Returns FilterBy<Body>

    FilterBy<Body>

filterByParentId

  • filterByParentId<Body>(id: string): FilterBy<Body>
  • This function will help construct requests for filtering Content Items or Slots

    equivalent to:

     client.filterBy('/_meta/hierarchy/parentId', id)

    Type parameters

    • Body

    Parameters

    • id: string

      ID of a Hierarchy Content Item

    Returns FilterBy<Body>

    FilterBy<Body>

filterContentItems

getContentItem

  • getContentItem<T>(contentItemId: string): Promise<ContentItem<T>>

getContentItemById

  • getContentItemById<T>(id: string): Promise<ContentItem<T>>
  • This function will load a Content Item or Slot by id and return a Promise of the result. If the content is not found the promise will reject with an error. If the content is found the promise will resolve with a parsed version of the content with all dependencies.

    The content body will match the format defined by your content type, however keep in mind that if you have evolved your content type some published content may still be in the older format.

    Some pre-processing is applied to the content body to make it easier to work with:

    • Linked content items are joined together into the root content item to create a single JSON document.
    • Media references (images and videos) are replaced with wrapper objects Image and Video which provide helper functions.
    • Content created using V1 of the CMS will be upgraded to the V2 format.

    You can convert the content back to plain JSON by calling the toJSON() function on the returned ContentItem.

    Type parameters

    • T: ContentBody

      The type of content returned. This is optional and by default the content returned is assumed to be “any”.

    Parameters

    • id: string

      Unique id of the Content Item or Slot to load

    Returns Promise<ContentItem<T>>

getContentItemByKey

  • getContentItemByKey<T>(key: string): Promise<ContentItem<T>>
  • This function will load a Content Item or Slot by key and return a Promise of the result. If the content is not found the promise will reject with an error. If the content is found the promise will resolve with a parsed version of the content with all dependencies.

    A delivery key can be a simple string or a path such as "home-page/feature-banner". This makes it simpler to write your integration code and allows users more control over where items of content are delivered. You can add a delivery key to a slot in the Dynamic Content app or to a content item or slot using the Dynamic Content Management API. Note that a delivery key may not start or end with "/" and must be between 1 and 150 characters. Delivery keys can contain the following alphanumeric characters: a to z, A to Z and 0 to 9. You can also include "-" and "_" and "/" as long as it is not included at the start or end of the key.

    The content body will match the format defined by your content type.

    Some pre-processing is applied to the content body to make it easier to work with:

    • Linked content items are joined together into the root content item to create a single JSON document.
    • Media references (images and videos) are replaced with wrapper objects Image and Video which provide helper functions.
    • Content created using V1 of the CMS will be upgraded to the V2 format.

    You can convert the content back to plain JSON by calling the toJSON() function on the returned ContentItem.

    Type parameters

    • T: ContentBody

      The type of content returned. This is optional and by default the content returned is assumed to be “any”.

    Parameters

    • key: string

    Returns Promise<ContentItem<T>>

getContentItems

  • getContentItems<Body>(requests: FetchRequest["requests"], parameters?: FetchRequest["parameters"]): Promise<FetchResponse<Body>>
  • This function will help construct requests for fetching multiple Content Items or Slots by delivery key and/or id and is equivalent to:

     client.fetchContentItems({
       parameters: {
         depth: 'all',
         format: 'inlined'
       },
       requests: [
         { id: '6cd4de36-591b-4ca2-874b-1dec7b681d7e' },
         { key: 'blog/article-1' },
       ],
     });

    Type parameters

    • Body

      The type of content returned. This is optional and by default the content returned is assumed to be “any”.

    Parameters

    • requests: FetchRequest["requests"]

      An array of delivery IDs of the content you wish to fetch

    • Optional parameters: FetchRequest["parameters"]

      Optional override of default parameters

    Returns Promise<FetchResponse<Body>>

    Promise<FetchResponse<Body>>

getContentItemsById

  • getContentItemsById<Body>(ids: Array<string>): Promise<FetchResponse<Body>>
  • This function will help construct requests for fetching multiple Content Items or Slots by delivery ID and is equivalent to:

     client.fetchContentItems({
       parameters: {
         depth: 'all',
         format: 'inlined'
       },
       requests: [
         { id: '6cd4de36-591b-4ca2-874b-1dec7b681d7e' },
         { id: 'c6d9e038-591b-4ca2-874b-da354f5d6e61' },
       ],
     });

    Type parameters

    • Body

      The type of content returned. This is optional and by default the content returned is assumed to be “any”.

    Parameters

    • ids: Array<string>

    Returns Promise<FetchResponse<Body>>

    Promise<FetchResponse<Body>>

getContentItemsByKey

  • getContentItemsByKey<Body>(keys: Array<string>): Promise<FetchResponse<Body>>
  • This function will help construct requests for fetching multiple Content Items or Slots by delivery key and is equivalent to:

     client.fetchContentItems({
       parameters: {
         depth: 'all',
         format: 'inlined'
       },
       requests: [
         { key: 'blog/article-1' },
         { key: 'blog/article-2' },
       ],
     });

    Type parameters

    • Body

      The type of content returned. This is optional and by default the content returned is assumed to be “any”.

    Parameters

    • keys: Array<string>

      An array of delivery IDs of the content you wish to fetch

    Returns Promise<FetchResponse<Body>>

    Promise<FetchResponse<Body>>

renderContentItem

  • renderContentItem(contentItemId: string, templateName: string, customParameters?: {}): Promise<RenderedContentItem>
  • Converts a Content Item or Slot into a custom format (e.g. HTML / XML) by applying a template server side.

    Parameters

    • contentItemId: string

      Unique id of the Content Item or Slot to convert using the rendering service

    • templateName: string

      Name of the template to render the content item or slot with. The template must be setup in your account

    • Optional customParameters: {}

      Custom parameters which will be sent to the rendering API and made avaliable to your template

      • [id: string]: string

    Returns Promise<RenderedContentItem>

Generated using TypeDoc