/// <summary> /// Gets information from create collector fields /// </summary> /// <returns></returns> private CreateCollectorRequest GetCCRequestFields() { CreateCollectorRequest frd = new CreateCollectorRequest(); if (txtSurveyID.Text.Trim().Length > 0) { frd.SurveyID = txtSurveyID.Text; } else { frd.SurveyID = null; } if (txtCollectorName.Text.Trim().Length > 0) { frd.Collector.Name = txtCollectorName.Text.Trim(); } if (txtCollectorThanks.Text.Trim().Length > 0) { frd.Collector.ThankYouMsg = txtCollectorThanks.Text.Trim(); } if (txtCollectorURL.Text.Trim().Length > 0) { frd.Collector.RedirectURL = txtCollectorURL.Text.Trim(); } return(frd); }
/// <summary> /// Specific for when sending request data for creating a new collector /// </summary> private string MakeApiRequest(string endPoint, CreateCollectorRequest data) { string url = BaseURL + endPoint; string serializedParameters = JsonConvert.SerializeObject(data); return(MakeApiRequest(url, serializedParameters)); }
/// <summary> /// Create a weblink collector. /// Notes /// Basic users can create a maximum of 3 collectors per survey /// Endpoint : https://api.surveymonkey.net/v2/collectors/create_collector?api_key=your_api_key /// Example Request /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/collectors/create_collector?api_key=your_api_key --data-binary '{"survey_id": "100399456", "collector":{"type": "weblink", "name": "My Collector"}}' /// </summary> private void BtnCreateCollector_Click(object sender, EventArgs e) { CreateCollectorResponse collector; CreateCollectorRequest brd = GetCCRequestFields(); collector = SurveyRequest.CreateCollector(brd); lblStatus.Text = collector.Status.ToString(); lblErrorMsg.Text = collector.ErrorMessage; try { List <CollectorInfo> ciList = new List <CollectorInfo>(); ciList.Add(collector.CollectorResult.Collector); dgvSurveyList.DataSource = ciList; } catch { } // do nothing }
/// <summary> /// Retrieve a given survey's metadata. /// Notes /// •Surveys with over 200 survey pages will not be returned /// •Surveys with over 1000 questions will not be returned /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_survey_details?api_key=your_api_key /// Example Request /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_survey_details/?api_key=your_api_key --data-binary '{"survey_id":"100399456"}' /// </summary> public CreateCollectorResponse CreateCollector(CreateCollectorRequest requestData) { CreateCollectorResponse collectorResponse; CreateCollectorRequest thisRequest = new CreateCollectorRequest(); // This request requires a survey id. if (requestData.SurveyID == null) { collectorResponse = new CreateCollectorResponse(); collectorResponse.Status = -4; collectorResponse.ErrorMessage = "Survey ID must be specified."; } else { requestData.Collector.Type = CollectorTypeEnum.WebLink; // currently API only allows weblink. JsonResponse = MakeApiRequest(CREATE_COLLECTOR, requestData); collectorResponse = JsonConvert.DeserializeObject <CreateCollectorResponse>(JsonResponse); } return(collectorResponse); }