Surveys
Surveys are reusable question sets that belong to a project. Create them once, then reference them when creating experiments so the question data is copied into the experiment configuration.
Creating a survey
import requests
API_KEY = 'YOUR_API_KEY'
PROJECT_ID = 'YOUR_PROJECT_ID'
headers = {'Authorization': f'Api-Key {API_KEY}'}
response = requests.post(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/surveys/',
headers=headers,
json={
'name': 'Post-task feedback',
'questions': [
{
'kind': 'textarea',
'dimension': 'Comment',
'question': 'What did you notice?',
},
{
'kind': 'radio',
'dimension': 'Preference',
'question': 'Which option sounded best?',
'choices': [
{'label': 'A'},
{'label': 'B'},
],
},
],
},
)
survey = response.json()
print(survey['id'])
Supported question kinds are textarea, radio, checkbox, discrete_slider, and
continuous_slider.
Saved surveys, survey experiments and pre- and post-surveys can hold
visibility rules, in the
survey format. For no visibility rules, omit rules when
creating a survey or send "rules": null or "rules": []. Responses represent no rules as [].
Deprecated config field
Use the top-level questions and rules fields for new integrations. They are stored separately
so you can update visibility rules without replacing the questions. The deprecated config
field remains the question array, readable and writable for existing clients. If a request
supplies both, questions takes precedence over config.
Updating a survey
Use PATCH to update the name, questions, or rules. Sending only rules preserves the questions.
response = requests.patch(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/surveys/{survey["id"]}/',
headers=headers,
json={'name': 'Updated post-task feedback'},
)
Using surveys in experiments
Pass survey IDs when creating an experiment:
response = requests.post(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/experiments/',
headers=headers,
json={
'name': 'Audio survey pilot',
'type': 'survey_audio',
'datasets': ['DATASET_ID'],
'pre_survey_id': 'PRE_SURVEY_ID',
'survey_id': survey['id'],
'post_survey_id': 'POST_SURVEY_ID',
},
)
pre_survey_id and post_survey_id can be used with any experiment type. survey_id is only for
survey experiment types: survey_audio, survey_image, survey_video, and survey_embed.
Inline survey formats
Inline surveys in config (under surveyAudio, surveyImage, surveyVideo or surveyEmbed,
and in preSurvey and postSurvey) use the survey format;
use the object form to supply rules.
Survey definitions are copied into the experiment config at creation time. The source survey IDs are not persisted. Updating the reusable survey later does not change existing experiment configs.