2

We were under the impression that we could add a webhook/url with each recipient we added using recipients/bulk. So if our recipients looked like the below, we would just be able to add the webhook data with each one of the entries. After looking around the docs for a little while, it doesn't appear this is the case.:

{
    "contacts" :[{
        "email":"email@here.com",
        "first_name": "John",
        "last_name": "Doe",
        "custom_fields": {
            "1": "2428156"
        }
    },
    {
        "email":"somebodyelse@here.com",
        "first_name": "Somebody",
        "last_name": "Else",
        "custom_fields": {
            "1": "2428143"
        }
    }]
}

Does anybody know if this is possible? If not, how does everybody else send recipients in bulk and have each one in that list go to the proper webhook URL to parse the responses?

Thanks in advance, Whoopah

whoopah
  • 159
  • 2
  • 11

1 Answers1

2

The webhook events available are for responses not recipients. What you would probably want to do is have one webhook for all your responses, example:

POST /v3/webhooks
{
    "name": "Test Webhook",
    "event_type": "response_completed",
    "object_type": "survey",
    "object_ids": ["<survey_id>"],
    "subscription_url": "http://example.com/mywebhook"
}

Then for every completed message for the specified surveys, you'll get a notification with a body something like this to your subscription_url:

{
    "respondent_id": "<response_id>",
    "recipient_id": "<recipient_id>",
    "survey_id": "<survey_id>",
    "user_id": "<user_id>",
    "collector_id": "<collector_id>"
}

The recipient_id will let you know which recipient that particular response was for which you can use for whatever your use case is. If you need more information then you can make a request to get the response details

GET /v3/surveys/<survey_id>/responses/<response_id>/details

Or don't include the /details if you don't want the answers, just want the metadata for that response.

Or if you want specifically more details about that recipient and not the responses you can fetch the recipient details

GET /v3/collectors/<collector_id>/recipients/<recipient_id>

Which gives you information you may have stored in extra_fields or whatnot.

General Kandalaft
  • 2,215
  • 2
  • 18
  • 25
  • 1
    Thanks for the detailed response, it really helps. So, I take it that we can create the webhook with an initial survey id or ids and then as we need to, just do a patch to the API to add survey ids? – whoopah Dec 20 '16 at 19:06
  • 1
    Yes exactly. You can also listen to `object_type` of `collector` and give a list of collector IDs in the `object_ids` if you prefer that as well. But yes, if you want to listen to more surveys/collectors then just patch the same one with the list of IDs you want to listen to now. – General Kandalaft Dec 20 '16 at 19:07
  • Awesome. thanks.... I have one more question regarding the webhooks. I am creating one now and just to test I am sending over exactly (a copy/paste actually) of what is used as an example on the API Docs and keep getting this response (which doesn't really tell what's wrong): {"error": {"docs": "https://developer.surveymonkey.com/api/v3/#error-codes", "message": "Invalid schema in the body provided.", "id": "1002", "name": "Bad Request", "http_status_code": 400}} – whoopah Dec 20 '16 at 19:09
  • Are you copy/pasting the response from the example? It includes keys like `id` and `href` which you are not allowed to send while creating. You will also get an error (more specific one) if you don't own the survey/collector IDs you provide. – General Kandalaft Dec 20 '16 at 19:12
  • good question but no, I'm copying from the request example and replacing the ids with one of our survey ids and the subscription URL with one of ours (that does exist): {"name":"My Webhook", "event_type":"response completed", "object_type":"survey", "object_ids":["1234","5678"],"subscription_url":"https://surveymonkey.com/webhook_reciever"} – whoopah Dec 20 '16 at 19:20
  • I think your subscription URL is failing the schema check for a proper URL, try adding `https://` if you don't already have that, otherwise seems to look fine. – General Kandalaft Dec 20 '16 at 19:21
  • oops, didn't pick that up in the copy/paste I did when adding the comment but it is in there. I did it with the URL in the example on the API documentation and same thing – whoopah Dec 20 '16 at 19:33
  • Ah the documentation has "response completed" with a space, should be "response_completed" for the event type, when I switched that it went through fine. – General Kandalaft Dec 20 '16 at 19:45