Kobo | R Documentation |
Interface class for the Kobo API that can handle KoboClient instances (sessions) for both API versions. The Class exposes both generic and specific methods for HTTP requests / interactions with the various endpoints.
session_v2
KoboClient session for v2 of the API
session_v1
KoboClient
session for v1 of the API
new()
Initialization method for class "Kobo".
Kobo$new( base_url_v2 = NULL, base_url_v1 = NULL, kobo_token = Sys.getenv("KBTBR_TOKEN"), session_v2 = NULL, session_v1 = NULL )
base_url_v2
character. The base URL of the API version 2 (known as /api/v2). For example: https://kobo.correlaid.org.
base_url_v1
character. The base URL of the API of your KoBoCAT API (also known as /api/v1). Defaults to NULL. For example: https://kc.correlaid.org.
kobo_token
character. The API token. Defaults to requesting
the systen environment KBTBR_TOKEN
.
session_v2
KoboClient To pass directly a KoboClient instance for the API version v2.
session_v1
KoboClient In addition to session_v2 one can pass also a KoboClient instance for the API version v1.
get()
Wrapper for the GET method of internal session objects.
Kobo$get(path, query = list(), version = "v2", format = "json", parse = TRUE)
path
character. Path component of the endpoint.
query
list. A named list which is parsed to the query component. The order is not hierarchical.
version
character. Indicates on which API version the request should be executed (available: v1
, v2
). Defaults to v2
.
format
character. the format to request from the server. either 'json' or 'csv'. defaults to 'json'
parse
whether or not to parse the HTTP response. defaults to TRUE.
a list encoding of the json server reply if parse=TRUE. Otherwise, it returns the server response as a crul::HttpResponse object.
post()
Wrapper for the POST method of internal session objects.
Kobo$post(path, body, version = "v2")
path
character. Path component of the endpoint.
body
R list. A data payload to be sent to the server.
version
character. Indicates on which API version the request
should be executed (available: v1
, v2
). Defaults to v2
.
Returns an object of class crul::HttpResponse
.
get_assets()
Returns a list of all assets available in the server as tibble
Kobo$get_assets()
get_surveys()
High-level GET request for surveys
endpoints endpoint
Kobo$get_surveys(show_all_cols = FALSE)
show_all_cols
if true returns all the columns available for an asset
An user-friendly summary of the available surveys as a tibble
get_asset()
Get an asset given its id.
Kobo$get_asset(id)
id
character. ID of the asset within the Kobo API.
Asset. object of class Asset
get_submissions()
Get the submissions for a survey.
Kobo$get_submissions(id)
id
character. ID of the survey asset within the Kobo API.
tibble. submissions as a tibble. if no submissions were made yet, the tibble will have no columns.
High-level POST request to clone an asset. assets
endpoint
(due to default to v2
, no further specification is needed).
clone_asset()
Kobo$clone_asset(clone_from, new_name, asset_type)
clone_from
character. UID of the asset to be cloned.
new_name
character. Name of the new asset.
asset_type
character. Type of the new asset. Can be "block", "question", "survey", "template".
Returns an object of class crul::HttpResponse
.
deploy_asset()
High-level POST request to deploy an asset.
assets/{uid}/deployment/
endpoint (due to
default to v2
, no further specification is needed).
Kobo$deploy_asset(uid)
uid
character. UID of the asset to be deployed.
Returns an object of class crul::HttpResponse
.
import_xls_form()
High-level POST request to import an XLS form. imports
endpoint
(due to default to v2
, no further specification is needed).
Kobo$import_xls_form(name, file_path)
name
character. Name of the new asset.
file_path
character. The path to the XLS form file.
Returns an object of class crul::HttpResponse
.
create_asset()
High-level POST request to create an empty asset. assets/
endpoint
(due to default to v2
, no further specification is needed).
Kobo$create_asset( name, asset_type, description = "", sector = list(label = "", value = ""), country = list(label = "", value = ""), share_metadata = FALSE )
name
character. Name of the new asset.
asset_type
character. Type of the new asset. Can be "block", "question", "survey", "template".
description
character. Optional.
sector
A list with elements label
and value
.
Optional. Corresponding labels and values can be found
here.
country
A list with elements label
and value
.
Optional. Corresponding labels and values can be found
here.
share_metadata
boolean. Optional.
Returns an object of class crul::HttpResponse
.
clone()
The objects of this class are cloneable with this method.
Kobo$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.