Santina Santina - 1 year ago 86
JSON Question

SurveyMonkey API Error400 on bad JSON string when JSON string for creating survey poll is valid

I was looking into ways to create surveys programmatically and came across SurveyMonkey APIs. I manually created an empty survey on my account and created a draft app and got an access token from there. And then I copied & pasted the example code from the API doc on the section of creating a survey question to try it out.

You can also see the code here where the survey ID and the page ID were obtained by using the

end points.

However, I get this following error.

{u'error': {u'docs': u'', u'message': u'The body provided was not a proper JSON string.', u'http_status_code': 400, u'id': u'1001', u'name': u'Bad Request'}}

I checked that the JSON object is valid and contains all the required parameters as specified in the doc. I also tried some smaller, simpler questions and still no success. If I passed in an empty JSON object, it does complain about the missing required parameters. I was wondering if someone could point out what I'm doing wrong. Thank you!

Answer Source

The issue is you aren't actually sending the body as json properly.

url = "" % (survey_id, page_id)
r =, data=payload)
print r.json()

You need to json.dumps(payload)

import json
url = "" % (survey_id, page_id)
r =, data=json.dumps(payload))
print r.json()

In newer version of the requests library you can use the json kwarg for that.

url = "" % (survey_id, page_id)
r =, json=payload)
print r.json()