Last active
August 29, 2015 13:57
-
-
Save rmoff/9474035 to your computer and use it in GitHub Desktop.
FluidSurvey API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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