Within the Sitecore CMS workflow, you can execute a webhook to request processing from an external source. In this article, we will check how this works.
Using webhooks in your workflow
It is possible to embed webhooks in workflows in the following versions of Sitecore and later.
- Sitecore XM Cloud
- Sitecore Experience Manager 10.3 or later
- Sitecore Experience Platform 10.3 or later
When adding an action to the workflow of an item you are managing, you can select a webhook.
There is also a workflow that includes a webhook as a sample workflow.
This time, we will use this sample workflow to set up a webhook to be triggered when content approval is complete, and check how it works.
Workflow settings
In this article, we will apply a workflow that uses webhooks to the standard Page template and check that it works. First, because it is possible to set the default values of the items when creating a Page in /sitecore/templates/Project/sxastarter/Page/__Standard Values, we will set up the workflow as follows so that it is a draft at the time of creation.
Next, we will verify the webhook settings for executing the workflow, again using the webhook.site service.
You have now completed the Workflow settings.
Creating and testing items
Create an item
This time, we will not run it as a web page, but will proceed with creating items and checking the operation of webhooks. First, create a Test item and set the content as follows.
The workflow you created is still in draft form.
Proceed with the workflow
The workflow for the item you created will proceed. The following screen shows the status after you have submitted the item and it is waiting for approval.
When the workflow is complete, the following Json data is passed to webhook.site.
Check the data.
The sample data acquired is as follows.
{
"ActionID": "d743186e-4fdd-4f06-859c-b6955fb2feb6",
"ActionName": "Webhook Submit Action",
"Comments": [{ "Key": "Comments", "Value": "" }],
"DataItem": {
"Language": "en",
"Version": 1,
"Id": "cc12f8c5-7355-4013-9147-0d9d26705f3b",
"Name": "Test",
"ParentId": "1f9e052e-27bb-4ca0-a46a-9303d9e1fee3",
"TemplateId": "ecbedbd8-54be-430e-b89e-681ee99e575d",
"TemplateName": "Page",
"MasterId": "00000000-0000-0000-0000-000000000000",
"SharedFields": [
{
"Id": "c7c26117-dbb1-42b2-ab5e-f7223845cca3",
"Value": "<image mediaid=\"{8E2AFE51-1415-4B7A-A3D2-EF48F49DB3F9}\" />"
},
{
"Id": "a4f985d9-98b3-4b52-aaaf-4344f6e747c6",
"Value": "{C9892497-0D1B-4A3F-B47C-62AB8B5AAFD7}"
}
],
"UnversionedFields": [],
"VersionedFields": [
{
"Id": "9f28e75d-2eaa-495a-93e0-e873da727ac7",
"Value": "Test",
"Version": 1,
"Language": "en"
},
{
"Id": "6e8afedc-d855-49de-ba2e-cc83f3c1947b",
"Value": "<h1>Test header 1</h1>\n<p>Paragraph</p>\n<p>paragraph</p>\n<h2>Test Header 2</h2>\n<p>Paragraph</p>",
"Version": 1,
"Language": "en"
},
{
"Id": "4e0720e9-9d50-4ddc-87cf-ecd65e8e94c8",
"Value": "Test",
"Version": 1,
"Language": "en"
},
{
"Id": "25bed78c-4957-4165-998a-ca1b52f67497",
"Value": "20240816T002532Z",
"Version": 1,
"Language": "en"
},
{
"Id": "8cdc337e-a112-42fb-bbb4-4143751e123f",
"Value": "fb7b5148-7341-4bf4-b29f-871d9817961d",
"Version": 1,
"Language": "en"
},
{
"Id": "d9cf14b1-fa16-4ba6-9288-e8a174d4d522",
"Value": "20240816T003018Z",
"Version": 1,
"Language": "en"
},
{
"Id": "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a",
"Value": "sitecore\\test@sitecore.com",
"Version": 1,
"Language": "en"
},
{
"Id": "3e431de1-525e-47a3-b6b0-1ccbec3a8c98",
"Value": "{72E21251-85B0-4A13-B181-FCE910B08232}",
"Version": 1,
"Language": "en"
},
{
"Id": "001dd393-96c5-490b-924a-b0f25cd9efd8",
"Value": "<r />",
"Version": 1,
"Language": "en"
}
]
},
"Message": "",
"NextState": null,
"PreviousState": {
"DisplayName": "Awaiting Approval",
"FinalState": false,
"Icon": "applications/16x16/document_ok.png",
"StateID": "{0B9F5233-0D63-41C1-A56B-542C71ECFAA4}",
"PreviewPublishingTargets": []
},
"UserName": "sitecore\\test@sitecore.com",
"WorkflowName": "Sample Webhook Workflow",
"WebhookItemId": "d743186e-4fdd-4f06-859c-b6955fb2feb6",
"WebhookItemName": "Webhook Submit Action"
}
Let's check the data a little. The JSON data above includes information about Workflow, but the key point is the contents of DataItem. Referring to the data in this, it looks like the following.
Column | Value |
---|---|
Id | Item ID |
Name | Item name |
ParentId | Parent ID |
TemplateId | Template ID |
VersionedFields | Item-held field |
There are also several items in VersiondFields. For the sake of clarity, if we look up the field names rather than the IDs, it will look like this.
ID | Value | Field Name |
---|---|---|
9f28e75d-2eaa-495a-93e0-e873da727ac7 | Test | Title |
6e8afedc-d855-49de-ba2e-cc83f3c1947b | <h1>Test header 1</h1>\n<p>Paragraph</p>\n<p>paragraph</p>\n<h2>Test Header 2</h2>\n<p>Paragraph</p> | Content |
4e0720e9-9d50-4ddc-87cf-ecd65e8e94c8 | Test | Navigation Title |
25bed78c-4957-4165-998a-ca1b52f67497 | 20240816T002532Z | __Created |
8cdc337e-a112-42fb-bbb4-4143751e123f | fb7b5148-7341-4bf4-b29f-871d9817961d | __Revision |
badd9cf9-53e0-4d0c-bcc0-2d784c282f6a | account name | __Updated by |
3e431de1-525e-47a3-b6b0-1ccbec3a8c98 | {72E21251-85B0-4A13-B181-FCE910B08232} | __Workflow state |
001dd393-96c5-490b-924a-b0f25cd9efd8 | <r /> | __Lock |
As shown above, this item contains the main information about the content that the item has.
Summary
This time, we added a Webhook action to the workflow and checked how the item data was being passed through the Webhook. By using this information, it is possible to process the item ID and content information using Json, process it externally, and process it through the API.