Product export template
Learn how to export Product data to external systems.
Connect application templates are for development purposes. They require further customization before being used in production projects.
The Product export template is Store-specific. Each Deployment handles Product export and synchronization from a single commercetools Store.
Our Product export template demonstrates how to export Products from Composable Commerce Projects to external systems. This functionality provides the ability to integrate with external services such as search, as well as enabling backup and archiving of data.
Implementation
The two applications within the Product export template are:
- Full export: an API endpoint which triggers a full export of all Products from a Store to an external system.
- Incremental updater: an event-driven application which synchronizes changes with a Product in a Store to an external system.
While the full export is triggered by sending a POST call to its endpoint, the incremental updater subscribes to Messages and performs actions when changes are made to Products, Stores, and Product Selections. Subscriptions use delivery guarantees to ensure receipt of Messages.
The following graph illustrates a high-level overview of how the full export and incremental updater applications operate.
Understand Subscriptions and Messages
Messages represent a change or an action performed on a resource, for example a Product or a Store. Previously, you needed to poll the Messages API to retrieve Messages, but now you can subscribe to them with a Subscription and retrieve Messages when these changes occur. The incremental updater application subscribes to Messages that are sent when the following actions occur:
- Change of Product Selections in a Store.
- Products added to a Product Selection.
- Products removed from a Product Selection.
- Updated Product Variant Selection of an existing Product Selection assignment.
- Products being published/un-published.
Create Connect applications
The Product export template contains two Connect applications which provide a good starting point for creating a Connector that will keep your Product catalog synced with an external system. You can customize and extend the Product export template based on your specific needs.
Adding or updating Products
The incremental updater application checks whether the corresponding Product belongs the current Store. If yes, the Product catalog data is synchronized with the external system, otherwise the Product is removed from the external system as it represents the Product is no longer inside the current Store.
Deleting Products
The incremental updater application gets the Product's unique identifier. If the Product belongs to the current Store, the updater removes the Product from the external system.
Reacting to changes on Product Selections
- When a Product is added to a Product Selection, get the Product Projection in the Store with the Product
id
in the received Message, and persist the returned data in the external system. - When a Product Variant inside a Product Selection is updated: get the Product Projection in the Store with the Product
id
in the received Message, and use the returned data to update the corresponding Product catalog data in the external system. - When a Product is removed from a Product Selection, remove the Product from the external system with the Product
id
in the received Message.
Reacting to changes on Stores
When there is a change of Product Selections in a Store, the incremental updater application first makes sure the updated Store is identical to the Store assigned to the Connector. If true, it performs the following tasks:
- Gets all Product Selections of the given Store.
- For each Product Selection, fetches all the Products.
- For each Product returned, gets the Product Projection in the Store with the Product
id
.
- If not found, it indicates the Product is no longer inside the Store and must be removed from the external system.
- If found, it persists the fetched Product Projections with the external system.
For more information, see Populating a Store-specific external search.
Conclusion
Exporting and syncing your Products provides the ability for integrating with services such as search, as well as enabling backup and archiving of data. You could also use this template as the starting point for exporting and syncing other Composable Commerce data with external systems.