Dispatch data to a third-party webhook
What you'll build
A custom trigger and an Action that POSTs JSON to a third-party URL when the trigger fires. Use Webhook.site as a temporary endpoint so you can inspect the request body and confirm delivery.
1. Prerequisites
- A unique URL from Webhook.site (copy Your unique URL, not the browser address bar)
- The
WEBHOOK_URLenvironment secret set to that URL
2. Create the trigger
Navigate to the Triggers section to create a new trigger. Configure it with the following settings:
- Name: Dispatch webhook
- Slug:
dispatch-webhook
On the Schema tab, export an interface that describes the payload callers must send:
export interface DispatchWebhookPayload {
event: string;
resourceId: string;
}See Triggers for more information on creating a trigger and defining a schema.
3. Create the action
Navigate to the Actions section to create a new action. Configure it with the following settings:
- Name: Post to webhook
- Trigger: Dispatch webhook
- Action Retries:
0 - Users: All Users
See Actions for more information on creating an action.
4. Update the workflow
Update the action's workflow to POST the trigger payload to your webhook URL. The destination comes from the WEBHOOK_URL environment variable:
const : = async ({ , , }) => {
const = as { ?: string; ?: string };
const = await (`${.}`, {
: "POST",
: {
"Content-Type": "application/json",
},
: .({
: . ?? "unknown",
: . ?? null,
: ?. ?? null,
: ?. ?? null,
}),
});
if (!.) {
return { : "failure", : { : . } };
}
return { : "success" };
};
export default ;5. Fire the trigger
From a Surface or other workflow, call utils.triggers.fire with the trigger slug and a payload that matches the schema:
await utils.triggers.fire(
"dispatch-webhook",
{ event: "resource.viewed", resourceId: resource.id ?? "" },
identity,
);See Call an action from a workflow for a complete Surface example.
Result
When the trigger fires, the action POSTs JSON to your Webhook.site URL. On the Webhook.site page for that URL, confirm a POST request arrived with event, resourceId, identity, and userType in the body.
In Observability, the action event shows success or failure based on the HTTP response status.