ruodk and kobotoolbox

Hello
I would like to use ruODK to export data from a kobotoolbox form, api for researchers (not humanitarian associations)
what is the URL?
I run this code

Sys.setenv(ODKC_URL="url")
Sys.setenv(ODKC_UN="..")
Sys.setenv(ODKC_PW="..")
ruODK::ru_setup(
    url = Sys.getenv("ODKC_URL"), 
    un = Sys.getenv("ODKC_UN"), 
    pw = Sys.getenv("ODKC_PW"),
    tz = "Europe/Rome",
    verbose = TRUE
)
ruODK::project_list()

https://kf.kobotoolbox.org/” doesn’t work at all
while “kf.kobotoolbox.org” tells me

Blockquote
Error in curl::curl_fetch_memory(url, handle = handle): Protocol “” not supported or disabled in libcurl

Thank you

@florianm are you able to help?

Maybe the kobotoolbox server is ODK Aggregate, so not ODK Central???

Hi @bonushenricus,

KoboToolbox is running a different server IIRC.

They have their own forum at https://community.kobotoolbox.org/ and hopefully some API documentation.

There’s an R package called koboloader (see also ruODK vignette comparison) A Metapackage for Survey Data Crunching • koboloadeR

ODK Briefcase seems to work with Kobo too, so that tells us that the Kobo API supports the OpenRosa endpoints like Aggregate and Central, but likely not the other Central endpoints which ruODK relies on.

Hope that helps!

1 Like

Hi Florian
koboloader has a lot of dependencies, it takes a long time to install, and it has a lot of features that don’t interest me
version 0.1.2 might be for me, but it has a problem (see here https://github.com/mrdwab/koboloadeR/issues/13)
Finally I found the karpi package https://github.com/nyuglobalties/karpi

Good to hear. Since Kobo is not ODK Central, ruODK definitely won’t work.

Hi @bonushenricus and @florianm

I hope all is good. I’m working on a package to access KoBotoolbox data using the v2 API.
The package is named robotoolbox and you can find the dev version here:

I’m still working on it but would grateful for feedbacks, issues, etc.

The main function of robotoolbox is kobo_data or kobo_submissions (alias), and to get the data you need to setup your account and the use your asset uid to read the data.

You’ll need to install this package using the remotes R package

## install.packages("remotes")
remotes::install_gitlab("dickoa/robotoolbox")

The first step is to get your API token using the kobo_token function.

library(robotoolbox)
token <- kobo_token(username = "cool_user_name", password = "myP@$$Word", 
                    url = "https://{kpi-url}/")

Now you can access all your projects and read the data from the project you picked. You can list project using kobo_asset_list() .

library(dplyr)
l <- kobo_asset_list() 
glimpse(l) # l is a data.frame with as many rows as projects
## $ uid            <chr> "b9kgvd7AXQCmo5qyUOBEl", "aRfJMpTSGRLzZ…"
## $ name           <chr> "Proj_A1", "Proj_A2", "Proj_A3", "Proj_A…"
## $ asset_type     <chr> "survey", "survey", "survey", "survey", …
## $ owner_username <chr> "xxxxxxxxxxxxxx", "xxxxxxxxxxxxxxx", "xx…"
## $ date_created   <dttm> 2020-04-27 20:34:23, 2020-04-27 21:21:1…
## $ date_modified  <dttm> 2021-06-17 01:52:57, 2021-06-17 01:52:5…
## $ submissions    <int> 2951, 2679, 2, 1, 0, 0, 287, 73, 0, 274,…

Let’s pick the first project and load it

uid <- l$uid[1]
asset <- kobo_asset(uid)
asset
## <robotoolbox asset>  b9agvd9AXQCmo5qyUOBEl
##   Asset Name: proj_A1
##   Asset Type: survey
##   Created: 2021-05-10 07:47:53
##   Last modified: 2021-08-16 12:35:50
##   Submissions: 941

With the asset you can now read the data (you can also read the data from the uid directly).

data <- kobo_data(asset)
glimpse(data)
## Rows: 941
## Columns: 17
## $ id                                                         <int> …
## $ start                                                      <dttm> …
## $ end                                                        <dttm> …
## $ today                                                      <date> …
## $ deviceid                                                   <chr> …
## $ test                                                       <chr+lbl> …
## $ round                                                      <date> …
## $ effective_date                                             <date> …
## $ collect_type                                               <chr+lbl> …
## $ covid_module                                               <chr+lbl> …
## $ country                                                    <chr+lbl> …
## $ interviewer_id                                             <chr> …
## $ respondent_is_major                                        <chr+lbl> …
## $ consent                                                    <chr+lbl> …
## $ admin_level_1                                              <chr+lbl> …
## $ admin_level_2                                              <chr+lbl> …
## $ admin_level_3                                              <chr+lbl> …

This package relies on the R package labelled to read labels into R. You can learn more here

Another feature, is the use of dm to handle repeating groups. More info in this vignette:

As I said, it’s still a WIP, and It might break with certain type of complex forms. Please, if it’s not working as expected don’t hesitate to reach out.

I want to thank @florianm for his work on ruODK it was inspiring, and I hope robotoolbox will be as robust to access KoBotoolbox data.

2 Likes

Oh this looks nice, @dickoa! I will add robotoolbox to the list of related packages in the ruODK docs.

1 Like

Thanks a lot @florianm. ruODK was one of the main inspiration while working on this, and I would love to pick your brain on the best strategy for testing this type of packages.

Sure thing! Shoot me a DM anytime here it in the ODK forum. I’ve got a dedicated test server for ruODK. Since most tests read from the server and need credentials via env vars, they wouldn’t run on CRAN so I didn’t bother with a CRAN submission.

1 Like