Kobo Api V1
Kobo JSON Rest API endpoints:
Data
- /api/v1/data - List, Retrieve submission data
Forms
- /api/v1/forms - List, Retrieve form information
- /api/v1/media - List, Retrieve media attachments
- /api/v1/metadata - List, Retrieve form metadata
- /api/v1/submissions - Submit XForms to a form
Users and Organizations
- /api/v1/user - Return authenticated user profile info
Status Codes
- 200 - Successful [
GET,PATCH,PUT] - 201 - Resource successfully created [
POST] - 204 - Resouce successfully deleted [
DELETE] - 403 - Permission denied to resource
- 404 - Resource was not found
Authentication
Kobo JSON API endpoints support both Basic authentication
and API Token Authentication through the Authorization header.
Basic Authentication
Example using curl:
curl -X GET https://example.com/api/v1/ -u username:password
Token Authentication
Example using curl:
curl -X GET https://example.com/api/v1/ -H "Authorization: Token TOKEN_KEY"
Kobo Tagging API
- Filter form list by tags.
- List Tags for a specific form.
- Tag Forms.
- Delete a specific tag.
- List form data by tag.
- Tag a specific submission
Using Oauth2 with the Kobo API
You can learn more about oauth2 here.
1. Register your client application with Kobo - register
name- name of your applicationclient_type- Client Type: select confidentialauthorization_grant_type- Authorization grant type: Authorization coderedirect_uri- Redirect urls: redirection endpoint
Keep note of the client_id and the client_secret, it is required when
requesting for an access_token.
2. Authorize client application.
The authorization url is of the form:
GET /o/authorize?client_id=XXXXXX&response_type=code&state=abc
example:
http://localhost:8000/o/authorize?client_id=e8&response_type=code&state=xyz
Note: Providing the url to any user will prompt for a password and
request for read and write permission for the application whose client_id is
specified.
Where:
client_id- is the client application id - ensure its urlencodedresponse_type- should be codestate- a random state string that you client application will get when redirection happens
What happens:
- a login page is presented, the username used to login determines the account that provides access.
- redirection to the client application occurs, the url is of the form:
REDIRECT_URI/?state=abc&code=YYYYYYYYY
example redirect uri
http://localhost:30000/?state=xyz&code=SWWk2PN6NdCwfpqiDiPRcLmvkw2uWd
code- is the code to use to request foraccess_tokenstate- same state string used during authorization request
Your client application should use the code to request for an access_token.
3. Request for access token.
You need to make a POST request with grant_type, code, client_id and
redirect_uri as POST payload params. You should authenticate the request
with Basic Authentication using your client_id and client_secret as
username:password pair.
Request:
POST/o/token
Payload:
grant_type=authorization_code&code=YYYYYYYYY&client_id=XXXXXX&
redirect_uri=http://redirect/uri/path
curl example:
curl -X POST -d "grant_type=authorization_code&
code=PSwrMilnJESZVFfFsyEmEukNv0sGZ8&
client_id=e8x4zzJJIyOikDqjPcsCJrmnU22QbpfHQo4HhRnv&
redirect_uri=http://localhost:30000" "http://localhost:8000/o/token/"
--user "e8:xo7i4LNpMj"
Response:
{
"access_token": "Q6dJBs9Vkf7a2lVI7NKLT8F7c6DfLD",
"token_type": "Bearer", "expires_in": 36000,
"refresh_token": "53yF3uz79K1fif2TPtNBUFJSFhgnpE",
"scope": "read write groups"
}
Where:
access_token- access token - expiresrefresh_token- token to use to request a newaccess_tokenin case it has expored.
Now that you have an access_token you can make API calls.
4. Accessing the KoBo API using the access_token.
Example using curl:
curl -X GET https://example.com/api/v1
-H "Authorization: Bearer ACCESS_TOKEN"
GET /api/v1/
{ "user": "https://kc.kobotoolbox.org/api/v1/user", "forms": "https://kc.kobotoolbox.org/api/v1/forms", "notes": "https://kc.kobotoolbox.org/api/v1/notes", "metadata": "https://kc.kobotoolbox.org/api/v1/metadata", "media": "https://kc.kobotoolbox.org/api/v1/media", "formlist": "https://kc.kobotoolbox.org/api/v1/formlist", "submissions": "https://kc.kobotoolbox.org/api/v1/submissions", "briefcase": "https://kc.kobotoolbox.org/api/v1/briefcase" }