Consume JSON from ODK Central

I want to consume a json API from odk central, can someone explain to me how I should do it from odk central? The API brings me information in a json from a postgress database

First, you will need to install pyODK, as the ODK Central API currently supports Python. You can find installation instructions in the documentation.

To consume a JSON API from ODK Central, start by ensuring you have the necessary access credentials, such as the ODK Central URL and user credentials. Use HTTP Basic Authentication, which is triggered automatically by the first API call on the Client or by explicitly calling Client.open().

Example of how your credentials should be set up:

# Example of user credentials
[central]
base_url = "https://www.example.com"
username = "my_user"
password = "my_password"
default_project_id = 123

Once authenticated, you can make HTTP requests. The API will return data in JSON format, which you can then parse and use in your application.

client.submissions.get_table() get the submission from specified form.

Simple example:

from pyodk.client import Client

client = Client()

PROJECT_ID = 3
FORM_ID = 'my_first_form'

# get the data using client.submissions.get_table, which returns JSON
master = client.submissions.get_table(form_id=FORM_ID, project_id=PROJECT_ID, filter="__system/reviewState ne 'rejected'")['value']
master

You can obtain the PROJECT_ID and FORM_ID values directly from ODK Central.

For more details you can read the documentation

I agree with @Joseph_Muganga that an API wrapper like pyodk or ruodk is often a really nice way to access the API!

If you want to use the API directly, the json data endpoint is documented at https://docs.getodk.org/central-api-odata-endpoints/#data-document

You can build the URL by navigating to your form in Central, copying the URL, adding .svc and then adding /Submissions or /name-of-repeat.

1 Like