Get Survey Monkey Data Using the REST API

API, Data, Tech Tips Comments (0)

Recently Survey Monkey updated their REST API to version 3, which increases the difficulty of requesting data for use in your analysis tools (e.g., R, Power BI, etc.). The language and instructions used in this post should be easy enough for a non-developer (with patience) to understand. The goal is to allow Survey Monkey account administrators to create Survey Monkey apps that then allow authenticating and getting data from their Survey Monkey account.

Why would you want to do this? Well there could be several reasons but, for most people, the main benefit is to get real-time, updated data while eliminating the need to login to Survey Monkey to perform several manual steps to get your data.

There are two parts of this process: 1. Authentication, and 2. Getting the data

You only need to authenticate occasionally since you can use a long lived token. For most people, the authentication part is the most difficult. Once we generate a token, getting data is pretty straightforward.

High-Level Workflow

  1. Survey Monkey account administrator creates a Survey Monkey app (or uses an existing app)
  2. Using the information provided with that app, get an access token to use for authentication with a data analysis tool
  3. Once access token has been acquired, use data analysis tool to authenticate into Survey Monkey REST API
  4. Retrieve Survey list to get survey ID
  5. Retrieve survey responses

Authenticate

Note: for the purposes of this guide, we will use Postman. You could choose a number of other routes but I think this is one of the more simple approaches for data analysts.

  1. Log in to Survey Monkey
    https://www.surveymonkey.com
  2. Go to My Apps in the Developer area
    https://developer.surveymonkey.com/apps/
    my_apps_survey_monkey_dev
  3. Either create a new app or use an existing app
    my_apps
  4. Click on Settings for your app and use this OAuth Redirect URL
    https://www.getpostman.com/oauth2/callback
    oauth_redirect
  5. Install Postman on your computer
    https://www.getpostman.com/
    Okay, this is where it gets complicated. I won’t go into details about why you have to use Postman. You could actually create a real app to interface with Survey Monkey but, since we just need to get data, this would be a lot of unnecessary work. So we fake it in order to get our access token using Postman.
  6. Open Postman and enter basic info
    survey_monkey_postman_connect
    a. Add this URL to GET
    https://api.surveymonkey.net/oauth/authorize

    b. Select OAuth 2.0 

    c. click Get New Access Token

  7. Now use the information from your Survey Monkey app in My Apps to complete the info and click Request Tokenaccess_token_postman_sm
  8. It will prompt you to login using your Survey Monkey admin credentials and ask you to complete a captcha in order to Authorize
  9. At long last, we will get our token. Use access_token to authenticate in your data analysis toolaccess_token_long_lived
    Note: you can create tokens that expire at a given date but that’s for another dayWhew! So with that out of the way, we can reuse this forever. You only have to do this once. Onward!

Examples

Power BI Authentication Example

  1. In Power BI Desktop, click on Get Data -> Blank Query
  2. Click on Advanced Editor and use this to get a list of surveys from your Survey Monkey account. The two parts of this that are important are the Survey Monkey API URL and you will replace “<<API-TOKEN>>” with the access token you generated using Postman.
    let
        Source = Web.Contents("https://api.surveymonkey.net/v3/surveys", [Headers=[#"Authorization"="bearer <<API-TOKEN>>"]]),
        convertToJson = Json.Document(Source),
        toTable = Table.FromRecords({convertToJson})
    in
        toTable

R Authentication Example

You will enter your access token you painstakingly generated in Postman in the space where it says “Enter your access token for SurveyMonkey” below:

sm_get_surveys <- function(auth_token, page = 1, per_page = 250) {
 if (missing(auth_token)) {
 auth_token <- readline('Enter your access token for SurveyMonkey: ')
 }
 auth <- paste("bearer", auth_token, sep=" ");
 url <- paste('https://api.surveymonkey.net/v3/surveys?page=', page, '&per_page=', per_page, sep='')
 survey_list_response <- httr::GET(url=url, add_headers("Content-Type" = "application/json", "Authorization" = auth ))
 
 if (survey_list_response$status_code != 200) {
 stop(paste('Bad response from server: ', httr::http_status(survey_list_response)))
 }
 json <- httr::content(survey_list_response, as = 'text')
 survey_list <- jsonlite::fromJSON(json)
 survey_list
}

 

Get the Data

So after you authenticate, you have to request the data. I’ll show you how to get all of the responses for a survey but there are a lot of options available:
https://developer.surveymonkey.com/api/v3/

  1. Get survey list (list of survey ids)
    https://api.surveymonkey.net/v3/surveys
  2. Use a specific survey id from the list retrieved in #1 to get responses in bulk
    https://api.surveymonkey.net/v3/surveys/{survey_id}/responses/bulk

 

 

» API, Data, Tech Tips » Get Survey Monkey Data Using...
On November 18, 2016
By
, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

« »