Help/Support   
Online Surveys Made Easy
UNLIMITED Surveys, UNLIMITED Responses, Easy to Use
Email Address:
or Take a Tour

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.

Screenshot
Survey Software Help Image

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) {
          System.out.println("Survey : " + jr.getString("id"));
          JSONObject stats = jr.getJSONObject("surveyStatistics");
          System.out.println("Viewed : " + stats.getString("viewedCount") +
           " Started : " + stats.getString("startedCount") +
           " Completed : " + stats.getString("completedCount"));
          } else {
            System.out.println("--------------------------------------------------------");
          }

           JSONArray responses = jr.getJSONArray("responses");
            for (int i=0; i < responses.length();i++) {
              JSONObject obj = (JSONObject)responses.get(i);
              System.out.println("\nRESPONSE ID : " + obj.getString("id"));
              JSONArray responseSet = obj.getJSONArray("responseSet");
              for (int j=0;j < responseSet.length();j++) {
                JSONObject questionResponse = (JSONObject)responseSet.get(j);

                System.out.println("\n\t" + (j+1) + ". " + questionResponse.getString("questionText"));
                System.out.println((questionResponse.has("questionDescription") ? "\n\t" +
                 "    " +  questionResponse.getString("questionDescription") : ""));

            JSONArray answerValues = questionResponse.getJSONArray("values");
             for (int k=0; k < answerValues.length();k++) {
               JSONObject value = (JSONObject)answerValues.get(k);
               System.out.println("\n\t\tANSWER ID : " + value.getString("id"));
               System.out.println("\n\t\tANSWER TEXT : " + value.getString("answerText"));
               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)
                System.out.println("\n\t\tAnswer Scale is : " + scale);

                //Incase the answer options included Other Option
                if (otherText != null)
                System.out.print("\n\t\tOther Text recorded is" + otherText);

                //Incase of dynamic textbox
                if (dynamicText != null)
                System.out.print("\n\t\tDynamic Text recorded is" + dynamicText);

                //Stored Answer Text
                if (valTxt != null)
                System.out.print("\n\t\tAnswer Text is" + valTxt);

                //for date time questions
                if (dateTimeText != null)
                System.out.print("\n\t\tDate Time recorded is" + dateTimeText);

                //For Constant Sum and Rank Order questions
                if (resultText != null)
                System.out.print("\n\t\tResult recorded is" + resultText);

                // For File Upload questions
                 if (fileLinkText != null)
                System.out.print("\n\t\tFile href recorded is" + fileLinkText);
               }
              }
             }
                pageIndex++;
                count = pageIndex * 100;
           } while (count < totalResponses);
        }
    }
 

You may also be interested in...
Join Now!
It's completely Free!
Survey Setup
Survey Distribution
Survey Analysis / Reporting
Accounts/Billing/Licensing
Site Policies and Procedures
New User Registration / Account Management
Multi-User Accounts : Corporate Accounts
Survey Creation - Details
Survey Building/Authoring - Details
Sending Survey - Details
Survey Administration - Details
Survey Tracking - Details
Analysis and Reporting - Details
Complex Logic Surveys
Conjoint Analysis
TURF Analysis
Trend Analysis
Pricing and Billing
Upgrading Access Restrictions
Advanced Survey Options
Enterprise Toolsets
Salesforce.com Integration
Tutorials
Student Research Sponsorship
Other (Sales/Billing/Partnerships)
© Copyright 2010 QuestionPro Survey Software a Division of Survey Analytics Enterprise Survey Software