From 338756439fe38389e877296f18a9643ebbf618ca Mon Sep 17 00:00:00 2001 From: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Date: Thu, 30 Nov 2023 23:22:55 +0530 Subject: [PATCH] fix: meeting ended incorrect content type (#12484) --- packages/features/webhooks/lib/cron.ts | 6 ++++++ packages/features/webhooks/lib/sendPayload.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/features/webhooks/lib/cron.ts b/packages/features/webhooks/lib/cron.ts index 089ddbbc5a..913217b274 100644 --- a/packages/features/webhooks/lib/cron.ts +++ b/packages/features/webhooks/lib/cron.ts @@ -5,6 +5,8 @@ import dayjs from "@calcom/dayjs"; import { defaultHandler } from "@calcom/lib/server"; import prisma from "@calcom/prisma"; +import { jsonParse } from "./sendPayload"; + async function handler(req: NextApiRequest, res: NextApiResponse) { const apiKey = req.headers.authorization || req.query.apiKey; if (process.env.CRON_API_KEY !== apiKey) { @@ -27,6 +29,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { await fetch(job.subscriberUrl, { method: "POST", body: job.payload, + headers: { + "Content-Type": + !job.payload || jsonParse(job.payload) ? "application/json" : "application/x-www-form-urlencoded", + }, }); } catch (error) { console.log(`Error running webhook trigger (retry count: ${job.retryCount}): ${error}`); diff --git a/packages/features/webhooks/lib/sendPayload.ts b/packages/features/webhooks/lib/sendPayload.ts index 7ff22d9577..dc6e76f1d2 100644 --- a/packages/features/webhooks/lib/sendPayload.ts +++ b/packages/features/webhooks/lib/sendPayload.ts @@ -87,7 +87,7 @@ function applyTemplate(template: string, data: WebhookDataType, contentType: Con return compiled; } -function jsonParse(jsonString: string) { +export function jsonParse(jsonString: string) { try { return JSON.parse(jsonString); } catch (e) {