dc-delivery-sdk-js
    Preparing search index...

    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.

    Implements

    • GetContentItemById
    • GetContentItemByKey
    Index

    Constructors

    • 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

    Methods

    • 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 = any

      Parameters

      • body: FetchRequest

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

      Returns Promise<FetchResponse<Body>>

      Promise<FetchResponse<Body>>

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

    • This function will help construct requests for filtering Content Items or Slots

      Type Parameters

      • Body = any
      • Value = any

      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>

    • This function will help construct requests for filtering Content Items or Slots

      equivalent to:

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

      Type Parameters

      • Body = any

      Parameters

      • contentTypeUri: string

        Content Type Uri you want to filter

      Returns FilterBy<Body>

      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 = any

      Parameters

      • id: string

        ID of a Hierarchy Content Item

      Returns FilterBy<Body>

      FilterBy<Body>

    • This function will help construct requests for filtering Content Items or Slots

      Type Parameters

      • Body = any

      Parameters

      • filterBy: FilterByRequest

        API options for /content/filter endpoint docs

      Returns Promise<FilterByResponse<Body>>

    • 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

      Parameters

      • id: string

        Unique id of the Content Item or Slot to load

      Returns Promise<ContentItem<T>>

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

    • 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

      Parameters

      • key: string

      Returns Promise<ContentItem<T>>

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

    • 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 = any

      Parameters

      • requests: (FetchRequestWithId | FetchRequestWithKey)[]

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

      • Optionalparameters: RequestOptions

        Optional override of default parameters

      Returns Promise<FetchResponse<Body>>

      Promise<FetchResponse<Body>>

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

    • These functions 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 = any

      Parameters

      • ids: string[]

      Returns Promise<FetchResponse<Body>>

      Promise<FetchResponse<Body>>

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

    • 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 = any

      Parameters

      • keys: string[]

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

      Returns Promise<FetchResponse<Body>>

      Promise<FetchResponse<Body>>

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

    • This function will help construct requests for filtering Content Items or Slots

      equivalent to:

       client.lookUpBy(key, value)
      

      Type Parameters

      • Body = any

      Parameters

      • key: string

        the key for the lookup eg: HIERARCHY_PARENT_META_DELIVERY_KEY

      • value: string

        the value for the lookup

      Returns FilterBy<Body>

      FilterBy<Body>

    • This function will help construct requests for filtering Content Items or Slots

      equivalent to:

       client.lookUpBy('HIERARCHY_PARENT_META_DELIVERY_KEY', deliveryKey)
      

      Type Parameters

      • Body = any

      Parameters

      • deliveryKey: string

        ID of a Hierarchy Content Item

      Returns FilterBy<Body>

      FilterBy<Body>

    • 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

      • OptionalcustomParameters: { [id: string]: string }

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

      Returns Promise<RenderedContentItem>