/// <summary>
        /// Create a survey based on template or existing survey.
        /// Notes
        ///     You cannot specify both template\_id and from\_survey\_id
        /// Endpoint : https://api.surveymonkey.net/v2/surveys/create_survey?api_key=your_api_key
        /// Example Request
        /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/create_survey?api_key=your_api_key --data-binary '{"template_id": "568", "survey_title": "Ice and Fire Event"}'
        /// </summary>
        public CreateSurveyResponse CreateSurvey (BasicRequestData requestData)
        {
            CreateSurveyResponse surveyList;
            BasicRequestData thisRequest = new BasicRequestData();

            // This request expects a from_survey_id not the standard survey_id
            if (requestData.SurveyID != null)
            {
                requestData.FromSurveyID = requestData.SurveyID;
                requestData.SurveyID = null;
            }

            // This request can only take one of FromSurveyID or TemplateID not both
            if ((requestData.FromSurveyID != null) && (requestData.TemplateID != null))
            {
                surveyList = new CreateSurveyResponse();
                surveyList.Status = -2;
                surveyList.ErrorMessage = "Specify either from_survey_id or template_id, not both.";
            }
            else if (requestData.SurveyTitle == null)
            {
                surveyList = new CreateSurveyResponse();
                surveyList.Status = -3;
                surveyList.ErrorMessage = "Survey Title (survey_title) is required for this call.";
            }
            else if ((requestData.FromSurveyID == null) && (requestData.TemplateID == null))
            {
                surveyList = new CreateSurveyResponse();
                surveyList.Status = -4;
                surveyList.ErrorMessage = "One of from_survey_id or template_id must be specified for this call.";
            }
            else
            {
                thisRequest.FromSurveyID = requestData.FromSurveyID;
                thisRequest.TemplateID = requestData.TemplateID;
                thisRequest.SurveyTitle = requestData.SurveyTitle;
                JsonResponse = MakeApiRequest(CREATE_SURVEY, requestData);
                surveyList = JsonConvert.DeserializeObject<CreateSurveyResponse>(JsonResponse);
            }

            return surveyList;
        }
        /// <summary>
        ///  Generic API request.  When only Basic Request Data is required.
        /// </summary>
        /// <returns></returns>
        private string MakeApiRequest(string endPoint, BasicRequestData data)
        {
            string url = BaseURL + endPoint;
            var serializedParameters = JsonConvert.SerializeObject(data);

            return MakeApiRequest(url, serializedParameters);
        }
        /// <summary>
        /// Retrieves a paged list of respondents for a given survey and optionally collector with all template items filled
        /// Notes
        ///     Surveys with over 500,000 respondents will not be returned
        ///     DateStrings must be in the format YYYY-MM-DD HH:MM:SS.All DateStrings are implicitly in UTC.
        ///     All start dates are greater than or equal to the date passed in
        ///     All end dates are strictly less than date passed in
        ///     Basic users will only have the first 100 responses returned and will have the upgrade\_info dictionary
        /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_respondent_list?api_key=your_api_key
        /// </summary>
        public GetRespondentListResponse GetRespondentListFull(BasicRequestData requestData)
        {
            // url, open, type, name, date_created, date_modified
            string[] fData = { "date_start", "date_modified", "collector_id", "collection_mode", "custom_id", "email"
                                , "first_name", "last_name", "ip_address", "status", "analysis_url", "recipient_id" };
            requestData.Fields = fData;

            return GetRespondentList(requestData);
        }
        /// <summary>
        /// Takes a list of respondent ids and returns the responses that correlate to them.To be used with 'get_survey_details'
        /// Notes
        ///     Surveys with over 500,000 reponses are not available via the API currently
        ///     Text responses returned are truncated after 32,768 characters
        ///     Max number of respondents per call is 100
        /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_responses?api_key=your_api_key
        /// Example Request
        /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_responses/?api_key=your_api_key --data-binary '{"survey_id":"103994756", "respondent_ids": ["2503019027", "2500039028", "2500039029", "2503019064"]}'
        /// </summary>
        public GetResponsesResponse GetResponses(BasicRequestData requestData)
        {
            JsonResponse = MakeApiRequest(GET_RESPONSES, requestData);
            GetResponsesResponse surveyList = JsonConvert.DeserializeObject<GetResponsesResponse>(JsonResponse);

            return surveyList;
        }
        /// <summary>
        /// Retrieves a paged list of collectors for a survey in a user's account with all template items filled
        /// Notes
        ///     DateStrings must be in the format YYYY-MM-DD HH:MM:SS.All DateStrings are implicitly in UTC.
        ///     All start dates are greater than or equal to the date passed in
        ///     All end dates are strictly less than the date passed in
        /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_collector_list?api_key=your_api_key
        /// </summary>
        public GetCollectorListResponse GetCollectorListFull(BasicRequestData requestData)
        {
            // url, open, type, name, date_created, date_modified
            string[] fData = { "url", "open", "type", "name", "date_created", "date_modified"};
            requestData.Fields = fData;

            return GetCollectorList(requestData);
        }
        /// <summary>
        /// Retrieves a paged list of collectors for a survey in a user's account
        /// Notes
        ///     DateStrings must be in the format YYYY-MM-DD HH:MM:SS.All DateStrings are implicitly in UTC.
        ///     All start dates are greater than or equal to the date passed in
        ///     All end dates are strictly less than the date passed in
        /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_collector_list?api_key=your_api_key
        /// Example Request
        ///     curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_collector_list/?api_key=your_api_key --data-binary '{"survey_id": "100399456", "fields":["collector_id", "url", "open", "type", "name", "date_created", "date_modified"], "start_date":"2013-02-05 00:00:00", "end_date":"2013-04-16 22:47:00", "order_asc":true, "page_size":1, "page":2}'
        /// </summary>
        public GetCollectorListResponse GetCollectorList(BasicRequestData requestData)
        {
            JsonResponse = MakeApiRequest(GET_COLLECTOR_LIST, requestData);
            GetCollectorListResponse surveyList = JsonConvert.DeserializeObject<GetCollectorListResponse>(JsonResponse);

            return surveyList;
        }
        /// <summary>
        /// Retrieves a paged list of surveys in a user's account with all template items filled.
        /// Notes
        ///     •DateStrings must be in the format YYYY-MM-DD HH:MM:SS.All DateStrings are implicitly in UTC.
        ///     •All start dates are greater than or equal to the date passed in
        ///     •All end dates are strictly less than the date passed in
        /// Endpoints : https://api.surveymonkey.net/v2/surveys/get_survey_list?api_key=your_api_key
        public GetSurveyListResponse GetSurveyListFull(BasicRequestData requestData)
        {
            string[] fData = { "title", "analysis_url", "preview_url", "date_created", "date_modified", "language_id", "question_count", "num_responses" };
            requestData.Fields = fData;

            return GetSurveyList(requestData);
        }
        /// <summary>
        /// Retrieves a paged list of surveys in a user's account.
        /// Notes
        ///     •DateStrings must be in the format YYYY-MM-DD HH:MM:SS.All DateStrings are implicitly in UTC.
        ///     •All start dates are greater than or equal to the date passed in
        ///     •All end dates are strictly less than the date passed in
        /// Endpoints : https://api.surveymonkey.net/v2/surveys/get_survey_list?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_list/?api_key=your_api_key --data-binary '{"fields":["title","analysis_url","date_created","date_modified"], "start_date":"2013-02-02 00:00:00", "end_date":"2013-04-12 22:43:01", "order_asc":false, "title":"test3"}'
        /// </summary>
        public GetSurveyListResponse GetSurveyList(BasicRequestData requestData)
        {
            if (requestData.SurveyTitle != null)
            {
                requestData.Title = requestData.SurveyTitle;
                requestData.SurveyTitle = null;
            }
            JsonResponse = MakeApiRequest(GET_SURVEY_LIST, requestData);
            GetSurveyListResponse surveyList = JsonConvert.DeserializeObject<GetSurveyListResponse>(JsonResponse);

            return surveyList;
        }
        /// <summary>
        /// Retrieves a paged list of templates with all template items filled out provided by Survey Monkey.
        /// Notes
        ///     If templates are returned that the user cannot access, the `upgrade_info` dictionary will be returned
        /// Endpoint : https://api.surveymonkey.net/v2/templates/get_template_list?api_key=your_api_key
        /// </summary>
        public GetTemplateListResponse GetTemplateListFull(BasicRequestData requestData)
        {
            string[] fData = { "title", "short_description", "preview_url", "date_created", "date_modified", "language_id", "question_count"
                            , "long_description", "is_available_to_current_user", "is_featured", "is_certified", "page_count"
                            , "category_id", "category_name", "category_description"};
            requestData.Fields = fData;

            return GetTemplateList(requestData);
        }
        /// <summary>
        /// Retrieves a paged list of templates provided by Survey Monkey.
        /// Notes
        ///     If templates are returned that the user cannot access, the `upgrade_info` dictionary will be returned
        /// Endpoint : https://api.surveymonkey.net/v2/templates/get_template_list?api_key=your_api_key
        /// Example Request
        /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/templates/get_template_list?api_key=your_api_key --data-binary '{"page": 1, "page_size": 10, "language_id": 1, "category_id": "131", "fields" : ["title"]}'
        /// </summary>
        public GetTemplateListResponse GetTemplateList(BasicRequestData requestData)
        {
            JsonResponse = MakeApiRequest(GET_TEMPLATE_LIST, requestData);
            GetTemplateListResponse surveyList = JsonConvert.DeserializeObject<GetTemplateListResponse>(JsonResponse);

            return surveyList;
        }
        /// <summary>
        /// Retrieves a paged list of surveys in a user's account.
        /// Notes
        ///     •DateStrings must be in the format YYYY-MM-DD HH:MM:SS.All DateStrings are implicitly in UTC.
        ///     •All start dates are greater than or equal to the date passed in
        ///     •All end dates are strictly less than the date passed in
        /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_survey_list?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_list/?api_key=your_api_key --data-binary '{"fields":["title","analysis_url","date_created","date_modified"], "start_date":"2013-02-02 00:00:00", "end_date":"2013-04-12 22:43:01", "order_asc":false, "title":"test3"}'
        /// </summary>
        public GetSurveyDetailsResponse GetSurveyDetails(BasicRequestData requestData)
        {
            JsonResponse = MakeApiRequest(GET_SURVEY_DETAILS, requestData);
            GetSurveyDetailsResponse surveyList = JsonConvert.DeserializeObject<GetSurveyDetailsResponse>(JsonResponse);

            return surveyList;
        }
