Working with Webhooks in Sitecore - Part 1

 

Working with Webhooks in Sitecore - Part 1


In this blog we will understand the concept of Webhooks and how we can use them in Sitecore. So before jumping into Webhooks in Sitecore, first lets understand what webhooks are? 

What is a Webhook?

They are typically created to connect/link different applications. They are much like API but different from them. Webhooks are one way that apps can send automated messages or information to other apps. 

Consider an example below:

 


 

Suppose, there is a user facing front application which showcase the product catalogs to its customers. This application is responsible for booking an order from its users. BUT the logistics is handle by different application. 

The second application (logistic app) has setup a webhook which is exposed over http and waiting to receive any confirmed orders. Once someone place any order which can be called as an event for the first application, then along with its operation it is passing the confirmed order payload to webhook link which is setup by second application. Hence allowing logistic app to begin with its own operation. 

So this is how 2 or more applications can be linked together thru webhooks. 

Webhook Vs API ?

Client application uses API for request and response, so its basically calls are initiated by recipient BUT in case of webhook, the call is initiated by source application and that too on some event, so its event driven. 

Webhooks could be a part of API but is not a complete application. They are easy to setup and are light weighted than API. 

In Sitecore, we need uses webhooks to let ping other application(s) whenever there is change in existing system like on item delete. We are not using the same endpoint to retrieve any external data. Specifically, webhooks exist to help two devices communicate, but that communication is really one-sided.

 


Now, as we know about Webhooks, What are they doing in Sitecore?

In Sitecore 10.3 and above, Webhooks are introduced to send real-time notifications when some event or submit action occurs in XM. Like, if any new Page item is created then Sitecore can send notification, having item details, to external systems or when any Item moves from one workflow state to another then could send notification to specified endpoint. 

The details could be in form of JSON or XML. 

Types of Webhooks

There are 3 types of webhooks available: 

1. Webhook Event Handler : They will be trigger whenever a specific event is triggered, Example : item:added, item:moved etc.

You can find list of all supportive events here: https://doc.sitecore.com/xp/en/developers/latest/sitecore-experience-manager/webhook-event-handler-configuration-fields.html#supported-events


2. Webhook Submit action : You can receive information when workflow state for an item gets changed or when a workflow command runs by adding a webhook submit action. Like, you can insert a webhook submit action in the approved state of a workflow. Then when an item using the workflow moves to the approved state, the webhook sends an HTTP request to a specified endpoint.


3. Webhook validation action : You need this type of webhook setup when you want to prevent an item from changing workflow state unless validated by a third-party service. The third-party service must receive and respond to make enable changes made to the workflow state of the item. Failing to do so will not allow to change the state of the item.

Webhooks in Action

I will dive into implementing webhook in Sitecore 10.3 XP in our next blog, so stay tuned !!

Comments

Popular posts from this blog

Working with Device Detection Module in Sitecore

Setup A/B Testing in Sitecore - Part 1