Survey Monkey- Custom Values via API v3

时光毁灭记忆、已成空白 提交于 2019-12-11 06:05:52

问题


I am currently unable to figure out how to obtain several custom fields via the API. The Excel extracts provide the columns I need, but I cannot find a v3 GET or POST protocol to obtain the desired fields.

From: api.surveymonkey.net/v3/surveys/[survey_id]/details

I see the desired fields:

  1. custom_variables.a = [Variable a Column Name]
  2. custom_variables.b = [Variable b Column Name]

With the following: api.surveymonkey.net/v3/surveys/[survey_id]/responses/bulk?page=[#]&per_page=[#]

  1. data.0.custom_value = blank
  2. data.0.recipient_id = blank

10/6/16 Update: Change Custom Variables Plan Requirement

Description of Changes: Make survey custom variables accessible to Gold plan and above.

Endpoints Affected: /surveys, /surveys/{id}, /surveys/{id}/responses/bulk, /collectors/{id}/responses/bulk, /surveys/{id}/responses/{id}, /collectors/{id}/responses/{id}, /surveys/{id}/responses/{id}/details, /collectors/{id}/responses/{id}/details

I hit my API call limit and have not been able to run the /collectors/{id}/responses yet. I thought it best to ask now and get the right answer (so I can finish off this project and hit my deadline when my "counter" gets reset). As information I am using Alteryx to make the calls, and once I get this piece completed will be posting the Workflow on the Alteryx site (to give a little back to the community).

Thank you in advance for your help!

-Drew


回答1:


So those are two different kinds of "custom values".

There are Custom Variables which are basically URL parameters that will be accepted and stored with the survey response. These only work for non-email based collectors, particularly for a Weblink collector. The custom variables are also stored on the Survey, so when you fetch with

GET /v3/surveys/<survey_id>

You'll get a response like

{
  "title": "My Survey",
  "custom_variables": {
    "name1": "label1",
    "name2": "label2"
    ...

  },
  ...
}

Then when you fetch survey responses, assuming they were filled in, you would get a response back like this:

GET /v3/surveys/<survey_id>/responses/<response_id>
{
  "id": "<response_id>",
  "response_status": "completed",
  "custom_variables": {
    "name1": "value1",
    "name2": "value2"
    ...
  },
  ...
}

With regards to Custom Values, these are custom data stored on a Contact resource in your address book used to create a recipient on an Email collector (not the Survey).

So when you create a new recipient on an email collector, you can set custom_fields which are stored on the contact as well as the recipient. When you fetch that recipient, it'll look something like this:

GET /v3/collectors/<collector_id>/recipients/<recipient_id>
{
    "id": "<recipient_id>",
    "email": "<email>",
    "first_name": "<first_name>",
    "last_name": "<last_name>",
    "custom_fields": {
      "1": "field1",
      "2": "field2",
      "3": "field3",
      ...
    }
    ...
}

And then when that specific recipient answers the survey and you fetch the response, you will get the contact information in the response metadata like:

GET /v3/surveys/<survey_id>/responses/<response_id>
{
  "id": "<response_id>",
  "response_status": "completed",
  "metadata": {
    "contact": {
        {
          "id": "<response_id>",
          "response_status": "completed",
          "metadata": {
            "contact": {
                "first_name": {
                  "type": "string",
                  "value": "<first_name>"
                },
                "last_name": {
                  "type": "string",
                  "value": "<last_name>"
                },
                "name1": {
                  "type": "string",
                  "value": "value1"
                },
                "name2": {
                  "type": "string",
                  "value": "value2"
                },
                "name3": {
                  "type": "string",
                  "value": "value3"
                }
            },
            ...
          },
          ...
        }
        ...
    },
    ...
  }
}

Note that metadata will only have the first name, last name, and email in the bulk responses endpoint. This is a current limitation in bulk responses.

Hope that helps clarify the difference.




回答2:


When you use the below url

https://api.surveymonkey.net/v3/surveys/{SURVEY_ID}/responses/bulk,

in response you get the custom variables ,

{
  "per_page": 50,
  "total": 6,
  "data": [
    {
      "total_time": 108,
      "href":"https://api.surveymonkey.net/v3/surveys/119486428/responses/6287196301",
      "custom_variables": {
      "key1": "value1",
      "key2": "value2"
    },
}    

I am using web collector . and adding custom variables as url parameter.



来源:https://stackoverflow.com/questions/42538510/survey-monkey-custom-values-via-api-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!