使用API​​创建SurveyMonkey收集器时如何启用多个答案?

时间:2016-01-19 15:23:59

标签: api surveymonkey

我有一个应用程序,使用' create_collector'为调查创建Survey Monkey收集器。 API方法。这非常有效。问题是,它始终会创建具有“多重响应”的收藏家。设为false。我需要通过API创建的收藏家才能拥有“多重回复”。设为true。似乎没有API调用中的任何选项来指定。

如何设置'多个回复'使用' create_collector' API?

这是我在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;

    }

谢谢,

1 个答案:

答案 0 :(得分:0)

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.