Kobotoolbox API Issue (v2 to download export as csv/xlsx)

Hi,
I have been trying to use API version 2 to create export (csv) and then download the export.
I am able to create export.

But I’m unable to retrieve data. Can you please help me identify the issue?

I followed the documentation:

[Update]

I tried using the URL: https://eu.kobotoolbox.org/api/v2/assets/aufBcR7TaVeTd8vbzGLkfN/export-settings/eRuitifrSF9koxpj3zjfK3/data.csv

But the query results in 404.

Thanks in advance.

Welcome back to the community, @scary.scarecrow! If your account is still on the browser you could use this API to download the data in XLS format:

https://[kpi]/api/v2/assets/<your asset UID>.xls

You could then replace the same with something you have in your account …

https://eu.kobotoolbox.org/api/v2/assets/abydtuXaoPSnn6mUbBaoTJ.xls

1 Like

Hi,
Thanks for your response. This did not help:

Further, I’m now unable to create exports using API. My R package (KoboconnectR) is crashing because of this (And there are several people using this). Is there any definitive and accurate documentation?

Host: eu.kobotoolbox.org
User-Agent: httr2/1.0.5 r-curl/5.2.3 libcurl/8.7.1
Accept: */*
Accept-Encoding: gzip
Authorization: <REDACTED>
Content-Type: application/x-www-form-urlencoded
Content-Length: 183

fields_from_all_versions=true&group_sep=%2F&hierarchy_in_labels=true&lang=English%20%28en%29&multiple_select=both&type=csv&flatten=false&xls_types_as_text=false&include_media_url=true

this returns 404.

Hi @scary.scarecrow, the first link you shared is correct but the error you faced might be causing by two thing

1- did you you provided any authorization? Token or username and password
2- you may confused by the form uuid and export uid.

as long as this two correct there shouldn’t be any problem as you see below

1 Like

Thanks @osmanburcu . I did not change anything in my package/code and now exports (not export-settings) work. Was it a server issue or did you make any changes?

I didn’t change anything, it might be a server issue

Thanks. Could you please let me know the process to create synchronous export and download data using API?

Sure, what do you wanna know exactly? Do you wanna use API v1? or V2? Do you wanna have it in JSON, xlsx, or csv format? In which application or program you are going to use it for? Power BI, excel, power query, python, R? If you elaborate more, i can provide more on point explanations

Thanks. I will use R and use API ver 2 to:

  1. Check existing exports
  2. Create new export
  3. Delete existing export and
  4. Extract data from export (CSV and XLS)

Hi,

1- if you would like to check existing export you can use the link https://eu.kobotoolbox. org/api/v2/assets/{form uuid}/exports/ . you need to send GET request to this link and it i will return the existing exports with full details.

2- Same link as above, just instead of GET request, you need to sent POST request with the options below, you can find the details of the fields in the link, just paste it to a browser and check the documentation. Including the type, all options are mandory, the rest is optional

 {
      "fields_from_all_versions": "true",
      "group_sep": "/",
      "hierarchy_in_labels": "true",
      "lang": "English (en)",
      "multiple_select": "both",
      "type": "geojson",
      "fields": ["field_1", "field_2"],
      "flatten": "true"
      "xls_types_as_text": "false",
      "include_media_url": "false",
      "submission_ids": [1, 2, 3, 4],
      "query": {
         "$and": [
             {"_submission_time": {"$gte": "2021-08-31"}},
             {"_submission_time": {"$lte": "2021-10-13"}}
         ]
       }
     }
   }

3- https://eu.kobotoolbox. org/api/v2/assets/{form uuid}/exports/{export uid} . You need to send DELETE request to this link, just you need to mention the uid of the export you would like to delete.

4- If you want to extract data form the export, https://eu.kobotoolbox. org/api/v2/assets/{form uuid}/exports/{export uid}.json from this link, you can get the link from result variable.

5- If you don’t want to deal with all this version, exports etc. You can just use the method mentioned in this video. You can use the same link in R and each time you run your code, you will get the most updated data. https://youtu.be/53Se9rWc9bc

For more documentation, please visit the https://eu.kobotoolbox. org/api/v2/assets/{form uuid}/exports/ and https://eu.kobotoolbox. org/api/v2/assets/{form uuid}/exports/{export uid}