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. questionpro.survey.sendSurveyMetaData - To get email groups and email templates information
  4. questionpro.survey.sendSurvey - To send survey invitations
  5. Base URL : http://api.questionpro.com/a/api/
  6. Access key parameter name : accessKey
  7. Example API call URL: http://api.questionpro.com/a/api/questionpro.survey.surveyResponses?accessKey=qthqs
    We serve only 100 responses per API call
  8. 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:

import  java.net.*;
import java.io.*;
import org.apache.http.impl.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.entity.*;
import org.apache.http.client.*;
import org.apache.http.*;
import org.json.*;

public class QPApi {
    
    long surveyID;
    String accessKey;
    
    public static void main(String [] args) throws Exception {
	QPApi api = new QPApi();
	api.setSurveyID(xxxxx);
	api.setAccessKey("xxxxx");
	api.printResponses();
        
    }

    public void setSurveyID(long val){surveyID=val;}
    public void setAccessKey(String val){accessKey=val;}
    
    public long getSurveyID(){return surveyID;}
    public String getAccessKey(){return accessKey;}

    public String getSurveyResponsesUrl() {
	return  "http://api.questionpro.com/a/api/questionpro.survey.surveyResponses?accessKey=" + getAccessKey();
    }

    public String getSurveyResponseUrl() {
    return  "http://api.questionpro.com/a/api/questionpro.survey.surveyResponse?accessKey=" + getAccessKey();
    }

    public String getSurveyResponseCountUrl() {
        return "http://api.questionpro.com/a/api/questionpro.survey.responseCount?accessKey=" + getAccessKey();
    }

    public String getSendSurveyMetaDataUrl() {
        return "http://api.questionpro.com/a/api/questionpro.survey.sendSurveyMetaData?accessKey=" + getAccessKey();
    }

    public String getSendSurveyUrl() {
        return "http://api.questionpro.com/a/api/questionpro.survey.sendSurvey?accessKey=" + getAccessKey();
    }


    public JSONObject getSendSurveyMetaData() throws Exception {
	String path = getSendSurveyMetaDataUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	//String data = "{\"surveyID\":\"" + getSurveyID() + "\"}";
	JSONObject data = new JSONObject();
	data.put("surveyID", getSurveyID());
	StringEntity se = new StringEntity(data.toString());
	httpost.setEntity(se);
	httpost.setHeader("Accept", "application/json");
	httpost.setHeader("Content-type", "application/json");
	ResponseHandler responseHandler = new BasicResponseHandler();
	Object resp = httpclient.execute(httpost, responseHandler);
	JSONObject meta =  new JSONObject( resp.toString());
        JSONObject response = meta.getJSONObject("response");
	JSONArray emailGroups = response.getJSONArray("emailGroups");
	JSONArray templates = response.getJSONArray("templates");
	
	for (int i=0; i < emailGroups.length();i++) {
	    JSONObject jsonEg = emailGroups.getJSONObject(i);
	    System.out.println("Email Group ID : " + jsonEg.getLong("emailGroupID") + " Name : " + 
			       jsonEg.getString("emailGroupName"));
	}
	
	for (int i=0; i < templates.length();i++) {
            JSONObject jsonSc = templates.getJSONObject(i);
            System.out.println("Template ID : " + jsonSc.getLong("templateID") + " Subject : " +
                               jsonSc.getString("templateSubject"));
        }
	return meta;
    }

    public JSONObject getSendReminder() throws Exception {
        String path = getSendReminderUrl();
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpost = new HttpPost(path);
        JSONObject data = new JSONObject();
        data.put("surveyID", getSurveyID());
        data.put("emailGroupID", 1234);
        data.put("templateID", 5678);
        StringEntity se = new StringEntity(data.toString());
        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 new JSONObject(resp.toString());
    }

    public JSONObject getSendSurvey1() throws Exception {
	String path = getSendSurveyUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	JSONObject data = new JSONObject();
        data.put("surveyID", getSurveyID());
	data.put("emailGroupID", 1234);
	data.put("templateID", 5678);
	data.put("mode", 1);
	StringEntity se = new StringEntity(data.toString());
	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 new JSONObject(resp.toString());	
    }

    public JSONObject getSendSurvey2() throws Exception {
	String path = getSendSurveyUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	JSONObject data = new JSONObject();
	JSONArray emails = new JSONArray();
	emails.put("test@g.com");
	emails.put("test2@g.com");

        data.put("surveyID", getSurveyID());
	data.put("emails", emails);
	data.put("templateID", 5678);
	data.put("mode", 2);
	StringEntity se = new StringEntity(data.toString());
	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 new JSONObject(resp.toString());	
    }

