#Setting Up Webhook's from external providers to call trigger.dev

1 messages · Page 1 of 1 (latest)

digital isle
#

Hey Guys, Is there a way for me to initiate a trigger tasks directly using a webhook url instead of using an api gateway.

light scrollBOT
#

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:

  1. 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

  2. Supabase Database Webhooks: You can trigger tasks from Supabase database changes.
    Supabase database webhooks guide

  3. Sequin Database Triggers: You can trigger tasks from database changes using Sequin.
    Sequin database triggers guide

The general pattern is to create an API endpoint in your application that receives the webhook, processes it, and then triggers the appropriate Trigger.dev task using the tasks.trigger() method.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: