- [Home page](https://www.brimit.com/)
- [Blog](https://www.brimit.com/blog)

# Sitecore Send - Webhooks

[Tech Talks](https://www.brimit.com/blog?categories=Tech%20Talks) [DXP](https://www.brimit.com/blog?platforms=DXP)
[Igor Zharikov](https://www.brimit.com/blog/author?authors=Igor%20Zharikov) on July 13, 2023

![Moosend logo](https://www.brimit.com/-/jssmedia/images/blog/sitecore-send-1-abandoned-cart/moosend-sitecore_logo_white-back-2.png?h=465&iar=0&w=882&hash=D18699DD3C6618600D6955F478E45C30)

Webhooks are great to connect services. Our custom service can be notified about some **events** which happened on external service. This is de facto a standard way of integration in a cloud-base infrastructure. And **Sitecore Send provides** this mechanism as well.

#### Where can I place webhooks in Sitecore Send?

Webhooks can be added to the Sitecore Send Automation as an **Action**.

![Webhook action select in automation](https://www.brimit.com/-/media/images/blog/sitecore-send-6-webhook/webhook-in-automation.png)

Then the URL is needed to be added:
![add Webhook URL](https://www.brimit.com/-/media/images/blog/sitecore-send-6-webhook/webhook-url.png)

As mentioned in the description, the endpoint should accept POST HTTP request with webhook payload.

#### How can I implement a custom webhook?

In this example a simple 'log' webhook will be implemented via Node.js [express](https://www.npmjs.com/package/express) module.

##### Webhook implementation

The endpoint logic is very simple:

```
import express from 'express';

const app = express();
app.use(express.json());

const port = 3002;

app.post('/log', (req, res) => {
    console.log(req.body, JSON.stringify(req.body));
    return res.send({success: true});
});

app.listen(port, () =>
    console.log(`server is listening on ${port}.`),
);
```

The key is `app.post('/log', ...)` to handle POST request on `/log` endpoint. Inside the callback we just log to console the body of request.

The full code sources can be found [here](https://github.com/izharikov/sitecore-send-webhook).

##### Webhook publication

To use the webhook in Sitecore Send we need to publish it.

The following publishing options are available:

- publish it to some cloud-based platform: Azure, AWS, Google Cloud Platform, etc.
- publish local server using e.g. [**Ngrok**](https://ngrok.com/)

Let's use **Ngrok** for simplicity:

###### Start the server

```
cd [webhook folder]
npm run start
```

###### Run Ngrok

```
cd [ngrok location]
.\ngrok http 3002
```

Then the URL needs to be copied:
![published url](https://www.brimit.com/-/media/images/blog/sitecore-send-6-webhook/ngrok-public-url.png)

So the final URL for the webhook is the following:

`https://3dc4-31-11-239-239.ngrok-free.app/log`

##### Configure Webhook in Sitecore Send

Then 'Post a webhook' action needs to be added to the automation:
![configure the webhook](https://www.brimit.com/-/media/images/blog/sitecore-send-6-webhook/sitecore-send-action-webhook.png)

*Explanation*. The Automation 'Reactivation' is configured to be triggered when the tag 'Reactivation' is added to **existing** member of specified list. Then the email should be sent. So before sending the email the 'Log' webhook is added.

##### Results

The results of webhook work can be observed in the terminal:
![webhook results log](https://www.brimit.com/-/media/images/blog/sitecore-send-6-webhook/webhook-results.png)

The payload received from Sitecore Send:

```
{
   "UserId":"f4deea67-ec17-4d30-854f-59cced186e59",
   "StepId":"5fd8ee40-20f6-11ee-9d8a-9bf853ab0b87",
   "AutomationId":"d3091761-8e4b-4d1a-8aa5-7c26bb6f5494",
   "Event":{
      "Id":"f288653d-8290-478f-8a94-665bc7a0bc19",
      "Ab":null,
      "UserId":"f4deea67-ec17-4d30-854f-59cced186e59",
      "SessionId":null,
      "EventName":"PROFILE_CHANGED",
      "Timestamp":"2023-07-12T21:06:53.7094041Z",
      "PingContext":null,
      "LinkContext":null,
      "BounceContext":null,
      "DeviceContext":null,
      "WebsiteContext":null,
      "ContactContext":{
         "Id":"f469d169-c38f-4717-b616-d7ebfd24194c",
         "Name":"John Oliver",
         "Mobile":null,
         "MailingListId":"426efbad-a306-4cf2-9071-1a847285785e",
         "MailingListMemberId":"f469d169-c38f-4717-b616-d7ebfd24194c",
         "Tags":null,
         "CustomFields":{

         },
         "FieldsDefinition":{
            "TestFieldName":{
               "Id":"c7f4bfdf-ce98-41f5-87b3-3c5cdcb5e08e",
               "Name":"TestFieldName",
               "Type":0,
               "DateFmt":null,
               "FallBackValue":"",
               "IsRequired":false
            }
         },
         "EmailAddress":"gogoh793581234@lukaat.com",
         "ContactToken":"gogoh793581234@lukaat.com",
         "ContactType":0
      },
      "LocationContext":null,
      "PurchaseContext":null,
      "CampaignContext":null,
      "AddToCartContext":null,
      "ComplaintContext":null,
      "ExitIntentContext":null,
      "ProductViewContext":null,
      "LeadGenerationContext":null,
      "ContactChangedContexts":[
         {
            "FieldName":"[membertags]",
            "NewFieldValue":[
               "reactivation"
            ],
            "OldFieldValue":[

            ]
         }
      ],
      "Properties":{
         "OptedInSource":"2",
         "OptedInFrom":"10.201.0.252",
         "OptedInOn":"2023-07-12T21:06:52.133Z",
         "UpdatedOn":"2023-07-12T21:06:55.150Z",
         "Tags":"[\"reactivation\"]"
      }
   }
}
```

#### Data scheme

Payload JSON schema can be found [here](https://gist.github.com/izharikov/1bccfd8979023204aab9e4d005e1a622).

#### Use cases

Webhook can be used in the following cases:

- You can setup custom **notifications** in Sitecore Send with a webhook.
- Data synchronization with some other storage or integration with another service.
- Logging & debugging

#### Links

[Sitecore Send Webhooks Documentation](https://docs.moosend.com/users/moosend/en/create-an-automation-to-post-a-webhook.html)

#### Sitecore Send Series

- [Abandoned Cart with Sitecore Send](https://www.brimit.com/blog/sitecore-send-1-abandoned-cart)
- [Sitecore Send Tracking HTTP API](https://www.brimit.com/blog/sitecore-send-2-http-api)
- [Sitecore Send REST API](https://www.brimit.com/blog/sitecore-send-3-rest-api)
- [Sitecore Send Integration with Sitecore Forms](https://www.brimit.com/blog/sitecore-send-4-forms-integration)
- [Sitecore Send - Dynamic Transactional Emails (with Mustache)](https://www.brimit.com/blog/sitecore-send-5-dynamic-transactional-emails)
- [Sitecore Send - Webhooks](https://www.brimit.com/blog/sitecore-send-6-webhooks)

###### Author

![Igor Zharikov - Senior Sitecore Developer, Sitecore MVP](https://www.brimit.com/-/jssmedia/feature/blogs/authors/igor-zharikov-2.jpg?h=700&iar=0&w=700&hash=292A84E8CB3E5CE57CA743385CFB1464)

Igor Zharikov

Sitecore MVP / Senior Sitecore Developer
[Igor Zharikov](https://www.brimit.com/blog/author?authors=Igor%20Zharikov)

###### More By Categories

[#Events](https://www.brimit.com/blog?categories=#Events) [#How-to](https://www.brimit.com/blog?categories=#How-to) [#News](https://www.brimit.com/blog?categories=#News) [#Guides](https://www.brimit.com/blog?categories=#Guides)

###### 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-to DXP E-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
[How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects](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-to DXP

##### 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
[Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story](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-to DXP E-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
[Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)](https://www.brimit.com/blog/going-headless-part-2-when-a-headless-cms-is-your-best-bet-if-you-have-sitecore)