    public JSONObject getSendSurvey3() throws Exception {
	String path = getSendSurveyUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	JSONObject data = new JSONObject();
	JSONObject template = new JSONObject();
	template.put("body", "Please take the survey : <SURVEY_LINK>");
	template.put("subject", "This is subject");
        data.put("surveyID", getSurveyID());
	data.put("emailGroupID", 1234);
	data.put("template", template);
	data.put("mode", 3);
	StringEntity se = new StringEntity(data.toString());
	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 new JSONObject(resp.toString());	
    }
    
    public JSONObject getSendSurvey4() throws Exception {
	String path = getSendSurveyUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	JSONObject data = new JSONObject();
	JSONArray emails = new JSONArray();
	emails.put("test@g.com");
	emails.put("test2@g.com");
	JSONObject template = new JSONObject();
	template.put("body", "Please take the survey : <SURVEY_LINK>");
	template.put("subject", "This is subject");

        data.put("surveyID", getSurveyID());
	data.put("emails", emails);
	data.put("template", template);
	data.put("mode", 4);
	StringEntity se = new StringEntity(data.toString());
	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 new JSONObject(resp.toString());	
    }

    public String getResponse() throws Exception {
       String path = getSurveyResponseUrl();
       DefaultHttpClient httpclient = new DefaultHttpClient();
       HttpPost httpost = new HttpPost(path);
       JSONObject data = new JSONObject();
       data.put("surveyID", getSurveyID());
       data.put("responseSetID", "1234");

       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 String getResponses(int startingResponseCounter) throws Exception {
	String path = getSurveyResponsesUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	String data = "{\"id\":\"" + getSurveyID() + "\",\"resultMode\":\"0\",\"startDate\":\"01/01/2013\"," +
	    "\"endDate\":\"07/24/2013\",\"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 long getResponseCount() throws Exception {
	String path = getSurveyResponseCountUrl();
	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPost httpost = new HttpPost(path);
	String data = "{\"id\":\""  + getSurveyID() + "\",\"resultMode\":\"0\", \"startDate\":\"01/14/2013\"," +
            "\"endDate\":\"01/15/2013\"}";
	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");
	System.out.println(" Survey : " + obj.opt("name") +
			   " Status  : " + obj.opt("status") +
			   " Overall Viewed : " + obj.optLong("overallViewedCount") +
			   " Overall Started : " + obj.optLong("overallStartedCount") +
			   " Overall Complete : " + obj.optLong("overallCompleteCount") +
			   " Started Count: " + obj.optLong("startedCount") +
			   " Complete Count : " + obj.optLong("completeCount"));

	return obj.getLong("overallStartedCount");
    }

    public void printResponses() throws Exception {
	long total = getResponseCount();
	int count = 0;
	for (int p=0; count < total;p++) {
	    count = p * 100;
	    if (count > total && p > 0) {
		break;
	    }
	    String responsesJson = getResponses(p);
	    System.out.println(responsesJson);
	    JSONObject jr = new JSONObject(responsesJson);
	    jr = jr.getJSONObject("response");
	    if (p ==0) {
		System.out.println("Survey : " + jr.getString("name") + " (" + jr.getLong("id") + ") status : " + 
				   jr.opt("status"));
		JSONObject stats = jr.getJSONObject("surveyStatistics");
		System.out.println(" Viewed : " + stats.getLong("viewedCount") +
				   " Started : " + stats.getLong("startedCount") +
				   " Completed : " + stats.getLong("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.getLong("id")  +
				   " Time Taken : " + obj.opt("timeTaken") +
				   " Custom 1 : " + obj.opt("custom1") + 
				   " Custom 2 : " + obj.opt("custom2") +
				   " Custom 3 : " + obj.opt("custom3") +
				   " Custom 4 : " + obj.opt("custom4") +
				   " Custom 5 : " + obj.opt("custom5") +
				   " Country : " + obj.opt("country") + 
				   " Region : " + obj.opt("region"));

		JSONArray responseSet = obj.getJSONArray("responseSet");
		for (int j=0;j < responseSet.length();j++) {
		    JSONObject setObj = (JSONObject)responseSet.get(j);
		    System.out.println("\n" + setObj.opt("questionDescription") + 
				       "\n\t" + (j+1) + ". " + setObj.getString("questionText") + 
				       " (" + setObj.opt("questionCode") +")");
		    JSONArray values = (JSONArray)setObj.getJSONArray("values");
		    for (int k=0; k < values.length();k++)  {
			JSONObject val = (JSONObject)values.get(k);
			JSONObject scaleObj = val.getJSONObject("value");
			System.out.println("\t  > " + val.getString("answerText") + " [Answer ID:" + val.getString("id") + "] " +
					   "  [DBValue:" + (scaleObj.has("scale") ? scaleObj.getString("scale") : 
							    (scaleObj.has("text") ? scaleObj.getString("text") : "NULL")) + "]");
		    }
		}
	    }
	    break;
	}
    }

}
 

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