Title: | Access kobo API via R |
---|---|
Description: | koboAPI is a package to access and interact with [KoBoToolbox](https://www.kobotoolbox.org/)-based APIs. |
Authors: | Elliott Messeiller [aut, cre] |
Maintainer: | Elliott Messeiller <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2024-11-27 04:40:12 UTC |
Source: | https://github.com/ElliottMess/koboAPI |
Assert that the api is valid
assert_api(api)
assert_api(api)
api |
(character) api to check |
Assert that arguments passed in are length 1 character vectors
assert_strings(...)
assert_strings(...)
... |
Character vectors to check |
Retrieves token if not provided in 'auth_token', then add a 'Authorization'
header via add_headers
to the API call.
authenticate_api(auth_type, auth_key = NULL, api)
authenticate_api(auth_type, auth_key = NULL, api)
auth_type |
(character) Two types of authentication are possible: - 'client': use the 'auth_key' 'user:password' to authenticate to the kobo API - 'token': uses the 'token' provided in 'auth_key' to authenticate |
auth_key |
(character) Can either be: - A combination of the kobo and password in format: 'user:password‘ (e.g. ’my_user:my_password') - A kobo API V2 token. See the https://support.kobotoolbox.org/api.html |
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
All authentication is based on token.
'Authorization' header call via add_headers
Get URL of api
get_api_url(api)
get_api_url(api)
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
character vector with the URL of the api
The function provides a high-level access to APIs based on kobotoolbox. It parses the base URL for the ´api´ and returns the JSON response in a standard format.
get_asset_id_df( api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
get_asset_id_df( api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
auth_type |
(character) Two types of authentication are possible: - 'client': use the 'auth_key' 'user:password' to authenticate to the kobo API - 'token': uses the 'token' provided in 'auth_key' to authenticate |
auth_key |
(character) Can either be: - A combination of the kobo and password in format: 'user:password‘ (e.g. ’my_user:my_password') - A kobo API V2 token. See the https://support.kobotoolbox.org/api.html |
A data frame with asset IDs, names, type, and deployment status.
The function provides a high-level access to APIs based on kobotoolbox. It parses the base URL for the ´api´ and returns the JSON response in a standard format.
get_asset_id_list( api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
get_asset_id_list( api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
auth_type |
(character) Two types of authentication are possible: - 'client': use the 'auth_key' 'user:password' to authenticate to the kobo API - 'token': uses the 'token' provided in 'auth_key' to authenticate |
auth_key |
(character) Can either be: - A combination of the kobo and password in format: 'user:password‘ (e.g. ’my_user:my_password') - A kobo API V2 token. See the https://support.kobotoolbox.org/api.html |
A named list of asset IDs
Download responses from the API for a specific asset
get_data( asset_id, api = api, auth_type = c("client", "token"), auth_key = NULL )
get_data( asset_id, api = api, auth_type = c("client", "token"), auth_key = NULL )
asset_id |
(character) The ID of the form to be accessed (as a character string). Must be a KPI-type ID (not api V1 ID). See download_forms_all for more details. |
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
auth_type |
(character) Two types of authentication are possible: - 'client': use the 'auth_key' 'user:password' to authenticate to the kobo API - 'token': uses the 'token' provided in 'auth_key' to authenticate |
auth_key |
(character) Can either be: - A combination of the kobo and password in format: 'user:password‘ (e.g. ’my_user:my_password') - A kobo API V2 token. See the https://support.kobotoolbox.org/api.html |
A data frame with the responses data for ´asset_id´
Download form for a specific asset ID
get_form( asset_id, api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
get_form( asset_id, api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
asset_id |
(character) The ID of the form to be accessed (as a character string). Must be a KPI-type ID (not api V1 ID). See download_forms_all for more details. |
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
auth_type |
(character) Two types of authentication are possible: - 'client': use the 'auth_key' 'user:password' to authenticate to the kobo API - 'token': uses the 'token' provided in 'auth_key' to authenticate |
auth_key |
(character) Can either be: - A combination of the kobo and password in format: 'user:password‘ (e.g. ’my_user:my_password') - A kobo API V2 token. See the https://support.kobotoolbox.org/api.html |
A list of three data frames that correspond to the structure of a XLSform: - "survey": a data frame with all the questions variables. - "choices" a data frame with all the choices variables. - "settings" a data frame with the basic settings for the form.
The function provides a high-level access to APIs based on kobotoolbox. It parses the base URL for the ´api´ and returns the JSON response in a standard format.
kobo_api( path, api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
kobo_api( path, api = c("humanitarian_response", "kobotoolbox"), auth_type = c("client", "token"), auth_key = NULL )
path |
(character) additional path to based to the base API URL. It should start with a '/'. |
api |
(character) The type of API to be used or URL at which the API can be accessed. Can be either: - 'humanitarian_response': "https:://kobo.humanitarianresponse.info" will be used as the base URL (default) - 'kobotoolbox': "https:://https://kf.kobotoolbox.org" will be used as the base URL - 'custom': custom URL. Must at least start with "https://" |
auth_type |
(character) Two types of authentication are possible: - 'client': use the 'auth_key' 'user:password' to authenticate to the kobo API - 'token': uses the 'token' provided in 'auth_key' to authenticate |
auth_key |
(character) Can either be: - A combination of the kobo and password in format: 'user:password‘ (e.g. ’my_user:my_password') - A kobo API V2 token. See the https://support.kobotoolbox.org/api.html |
a 'kobo_api' object consisting of a list of: - 'content': parsed content from the request - 'path': - 'response': JSON response to request