Umbraco webhooks enable seamless integration and real-time updates by notifying external services about content changes and events within the Umbraco CMS
Webhooks provide real-time, event-driven communication within Umbraco. They enable external services to react to content changes instantly by sending HTTP requests when specific events occur. This allows you to integrate with third-party services, automate workflows, and synchronize data effortlessly.
To manage webhooks, navigate to Settings > Webhooks in the Umbraco backoffice.
To create a webhook, click Create. This opens the webhook creation screen where you can configure the necessary details.
The Url
is the endpoint where the webhook will send an HTTP request when the selected event is triggered. Ensure this endpoint is publicly accessible and capable of handling incoming requests.
Webhooks are triggered by specific events in Umbraco. By default, the following events are available:
Content Published
Fires when content is published.
Content Unpublished
Fires when content is unpublished.
Content Deleted
Fires when content is deleted.
Media Deleted
Fires when a media item is deleted.
Media Saved
Fires when a media item is saved.
For Content or Media events, you can specify whether the webhook should trigger for all content types or only specific ones. This is useful when you only need webhooks for certain document types, such as blog posts or products.
You can define custom HTTP headers that will be included in the webhook request. Common use cases include:
Specifying request format: Accept: application/json
Adding authentication tokens: Authorization: Bearer <your-token>
Including security headers
Umbraco webhooks come with predefined settings and behaviors.
Each webhook event sends a JSON payload. For example, the Content Published
event includes full content details:
The Content Deleted
event sends only the content ID:
Webhook requests include the following headers by default:
user-agent: Umbraco-Cms/{version}
Identifies the Umbraco version sending the webhook.
umb-webhook-retrycount: {number}
Indicates the retry count for a webhook request.
umb-webhook-event: {event}
Specifies the event that triggered the request. Example: umb-webhook-event: Umbraco.ContentPublished
.
You can extend the list of webhook events using IUmbracoBuilder
and IComposer
. Here’s an example of how to add custom webhook events:
To enable all available events, use:
You can modify existing webhook events, such as changing the payload format, by creating a custom implementation:
To replace the default Umbraco webhook with your custom implementation:
Webhook settings are configured in appsettings.*.json
under Umbraco::CMS
:
Enabled
Enables or disables webhooks.
MaximumRetries
Sets the maximum number of retry attempts.
Period
Defines the retry interval.
EnableLoggingCleanup
Enables automatic cleanup of logs.
KeepLogsForDays
Determines how long webhook logs are retained.
Use Beeceptor or RequestBin to test your event trigger integrations before deploying them to production.
Explore new webhook event options, detailed setup, specific content triggers, and improved logging and retry mechanisms
With Umbraco, you can create your own webhook events.
This documentation guides you through the process of implementing your webhook events using the WebhookEventBase<TNotification>
base class.
The WebhookEventBase<TNotification>
class serves as the foundation for creating custom webhook events. Here's a brief overview of its key components:
Alias: The property that must be overridden to provide a unique identifier for your webhook event.
EventName: A property that represents the name of the event. It is automatically set based on the provided alias unless explicitly specified.
EventType: A property that categorizes the event type. It defaults to "Others" but can be customized using the WebhookEventAttribute
.
WebhookSettings: The property containing the current webhook settings.
ProcessWebhooks: The method responsible for processing webhooks for a given notification.
ShouldFireWebhookForNotification: The method determining whether webhooks should be fired for a specific notification.
ConvertNotificationToRequestPayload: An optional method allowing customization of the notification payload before sending it to webhooks.
To create a custom webhook event, follow these steps:
Derive from WebhookEventBase<TNotification>
:
Override the Alias Property:
Provide a unique identifier for your event using the Alias
property:
Apply WebhookEventAttribute
(Optional):
You can use the WebhookEventAttribute
to specify the event name and type. Apply this attribute to your custom event class:
Umbraco already has some types as constants, which you can find at Constants.WebhookEvents.Types
. If you do not specify this attribute, the event name will default to your alias, and the type will default to Other
.
Implement Notification Handling:
If needed, customize the handling of the notification in the HandleAsync
method.
Register Your Webhook Event:
Ensure that Umbraco is aware of your custom event by registering it in a composer:
Implement Optional Overrides: Depending on your requirements, you can override methods such as ConvertNotificationToRequestPayload
and ShouldFireWebhookForNotification
to customize the behavior of your webhook event.
Here's a basic example of a custom webhook event:
For scenarios where your webhook event is content-specific, Umbraco provides another base class: WebhookEventContentBase<TNotification, TEntity>
. This class is an extension of the generic WebhookEventBase<TNotification>
and introduces content-related functionalities.
The WebhookEventContentBase<TNotification, TEntity>
class is designed for content-specific webhook events, where TEntity
is expected to be a type that implements the IContentBase
interface.
To leverage the WebhookEventContentBase<TNotification, TEntity>
class, follow these steps:
Derive from WebhookEventContentBase<TNotification, TEntity>
:
Override the Required Methods:
GetEntitiesFromNotification: Implement this method to extract content entities from the notification.
ConvertEntityToRequestPayload: Implement this method to customize the content entity payload before sending it to webhooks.
If we take a look at the ContentPublishedWebhookEvent
, we can see how these methods are overriden.
The following example uses IPublishedSnapshotAccessor
, which is obsolete in Umbraco 15 and will be removed in a future version. For more information, see the Version specific upgrades article.
ProcessWebhooks Implementation:
The ProcessWebhooks
method in this class has been enhanced to iterate through content entities obtained from the notification. It checks the content type of each entity against the specified webhook's content type keys, firing webhooks only for matching entities.