Webhook
Webhook
The Webhook class creates, fetches, lists, updates, and deletes the webhooks of a stack, and reads and retries their executions. A webhook sends a request to your URL when an event happens in the stack.
When to Use This Class: Use this class to connect a stack to another service, for example to trigger a site build when an entry publishes.
Conceptual Role: Acts as the Content Management API (CMA) client for the /webhooks endpoint. Call stack.Webhook() to get an instance.
Returns: Webhook. An object for webhook operations.
Instance State
The UID you pass to stack.Webhook() decides which methods you can call on the instance:
- Call stack.Webhook() without a UID to work with the webhook collection, for example Create or Query.
- Call stack.Webhook("<WEBHOOK_UID>") to work with one webhook, for example Fetch or Executions.
If you call a method from the other group, it throws before any request leaves the SDK. A collection method on an instance that has a UID throws InvalidOperationException, and a single-webhook method on an instance with no UID throws ArgumentException. The Method Index below lists every method in each group.
Retry and Logs act on an execution, not on the webhook, but the SDK still requires a webhook UID on the instance. Call them on stack.Webhook("<WEBHOOK_UID>").
Warning The SDK treats an empty string as no UID for its checks, but still adds it to the request path. stack.Webhook("") allows Create and Query, which then send their requests to /webhooks/ with a trailing slash. Call stack.Webhook() with no argument when you mean the collection.
Class-Level Notes
Authentication.
- stack.Webhook() throws InvalidOperationException when the client has no authtoken and the stack has no management token.
- The CMA reference accepts an authtoken, a management token, or an Open Authorization (OAuth) token for every webhook request.
Requests and responses.
- Every method that sends a request returns the raw API response as a ContentstackResponse. Read it with OpenJsonObjectResponse().
- Create and Update serialize a WebhookModel under the webhook key and leave out its null properties.
Executions.
- Each time a webhook fires, the API records an execution with its own UID. Executions lists them, and Retry and Logs take one execution UID.
Capability Matrix
| Capability | Supported | Notes / Alternative |
|---|---|---|
| Export a webhook to a JSON file | No | The SDK has no method for the CMA Export a Webhook request. |
| Import a webhook from a JSON file | No | The SDK has no method for the CMA Import a Webhook requests. |
| Pause a webhook without deleting it | Yes | Call Update with Disabled = true. |
Method Index
Work with the webhook collection. Available on stack.Webhook() when you pass no UID.
| Method Name | Returns | Description |
|---|---|---|
| Query | A new query for webhooks. | Builds a query that lists webhooks. |
| Create | The API response with the created webhook. | Creates a webhook. |
| CreateAsync | The API response with the created webhook. | Creates a webhook asynchronously. |
Work with one webhook. Available on stack.Webhook("<WEBHOOK_UID>").
| Method Name | Returns | Description |
|---|---|---|
| Fetch | The API response with the requested webhook. | Retrieves one webhook. |
| FetchAsync | The API response with the requested webhook. | Retrieves one webhook asynchronously. |
| Update | The API response with the updated webhook. | Replaces the details of a webhook. |
| UpdateAsync | The API response with the updated webhook. | Replaces the details of a webhook asynchronously. |
| Delete | The API response with the deletion notice. | Deletes a webhook. |
| DeleteAsync | The API response with the deletion notice. | Deletes a webhook asynchronously. |
Work with executions. Available on stack.Webhook("<WEBHOOK_UID>").
| Method Name | Returns | Description |
|---|---|---|
| Executions | The API response with the executions of the webhook. | Lists the executions of a webhook. |
| ExecutionsAsync | The API response with the executions of the webhook. | Lists the executions of a webhook asynchronously. |
| Retry | The API response with the retry notice. | Retries one execution. |
| RetryAsync | The API response with the retry notice. | Retries one execution asynchronously. |
| Logs | The API response with the execution log. | Retrieves the latest log of one execution. |
| LogsAsync | The API response with the execution log. | Retrieves the latest log of one execution asynchronously. |
Class-Level Snippet
This snippet creates a webhook, lists the first page of webhooks, and reads the executions of an existing webhook.
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>");
Stack stack = client.Stack("<API_KEY>");
WebhookModel model = new WebhookModel()
{
Name = "Notify Search Indexer",
destinations = new List<WebhookTarget>
{
new WebhookTarget() { TargetUrl = "https://example.com/hooks/contentstack" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
try
{
ContentstackResponse created = await stack.Webhook().CreateAsync(model);
Console.WriteLine(created.OpenJsonObjectResponse().ToJsonString());
ContentstackResponse list = await stack.Webhook().Query().Limit(10).FindAsync();
Console.WriteLine(list.OpenJsonObjectResponse().ToJsonString());
ContentstackResponse executions = await stack.Webhook("<WEBHOOK_UID>").ExecutionsAsync();
Console.WriteLine(executions.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Methods
Each method of the Webhook class has its own section below, with its parameters, validation rules, behavior, and examples.
Create
Create creates a webhook that sends a request to its target URLs when the events in its channels occur.
| Name | Type | Description |
|---|---|---|
| model (required) | WebhookModel | Sets the name, target URLs, channels, and delivery options. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the created webhook.
Validation
- Throws InvalidOperationException if the instance has a UID, because Create posts to the webhook collection. Call stack.Webhook() with no UID.
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- The SDK does not check the properties of model. The API validates them.
- Throws ContentstackErrorException when the API rejects the request, for example a target URL that is not a valid URL.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST request to /webhooks, with model serialized under a webhook key. See Create a webhook in the Content Management API (CMA) reference.
- Leaves every null property of model out of the request body.
- Always sends disabled and concise_payload, because Disabled and ConcisePayload are bool properties. Their defaults are false and true, so a new webhook starts enabled and sends a concise payload unless you change them.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: create a webhook for entry publish events
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)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: create a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
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" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook().Create(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: calling Create on an instance that has a UID
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" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
try
{
// Create adds a new webhook, so call it on Webhook() with no UID.
client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Create(model);
}
catch (InvalidOperationException e)
{
// Fires before any request, because the instance has a UID
Console.WriteLine(e.Message);
}CreateAsync
CreateAsync creates a webhook that sends a request to its target URLs when the events in its channels occur, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| model (required) | WebhookModel | Sets the name, target URLs, channels, and delivery options. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the created webhook.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws InvalidOperationException if the instance has a UID, because CreateAsync posts to the webhook collection. Call stack.Webhook() with no UID.
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- The SDK does not check the properties of model. The API validates them.
- The SDK throws the client-side exceptions above when you call CreateAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request, for example a target URL that is not a valid URL.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Create.
Example
Basic usage: create a webhook for entry publish events
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 = await client.Stack("<API_KEY>").Webhook().CreateAsync(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: create a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
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" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook().CreateAsync(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Delete
Delete deletes one webhook from the stack.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the deletion notice.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because Delete removes one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one DELETE request to /webhooks/<WEBHOOK_UID>. See Delete webhook in the Content Management API (CMA) reference.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Warning Deleting a webhook stops every future request to its target URLs. The SDK offers no way to restore it. To pause a webhook, use the Update method with Disabled = true instead.
Example
Basic usage: delete a webhook
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>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Delete();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: delete a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Delete(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}DeleteAsync
DeleteAsync deletes one webhook from the stack, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the deletion notice.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because DeleteAsync removes one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK throws the client-side exceptions above when you call DeleteAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Delete.
Warning Deleting a webhook stops every future request to its target URLs. The SDK offers no way to restore it. To pause a webhook, use the Update method with Disabled = true instead.
Example
Basic usage: delete a webhook
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>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").DeleteAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: delete a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").DeleteAsync(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Authentication: use a management token instead of an authtoken
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").DeleteAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Executions
Executions retrieves the executions of one webhook, each with its execution UID, status, and request details.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds filters such as from, to, and query. |
Returns: ContentstackResponse. The API response with the executions of the webhook.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because Executions reads the executions of one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK does not check the entries of collection. The API validates the dates and the query.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET request to /webhooks/<WEBHOOK_UID>/executions. See Get executions of a webhook in the Content Management API (CMA) reference.
- The CMA reference lists the following four query parameters for this request:
- from and to: the start and end of a date range, in ISO 8601 format.
- query: a JSON query on the execution, for example on status. Add it with collection.AddQuery.
- only_events: true leaves request_details out of the response.
- Each execution in the response carries an execution UID. Pass it to the Retry or Logs method.
- The CMA reference states that execution details cover the 30 days before the current day.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: list the executions of a webhook
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Executions();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: failed executions in a date range, without request details
using System;
using System.Text.Json.Nodes;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection collection = new ParameterCollection();
collection.Add("from", "2026-11-01T00:00:00.000Z");
collection.Add("to", "2026-11-13T23:59:59.999Z");
collection.Add("only_events", true);
// AddQuery serializes and URL-encodes the JSON query
collection.AddQuery(new JsonObject { ["status"] = new JsonObject { ["$gte"] = "400" } });
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Executions(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Authentication: use a management token instead of an authtoken
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").Executions();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}ExecutionsAsync
ExecutionsAsync retrieves the executions of one webhook, each with its execution UID, status, and request details, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds filters such as from, to, and query. |
Returns: Task<ContentstackResponse>. The API response with the executions of the webhook.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because ExecutionsAsync reads the executions of one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK does not check the entries of collection. The API validates the dates and the query.
- The SDK throws the client-side exceptions above when you call ExecutionsAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Executions.
Example
Basic usage: list the executions of a webhook
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").ExecutionsAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: failed executions in a date range, without request details
using System;
using System.Text.Json.Nodes;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection collection = new ParameterCollection();
collection.Add("from", "2026-11-01T00:00:00.000Z");
collection.Add("to", "2026-11-13T23:59:59.999Z");
collection.Add("only_events", true);
// AddQuery serializes and URL-encodes the JSON query
collection.AddQuery(new JsonObject { ["status"] = new JsonObject { ["$gte"] = "400" } });
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").ExecutionsAsync(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Fetch
Fetch retrieves the details of one webhook.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the requested webhook.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because Fetch reads one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET request to /webhooks/<WEBHOOK_UID>. See Get webhook in the Content Management API (CMA) reference.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: fetch a webhook
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>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: fetch a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Fetch(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Authentication: use a management token instead of an authtoken
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}FetchAsync
FetchAsync retrieves the details of one webhook, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the requested webhook.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because FetchAsync reads one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK throws the client-side exceptions above when you call FetchAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Fetch.
Example
Basic usage: fetch a webhook
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>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").FetchAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: fetch a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").FetchAsync(collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Logs
Logs retrieves the latest execution log of one webhook execution.
| Name | Type | Description |
|---|---|---|
| executionUid (required) | string | UID of the execution, from Executions. |
Returns: ContentstackResponse. The API response with the execution log.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no webhook UID, because the SDK checks for one even though the request path holds only the execution UID. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK does not check executionUid. A null or empty value builds the path /webhooks//logs, and the API rejects the request.
- Throws ContentstackErrorException when the API rejects the request, for example an execution UID that does not exist.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET request to /webhooks/<EXECUTION_UID>/logs. See Get latest execution log of a webhook in the Content Management API (CMA) reference.
- Leaves the webhook UID of the instance out of the request. The API finds the execution by its UID alone.
- Sends no request body and no query parameters.
- Returns the raw API response.
Example
Basic usage: read the log of an execution
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Logs("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Authentication: use a management token instead of an authtoken
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").Logs("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: calling Logs without a webhook UID
using System;
using Contentstack.Management.Core;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
// The execution UID alone is not enough. The SDK also needs a webhook UID on the instance.
client.Stack("<API_KEY>").Webhook().Logs("<EXECUTION_UID>");
}
catch (ArgumentException e)
{
// Fires before any request, because the instance has no webhook UID
Console.WriteLine(e.Message);
}LogsAsync
LogsAsync retrieves the latest execution log of one webhook execution, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| executionUid (required) | string | UID of the execution, from Executions. |
Returns: Task<ContentstackResponse>. The API response with the execution log.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no webhook UID, because the SDK checks for one even though the request path holds only the execution UID. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK does not check executionUid. A null or empty value builds the path /webhooks//logs, and the API rejects the request.
- The SDK throws the client-side exceptions above when you call LogsAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request, for example an execution UID that does not exist.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Logs.
Example
Basic usage: read the log of an execution
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").LogsAsync("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Authentication: use a management token instead of an authtoken
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").LogsAsync("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Query
Query returns a query object that lists the webhooks of the stack when you call Find or FindAsync on it.
This method takes no parameters. Chain Limit, Skip, and IncludeCount on the query object, then call Find or FindAsync to send the request.
Returns: Query. A new query for webhooks.
Validation
- Throws InvalidOperationException if the instance has a UID, because Query lists the webhook collection. Call stack.Webhook() with no UID.
- Query sends no request. Errors that do occur come from the Find or FindAsync call that follows, not from Query.
- Find and FindAsync throw InvalidOperationException if the client has no authtoken and the stack has no management token, and ContentstackErrorException when the API rejects the request.
- Limit, Skip, and IncludeCount each add a query parameter to a dictionary that rejects duplicate keys. The SDK throws ArgumentException before any request in the following two cases:
- You chain the same method twice.
- The collection you pass to Find repeats a key that a chained method already set.
- A query object keeps its parameters after Find runs. A second Find call with a collection that repeats a key throws ArgumentException. Build a new query for each request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Find and FindAsync send one GET request to /webhooks, with every parameter you set in the query string. See Get all webhooks in the Content Management API (CMA) reference.
- Returns the raw API response.
- Does not page through the results. Without Limit and Skip, the API applies its own page size. To read the next page, build a new query with a higher Skip value.
- The query object has the five methods below. See the Query class for details.
| Method | Returns | Description |
|---|---|---|
| Limit(double value) | Query | Sets the number of webhooks per page. |
| Skip(double value) | Query | Sets the number of webhooks to skip. |
| IncludeCount() | Query | Adds the total count to the response. |
| Find(ParameterCollection? collection = null) | ContentstackResponse | Sends the request. |
| FindAsync(ParameterCollection? collection = null) | Task<ContentstackResponse> | Sends the request without blocking the calling thread. |
Example
Basic usage: list the webhooks of a stack
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>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Paging: read one page with a total count
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>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook()
.Query()
.Limit(10)
.Skip(0)
.IncludeCount()
.FindAsync();
Console.WriteLine($"Total: {response.OpenJsonObjectResponse()["count"]}");
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: setting a query parameter twice
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Query query = client.Stack("<API_KEY>").Webhook().Query().Limit(5);
ParameterCollection collection = new ParameterCollection();
collection.Add("limit", 10);
try
{
// Limit(5) already set "limit", so adding it again fails.
query.Find(collection);
}
catch (ArgumentException e)
{
// Fires before any request, when a query parameter is set twice
Console.WriteLine(e.Message);
}Retry
Retry makes a manual attempt to run a webhook execution again, after the webhook finished its automatic attempts.
| Name | Type | Description |
|---|---|---|
| executionUid (required) | string | UID of the execution, from Executions. |
Returns: ContentstackResponse. The API response with the retry notice.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no webhook UID, because the SDK checks for one even though the request path holds only the execution UID. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK does not check executionUid. A null or empty value builds the path /webhooks//retry, and the API rejects the request.
- Throws ContentstackErrorException when the API rejects the request, for example an execution UID that does not exist.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST request to /webhooks/<EXECUTION_UID>/retry. See Retry a webhook in the Content Management API (CMA) reference.
- Leaves the webhook UID of the instance out of the request. The API finds the execution by its UID alone.
- Sends no request body and no query parameters.
- Returns the raw API response.
Example
Basic usage: retry an execution
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Retry("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Authentication: use a management token instead of an authtoken
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").Retry("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: calling Retry without a webhook UID
using System;
using Contentstack.Management.Core;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
// The execution UID alone is not enough. The SDK also needs a webhook UID on the instance.
client.Stack("<API_KEY>").Webhook().Retry("<EXECUTION_UID>");
}
catch (ArgumentException e)
{
// Fires before any request, because the instance has no webhook UID
Console.WriteLine(e.Message);
}RetryAsync
RetryAsync makes a manual attempt to run a webhook execution again, after the webhook finished its automatic attempts, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| executionUid (required) | string | UID of the execution, from Executions. |
Returns: Task<ContentstackResponse>. The API response with the retry notice.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no webhook UID, because the SDK checks for one even though the request path holds only the execution UID. Call stack.Webhook("<WEBHOOK_UID>").
- The SDK does not check executionUid. A null or empty value builds the path /webhooks//retry, and the API rejects the request.
- The SDK throws the client-side exceptions above when you call RetryAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request, for example an execution UID that does not exist.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Retry.
Example
Basic usage: retry an execution
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").RetryAsync("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Authentication: use a management token instead of an authtoken
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").RetryAsync("<EXECUTION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Update
Update replaces the details of a webhook with the values in the model.
| Name | Type | Description |
|---|---|---|
| model (required) | WebhookModel | Sets the full webhook, including its targets and channels. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: ContentstackResponse. The API response with the updated webhook.
Validation
- Throws ArgumentException (parameter uid) if the instance has no UID, because Update changes one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one PUT request to /webhooks/<WEBHOOK_UID>, with model serialized under a webhook key. See Update webhook in the Content Management API (CMA) reference.
- Leaves every null property of model out of the request body.
- Always sends disabled and concise_payload. A model that leaves Disabled at its default of false enables a disabled webhook.
- Adds the entries of collection to the query string. null or an empty collection adds none.
- Returns the raw API response.
Example
Basic usage: change the channels and target of a webhook
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("<WEBHOOK_UID>").Update(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: update a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
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" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Update(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: disable a webhook without deleting 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" }
},
Channels = new List<string> { "content_types.entries.publish" },
Disabled = true
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Update(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}UpdateAsync
UpdateAsync replaces the details of a webhook with the values in the model, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| model (required) | WebhookModel | Sets the full webhook, including its targets and channels. |
| collection | ParameterCollection? | Adds query parameters to the request. |
Returns: Task<ContentstackResponse>. The API response with the updated webhook.
Validation
- Throws InvalidOperationException if the client has no authtoken and the stack has no management token, because the request needs credentials.
- Throws ArgumentException (parameter uid) if the instance has no UID, because UpdateAsync changes one webhook. Call stack.Webhook("<WEBHOOK_UID>").
- Throws ArgumentNullException (parameter dataModel) if model is null, because the SDK builds the request body from it.
- The SDK throws the client-side exceptions above when you call UpdateAsync, before it returns a task. An API rejection surfaces when you await the task.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Completes the task when the API responds.
- Otherwise behaves like Update.
Example
Basic usage: change the channels and target of a webhook
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 = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").UpdateAsync(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: update a webhook with a query parameter collection
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
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" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
// The CMA reference lists no query parameters for this request. Add any parameter the API accepts.
ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").UpdateAsync(model, collection);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Authentication: update with a management token
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
WebhookModel model = new WebhookModel()
{
Name = "Notify Search Indexer",
destinations = new List<WebhookTarget>
{
new WebhookTarget() { TargetUrl = "https://example.com/hooks/contentstack" }
},
Channels = new List<string> { "content_types.entries.publish" }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook("<WEBHOOK_UID>").UpdateAsync(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}