Get Survey Monkey Data Using the REST API

Update 12/22/17 Survey Monkey requires you to alter the OAuth redirect url and update the scopes before you can deploy your app. I’ve updated the post to reflect these changes.
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 long story short instructions.

Long Story Short

When we talk about an “app” in our case, we’re just sort of faking it so that we can get an access token.

Instead of generating a “long lived” token (i.e., lasts more than 90 days), I would recommend just following these simple steps:

Click on add a new app and then make sure to change OAuth redirect url and add scopes

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

2. Give your app a nickname

3. Set it to Public App

4. Click Create App

5. Click on Settings

6. Change the OAuth Redirect URL to anything (e.g., your personal site, https://google.com, etc.)

7. Click Submit Changes

8. Modify the scopes (e.g., set them to “Optional”>

9. Click Update Scopes

10. Click Deploy

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

That’s it. You don’t need to do anything else in terms of the app set up and configuration for our purposes.

Now that you have your access token you can request your survey data.
If you like Python you could use this:

import requests
import json

client = requests.session()

headers = {
"Authorization": "bearer %s" % "YOUR_ACCESS_TOKEN",
"Content-Type": "application/json"
}

data = {}

HOST = "https://api.surveymonkey.net"
SURVEY_LIST_ENDPOINT = "/v3/surveys"

uri = "%s%s" % (HOST, SURVEY_LIST_ENDPOINT)

response = client.get(uri, headers=headers)

response_json = response.json()
#survey_list = response_json["data"]["surveys"]

print(response_json)

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

For cURL

curl -i -X GET -H "Authorization:bearer YOUR_ACCESS_TOKEN" -H "Content-Type": "application/json" https://api.surveymonkey.net/v3/surveys

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

 

 


Comments

20 responses to “Get Survey Monkey Data Using the REST API”

  1. Elisabethe Rousselet Avatar
    Elisabethe Rousselet

    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’

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

      1. Elisabethe Rousselet Avatar
        Elisabethe Rousselet

        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?

        1. 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 Avatar
    Matthew Armstrong

    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

    1. 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 Avatar
    Andrew

    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

    1. 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. 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

    1. 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

  5. Hi! I followed exactly your example, replacing YOUR_ACCESS_TOKEN with the access token in my app, but I always get 403.
    Can you help me?
    Thanks

    1. Hi Sabrina,
      Looks like Survey Monkey has altered their API flow a bit since I created this article. I just tested it and it works fine but you need to 1. go into your app (https://developer.surveymonkey.com/apps/) and change the OAuth redirect url to something (anything you want) and also 2. update the scopes (e.g., just set them all to optional). Once you do this, you will get data just fine. I’d recommend just testing with cURL to make sure you’re getting 200

      curl -i -X GET -H “Authorization:bearer YOUR_ACCESS_TOKEN” -H “Content-Type”: “application/json” https://api.surveymonkey.net/v3/surveys

      1. I also just updated the example python script to print something in case you’d rather use that than cURL. And I created a quick gif of what you need to do https://3mvpqu23dm0g2krv0d3muay4-wpengine.netdna-ssl.com/wp-content/uploads/2016/11/survey-monkey-api.gif

  6. Hi nathan,

    I am trying to extract the survey monkey data using your python code, it gets me to the stage where I am able to see the counts of questions, but I am not able to get one step below to get all the results.

    What I am looking for is getting the data from the survey using my Matillion Job(Python Script or API Query tool) and pass on this data into the Redshift table.

    Please help.

    thanks

  7. Harsh Vardhan Avatar
    Harsh Vardhan

    Can we get a back date entry in the last page of the JSON response by using bulk response method:

    https://api.surveymonkey.com/v3/surveys/{Survey_id}/responses/bulk?page={Max_page_no.}&per_page=100

  8. hi how to post the form data to survey monkey via curl or ajax

  9. Shivam Rathore Avatar
    Shivam Rathore

    i have client id and secret key and access token after creating an app in surveymonkey but how to authorize through postman ,like above till step 7 am getting the suvey monkey screeen but after that iam not getting anything?

  10. Hi, I am using R to get responses, but the only response i get when i ran the code snippet u provided is the success status and not the list of survey ids.
    can u please help do i get the list of surveys

  11. Will this approach work for free survey monkey account?

  12. Thanks for posting this. It really helped me.

Leave a Reply

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