Back to Website
Show / Hide Table of Contents

Initialization

  • Last updated on March 10, 2025
  • •
  • 4-5 minutes to read

In this article, you'll learn how to embed the Simple Editor as a web component on a page (store, website, etc.), as well as the settings necessary for its operation. We will assume that the workflow file contains a single workflow element in a file, simple-editor.

Workflow Element Tag Script Styles
Simple Editor <au-simple-editor> workflow-elements/simple-editor/index.js workflow-elements/simple-editor/styles.css

Prerequisites

  1. Before embedding the Simple Editor on a page, create a PIM product in your Customer's Canvas tenant as described in the Creating products topic.

  2. To configure the editor, create a workflow of the Workflow Elements type as described in the Overview topic.

  3. To launch the Simple Editor, you need a URL linking to the Workflow Elements library. In the user interface, you can find this link through Settings > Applications > Workflow Elements URL. In real applications, get the application URLs by using the endpoint GET /api/storefront/v1/tenant-info/applications.

    This URL will look as follows:

    https://staticjs-aurigma.azureedge.net/libs/<environment>/workflow-elements/<application>

Adding an editor to a page

There are two methods to integrate an editor:

  • Dynamically as described in the integration basics
  • Statically as described below

1. Add links to script and styles

Use the base URL from your tenant settings, the component name, and the script file names. To learn how to dynamically add these links, you can refer to the What are Workflow Elements.

Add tyles to the page head.

<html>
  <head>
    <link href="https://staticjs-aurigma.azureedge.net/libs/us/workflow-elements/simple-editor/styles.css" rel="stylesheet" type="text/css">
    ...
  </head>
  ...

Place the script in the <body> tag after all the main content.

<body>
  ...
  <script defer src="https://staticjs-aurigma.azureedge.net/libs/us/workflow-elements/simple-editor/index.js"></script>
</body>

Here, we have hardcoded the us environment. This is the case when we use a US tenant with the Simple Editor deployed.

Important

The environment of the Workflow Elements must match the environment of your tenant. So, if your tenant is deployed on the European servers, specify eu here. For Australian servers, specify au.

2. Add a tag to the page

When you know in advance the workflow element tag, you can statically add it as follows:

<body>
    <au-simple-editor></au-simple-editor>
</body>

3. Provide configuration parameters

To initialize the editor, use the workflowElement.init(config) method, which takes integration settings, product properties, and parameters of the workflow element in the config in the following format:

{
    "configVersion": 2,
    "integration": {
        "tenantId": <yourTenantId>,
        "storefrontId": <yourStorefrontId>,
        "cchubApiGatewayUrl": "<yourCchubApiGatewayUrl>",
        "user": {
            "id": "<userId>",
            "token": "<userToken>"
        }
    },
    "input": {},
    "settings": {},
    "resources": {},
    "localization": {}
}

The settings, resources, and localization objects are usually taken from workflow files in your tenant. You can retrieve a workflow file specified for a product by using the endpoint GET /api/storefront/v1/products/{id}/personalization-workflow as described in Opening products for editing. To learn how you can configure the editor appearance, refer to the Settings topic.

Creating the integration object

The integration object has the following properties:

  • tenantId: take this from the tenant's settings.
  • storefrontId: register your integration as described in the Integrations topic.
  • cchubApiGatewayUrl: define either https://api.eu.customerscanvashub.com, https://api.au.customerscanvashub.com, or https://api.customerscanvashub.com, depending on where your tenant is hosted — in Europe, Australia, or the USA.
  • user.id: register your users as described in the Registering customers topic.
  • user.token: generate a token as described in the Registering customers topic.

This is how the integration object may look like:

{
    "integration": {
        "tenantId": 12345,
        "storefrontId": 123456,
        "cchubApiGatewayUrl": "https://api.customerscanvashub.com/",
        "user": {
            "id": "john.wood",
            "token": "fcmVhZCIsIlN0b3JlZnJvbnRVc2Vyc19mdWxsIiwiU3R..."
        }
    }
}

Creating the input object

The input contains product properties to load the product into the editor. These properties allows you to retrieve products defined in Customer's Canvas in two ways. Let's take a look at them.

Product reference

If you integrate Customer's Canvas with a standard e-commerce platform, like Shopify, you can load the editor based on a product ID from that system. In this scenario, Customer's Canvas uses the external product ID to link the product, as described in the Product links article.

To get such an external product reference, you can call the api/storefront/v1/product-references/ext endpoint.

To load external products to the editor, pass the following properties to the input:

  • productReferenceId is a product ID in an e-commerce system.
  • productId is a product ID in Customer's Canvas.
const input = {
    "productReferenceId": "8255218868440",
    "productId": 2502
};

The productId property is optional here. However, it's highly recommended to use it, as it allows fetching product variants earlier, reducing the editor initialization time.

PIM data

Use this approach with custom e-commerce integrations, when an external system knows the product ID from Customer's Canvas PIM module. In this case, you create products in Customer's Canvas and receive a product list in the admin panel of your store. You can also use the Storefront API to get a product list /api/storefront/v1/products and product links /api/storefront/v1/products/{id}/links endpoint.

The input object will have the following properties:

  • productId is a product ID in Customer's Canvas.
  • productLinkId is a Cusomer's Canvas product link identifier.
const input = {
    "productId": 2502,
    "productLinkId": 26468
};

Note that the product link is optional here. For example, you can load the Simple Editor to preview a PIM product just by using its productId from Customer's Canvas:

const input = {
    "productId": 2502
};

4. Load the editor

You can access the component's DOM element using document.getElementsByTagName. Note that methods of a workflow element can only be called after its script has been loaded.

document.addEventListener("DOMContentLoaded", async () => {

    let simpleEditor = document.getElementsByTagName("au-simple-editor").item(0);

    simpleEditor.init({
        "configVersion": 2,
        "integration": {
            "tenantId": 12345,
            "storefrontId": 123456,
            "cchubApiGatewayUrl": "https://api.customerscanvashub.com/",
            "user": {
                "id": "john.wood",
                "token": "fcmVhZCIsIlN0b3JlZnJvbnRVc2Vyc19mdWxsIiwiU3R..."
            }
        }
        "input": {
            "productId": 2502
        },
        "settings": {
            "pageSelector": { "enabled": true },
            "options": { "disableUnavailable": true }
        },
        "resources": {}
    });
});

5. Handle the output

To receive data from the component, subscribe to the submit event.

simpleEditor.addEventListener("addtocart ", event => console.log(event));

To learn more about the result, refer to the Output data topic.

Was this page helpful?
Thanks for your feedback!
Back to top Copyright © 2001–2025 Aurigma, Inc. All rights reserved.
Loading...
    Thank for your vote
    Your opinion is important to us. To provide details, send feedback.
    Send feedback