简体   繁体   中英

How to enable multiple answers when creating a SurveyMonkey collector using the API?

I have an application that creates Survey Monkey collectors for a survey using the 'create_collector' API method. That works perfectly. The problem is that it always creates collectors with the 'Multiple Responses' set to false. I need collectors created through the API to have 'Multiple Responses' set to true. There doesn't seem to be any option in the API call to specify that.

How can I set 'Multiple Responses' to true using the 'create_collector' API?

Here is my code in c#:

class CollectorJSON
{
    public string type { get; set; }
    public string name { get; set; }
}

private string CreateCollectorURL = "https://api.surveymonkey.net/v2/collectors/create_collector?api_key={API_KEY_VALUE}";

public CollectorResponseJSONWrapper CreateCollector(string APIKey, string AccessToken, long SurveyId, string CollectorName)
    {
        _LastException = null;

        CollectorResponseJSONWrapper collectorRv = new CollectorResponseJSONWrapper();
        collectorRv.status = -1;

        try
        {
            string url = CreateCollectorURL.Replace("{API_KEY_VALUE}", APIKey);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";

            request.Headers.Add("Authorization", "bearer " + AccessToken);

            CollectorJSON collector = new CollectorJSON()
            {
                type = "weblink",
                name = CollectorName

            };

            CollectorJSONWrapper wrapper = new CollectorJSONWrapper()
            {
                survey_id = SurveyId.ToString(),
                collector = collector
            };

            string JSONData = JsonConvert.SerializeObject(wrapper);

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(JSONData);

            request.ContentType = "application/json";
            request.ContentLength = bytes.Length;

            Stream rstream = request.GetRequestStream();
            rstream.Write(bytes, 0, bytes.Length);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            string responseBody = string.Empty;

            using (var reader = new StreamReader(response.GetResponseStream(), ASCIIEncoding.ASCII))
            {
                responseBody = reader.ReadToEnd();
            }

            collectorRv = JsonConvert.DeserializeObject<CollectorResponseJSONWrapper>(responseBody);


        }
        catch( Exception ex )
        {
            _LastException = ex;
        }

        return collectorRv;

    }

Thanks,

This was not supported in API v2 but can now be done using API v3, https://developer.surveymonkey.com/api/v3/#surveys-id-collectors

By setting the field allow_multiple_responses when doing a POST to /surveys/{id}/collectors to create a new collector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM