How to implement the integration for Talon.One and commercetools

Care to share?

Modern eCommerce is moving towards a composable approach. This lets you easily integrate best-of-breed platforms and combine them into your own closely adapted system. We’ve launched multiple integrations to support this vision.

For more than 12 years, Divante has been helping eCommerce companies choose the right technical solutions for end-to-end eCommerce implementations. We’re the Premier Partner of commercetools and other leading eCommerce platforms, such as Shopware, Magento, and VTEX. 

We strongly believe that a large eCommerce needs a proper promotions engine. Besides Open Loyalty, which was launched within Divante, we’re also partners of Talon.One, who delivers extraordinary promotion features. Up to this day, it’s lacked a proper integration with commercetools, who is the top headless eCommerce engine on the market.

Here’s the result of our cooperation to change this.

How does the Talon.One and commercetools integrator work?

Our Talon.One and commercetools integrator is an open-source microservice connector. It consists of three main processes:

  1. Updating customer profiles in Talon.One every time something changes in commercetools.
  2. Sending events from commercetools to Talon.One each time a customer creates or updates their cart in commercetools. 
  3. Fetching recalculated promotion rules from Talon.One and returning this data to a client app via standard commercetools response.

Take a look at the official tutorial and documentation from Talon.One.

commercetools API extensions

It all requires event-driven architecture and real-time communication. That’s why we decided to implement this microservice as a set of commercetools API extensions that are triggered by commercetools events like:

  • Customer created or updated
  • Cart created or updated
  • Order created

For those who are not familiar with commercetools, API extensions allow you to modify the response of an API call. You can easily extend commercetools’ response objects with new fields from Talon.One and return them to the front-end application.

Find out more about commercetools API extensions.

An example of how it works in practice

  • The client application, like Vue Storefront or any other progressive web app (PWA) or mobile app, requests commercetools to change something in the cart.
  • Immediately in the same request-response loop, our serverless function will be triggered. 
    • It exchanges data with Talon.One.
    • It saves results in commercetools.
    • commercetools returns a modified response to the client app with all the Talon.One information about valid and applied promotion rules.

How do we implement the promotion integration?

Together with Talon.One, we wanted to create an integration with commercetools that will be extremely quick, scalable, super easy to develop, and also easy to launch and maintain in the future. That's why we decided to create a single serverless microservice written in Node.js. It’s in pure js, not TS, which is very well known by all developers. 

We also supported major cloud providers, such as AWS and Google Cloud, through Serverless Framework. This helps us describe the infrastructure as code and gives us additional tools like deploying and managing serverless functions locally or in a direct cloud environment.

If you’re not familiar with Serverless Framework, you can dig deeper into it here.

How does our Talon.One integration affect commercetools’ API?

Check out our documentation on GitHub. There, you’ll find all the information about how to interact with commercetools’ API to leverage Talon.One. It also describes how our integration extends the standard commercetools’ API with a couple of examples.

How we process customer events from commercetools to Talon.One

Let's take a look at the details for the process of sending customer events. When your client application requests commercetools, via REST or GraphQL, to create or update customers, commercetools triggers a serverless function. This transforms data from commercetools to the Talon.One data format and stores this information in Talon.One through standard REST API.

How we process cart events from commercetools to Talon.One

When your client application requests commercetools, via REST or GraphQL, to change anything on the cart level in commercetools, commercetools triggers a serverless function. It transforms data from commercetools to the Talon.One data format and stores this information in Talon.One through REST API. 

At the same time, Talon.One returns information about valid promotion rules, which are called Effects. These are again transformed and returned to commercetools.

In the last step, commercetools returns a standard response to the client app. That response includes extended information about applied Talon.One Effects. 

How to exchange attributes between systems

What about attributes? Both commercetools and Talon.One have their own specific attributes and support for creating custom attributes on the customer, cart, and cart item levels. 

Our integration supports all standard and custom fields on both systems. 

All that you need to do is define the mapping in a special *.env configuration file. All of these attributes will be exchanged automatically between the systems.

More information about configuring mappings.

Getting started with the connector

Our integration microservice is an open-source project available on the official GitHub of Talon.One. If you have any kind of issues, ideas, or questions please, report them via GitHub. Someone from either Talon.One or Divante will definitely reply to it. Feel free to clone the repository, fork it, have fun, and contribute. :) 

Six simple steps to launch the integration in minutes

As we said at the beginning, it was really important for us to make it really easy to use. With just a few commands, you’ll have the integration up and running in no time. Let's go through six simple steps to set it up.

  1. After cloning the repository and installing required tools like the Yarn package manager, you can easily install all other dependencies via a single command called yarn install.

  2. Next, you need to edit configuration variables which are placed in *.env file.

    Here’s more information on how to prepare a configuration file.

  3. Type command yarn register-api-types to create custom fields in commercetools that are required by this integration.

  4. Next, type command yarn register-api-extension to register the proper API extensions in commercetools.

  5. Finally, type yarn deploy to deploy the serverless function on the configured cloud provider.

  6. That’s it. Now you can go to the Talon. One dashboard and check Integration API Logs to see whether your integration works and communicates properly with commercetools.

An example implementation of an integration on Vue Storefront

If you’d like to take a look at how the commercetools and Talon.One integration works from a client application perspective, here’s a link to a demo. It’s an example implementation based on the Vue Storefront PWA application. 

Feel free to play around with it and see for yourself how powerful Talon.One is and how it integrates with other technologies like Vue Storefront.

Published October 19, 2021