3

After creating the webhook, when I fill in a form it sends a POST request to my API, but the body comes empty.

I can not find anything on the internet, the SM documentation leaves much to be desired.

My API

async testWebhook({ request, response }) {
   console.log('request.body', request.body)
   response.status(200).send()
   return
}

What can it be?

2 Answers2

4

I found an answer if your app is running on Express.js

The Survey Monkey Webhook POST declares a header 'application/vnd.surveymonkey.response.v1+json'

If you don't handle this in Express, the request.body object will be empty.

You can use body-parser and define the header:

app.use(bodyParser.json({
    type: 'application/vnd.surveymonkey.response.v1+json'
}));

See documentation here - body-parser types

I should also mention that when I created my Webhook with Survey Monkey, I did include 'content-type' but it wasn't until I added this extra configuration in my app that it started showing me POST data.

Example Webhook creation:

{
    "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"
}
danlong
  • 570
  • 4
  • 16
0

The body should have a JSON with a body similar to the example. One possible issue is that the webhook from SurveyMonkey sends the body with a custom content type header, something like application/vnd.surveymonkey.survey.v1 which may not be playing nice with your server.

I'm not sure if it's documented but you can specify application/json as your content type by including that in the body when you're creating a webhook:

POST /v3/webhooks
{
  ...
  "content_type": "application/json"
}

Which may make it work without any changes to your body parser settings in your server.

General Kandalaft
  • 2,087
  • 2
  • 16
  • 25