Yel*_*ink 3 webhooks node.js surveymonkey
创建 webhook 后,当我填写表单时,它会向我的 API 发送 POST 请求,但正文为空。
我在互联网上找不到任何东西,SM 文档还有很多不足之处。
我的API
async testWebhook({ request, response }) {
console.log('request.body', request.body)
response.status(200).send()
return
}
Run Code Online (Sandbox Code Playgroud)
会是什么?
如果您的应用程序在 Express.js 上运行,我找到了答案
Survey Monkey Webhook POST 声明标头“application/vnd.surveymonkey.response.v1+json”
如果你不在 Express 中处理这个问题, request.body 对象将为空。
您可以使用body-parser并定义标头:
app.use(bodyParser.json({
type: 'application/vnd.surveymonkey.response.v1+json'
}));
Run Code Online (Sandbox Code Playgroud)
请参阅此处的文档 -主体解析器类型
我还应该提到,当我使用 Survey Monkey 创建 Webhook 时,我确实包含了“内容类型”,但直到我在应用程序中添加了这个额外的配置,它才开始向我显示 POST 数据。
Webhook 创建示例:
{
"name": "My Survey Completed Webhook",
"event_type": "response_completed",
"object_type": "survey",
"object_ids": ["1234"],
"subscription_url": "https://APP_URL/survey-responses",
"content_type": "application/json"
}
Run Code Online (Sandbox Code Playgroud)