WebhookModel
WebhookModel
WebhookModel holds the details of a webhook: its name, target URLs, the event channels it listens to, and its delivery options. Pass it to the Create or Update method of Webhook.
When to Use This Class: Use this class to build the request body when you create or change a webhook.
Conceptual Role: Acts as the data model that Webhook serializes under the webhook key of a request.
Returns: WebhookModel. The details of a webhook.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Name | string? | No | null | Name of the webhook. Serialized as name. |
| destinations | List<WebhookTarget>? | No | null | Target URLs and their credentials, as WebhookTarget items. Serialized as destinations. |
| Channels | List<string>? | No | null | Events that trigger the webhook. Serialized as channels. |
| Branches | List<string>? | No | null | UIDs of the branches the webhook listens to. Serialized as branches. |
| RetryPolicy | string? | No | null | Retry policy for failed requests. Serialized as retry_policy. |
| Disabled | bool | No | false | true disables the webhook. Serialized as disabled. |
| ConcisePayload | bool | No | true | true sends a concise JSON payload to the target URL. Serialized as concise_payload. |
Class-Level Notes
What the SDK sends.
- The SDK leaves every null property out of the request body.
- Disabled and ConcisePayload are bool properties, so the SDK always sends them. A new model sends disabled: false and concise_payload: true.
- The destinations property starts with a lowercase letter, unlike the other properties. Write it that way in your code.
Additional Resource Refer to Create a webhook for the request body.
Method Index
WebhookModel has no methods. Set its properties and pass it to the Create or Update method of Webhook.
Class-Level Snippet
This snippet builds a webhook that calls one target URL with basic authentication and a custom header, and creates it.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
WebhookModel model = new WebhookModel()
{
Name = "Notify Search Indexer",
destinations = new List<WebhookTarget>
{
new WebhookTarget()
{
TargetUrl = "https://example.com/hooks/contentstack",
HttpBasicAuth = "<BASIC_AUTH_USERNAME>",
HttpBasicPassword = "<BASIC_AUTH_PASSWORD>",
CustomHeader = new List<Dictionary<string, object>>
{
new Dictionary<string, object> { ["header_name"] = "X-Source", ["value"] = "contentstack" }
}
}
},
Channels = new List<string> { "content_types.entries.publish" },
Branches = new List<string> { "main" },
RetryPolicy = "manual",
Disabled = false,
ConcisePayload = true
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}