Skip to main content

Use parameters

After you install the Commercetools integration, the following parameter types are available. You can use these to incorporate content from Commercetools into your components and compositions.

Parameter typeDescription
Commercetools ProductSelect a single product from Commercetools.
Commercetools Product ListSelect multiple products from Commercetools.

Commercetools Product

This parameter type allows a Uniform user to select a single Commercetools product.

Add parameter to component

In order to allow a user to select a product from Commercetools, you must add a parameter to a component. The parameter is used to store the identifier to the selected product when the user selects a product.

  1. In Uniform, navigate to your component.

  2. Add a new parameter using the parameter type Commercetools Product.

    Commercetools Product parameter configuration.

Edit parameter value

When you use a component with a Commercetools Product parameter, by default no product will be selected. You are prompted to select a product.

  1. Click Select.

  2. Click the product you want to select.

    About this step

    A couple of filters are available. The dropdown allows you to filter by category. The text box allows you to filter by product name.

  3. Click Accept to save your selection.

  4. You will see details about the product you selected, including the name, category, and price.

    About this step

    After your selection is saved, you are presented with the following options:

    • If you want to unselect the product, click the red X.

Configure an enhancer

When a product is selected, Uniform only stores the identifier for the product. Your front-end application must retrieve the details for the product. Uniform provides an enhancer to simplify this process.


Using the enhancer provided by Uniform saves you from having to write logic to interact directly with Commercetools.

How Uniform stores the selected product

The following is an example of what Uniform stores for the parameter.

"type": "commercetoolsProduct",
"value": "######################"

The product ID is stored as the value.

Add the enhancer

Uniform provides an enhancer so you don't need to write the API calls to Commercetools to retrieve data for products.


For more information about the enhancer, see the package documentation.

  1. Add the following npm packages to your front-end application:

  2. Add the following file:

      import getConfig from 'next/config';
    import { ApiRoot, createApiBuilderFromCtpClient } from '@commercetools/platform-sdk';
    import { createClient } from '@commercetools/sdk-client';
    import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth';
    import { createHttpMiddleware } from '@commercetools/sdk-middleware-http';
    import { createCommercetoolsEnhancer } from '@uniformdev/canvas-commercetools';
    import fetch from 'node-fetch';

    const commercetoolsAuthUrl = [!!! YOUR CT AUTH URL !!!];
    const commercetoolsProjectKey = [!!! YOUR CT PROJECT KEY !!!];
    const commercetoolsClientId = [!!! YOUR CT CLIENT ID !!!];
    const commercetoolsClientSecret = [!!! YOUR CT CLIENT SECRET !!!];
    const commercetoolsApiUrl = [!!! YOUR CT API URL !!!];

    const authMiddleware = createAuthMiddlewareForClientCredentialsFlow({
    host: commercetoolsAuthUrl,
    projectKey: commercetoolsProjectKey,
    credentials: {
    clientId: commercetoolsClientId,
    clientSecret: commercetoolsClientSecret,

    const httpMiddleware = createHttpMiddleware({
    host: commercetoolsApiUrl,

    const ctpClient = createClient({
    middlewares: [authMiddleware, httpMiddleware],

    const apiRoot: ApiRoot = createApiBuilderFromCtpClient(ctpClient);

    export const commercetoolsEnhancer = createCommercetoolsEnhancer({
    projectKey: commercetoolsProjectKey,
    About this step

    We recommend you moving the Commercetools credentials to environment variables rather than hard-coding them in the front-end app.

  3. In a text editor, open the file where you retrieve the composition definition from Uniform.

    About this step

    You are looking for the code calls the async function getComposition. The code below assumes the object returned is set in a variable composition.

  4. Add the following import statements:

    import { EnhancerBuilder, enhance } from '@uniformdev/canvas';
    import {
    } from '@uniformdev/canvas-commercetools';
    import {
    } from '../lib/commercetoolsEnhancer';
  5. Add the following code:

    await enhance({
    enhancers: new EnhancerBuilder().parameterType(
    context: {},
    About this step

    This registers the enhancer to be used for any occurrence of the Commercetools Product parameter.

Next steps

Now, the parameter value in the composition is mutated to include the field values for the selected Commercetools product (instead of just being identifiers).

Commercetools Product List

This parameter type allows a Uniform user to select multiple Commercetools products.

Add parameter to component

In order to allow a user to select multiple products from Commercetools, you must add a parameter to a component. The parameter is used to store the identifiers to the selected products when the user selects products.

  1. In Uniform, navigate to your component.

  2. Add a new parameter using the parameter type Commercetools Product List.

    Commercetools Product List parameter configuration.

Edit parameter value

This parameter type works the same way as Commercetools Product, adding the ability to select multiple products from the list when the parameter value is edited.

Example of the editing interface for an Commercetools Product List parameter on a component.

Configure an enhancer

This parameter type uses the same enhancer as the Commercetools Product parameter type.


The parameter settings are stored in Canvas in a slightly different format. Instead of a single product ID being stored, the value is stored as an array of product IDs.

"type": "commercetoolsProductList",
"value": [