Skip to main content

Managing Webhooks

Ductape allows you to automatically handle webhooks and their associated logic. Each webhook can have multiple events attached to it, acting as a single point of registration for the events your app emits. You can manage multiple webhooks and configure the events your partners will receive.

Setting Up Webhooks

There are two main ways to set up webhooks:

  • Generating a link for use in a dashboard
  • Registering directly with Ductape

To create a webhook in Ductape, use the create function from the app.webhooks interface. Each webhook must be configured with appropriate settings depending on the registration method and environment.

Example: Users Register Directly with Ductape

const webhook = await ductape.app.webhooks.create({
name: "New Webhook",
tag: "new-webhook",
description: "New Webhook Description",
envs: [
{
slug: "prd",
registration_url: "https://api.webhook.com/register",
method: HttpMethods.POST,
sample: {
headers: {
Authorization: "Bearer ehwywjwjsnsnsnsnsns",
},
query: {},
body: {},
params: {},
},
},
{
slug: "snd",
registration_url: "https://sandbox.webhook.com/register",
method: HttpMethods.POST,
sample: {
headers: {
Authorization: "Bearer ehwywjwjsnsnsnsnsns",
},
query: {},
body: {},
params: {},
},
},
],
});

In this example, you provide the full registration flow details: the API URL, HTTP method, and the data structure expected from the user.

const webhook = await ductape.app.webhooks.create({
name: "New Webhook",
tag: "new-webhook",
description: "New Webhook Description",
envs: [
{ slug: "prd" },
{ slug: "snd" },
],
});

In this case, you only provide the environment slugs. Ductape will generate a webhook link that users can supply to their dashboard.

Note: You can mix both methods. The example below is valid and combines both approaches:

const webhook = await ductape.app.webhooks.create({
name: "New Webhook",
tag: "new-webhook",
description: "New Webhook Description",
envs: [
{ slug: "prd" },
{
slug: "snd",
registration_url: "https://sandbox.webhook.com/register",
method: HttpMethods.POST,
sample: {
headers: {
Authorization: "Bearer ehwywjwjsnsnsnsnsns",
},
query: {},
body: {},
params: {},
},
},
],
});

Webhook Fields

FieldTypeDescription
namestringA human-readable name for the webhook.
tagstringA unique identifier for the webhook.
descriptionstringA brief description of what the webhook does.
envsEnvConfig[]An array of environment-specific configurations.

EnvConfig Fields

FieldTypeDescription
slugstringEnvironment identifier (e.g., "prd" for production).
registration_urlstringURL for registering the webhook.
methodHttpMethodsHTTP method used for registration (e.g., POST, GET).
sampleWebhookSampleA sample payload structure used for webhook testing.

WebhookSample Fields

FieldTypeDescription
headersRecord<string, string>HTTP headers to be sent with the webhook request.
queryRecord<string, any>Query parameters to be included in the webhook request.
bodyRecord<string, any>Request body to be sent with the webhook.
paramsRecord<string, any>URL parameters to be included in the webhook request.

Updating Webhooks

To update an existing webhook, use the update function from the app.webhooks interface. You can modify environment-specific configurations, including URLs, methods, and payload samples.

Example

const updatedWebhook = await ductape.app.webhooks.update("new-webhook", {
envs: [
{
slug: "prd",
registration_url: "https://live.webhook.com/register",
method: HttpMethods.POST,
sample: {
headers: {
Authorization: "Bearer ehwywjwjsnsnsnsnsns",
},
query: {},
body: {},
params: {},
},
},
],
});

Fetching Webhooks

To retrieve all webhooks associated with your app, use the fetchAll function:

const webhooks = await ductape.app.webhooks.fetchAll();

Fetching a Single Webhook

To retrieve a specific webhook, use the fetch function and pass the webhook's tag:

const webhook = await ductape.app.webhooks.fetch("new-webhook");