Working with Webhooks in Sitecore - Part 2
In my previous blog, we discussed the concept of Webhooks. In this blog, we will set up a simple webhook in Sitecore.
To understand the implementation better I have kept the things very simple. So in this example, I will be using No Authorization Item. Talking about it in brief then, you need to set up an Authorization item if your endpoint webhook requires Authentication. Although I would strongly recommend to use Authorization to keep your endpoint safe and secure in real scenarios.
Webhook authentication types
Currently in Sitecore, there are 5 types of Authentication available.
1. Basic : This requires username and password fields.
2. Digest : This requires username and password fields.
3. API Key : This requires Key, Value and Add to fields.
4. OAuth2.0 Client Credentials Grant : This requires Authority URL, Client ID, Client Secret, Scope, Header Prefix (The default value is Bearer), Additional endpoint base addresses fields.
5. OAuth2.0 Password Credentials Grant : This requires Authority URL, Client ID, Client Secret, Scope, Header Prefix (The default value is Bearer), Username, Password, Additional endpoint base addresses
Webhook Endpoint
Lets set up an endpoint first. This endpoint will receive data in JSON format. As discussed earlier, your endpoint could be in any code base. But to test, we can use Online tools which provide us the endpoint url.
For this example, I will be using webhook.site to show the data we get thru POST. So once you open the site, it will show you like below:
So that’s your endpoint which is listening to some data
Sitecore Webhook Setup
Step 1: The first step is to create Webhook Event Handler.
For this open Content Editor and go to /sitecore/system/Webhooks path.
Step 2: Create New Item named Sample - Site 1 - Item Added
Please note that I have added item_added event as selection. That means if any item is created then it will post the json data related to same item to the configured webhook url.
Step 3: Configure the webhook endpoint
Keeping this example as simple, I have not added any rules. BUT rules must be added so that you can filter the actions.
The value in the URL field is the same to the webhook link which I have created webhook.site and make sure you enabled the webhook.
And that’s it. Your webhook is all set to test.
Step 4: Testing the webhook.
To test this, create any item under home item, like below:
Once created, then lets see webhook.site
In above snapshot you can see that all the item details are pushed from Sitecore to webhook url.
Comments
Post a Comment