← Back to knowledge base |
  • Kentico Xperience 13

Sync form submissions with Integration bus in Kentico Xperience 13

In this post, I will provide a code snippet and tips on how to synchronize new form submissions with an external system via its REST API using the Integration Bus in Kentico Xperience 13.

Problem

When you need to react to events in Kentico Xperience 13 and communicate with external systems, you have several implementation options. One of the most popular approaches is using Global Event Handlers. However, they are synchronous, and you may lose data if the external system is unavailable at the time of synchronization.

Another approach is using the Integration Bus, which can be implemented asynchronously. If the external system is unavailable, Xperience retries the synchronization task, preventing data loss. Additionally, Xperience provides a user-friendly UI for managing synchronization tasks.

In one of my projects, I chose to use the Integration Bus to synchronize form submissions through a REST API. Despite Xperience’s extensive documentation, I encountered some challenges during implementation, which I will discuss. I will also provide a code snippet that accomplishes this task.

Solution

I love code examples, and the best way to start implementing the Integration Bus in your project is by following the example outlined in the Xperience documentation. However, after implementing the example on my machine, I ended up with a partially working solution. The form submission tasks were not tracked by the Integration Bus because I did not reference the new class library in both the live site and Xperience administration projects.

Another issue was finding the object type codename for form submissions. By specifying the object type, the Integration Bus can subscribe to object events. Object types registered in Xperience can be found in the System > Object Types application. Unfortunately, there is no mention of an object type representing a form submission. Eventually, I discovered that the object type codename has the following format: bizformitem.bizform.<your_form_codename_lowercased>. This detail is not mentioned in the documentation.

The following code snippet outlines an Integration Bus class library that:

  1. Subscribes to the Create object event for your form submissions.
  2. When the event occurs, the form data is serialized into a JSON structure and sent through a REST API.
  3. The snippet also demonstrates how to:
    • Access form attachments and convert them to Base64.
    • Log messages in the Event Log.
Loading...

Syncing Form Submissions from Multiple Forms

If you need to synchronize form submissions from multiple forms, and you cannot specify them by form codename, there is a solution. This approach also applies to forms that will be created in the future. The implementation of the Init method differs in this case. You need to create an ObjectIntegrationSubscription object and then call the SubscribeTo method with that object as a parameter.

The crucial aspect is the object type, which uses a wildcard to ensure that form submissions from all forms are observed. Here is the code snippet:

Loading...

About the author

Milan Lund is a freelance web developer with expertise in Kentico. He specializes in building and maintaining websites on the Kentico platform. Milan writes articles based on his project experiences to assist both his future self and other developers.

Find out more
Milan Lund