- Kentico EMS & Xperience
Sync form submissions with Integration bus in Kentico Xperience
In this post, I will provide you with a code snippet and tips on how to synchronize new form submissions with an external system through its REST API using the Integration bus in Kentico Xperience.
When you need to react to events that happen in Xperience and communicate with external systems, you have multiple options of implementing it. One of the most popular approaches is Global event handlers. Regrettably, they are synchronous and you may lose your data when the external system is not available at the time of the synchronization.
Another approach is using the Integration bus. It could be implemented in an asynchronous fashion. Also, when the external system is not available, Xperience retries the synchronization task which prevents you from losing your data. Moreover, Xperience has a nice UI where you can manage the synchronization tasks.
In one of my projects, I decided to use the Integration bus to synchronize form submissions through REST API. Despite the fact that Xperience has complex documentation, I battled a few things during the implementation and I will mention them. Also, I will provide you with a code snippet that does the job.
I love code examples and the best way to start implementing the Integration bus in your project is the example outlined in the Xperience docs. When I finished implementing the example on my machine, I ended up with a partially working outcome. The form submission tasks did not get tracked by the Integration bus. The problem was that I did not reference the new Class library in both live site and Xperience administration projects.
The other problem was that I wasn't able to find an object type codename of 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. Regrettably, there is no mention of an object type that would represent a form submission. In the end, I found out the object type codename has the following format
bizformitem.bizform.<your_form_codename_lowercased>. This is not mentioned in the documentation.
In the following code snippet, I outline code for an Integration bus Class library. The code does the following actions:
- Subscribes to Create object event of your form submissions.
- When the event occurs, the form data get serialized in a JSON structure and sent through a REST API.
- The snippet also shows
- how to access form attachments and convert them in Base64,
- how to log messages in the Event log
Syncing form submission from multiple forms
If you need to synchronize form submission from multiple forms that you are not able to specify with form codename, there is a way. This also applies to forms that will be created in the future. The
Init method implementation is different. You need to specify the
ObjectIntegrationSubscription object and then call the
SubscribeTo method with that object as a parameter.
The crucial aspect is the object type that uses a wildcard that ensures form submissions are observed in all forms. here is the code snippet:Loading...