koboAPI is a package to access and interact with KoboToolbox-based APIs via R. The package technically supports any API that is based on KoboToolbox. It is however made simpler for KoboToolbox and humanitarianresponse.info servers.
KoboAPI provides simple functions to retrieve forms and data set from KoboToolbox.
The documentation of the kobo APIs is incomplete. Some community-based examples on how to access and interact with the API can be found here.
devtools::install_github("ElliottMess/koboAPI")
Two type of authentication is available:
client
: client authentication by providing a valid auth_key
whick follows the format '{user}:{password}'token
: authentication through a token. See here to get a tokenEventually, all authentication will result in retrieving token.
The easiest way to use the package is to set the API token in the R environment:
usethis::edit_r_environ()
'.Renviron'
file with either:'.Renviron'
ends in a new line, save it, and restart RThe core function of the package is kobo_api
. It makes a call to the API and return the response in a helpful object.
For instance, if you want to retrieve all the assets linked to your access token, you can use:
kobo_api(path = "/assets", auth_type = "token", auth_key = "HERE_A_TOKEN", api = "kobotoolbox")
Any valid GET call to the API can passed to kobo_api()
.
A few convenience wrappers around kobo_api are provided for convienence. They return objects that are close to what can be found downloaded from the kobotoolbox-based web interfaces. All of them are based on passing a valid asset_id
. Assets IDs available to you can be found through get_asset_id_list
for a named list of IDs or get_asset_id_df
for a dataframe with a bit more information.
get_form
: retrieves the form for the asset_id
. The output is a list of three dataframes that are the three sheets of a XLSform.get_data
: retrieves the data with the asset_id
responses.The package provides basic functions, and a lot more could be done:
exports
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.