Transformation templates

Constructor connectors leverage transformation templates to allow you to customize how your data is ingested. While partner connectors provide a base layer of transformation, the Omni Connector relies on you to specify how the data is transformed.

There are three types of transformation templates:

  • Item: Allows you to customize how your Constructor items are transformed.
  • Variation: Allows you to customize how your Constructor variations are transformed.
  • Item Group: Allows you to customize how your Constructor item groups are transformed.

Keep in mind that fixtures stored in the repository represent the data that flows through a connector in a live integration. It will always follow the same structure, so you can refer to a fixture to see how to reach for the pieces of data you want to use.

Each transformation template is expected to return an object with the data that should be ingested. This data mostly follows the CSV Feed Format for items, variations, and item groups, but note that templates might provide additional fields to expose connector features.

The Connect CLI Data Transformation Process

The data transformation process

Data structure

As mentioned preceding, each template is expected to return a specific set of fields to be ingested.

Note that in templates, fields are optional. For the case of partner connectors, not returning a field means you will not override what the connector is doing, and for the Omni Connector, not returning a field means that Constructor will not ingest it.

Please note that not returning a required field (for example, id) might cause your ingestion to fail.

Item template

The item template is expected to return an object containing the following fields:

Field nameTypeDescription
idstring | numberThe unique item id
item_namestringThe display name
activebooleanIf false, the whole item will not be returned in any API requests
urlstringThe item URL
image_urlstringThe main image URL
descriptionstringThe item description
keywordsarray of stringsA list of keywords to match
group_idsarray of stringsThe list of item group ids this item relates to
metadataarray of MetadataA list of metadata in a key-value pair format. Values can be JSON
removebooleanIf true, this record will be removed from the ingestion, thus not being indexed in Constructor.

Variation template

The variation template is expected to return an object containing the following fields:

Field nameTypeDescription
variation_idstring | numberThe unique variation id
item_idstring | numberThe unique item id this variation belongs to
item_namestringThe variation display name
activebooleanIf false, the variation will not be returned in any API requests
urlstringThe variation URL
image_urlstringThe variation image URL
keywordsarray of stringsA list of keywords to match
group_idsarray of stringsThe list of item group ids this variation relates to
metadataarray of MetadataA list of metadata in a key-value pair format. Values can be JSON
removebooleanIf true, this record will be removed from the ingestion, thus not being indexed in Constructor.

Item group template

The item group template is expected to return an object containing the following fields:

Field nameTypeDescription
idstring | numberThe unique item group id
parent_idstring | numberThe item group id this item group belongs to
namestringThe display name
dataobjectAn object to store any custom data
removebooleanIf true, this record will be removed from the ingestion, thus not being indexed in Constructor.

Note that any JSON data can be ingested into the item group data field, similarly to how metadata works with JSON.

Metadata

Both items and variations can ingest the same metadata array. It is data shaped in a key-value pair that will be ingested into your Metadata. Here is how each object should look inside the key-value pair array:

Field nameTypeDescription
keystringThe metadata key
valuestring | number | object | array of strings, numbers or objectsThe metadata value
jsonbooleanIf true, it'll force the field to be ingested as a JSON regardless of the value.

Metadata fields can hold JSON data. To achieve this, specify a JSON piece of data in the value and it will be ingested and returned as JSON during API calls.

Here is an example of valid metadata values:

{
  "metadata": [
    {
      "key": "allergens",
      "value": "gluten"
    },
    {
      "key": "rating",
      "value": 4.99
    },
    {
      "key": "reviews",
      "value": [
        {
          "author": "John Doe",
          "rating": 5,
          "comment": "Great!"
        },
        {
          "author": "Jane Doe",
          "rating": 4,
          "comment": "Good!"
        }
      ]
    }
  ]
}

šŸš§

A note on facets

Facets are no longer defined in a catalog file. Instead, you should ingest this data as metadata and configure it as facetable via the Constructor dashboard or our API.

How do I create a transformation template?

Prerequisites

To develop transformation templates, you will need:

  • A mapping template: Required if you are using the Omni Connector. This allows you to generate fixtures.
  • Fixtures: Ideally, a fixture for each template type you will develop.

Develop your transformation templates

Follow the development flow to develop and test each transformation template.

Refer to your fixtures to understand the data structure, and write each template according to the tables preceding to map it in a way Constructor can understand. Make sure you also cover any cases for your integration.

Once you are happy with how your template looks, you can execute it and create automated tests to ensure it works properly. Finally, when you are satisfied with all of your templates, you can deploy them.

šŸ“˜

Need more information on developing transformation templates?

Please refer to the README.md file within your Connect CLI repository for more details and examples on developing item, variations, and item groups templates.


Whatā€™s Next