This function is used by other functions to read and write values.
Usage
kernel_api(
redcap_uri,
post_body,
config_options,
encoding = "UTF-8",
content_type = "text/csv",
handle_httr = NULL,
encode_httr = "form"
)
Arguments
- redcap_uri
The uri/url of the REDCap server typically formatted as "https://server.org/apps/redcap/api/". Required.
- post_body
List of contents expected by the REDCap API. Required.
- config_options
A list of options passed to
httr::POST()
. See details athttr::httr_options()
. Optional.- encoding
The encoding value passed to
httr::content()
. Defaults to 'UTF-8'.- content_type
The MIME value passed to
httr::content()
. Defaults to 'text/csv'.- handle_httr
The value passed to the
handle
parameter ofhttr::POST()
. This is useful for only unconventional authentication approaches. It should beNULL
for most institutions.- encode_httr
The value passed to the
encode
parameter ofhttr::POST()
. Defaults to"form"
, which is appropriate for most actions. (Currently, the only exception is importing a file, which uses "multipart".)
Details
If the API call is unsuccessful, a value of
base::package_version("0.0.0")
will be returned. This ensures that a
the function will always return an object of class base::package_version.
It guarantees the value can always be used in utils::compareVersion()
.
Examples
config_options <- NULL
uri <- "https://bbmc.ouhsc.edu/redcap/api/"
token <- "9A81268476645C4E5F03428B8AC3AA7B"
post_body <- list(
token = token,
content = "project",
format = "csv"
)
# \dontrun{
kernel <- REDCapR:::kernel_api(uri, post_body, config_options)
# Consume the results in a few different ways.
kernel$result
#> Response [https://bbmc.ouhsc.edu/redcap/api/]
#> Date: 2024-09-11 13:20
#> Status: 200
#> Content-Type: text/csv; charset=utf-8
#> Size: 717 B
#> project_id,project_title,creation_time,production_time,in_production,project_...
#> 153,"REDCapR Target Simple Static -see https://github.com/OuhscBbmc/REDCapR",...
read.csv(text = kernel$raw_text)
#> project_id
#> 1 153
#> project_title
#> 1 REDCapR Target Simple Static -see https://github.com/OuhscBbmc/REDCapR
#> creation_time production_time in_production project_language purpose
#> 1 2013-11-29 15:58:20 NA 0 English 0
#> purpose_other project_notes custom_record_label secondary_unique_field
#> 1 NA NA NA NA
#> is_longitudinal has_repeating_instruments_or_events surveys_enabled
#> 1 0 0 0
#> scheduling_enabled record_autonumbering_enabled randomization_enabled
#> 1 0 1 0
#> ddp_enabled project_irb_number project_grant_number project_pi_firstname
#> 1 0 NA NA NA
#> project_pi_lastname display_today_now_button missing_data_codes
#> 1 NA 1 NA
#> external_modules
#> 1 cross_project_piping,form_status_tweaks,redcap_autofill,data_driven_project_banner
#> bypass_branching_erase_field_prompt
#> 1 0
as.list(read.csv(text = kernel$raw_text))
#> $project_id
#> [1] 153
#>
#> $project_title
#> [1] "REDCapR Target Simple Static -see https://github.com/OuhscBbmc/REDCapR"
#>
#> $creation_time
#> [1] "2013-11-29 15:58:20"
#>
#> $production_time
#> [1] NA
#>
#> $in_production
#> [1] 0
#>
#> $project_language
#> [1] "English"
#>
#> $purpose
#> [1] 0
#>
#> $purpose_other
#> [1] NA
#>
#> $project_notes
#> [1] NA
#>
#> $custom_record_label
#> [1] NA
#>
#> $secondary_unique_field
#> [1] NA
#>
#> $is_longitudinal
#> [1] 0
#>
#> $has_repeating_instruments_or_events
#> [1] 0
#>
#> $surveys_enabled
#> [1] 0
#>
#> $scheduling_enabled
#> [1] 0
#>
#> $record_autonumbering_enabled
#> [1] 1
#>
#> $randomization_enabled
#> [1] 0
#>
#> $ddp_enabled
#> [1] 0
#>
#> $project_irb_number
#> [1] NA
#>
#> $project_grant_number
#> [1] NA
#>
#> $project_pi_firstname
#> [1] NA
#>
#> $project_pi_lastname
#> [1] NA
#>
#> $display_today_now_button
#> [1] 1
#>
#> $missing_data_codes
#> [1] NA
#>
#> $external_modules
#> [1] "cross_project_piping,form_status_tweaks,redcap_autofill,data_driven_project_banner"
#>
#> $bypass_branching_erase_field_prompt
#> [1] 0
#>
# }