soacq
soacq

Reputation: 37

survey monkey api: authorization token was not provided error

I am trying to use survey monkey APIs to pull data from a survey we launched last week but I keep getting error. I already registered an app in the developer portal. I added 'OAuth Redirect URL' in this format "https://api.surveymonkey.com/oauth/authorize?response_type=code&redirect_uri=https%3A%2F%2Fapi.surveymonkey.com%2Fapi_console%2Foauth2callback&client_id=SurveyMonkeyApiConsole&api_key=u366xz3zv6s9jje5mm3495fk" as mentioned in Survey Monkey OAuth developer Cheat Sheet (https://gist.github.com/api-admin/11302313). I also set scopes and marked app status as 'public'.

Here is my code to call an API .

import requests
url = "https://api.surveymonkey.net/v3/surveys/%s?api_key=%s" % (survey_id, YOUR_API_KEY)
s = requests.Session()
s.get(url).text

This is the error I get.

Out[41]: u'{"error": {"docs": "https://developer.surveymonkey.com/api/v3/#error-codes", "message": "The authorization token was not provided.", "id": "1010", "name": "Authorization Error", "http_status_code": 401}}'

What else needs to be done to download data using APIs? I am using SELECT annual plan subscription.

Upvotes: 0

Views: 1775

Answers (1)

General Kandalaft
General Kandalaft

Reputation: 2295

You need to set the access token in the header. I just checked the example in the docs and that is missing. The docs should be fixed.

OAuth example is here. So for that request in particular you'll need to do:

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'bearer ACCESS_TOKEN_HERE'
}

s.get(url, headers=headers)

That should work for you.

Upvotes: 1

Related Questions