API Connector Documentation
Import KoBoToolbox Data to Google Sheets
In this guide, we’ll walk through how to pull Kobo API data directly into Google Sheets, using the API Connector add-on for Sheets.
We'll first get an API key from Kobo, and then set up a request to pull in data to your spreadsheet.
Contents
- Before You Begin
- Part 1: Get your Kobo API Key
- Part 2: Pull Data from Kobo to Sheets
- Part 3: Create a Custom API Request
- Part 4: Handle Pagination
- Part 5: API Documentation & Information
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Get your Kobo API Key
- While logged in to your Kobo account, check the domain in the address bar. For most people, this will be either kf.kobotoolbox.org or kobo.humanitarianresponse.info (this article describes the difference).
- Now navigate to https://YOUR_DOMAIN/token, i.e.
https://kf.kobotoolbox.org/token/
orhttp://kobo.humanitarianresponse.info/token
. Copy the token that you see there. That's it, you can now access Kobo's API.
Part 2: Pull Data from Kobo to Sheets
The easiest way to get started with the Kobo API is through API Connector’s built-in integration.
- In Sheets, open API Connector and create a new request (Extensions > API Connector > Open > Create request)
- Select KoboToolBox from the drop-down list of applications
- Under Authorization, enter your API key with the word
Token
in front of it. - Choose an endpoint. We’ll start with
/assets.json
which is the endpoint to get a list of your assets. - Under
kpi-url
, select your hostname (e.g.kf.kobotoolbox.org
orkobo.humanitarianresponse.info
, etc.) - Choose a destination sheet, name your request, and hit Run to see the response data in your sheet.
- Note the ID in the results.uid field, as you can plug that into the asset_uid input box for subsequent requests.
- When you run these requests, select grid mode with the Unwind option selected to get response data in table.
Part 3: Create a Custom Request
Alternatively, you can run your own custom requests instead of using API Connector’s pre-built integration. This enables some more advanced features like filtering by date, e.g. https://kobo.humanitarianresponse.info/api/v2/assets/aQ111111111/data.json?query={"_submission_time":{"$gt":"2022-09-23"}}
. Here's an example request setup:
- Application:
Custom
- Method:
GET
- Request URL:
https://kf.kobotoolbox.org/api/v2/assets.json
- Headers:
Authorization
:Token your_api_token
Accept
:application/json
Part 4: Handle Pagination
Kobo limits response data to 30,000 records as described here.
To get more records, you'll need to run your request in batches, where you first fetch 30K records, and then the next set of 30K, and so on. In API Connector, you can cycle through automatically with a multi-query request, like this:
https://kobo.humanitarianresponse.info/api/v2/assets/1111111111/data.json?sort={"_id":1}&start=0
https://kobo.humanitarianresponse.info/api/v2/assets/1111111111/data.json?sort={"_id":1}&start=30000
Part 5: API Documentation & Information
Kobo hasn't provided much documentation, but here are a few links for more information:
- Official API documentation: https://support.kobotoolbox.org/api.html
- Kobo's API community forum: https://community.kobotoolbox.org/c/kobo-users/api/24 (especially this post)
I Import KoBoToolbox Data to Google Sheets. After the asset, then how do you display the data?
Hey there, you can see some example requests in this section. For example,
https://YOUR_DOMAIN/api/v2/{asset_uid}/data/
, where you substitute in your own domain and asset UID. You can also check this forum post for more info: https://community.kobotoolbox.org/t/kobotoolbox-google-sheet-sync/622/72can you please give us step by step guidance to receive one kobo form data into google sheet
please reply
The article contains step by step instructions to get your asset ID.
Once you have your asset ID run another request exactly the same way, just substitute in your asset ID to this URL:
https://YOUR_DOMAIN/api/v2/asset_id/data/
Where can I find the asset UID?
Hey Paul,
https://kf.kobotoolbox.org/api/v2/assets.json
should return your asset UIDs.Hi, how to auto fetch to Google Sheets?
Please see our article on scheduling.
Thanks for the reply. I used this guide to crowdsource message of support to Ukraine. If you are interested, https://www.arcgis.com/apps/instant/minimalist/index.html?appid=96c79a72db8747a8a26bc0bc58608b1d
Hello,
I have two questions:
1. Is there any free way to have the document updated at regular intervals?
2. How do I import the data labels, and not the names?
Thanks, this is a really helpful page!
Sorry, scheduling is a paid feature (if you're working for a nonprofit, we can offer a discount). I'm not sure what you mean by data labels though. What is the data label?
Thanks so much for your reply Ana. Ok, that's fair - thanks. It is for a non-profit but manual is ok for now and I checked the pricing, it is fair so will upgrade if necessary.
By labels, I mean the label within Kobo. So let's say I have a question: Where do you live, and it has multiple answer options. The label is what the enumerator sees in the Kobo form "Lives in a house" but what is imported is the name "lives_house", which is how the data is stored. I might not be using the right terms sorry, but hopefully I'm explaining that clearly. The connector is excellent but it's pulling over "lives_house" which doesn't read well when used in Data Studio - I would like it to pull over "Lives in a house". Does that make sense? Is there a way to do that?
That does make sense, but we already return everything that gets sent back by their API. So unfortunately if you don't see the label in the response, that means the API doesn't send that data back, and we have no way to include it. If you're familiar with Sheets functions, you could do something a little clever, like manually create a mapping table where column A contains the name and column B contains the label, and then use VLOOKUP to pull in the label to your sheet before importing it into Data Studio.
Yes, that was plan B 🙂 Got it, thanks so much for your help!
Dear Ana,
When I followed the steps mentioned in this article, I am getting the following as an output:
count next previous results.1
0
Can you please help me to resolve this matter? I am not able to get the results.uid and other columns.
Thank you for your support.
Regards,
Tarek
I believe that just means there aren't any results. Please double check that you've entered an asset ID or date range that contains data.
hello Ana, when pulling a form with sub-form I am only able to pull the parent form. any idea why? filippo
Sorry, I'm not really sure what a sub-form is (I don't use Kobo myself), and don't see anything about this in their documentation. Does the sub-form have its own ID that you could plug in to your request URL? If not, maybe you could try asking in their API support forum.
I'm a newbie. The step 2 does not tell where should i do the procedure.
Sorry for the confusion! Just open API Connector and click Create Request to see the screen in part 2. Or you can check this guide for more detailed information on using API Connector: https://mixedanalytics.com/knowledge-base/api-connector-quick-start/
Thank you! I just had to change the endpoint, from "View Assets" to "View submitted form data".
Hello Ana,
I followed your instruction (both for "Custom" and for "Kobotoolbox") and as far as I can see it the request is successfully completed (after clicking "Run" it shows "Request completed successfully").
But it doesn't show the expected columns and entries (there are data entries in the form I tested) but the following columns:
"user" / "forms" / "notes" / "metadata" / "media" / "formlist" / "submissons" / "briefcase"
and the entries are links like "https://kc.humanitarianresponse.info/api/v1/user" for "user" column or "https://kc.humanitarianresponse.info/api/v1/forms" for "forms" column
This happens with all the endpoints (I included the right asset UID)
Do you have any idea what I do wrong?
Can you please check if data has been filtered out? You can open the field editor and reset any field filters by clicking Edit fields > Refresh fields. Also, please check that you haven't included any JMESPath filter (located at Output options > More > JMESPath).
Thank you very much for your quick reply.
I clicked "Refresh fields" in edit fields and checked if something is filtered out. Nothing is filtered there.
The "raw response" says following:
{
"user": "https://kc.humanitarianresponse.info/api/v1/user",
"forms": "https://kc.humanitarianresponse.info/api/v1/forms",
"notes": "https://kc.humanitarianresponse.info/api/v1/notes",
"metadata": "https://kc.humanitarianresponse.info/api/v1/metadata",
"media": "https://kc.humanitarianresponse.info/api/v1/media",
"formlist": "https://kc.humanitarianresponse.info/api/v1/formlist",
"submissions": "https://kc.humanitarianresponse.info/api/v1/submissions",
"briefcase": "https://kc.humanitarianresponse.info/api/v1/briefcase"
}
I also checked that JMESPath is empty.
Do you have any other idea?
I see, in that case there's no error per se, that's just the response from KoboToolbox. I'm not sure which endpoint that was in response to, but it looks like a list of available URLs. What happens if you copy/paste one of those URLs into the Request URL field?
I tried with four of the mentioned URLs in the URL field and tried all endpoint. Always the same response with the same columns and links. That is, no matter what URL path and which endpoint I take, I receive the same response.
Any other idea?
Since API Connector is "working" (i.e. it's connecting and returning Kobo's response; I realize it doesn't include the data you expected), I'm afraid I don't have any further suggestions. You may have better luck asking on or checking Kobo's forum, e.g. this thread gives a few reasons why data responses may be empty (in general, they're saying that there may not be any data available for those assets).
Dear Admin
I have created a form in https://kobo.unhcr.org/.
https://kobo.unhcr.org/ is not in the Application list yet.
Be advice!!
Hi Sai, you can type
kobo.unhcr.org
into the "kpi-url" dropdown menu and click enter. It will then appear there so you can select it.Dear Ana
Thank you for your reply. I will try it.
Thank you! I will try it.
Dear Ana
It says that "{"detail":"Authentication credentials were not provided."}"
What should I do?
Please make sure you've entered your token into the Authorization section. It should look like
Token 123456789
.