WebhookTarget
WebhookTarget
WebhookTarget holds one destination of a webhook: the target URL, the basic authentication credentials, and custom headers. Add targets to WebhookModel.destinations.
When to Use This Class: Use this class to set the target URL and the credentials of a webhook.
Conceptual Role: Acts as the item type of WebhookModel.destinations. The SDK serializes the list under the destinations key.
Returns: WebhookTarget. One destination of a webhook.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| TargetUrl | string? | No | null | URL that receives the webhook request. Serialized as target_url. |
| HttpBasicAuth | string? | No | null | User name for HTTP basic authentication. Serialized as http_basic_auth. |
| HttpBasicPassword | string? | No | null | Password for HTTP basic authentication. Serialized as http_basic_password. |
| CustomHeader | List<Dictionary<string, object>>? | No | null | Custom headers to send, one dictionary per header. Serialized as custom_header. |
Class-Level Notes
What the SDK sends.
- The SDK leaves every null property out of the request body and sends each CustomHeader dictionary as a JSON object, unchanged.
- The SDK does not check TargetUrl. The API validates it.
Additional Resource Refer to Create a webhook for the destination fields.
Method Index
WebhookTarget has no methods. Add it to WebhookModel.destinations and pass the model to the Create or Update method of Webhook.
Class-Level Snippet
This snippet builds a target with basic authentication and a custom header, then updates an existing webhook to use 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>");
WebhookTarget target = 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" }
}
};
WebhookModel model = new WebhookModel()
{
Name = "Notify Search Indexer",
destinations = new List<WebhookTarget> { target },
Channels = new List<string> { "content_types.entries.publish" }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Update(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}