예제 #12
0
        /// <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>
        private void BtnGetSurveyDetails_Click(object sender, EventArgs e)
        {
            GetSurveyDetailsResponse surveyDetails;
            BasicRequestData brd = new BasicRequestData();
            SurveyQuestionView surveyView = new SurveyQuestionView();

            if (txtSurveyID.Text.Trim().Length > 0)
            {
                brd.SurveyID = txtSurveyID.Text;
            }
            else
            {
                brd.SurveyID = null;
            }

            if (brd.SurveyID == null)
            {
                MessageBox.Show("no survey id specified.  Going to get error back.");
            }

            surveyDetails = SurveyRequest.GetSurveyDetails(brd);

            lblStatus.Text = surveyDetails.Status.ToString();
            lblErrorMsg.Text = surveyDetails.ErrorMessage;

            try
            {
                if (chkSurveyAnswers.Checked)
                {
                    surveyView.LoadSurvey(surveyDetails);
                    dgvSurveyList.DataSource = surveyView.SurveyWithAnswers;
                }
                else
                {
                    List<SurveyTInfo> sdrList = new List<SurveyTInfo>();
                    sdrList.Add(surveyDetails.SurveyDetailsResult);
                    dgvSurveyList.DataSource = sdrList;
                }
            }
            catch { } // do nothing
        }
