Add Kontent.ai

Before you start

This guide helps you get started with the Kontent.ai-specific integration. For more general tips on working with external data sources, check out the guide on connecting to an external data source.

The Kontent.ai integration for Uniform brings your structured content from Kontent.ai into the composition layer, Uniform Canvas. Team members can now leverage your Kontent.ai content, along with data from any of your other sources, to create experiences without needing a developer.

This integration comes with these archetypes to help connect your Kontent.ai items to your Uniform components:

  • Query
  • Single Item
  • Multiple Items
  • Items by element

Before you start

You must the following available to complete this setup:

  • Kontent.ai account with administrator access.
  • A Delivery API key with permissions for content preview and also secure access if the project is configured to require it.
  • Uniform account with administrator access. If you don't already have one, you can request an account at https://uniform.dev/try.
  1. In Uniform, open your project.

  2. Navigate to the Integrations tab.

  3. Scroll to the section Browse integrations.

  4. Click Kontent.ai.

    add-kontentai-integration
    The screen to add the Kontent integration to your project.
  5. Click Add to project.

Once you've installed the integration, the next step is to connect your Kontent.ai environment to your Uniform project by creating a new data source.

  1. Navigate to Experience > Data Types. A data type is an element that can be retrieved from a data source, so the first step is to identify a data source.

  2. Create a new data source by clicking the Add data type button and select the "Create new" option under the Kontent.ai label.

    add-data-source
    Add a data type.
    create-kontentai-data-type
    Where to create a new data type from the available data sources.
  3. Enter the credentials.

    configure-kontentai-data-type
    There is a drop down list of sources available to your project.
  4. Name your data source. Choose a name that helps to inform your editorial users where the content is coming from. The name of the Kontent.ai environment is a good option here.

Before you start connecting Kontent.ai data to your Uniform compositions, it's important to first create some data types. Data types define which types of Kontent.ai data editors can use. This could be simple, like allowing an editor to select a single "hero" entity, or more perhaps a more complex query such as "the five latest news article entries."

  1. Go to Experience > Data Types and click the Add data type button from below the Kontent.ai data source that you set-up earlier.

    add-kontentai-data-type
    Add a data type after selecting the data source.
  2. Next, you will want to select and configure an archetype from the options below.

The query archetype will return a list of content entries containing the queried terms, up to the depth set by the editor in Uniform. This can be useful for dynamic queries where the most up-to-date information is needed, such as a "latest content" section.

Once you configure the archetype, you can test to see what JSON data would be returned when it's used in an experience.

test-query-archetype
The data returned searching 'Title.'

The single item archetype will always return a single entry from Kontent.ai, based on a selection by the editor in Uniform. This is useful for non-list elements that render as an independent item, such as a single "hero" entry or "article" entry. It can accept a variable from a dynamic token (such as a slug) and retrieve the corresponding entry.

test-single-item
Select a single item from available data.

The multiple items archetype lets an editor hand pick multiple entries to render as a list. This is useful when a small selection of specific entries is required, such as in a "featured articles" carousel.

test-mulitple-items
Showing the data returned after selecting mutliple items from the source.

The Items by element archetype will return a list of content entries containing the exact matches to queried terms. This can be useful for dynamic queries where the most up-to-date information is needed, such as a "latest content" section.

test-items-by-element
Showing the data returned after searching elements.

Next steps

Now you are ready to bring content directly into your components in Canvas:

  1. Open any composition
  2. Find component which parameter you want to connect to content from Kontent.ai
  3. Click on the connect icon next to the parameter.
  4. You will be prompted to create a new data resource using one of the data types you created.

Uniform provides Edge Cache invalidation API for invalidating Uniform data type caches by surrogate keys. Surrogate keys enable Uniform to map the CMS items used in a Uniform data type the cached copy of the content in Uniform's edge cache.

The Kontent.ai integration collects surrogate keys for each data resource (i.e. Kontent.ai items, including linked content) used in a composition.

Kontent.ai webhooks can be configured to notify Uniform about changed content and surgically invalidate affected Uniform data resources. Uniform provides the following endpoints that a Kontent.ai webhook can be configured to use:

URLhttps://kontentai.mesh.uniform.app/api/invalidation
DescriptionThis endpoint invalidates all caches for the specified data type. No surrogate keys are used.
The following query strings are required:
Parameter nameDescriptionSample value
projectIdUniform project ID00000000-042b-47e3-95ed-2b0ac0200991
dataTypeIdUniform data type IDhero
purgeKeyUniform purge key00000000-ec0c-4fb2-8841-f4c87b8992bf

The following is a sample URL to call the endpoint:

https://kontentai.mesh.uniform.app/api/invalidation? projectId=00000000-042b-47e3-95ed-2b0ac0200991& dataTypeId=hero& purgeKey=00000000-ec0c-4fb2-8841-f4c87b8992bf
URLhttps://kontentai.mesh.uniform.app/api/incremental-invalidation
DescriptionThis endpoint invalidates all caches for the specified data type, using the surrogate keys included in the payload.
The following query strings are required:
Parameter nameDescriptionSample value
projectIdUniform project ID00000000-042b-47e3-95ed-2b0ac0200991
dataTypeIdUniform data type IDhero
purgeKeyUniform purge key00000000-ec0c-4fb2-8841-f4c87b8992bf

The following is a sample URL to call the endpoint:

https://kontentai.mesh.uniform.app/api/incremental-invalidation? projectId=00000000-042b-47e3-95ed-2b0ac0200991& dataTypeId=hero& purgeKey=00000000-ec0c-4fb2-8841-f4c87b8992bf

The following table describes how each of the events that can be included in the payload are handled:

Event typeHow events are handled.
Content itemInvalidation by Content Item ID.
Content typeinvalidation by Content Type codename.
AssetInvalidation by Asset ID and Asset name.
TaxonomyInvalidation by Taxonomy Group codename.
LanguageAll caches for the specified Uniform data type will be invalidated.

info

You can find a list of Kontent.ai webhook events in the documentation.

  1. Register a new webhook as described in the Kontent.ai documentation. Use the URL for the appropriate Uniform endpoint in the field Webhook URL.
  2. In the Triggers section, select Published data.
  3. (optional) Configure Specific events for a data type, or keep All events.
webhook-triggers
Kontent.ai configuration page for webhook triggers.

You should configure a separate webhook for each Uniform data type.

Kontent.ai Delivery API may serve stale content (if content has been cached by CDN) while fetching the new content. Delivery API provides Wait for loading new content option to bypass CDN cache.

Bypassing Kontent.ai CDN cache affects API response time and rate limits.

This option can be configured in Uniform UI per data type.

wait-for-loading-new-content
'Wait for loading new content' option

CanvasClient and RouteClient use stale-while-revalidate approach by default, so Uniform APIs may serve stale data resources content while revalidating in background. This behavior can be changed by specifying disableSWR: true option for the client.

newer package version needed

This settings is available with @uniformdev npm packages version 19.91.0 or higher. If you want to use this setting, consider updating your Uniform packages. In versions before 19.91.0, use the following setting instead: bypassCache: true