Get Survey Monkey Data Using the REST API

API, Data, Tech Tips Comments (10)

Update 3/31/17: Survey Monkey now provides an access token for 90 days when you create an app. So unless you need to use the API for more than 90 days and you have a Platinum plan, then you can just read these abbreviated instructions.

Instead of generating a “long lived” token (i.e., lasts more than 90 days), you can follow these steps:

1. Go to My Apps and click Add New App
https://developer.surveymonkey.com/apps/

2. Give your app a name and click Create

3. Click on Settings for your new app and scroll to the bottom

4. Copy your access token and use it for authorization in your request

For example, if you were using Python you could use

import requests

s = requests.Session()
s.headers.update({
"Authorization": "Bearer %s" % YOUR_ACCESS_TOKEN,
"Content-Type": "application/json"
})

payload = {
"title": "My Survey"
}
url = "https://api.surveymonkey.net/v3/surveys"
s.post(url, json=payload)

and replace “YOUR_ACCESS_TOKEN” with the access token in your app.

Similarly, if you were using this in Power BI or Excel’s Get & Transform, you could

1. Get Data -> Web
2. Paste https://api.surveymonkey.net/v3/surveys into the web source field
3. Click Advanced
4. Select Authorization in the dropdown and then in the field enter Bearer YOUR_ACCESS_TOKEN


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
, , ,

10 Responses to Get Survey Monkey Data Using the REST API

  1. Elisabethe Rousselet says:

    Hi,
    Everything works fine until step 8. After Survey Monkey has authorized the access, nothing happens in Postman and I still have the same screen as in step 7. Do you have an idea as to what I am missing?
    Many thanks,
    E’

    • Can you include a screenshot of what you see when you click Authorize and complete the captcha?

      • Elisabethe Rousselet says:

        There is nothing to be seen actually. I am authorized, but no token get added in Postman. At the end of step 8, I am back to step 7, in other words. Note: when creating my app in SurveyMonkey, a token is automatically generated. However, I have no idea on how to enter in in Postman, or event if I should. I saw here: developer.surveymonkey.com/api/v3/ that the app authentification had changed in November. Could that explain my issue?

        • Elisabethe, I’ll email you directly. This is for V3 of the Survey Monkey API. Before V3, you could use the API Key and Client and now you have to use the access token. Sometime in the last two months SM started providing the access token for 90 days when you create an app without needing to generate one. While it doesn’t explicitly say in the docs, I think this access_token expires after 90 days. Not a huge deal since you could just create a new one (if your goal is to just retrieve your SM data in a data analysis tool).

  2. Matthew Armstrong says:

    Hi Nathan, I am experiencing exactly the same issue as Elisabethe – no response in Postman following the authorise. I notice that in my trial draft app that a token is generated but am unsure how to use this in Postman. Any and all help would be appreciated

    • Hi Matthew,

      With the revised auth for non-Platinum accounts, you can just use the access token provided to you. You can use it in postmany really simple like this

      access_token_postman_auth

      Basically just open Postman, put this into the field to test that it’s working
      https://api.surveymonkey.net/v3/surveys

      Click on Headers and select Authorization and then put Bearer youraccesstoken

      then hit send and you’ll see your json data

      This will be true in Python or Excel Get & Transform, etc. The downside to these draft apps in SM is that the access token expires in 90 days and you have to create a new app. There are also some more strict api request limits.

  3. Andrew says:

    Hi Nathan,
    I am trying to follow the above with regards to accessing my survey Data through PowerBI. I have used the https://api.surveymonkey.net/v3/surveys/{SurveyID}/responses/bulk to try an get a bulk return of responses, however all i get back in PowerBI is the hader info – per_page, total, Data,Page, links.

    Have you been able to get useful data pulled into PowerBi from Surveymonkey

    • Hi Andrew,

      This sounds like you’re missing a step in Power BI. When you get the data from survey monkey, you’ll have to click “Into Table” in PBI and then expand the rows. It’s kind of weird workflow but it’s much easier than doing this in R or Python. If you skip down to the PBI/Excel steps in this article

      https://digitalborn.org/data-insights-wordpress-api-power-bi/

      you’ll see what I mean. Let me know if it’s actually not getting any of the data and is just getting a plain html document. This would indicate a problem with the authentication.

      NG

  4. ian says:

    Hi, Many thanks for this. The R example would be very helpful but unfortunately has much of the syntax cropped out due to what looks like a copy/paste issue. Would it be possible for you to post it in complete form? Thanks again, Ian

    • Hi Ian,
      Thanks for the note! Looks like pre tag wasn’t set to wrap in the CSS of this theme and was getting cut off. I just fixed that so you should now see the full R auth example.
      NG

Leave a Reply

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

« »