calendly

Why I am getting POST 404 when Calendly is posting data to my endpoint


I created Calendly Webhook Subscription by following their instructions. My backend is written in NodeJS + Express. I am trying to implement Calendly webhook while I got the trial period. I am exposing the endpoint /webhooks/calendly/calendlyWebhook on localhost:8080 and I am doing it through ngrok, because Calendly supports only https protocol. I see in my logs Calendly sending a post request to the endpoint, but I am seeing it being 404: POST /webhooks/calendly/calendlyWebhook 404.

Here is my webhook file called calendlyWebhook.js

const { Router } = require('express');

const calendlyWebhookRouter = Router();

calendlyWebhookRouter.post('/calendlyWebhook', async (req, res) => {
  console.log("Hello from calendly webhook ✅")
  return res.statusCode(200).send('Ok')
})

module.exports = {
  calendlyWebhookRouter,
};

And here is my index.js file where I initialize the router

...
...

const {calendlyWebhookRouter} = require('./webhooks/calendlyWebhook');
app.use('/webhooks/calendly/calendlyWebhook', calendlyWebhookRouter);

...

What exactly I am doing wrong?


Solution

  • The webhook route contains calendlyWebhook twice (once in the app.use path and once in the calendlyWebhookRouter path). As a result, calendlyWebhookRouter will only be called when a POST request is sent to /webhooks/calendly/calendlyWebhook/calendlyWebhook.

    Removing calendlyWebhook from the app.use route path should resolve the issue:

    app.use('/webhooks/calendly', calendlyWebhookRouter);