Programmatically access forms and submissions through the Kobo API, export data in multiple formats, and manage submissions, media attachments, and data quality at scale.
Once field data is collected, the challenge shifts to managing, exporting, and integrating it efficiently. The KoboToolbox API provides programmatic access to forms, submissions, and media, enabling automation of data pipelines and integration with external systems.
This module covers API authentication, endpoints for forms and submissions, data export formats including GeoJSON for spatial integration, media handling, and data quality controls. Learners will build scripts that retrieve submissions, validate data, and export it in formats suitable for analysis and mapping.
The Kobo API is RESTful and returns JSON. Most endpoints require authentication via a token passed in the request header. Understanding endpoints and pagination is essential for building reliable integrations.
https://kf.kobotoolbox.org/api/v2/ for the humanitarian server.Authorization: Token <token> header.limit and offset or follow next links.# List projects
curl -H "Authorization: Token YOUR_TOKEN" \
https://kf.kobotoolbox.org/api/v2/assets/?asset_type=survey
# Retrieve submissions for a form
curl -H "Authorization: Token YOUR_TOKEN" \
https://kf.kobotoolbox.org/api/v2/assets/{asset_uid}/data/
Kobo organizes content into projects (assets), each of which may contain multiple forms. The API exposes project metadata, form versions, and deployment status.
| Endpoint | Purpose |
|---|---|
/assets/ | List all assets |
/assets/{uid}/ | Retrieve a specific asset |
/assets/{uid}/data/ | List submissions for an asset |
/assets/{uid}/files/ | Manage media files |
Submissions are the completed responses to a form. The API allows retrieval, filtering, and management of submissions, including validation status.
data endpoint.# Example submission retrieval with pagination
import requests, os
token = os.environ["KOBO_TOKEN"]
asset_uid = "aXXXXXXXXXXXX"
headers = {"Authorization": f"Token {token}"}
url = f"https://kf.kobotoolbox.org/api/v2/assets/{asset_uid}/data/"
submissions = []
while url:
r = requests.get(url, headers=headers)
r.raise_for_status()
data = r.json()
submissions.extend(data["results"])
url = data["next"]
print(f"Retrieved {len(submissions)} submissions")
Data can be exported in multiple formats depending on the analysis or integration needs. GeoJSON exports are particularly important for spatial data collected via geopoint, geotrace, or geoshape questions.
# Example GeoJSON export
GET /api/v2/assets/{asset_uid}/data/?format=geojson
# Example export with GPS columns
GET /api/v2/assets/{asset_uid}/data/?format=csv
Forms with image, audio, or file questions produce media attachments. These must be downloaded and managed separately from the submission data.
files endpoint to list attachments.# List media files for an asset
GET /api/v2/assets/{asset_uid}/files/
# Download a media file
GET /api/v2/assets/{asset_uid}/files/{file_uid}/
Data quality is essential for reliable analysis. The API and post-processing scripts can enforce validation rules and detect problems.
| Quality Check | Method | Action |
|---|---|---|
| Missing required fields | Constraint validation | Flag for follow-up |
| Duplicate submissions | Unique ID comparison | Remove or merge |
| Outliers | Statistical range checks | Manual review |
| Invalid GPS | Coordinate range checks | Reject or correct |
In this lab, you will build a Python script that authenticates to the Kobo API, retrieves all submissions for a form, validates data quality, exports to GeoJSON, and downloads media attachments.
| Criteria | Weight |
|---|---|
| API authentication and endpoint usage | 20% |
| Paginated submission retrieval | 20% |
| Data exports (CSV and GeoJSON) | 20% |
| Data quality validation | 20% |
| Media attachment handling | 10% |
| Documentation and error handling | 10% |
Pass mark for this module: 70%