Contact Sales »» 866-434-3217  

Contact Us   -   Login   -   FREE Basic Account  

Create Your Survey Now!
market research,software,survey,online
Webservice Integration

QuestionPro - Developer API Key

What is an API Key? Where can I get an API Key?

An application programing interface key (API key) is a code generated by websites that allow users to access
their application programming interface.

To generate an API key, go to:

Login >> Surveys >> Reports >> Export Data

Click on Get API Key and the key will be generated. Use this key for setting up API integration.

QuestionPro Web-Service API

How does API integration work?

Based on parameters received through a JSON request body, the API will fetch responses stored.
These responses will be returned in the form of JSON. To access the API we need to pass the
access key and the specific API call to be made.
We also need to pass attributes of the request as a JSON body which will contain at the least the survey ID
for which we want to fetch responses.
We can add additional attributes to the JSON body to further refine the request.(eg. Start Date and End Date etc)

API Calls available:

  1. questionpro.survey.surveyResponses - To retrieve responses based on the filtering criteria
  2. questionpro.survey.responseCount - To get total response count for the specified criteria
  3. Base URL : http://api.questionpro.com/a/api/
  4. Access key parameter name : accessKey
  5. Example API call URL:
    http://api.questionpro.com/a/api/questionpro.survey.surveyResponses?accessKey=qthqs
    We serve only 100 responses per API call
  6. Parameters to specify as criteria in the JSON body:
    • a) id - Survey ID
    • b) resultMode - Completed/Started/Viewed
      • i) All - 0 (Default)
      • ii) Started but Not Completed - 1
      • iii) Completed - 2
      • iv) Terminated via Branching - 3
    • c) startDate - Start Date for response time range - Date Format is MM/DD/YYYY
    • d) endDate - End Date for response time range - Date Format is MM/DD/YYYY
    • Either both Start Date and End Date have to be entered else neither
    • e) startingResponseCounter - The response counter. If not specified the first 100 will be served,
      if 2 is specified, responses in the range 201-300 will be served.

Sample Java Code:

    package com.apicall;

    import org.apache.http.client.ResponseHandler;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.BasicResponseHandler;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONObject;

    public class QuestionProAPIExample {

      public static final String API_ACCESS_KEY = "wvcfq";
      public static final String API_URL = "http://api.questionpro.com/a/api/";
      public static final String RESPONSE_COUNT_METHOD_NAME = "questionpro.survey.responseCount";
      public static final String SURVEY_RESPONSES_METHOD_NAME = "questionpro.survey.surveyResponses";
      public long surveyID = 3190054;

      public long getResponseCount() throws Exception {
        String path = API_URL + RESPONSE_COUNT_METHOD_NAME + "?accessKey=" + API_ACCESS_KEY;
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpost = new HttpPost(path);
        String data = "{\"id\":\"" + surveyID + "\",\"resultMode\":\"0\"}";
        StringEntity se = new StringEntity(data);
        httpost.setEntity(se);
        httpost.setHeader("Accept", "application/json");
        httpost.setHeader("Content-type", "application/json");
        ResponseHandler responseHandler = new BasicResponseHandler();
        Object resp = httpclient.execute(httpost, responseHandler);
        String json =  resp.toString();
        JSONObject obj = new JSONObject(json);
        obj = obj.getJSONObject("response");
        return Long.parseLong(obj.getString("partialCount"));
        }

        public String getResponses(int startingResponseCounter) throws Exception {
         String path = API_URL + SURVEY_RESPONSES_METHOD_NAME + "?accessKey=" + API_ACCESS_KEY;
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpPost httpost = new HttpPost(path);
         String data = "{\"id\":\"" + surveyID + "\",\"resultMode\":\"0\",\"startDate\":\"08/15/2012\"," +
          "\"endDate\":\"09/15/2012\",\"startingResponseCounter\":\""+ startingResponseCounter +"\"}";
         StringEntity se = new StringEntity(data);
         httpost.setEntity(se);
         httpost.setHeader("Accept", "application/json");
         httpost.setHeader("Content-type", "application/json");
         ResponseHandler responseHandler = new BasicResponseHandler();
         Object resp = httpclient.execute(httpost, responseHandler);
         return resp.toString();
          }

        public void printResponses() throws Exception {
         long totalResponses = getResponseCount();
         int count = 0;
         int pageIndex = 0;
         do {
           String responsesJson = getResponses(pageIndex);
           JSONObject jr = new JSONObject(responsesJson);
           jr = jr.getJSONObject("response");
           if (pageIndex == 0) {
             JSONObject stats = jr.getJSONObject("surveyStatistics");
             } else {
             }

              JSONArray responses = jr.getJSONArray("responses");
               for (int i=0; i < responses.length();i++) {
                 JSONObject obj = (JSONObject)responses.get(i);
                 JSONArray responseSet = obj.getJSONArray("responseSet");
                 for (int j=0;j < responseSet.length();j++) {
                   JSONObject questionResponse = (JSONObject)responseSet.get(j);


               JSONArray answerValues = questionResponse.getJSONArray("values");
                for (int k=0; k < answerValues.length();k++) {
                  JSONObject value = (JSONObject)answerValues.get(k);
                  JSONObject ansVal = value.getJSONObject("value");
                  String scale = (String) (ansVal != null ? ansVal.has("scale")
                                  ? ansVal.get("scale") : null : null);
                  String otherText = (String) (ansVal != null ? ansVal.has("other")
                                  ?  ansVal.get("other") : null : null) ;
                  String dynamicText = (String) (ansVal != null ? ansVal.has("dynamic")
                                  ? ansVal.get("dynamic") : null :null);
                  String valTxt = (String) (ansVal != null ? ansVal.has("text")
                                  ?  ansVal.get("text") : null : null);
                  String dateTimeText = (String) (ansVal != null ? ansVal.has("dateTime")
                                  ?  ansVal.get("dateTime") : null : null);
                  String resultText = (String) (ansVal != null ? ansVal.has("result")
                                  ?  ansVal.get("result") : null : null);
                  String fileLinkText = (String) (ansVal != null ? ansVal.has("fileLink")
                                  ?  ansVal.get("fileLink") : null : null);

                   if (scale != null)

                   //Incase the answer options included Other Option
                   if (otherText != null)

                   //Incase of dynamic textbox
                   if (dynamicText != null)

                   //Stored Answer Text
                   if (valTxt != null)

                   //for date time questions
                   if (dateTimeText != null)

                   //For Constant Sum and Rank Order questions
                   if (resultText != null)

                   // For File Upload questions
                    if (fileLinkText != null)
                  }
                 }
                }
                   pageIndex++;
                   count = pageIndex * 100;
              } while (count < totalResponses);
           }
       }
    

Get Started today for FREE!
Email Address:
References and Related Articles
  • Online Research Handbook
    Tips and Tricks for conducting research online.
Download Free eBook »


Privacy Policy   |   Terms of Use   |   Online Surveys   |   Website Polls   |   Pricing   |   Contact Us   |   Free Survey Templates
Help   |   Sample Surveys   |   Site   |  
Online Market Research Forum   |   Free Research Blog   |   Survey   |   Free Online Poll   |   Website Polls   |   Brainstorming Tool   |   Survey Programming
© Copyright SurveyConsole Survey Software   |   Powered by QuestionPro Online Survey Software