Using the API

Last updated: 21 Sep 2023

KoboToolbox has a number of advanced features built in based on our open source libraries, which include useful add-ons for advanced use cases. There are many ways to use our API. For some hands-on examples, see this post.

KoboToolbox has two APIs for its primary tools, kpi and kc. Originally kc was the only api for deploying forms and retrieving data. Now, kpi is the primary API that should be used.

The base URL depends on the server you are using: for most users it is kf.kobotoolbox.org or eu.kobotoolbox.org. Below we only use [kpi-url] to refer to this base URL.

Getting your API Token:

There are different ways to get your API Token.

Method 1:

To find your API token go to https://[kpi-url]/token/?format=json

image

Method 2:

  • Select ACCOUNT SETTINGS (from where you normally log out) as shown in the image below:

    image

  • Then press the eye like button to view your Token as shown in the image below:

    image

Method 3:

You could use the following curl command:

curl -u username:password "https:/[kpi-url]/token/?format=json"

Testing your API:

To test it use this command:

curl -X GET https://[kpi-url]/api/v2/assets.json -H "Authorization: Token [your_token_goes_here]"

You can also use tools like Postman to build and test your API snippets:

image

For more details on using the API follow these endpoints (selection only):

https://[kpi-url]/api/v2/assets/ (list of all assets, including forms/projects, questions, blocks, templates, collections; for each asset there are several additional sub-endpoints) https://[kpi-url]/api/v2/assets/{asset_uid}/data/ (access submitted data) https://[kpi-url]/exports/ (create or view data exports)

You can find more examples in this forum post.