예제 #13
0
        /// <summary>
        /// Get information from the pop-up forms
        /// </summary>
        /// <returns></returns>
        private BasicRequestData GetRequestFields()
        {
            BasicRequestData brd = new BasicRequestData();
            try
            {
                brd.Page = int.Parse(txtPage.Text);
            }
            catch
            {
                brd.Page = 1;
            }

            try
            {
                brd.PageSize = int.Parse(txtPageSize.Text);
            }
            catch
            {
                brd.PageSize = 20;
            }

            if (txtSurveyID.Text.Trim().Length > 0)
            {
                brd.SurveyID = txtSurveyID.Text;
            }
            else
            {
                brd.SurveyID = null;
            }

            if (txtTemplateID.Text.Trim().Length > 0)
            {
                brd.TemplateID = txtTemplateID.Text;
            }
            else
            {
                brd.TemplateID = null;
            }

            if (txtCollectorID.Text.Trim().Length > 0)
            {
                brd.CollectorID = txtCollectorID.Text;
            }
            else
            {
                brd.CollectorID = null;
            }

            if (txtSurveyName.Text.Trim().Length > 0)
            {
                brd.SurveyTitle = txtSurveyName.Text;
            }

            List<string> respondantID = new List<string>();
            if (txtResID1.Text.Trim().Length > 0)
            {
                respondantID.Add(txtResID1.Text);
            }
            if (txtResID2.Text.Trim().Length > 0)
            {
                respondantID.Add(txtResID2.Text);
            }
            if (txtResID3.Text.Trim().Length > 0)
            {
                respondantID.Add(txtResID3.Text);
            }
            if (txtResID4.Text.Trim().Length > 0)
            {
                respondantID.Add(txtResID4.Text);
            }

            if (respondantID.Count > 0) brd.RespondentIDList = respondantID.ToArray();

            return brd;
        }
