Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Implement unsubscribe functionality for Zapier webhooks.

Kiran K6ecb9a25709e
diff --git a/apps/web/app/api/webhooks/callback/route.ts b/apps/web/app/api/webhooks/callback/route.ts
index 36a4373dfd..82539ec509 100644
--- a/apps/web/app/api/webhooks/callback/route.ts
+++ b/apps/web/app/api/webhooks/callback/route.ts
@@ -41,6 +41,21 @@ export const POST = async (req: Request) => {
const response = Buffer.from(body, "base64").toString("utf-8");
const isFailed = status >= 400;
+ // Unsubscribe Zapier webhook
+ if (
+ webhook.receiver === "zapier" &&
+ webhook.installationId &&
+ status === 410
+ ) {
+ await prisma.webhook.delete({
+ where: {
+ id: webhookId,
+ },
+ });
+
+ return new Response(`Unsubscribed Zapier webhook ${webhookId}`);
+ }
+
await Promise.all([
// Record the webhook event
recordWebhookEvent({
@@ -63,5 +78,5 @@ export const POST = async (req: Request) => {
: []),
]);
- return new Response("OK");
+ return new Response(`Webhook ${webhookId} processed`);
};