This guide outlines how to export media via Phonic’s API. Exporting via the API is the best option for surveys with media exports larger than 1GB.


Required Python Packages

Phonic’s media export scripts run on Python 3, using the below packages.

requests

wget

Python Files

You can choose to export your media by survey question or by survey session.


Media sorted by Question ID (i.e., folders are labelled with Question ID). Individual media files are labelled with Response ID. These IDs can be found in your survey’s CSV export.

Media sorted by Question ID (i.e., folders are labelled with Question ID). Individual media files are labelled with Response ID. These IDs can be found in your survey’s CSV export.

Media sorted by Session ID (i.e., folders are labelled with Session ID). Individual media files are labelled with Response ID. These IDs can be found in your survey’s CSV export.

Media sorted by Session ID (i.e., folders are labelled with Session ID). Individual media files are labelled with Response ID. These IDs can be found in your survey’s CSV export.

Sign-in Credentials & Survey ID

Find the lines of code below (they will be in the first few lines of the Python file) and replace with your survey ID and login credentials, accordingly.

login_result = requests.request("GET", PHONIC_LOGIN,
auth=HTTPBasicAuth('USERNAME', 'PASSWORD'))
token = login_result.json()['idToken']
SURVEY_ID = "INSERT SURVEY ID"

Run the Python File

Type python3 and the name of the Python file (see example below) to run the Python script.

python3 download_media_by_question.py

Survey responses will begin to download, and will be saved in your working directory in a folder labelled "responses" or “sessions”.

Download Responses For A Survey - Code Explained

<aside> ❓ This section breaks down the Python code necessary to export media for a survey sorted by question. Media can also be sorted by respondent (see file download options above).

</aside>

import requests
import wget
import os
from requests.auth import HTTPBasicAuth
# Constants
SURVEY_ID = "SURVEY ID"
PHONIC_BASE = '[<http://api.phonic.ai/{}>](<http://api.phonic.ai/%7B%7D>)'
PHONIC_LOGIN = PHONIC_BASE.format("/login")
PHONIC_SURVEY_ROUTE = "/surveys/{}"
PHONIC_RESPONSES_ROUTE = "/surveys/{}/question/{}/responses"
# Get User Auth Token
login_result = requests.request("GET", PHONIC_LOGIN,
auth=HTTPBasicAuth('USER_ID', 'PASSWORD'))
token = login_result.json()['idToken']
# Get Survey JSON
headers = {'Authorization': "Bearer {}".format(token)}
survey = requests.request(
"GET", PHONIC_BASE.format(PHONIC_SURVEY_ROUTE.format(SURVEY_ID)),
headers=headers).json()
os.mkdir("./responses")