Skip to content

Instantly share code, notes, and snippets.

@rmoff

rmoff/fs_example.py

Last active Aug 29, 2015
Embed
What would you like to do?
FluidSurvey API example
#!/usr/bin/python
#
# Example of calling the FluidSurveys API from python
#
# March 10, 2014
#
# @rmoff
# --------------------------
#
# To explore the API, use this syntax with curl:
#
# curl -u your_fs_email@example.com:password -X GET https://fluidsurveys.com/api/v2/surveys/
#
# ----------------------------
import requests, json, os
email='your_fs_email@example.com'
pw='xxxxxx'
# -----------------------------------------------
headers = {'Accept':'application/json'}
# List all surveys
url='https://fluidsurveys.com/api/v2/surveys/'
surveysr=requests.get(url, auth=(email,pw), headers=headers)
if (surveysr.status_code==200):
surveys=json.loads(surveysr.content)['surveys']
for survey in surveys:
print '\tSurvey %s (id: %s)' % (survey['name'].encode('utf-8'),survey['id'])
else:
print 'Request failed'
# Duplicate a survey
master_survey_id=123456
new_name="New survey name"
data="name=%s" % new_name
url='https://fluidsurveys.com/api/v2/surveys/%s/duplicate/' % (master_survey_id)
new_surveyr=requests.post(url, auth=(email,pw), headers=headers,data=data)
if (new_surveyr.status_code==200):
new_survey=json.loads(new_surveyr.content)
survey_url=new_survey['online_url']
print '\nSurvey %s is now online at %s\n\n' % (new_survey['name'],survey_url)
else:
print 'Request failed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.