Skip to main content

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',
'config': [
{
'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.

Updating a survey​

Use PATCH to update the name, the questions, or both.

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.

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.