﻿![]()

#### 

Sitecore OrderCloud Webhooks are user-defined HTTP callbacks. It’s one of the possible types of extensibility for OrderCloud. You can choose which OrderCloud API endpoints will trigger your hook, the roles to be passed onto the configured Base URL, and any additional configuration data OrderCloud may need to authenticate into 3rd party systems.

Sitecore OrderCloud Webhooks can only be triggered for OrderCloud API endpoints that write to the database (POST, PUT, PATCH, DELETE).

There are two types of Webhooks:

1. Pre-Hook (Webhook will be triggered before executing OrderCloud API endpoint, mostly used for any custom validation)

2. Post-Hook (Webhook will be triggered after executing OrderCloud API endpoint, for example, send order details to 3rd party system)

I will show you how you can extend the existing OrderCloud Headstart Middleware with the custom Webhook. I will create the webhook for Create LineItem (Add to cart).

Let’s create WebhookController under Headstart.API project:

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_1.png?h=513&amp;w=700&amp;hash=7F5ED1291B455711265A856BBC35EA40)

WebhookController inherits **OrderCloud.Catalyst.BaseController**. Make sure to add OrderCloud.Catalyst NuGet package if it is missing. We have to provide route for HTTP POST request and the OrderCloudWebhookAuth attribute for the webhook endpoint. OrderCloudWebhookAuthAttribute is a security feature that blocks requests that do not come from OrderCloud webhooks

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_2.png?h=83&amp;w=700&amp;hash=FA15B296F5AE3794021EEF5DBE476CD0)

OrderCloudWebhookAuthAttribute has to use WebhookHashKey from the Azure App Configuration. We will configure this string in OrderCloud to give webhook access to your protected route.

Once everything is ready from the middleware perspective, we can deploy and run it.

As a result in Swagger we will be able to see our endpoint:

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_3.png?h=354.5&amp;w=494&amp;hash=091B227FEC9BDFD0B6F88236A8ED2315)

Now we have to create/register our webhook in OrderCloud. We have to navigate to the OrderCloud portal and create the webhook:

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_4.png?h=290&amp;w=700&amp;hash=73A95778EEF85EDEBC4B85CF92D2E454)

We have to provide the webhook name, secret, payload URL, and enable the Pre-Hook switcher. The value for the Secret field you can get from your Azure App Configuration for OrderCloudSettings:WebhookHashKey key.

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_5.png?h=427&amp;w=700&amp;hash=9F071E9ABD5367320A16B54125207CE3)

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_6.png?h=371&amp;w=700&amp;hash=86E0AFB344C8F695116068B5B1EE40F0)

You can check all API Clients, provide any Configuration Data if it is needed and choose Trigger Events. In my case, I will select LineItems |  Post (Create a line item). Save it and test.

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_7.png?h=196&amp;w=700&amp;hash=B6F6870B49CB08B6F44F8A2DA3A52A69)

If we will try to add any product with a quantity greater than 5 we will see the following:

![](https://www.brimit.com/-/media/images/blog/ordercloud/ordercloud_customwebhook_8.png?h=201&amp;w=700&amp;hash=39490A7A4438B4A23F3C330AD17BF4CD)

As far as we can see, OrderCloud Webhooks is very flexible and extension mechanism which can be used for different business needs.

Happy coding!

###### Author

[!\[apaliakou\](https://www.brimit.com/-/jssmedia/feature/blogs/authors/apaliakou.jpg?h=216&amp;iar=0&amp;w=360&amp;hash=5BE96F17AE5B47F66D9F684B87773675)
Andrei Paliakou
Sitecore MVP/ Lead Developer](https://www.brimit.com/blog/author?authors=Andrei%20Paliakou)

###### More By Categories

[#E-commerce](https://www.brimit.com/blog?categories=#E-commerce)[#How-to](https://www.brimit.com/blog?categories=#How-to)[#Guides](https://www.brimit.com/blog?categories=#Guides)[Tech Talks](https://www.brimit.com/blog?categories=Tech%20Talks)[#OrderCloud](https://www.brimit.com/blog?categories=#OrderCloud)

###### More by Platform

[Data and AI](https://www.brimit.com/blog?platforms=Data%20and%20AI)[DXP](https://www.brimit.com/blog?platforms=DXP)[E-commerce](https://www.brimit.com/blog?platforms=E-commerce)[Internet of Things](https://www.brimit.com/blog?platforms=Internet%20of%20Things)[Sales and marketing automation](https://www.brimit.com/blog?platforms=Sales%20and%20marketing%20automation)

#### More on Sitecore

[!\[How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2024/vercel_cover-image.png)
#Guides#How-toDXPE-commerce
##### How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects
Optimize and accelerate the development and deployment of complex multisite Sitecore projects.
Alexei Vershalovich on July 17, 2024](https://www.brimit.com/blog/how-vercel-will-help-you-save-effort-when-deploying-sophisticated-sitecore-projects)

[!\[Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2023/sitecore-mentoring---cover-image.png)
#How-toDXP
##### Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story
How to participate in the Sitecore Mentor program and help younger colleagues jump-start a career in Sitecore development.
Sergey Baranov on October 2, 2023](https://www.brimit.com/blog/training-up-tomorrows-sitecore-mvps)

[!\[Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2022/headless/adobestock_456986731.jpg)
#How-toDXPE-commerce
##### Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)
Discover how a headless CMS can benefit organizations that use Sitecore.
Daniil Raschupkin, Palina Trokhautsava on September 15, 2022](https://www.brimit.com/blog/going-headless-part-2-when-a-headless-cms-is-your-best-bet-if-you-have-sitecore)

![](https://bat.bing.net/action/0?ti=187017043&amp;tm=gtm002&amp;Ver=2&amp;mid=194e0a7c-9f1c-49dc-a9b2-f6843e98a11b&amp;bo=2&amp;gtm_tag_source=1&amp;pi=0&amp;lg=en-US&amp;sw=800&amp;sh=600&amp;sc=24&amp;nwd=1&amp;tl=How%20to%20create%20a%20custom%20Webhook%20for%20Sitecore%20OrderCloud&amp;kw=Webhook,%20Sitecore,%20OrderCloud&amp;p=https%3A%2F%2Fwww.brimit.com%2Fblog%2Fhow-to-create-a-custom-webhook-for-sitecore-ordercloud&amp;r=&amp;lt=270&amp;evt=pageLoad&amp;sv=2&amp;asc=D&amp;cdb=AQAY&amp;rn=951471)