Calendly Webhook创建失败报错“资源未找到”求助
Calendly Webhook创建失败:Resource Not Found 问题排查
我正尝试搭建Calendly Webhook,在用户提交预约时获取实时数据,使用Node.js Express服务器,但创建Webhook时遇到错误:
Webhook creation failed: {
title: 'Resource Not Found',
message: 'The requested path does not exist'
}
我的服务器代码如下:
const port = process.env.PORT || 5000; const express = require('express'); const axios = require('axios'); const app = express(); const API_KEY = 'MY_API_KEY'; const TOKEN = 'MY_TOKEN'; app.post('/calendly-webhook', (req, res) => { // Retrieve real-time data from the request payload const data = req.body; // Log the data to the console console.log('Calendly webhook data:', data); res.send('Webhook received'); }); app.listen(port, () => { console.log('Server listening on port 5000'); // Create a new webhook axios({ method: 'post', url: 'https://api.calendly.com/webhooks', headers: { 'Authorization': `Bearer ${API_KEY}`, 'X-Token-Auth': TOKEN }, data: { url: 'http://localhost:5000/calendly-webhook', events: ['invitee.created'] } }) .then(response => { console.log('Webhook created:', response.data); }) .catch(error => { console.error('Webhook creation failed:', error.response.data); }); });
问题排查及修复步骤
- 修正API端点URL:Calendly创建Webhook的正确端点是
https://api.calendly.com/webhook_subscriptions,你代码里写的/webhooks是错误路径,这是触发"Resource Not Found"的核心原因。 - 简化认证头:Calendly API仅需要
Authorization: Bearer {个人访问令牌}这一个认证头,不需要X-Token-Auth。直接用你的个人访问令牌替换API_KEY,删除X-Token-Auth相关代码。 - 替换本地URL为公网可访问地址:Calendly无法向
localhost发送请求,需要用ngrok等工具将本地端口映射为公网URL,把data.url里的http://localhost:5000/calendly-webhook替换成映射后的公网地址。 - 添加JSON解析中间件:你的Express服务器没有配置JSON请求体解析,Calendly发送的Webhook payload是JSON格式,需要在
app.post之前添加app.use(express.json());,否则req.body会是undefined。
修改后的核心代码片段
// 添加JSON解析中间件 app.use(express.json()); // 创建Webhook的Axios请求修正 axios({ method: 'post', url: 'https://api.calendly.com/webhook_subscriptions', headers: { 'Authorization': `Bearer ${YOUR_PERSONAL_ACCESS_TOKEN}`, 'Content-Type': 'application/json' }, data: { url: 'https://xxx.ngrok.io/calendly-webhook', // 替换为你的公网URL events: ['invitee.created'] } })
内容的提问来源于stack exchange,提问作者john doe
相关产品推荐
相关产品推荐

