#Setting Up Webhook's from external providers to call trigger.dev
1 messages · Page 1 of 1 (latest)
Hi @digital isle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To trigger tasks from external providers using webhooks, you need to set up a webhook handler in your application that can receive the webhook payload and then trigger a Trigger.dev task. Trigger.dev doesn't provide direct webhook URLs that you can use without an API gateway or handler.
Here's how you can set this up in different frameworks:
Next.js
For Next.js, you can create a webhook handler as an API route:
App Router
// app/api/webhook-handler/route.ts
import type { helloWorldTask } from "@/trigger/example";
import { tasks } from "@trigger.dev/sdk/v3";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
// Parse the webhook payload
const payload = await req.json();
// Trigger the helloWorldTask with the webhook data as the payload
await tasks.trigger<typeof helloWorldTask>("hello-world", payload);
return NextResponse.json("OK", { status: 200 });
}
Pages Router
// pages/api/webhook-handler.ts
import { helloWorldTask } from "@/trigger/example";
import { tasks } from "@trigger.dev/sdk/v3";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
// Parse the webhook payload
const payload = req.body;
// Trigger the helloWorldTask with the webhook data as the payload
await tasks.trigger<typeof helloWorldTask>("hello-world", payload);
res.status(200).json({ message: "OK" });
}
Next.js - triggering tasks using webhooks
Remix
For Remix, you can create a webhook handler as an API route:
// app/routes/api.webhook-handler.ts
import type { ActionFunctionArgs } from "@remix-run/node";
import { tasks } from "@trigger.dev/sdk/v3";
import { helloWorldTask } from "src/trigger/example";
export async function action({ request }: ActionFunctionArgs) {
const payload = await request.json();
// Trigger the helloWorldTask with the webhook data as the payload
await tasks.trigger<typeof helloWorldTask>("hello-world", payload);
return new Response("OK", { status: 200 });
}
Remix - triggering tasks using webhooks
Specific Provider Examples
Trigger.dev also provides guides for specific webhook providers:
-
Stripe Webhooks: You can set up a handler for Stripe webhook events, which verifies the signature and triggers a task when specific events occur.
Stripe webhooks guide -
Supabase Database Webhooks: You can trigger tasks from Supabase database changes.
Supabase database webhooks guide -
Sequin Database Triggers: You can trigger tasks from database changes using Sequin.
Sequin database triggers guide