예제 #14
0
 /// <summary>
 /// Adds new ResponseResults to the existing list
 /// </summary>
 /// <param name="responses">batch of responses to a survey</param>
 /// <param name="brd"></param>
 /// <param name="isProcessed">Whether the first hundred responses have been processed</param>
 /// <returns></returns>
 private GetResponsesResponse GetRespondenses(GetResponsesResponse responses, BasicRequestData brd, bool isProcessed)
 {
     if (!isProcessed)
     {
         return SurveyRequest.GetResponses(brd);
     }
     else
     {
         GetResponsesResponse temp = SurveyRequest.GetResponses(brd);
         List<GetResponsesResult> newResponsesResultList = new List<GetResponsesResult>();
         newResponsesResultList.AddRange(responses.ResponseResultList);
         newResponsesResultList.AddRange(temp.ResponseResultList);
         responses.ResponseResultList = newResponsesResultList.ToArray();
         return responses;
     }
 }
예제 #15
0
        /// <summary>
        /// Returns basic information about the logged-in user
        /// Endpoint : https://api.surveymonkey.net/v2/user/get_user_details?api_key=your_api_key
        /// Example Request
        ///     curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/user/get_user_details/?api_key=your_api_key
        /// </summary>
        private void BtnGetUserDetails_Click(object sender, EventArgs e)
        {
            GetUserDetailsResponse surveyDetails;
            BasicRequestData brd = new BasicRequestData();

            surveyDetails = SurveyRequest.GetUserDetails(brd);

            lblStatus.Text = surveyDetails.Status.ToString();
            lblErrorMsg.Text = surveyDetails.ErrorMessage;

            try
            {
                List<GetUserDetailsResult> sdrList = new List<GetUserDetailsResult>();
                sdrList.Add(surveyDetails.UserDetailsResult);
                dgvSurveyList.DataSource = sdrList;
            }
            catch { } // do nothing
        }