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) {