if (FALSE) {
url <- "Enter your API URL here"
token <- "Enter your API token here"
rcon <- redcapConnection(url = url,
token = token)
MetaData <-
makeApiCall(rcon = rcon,
body = list(content = "metadata",
format = "csv",
returnFormat = "csv"))
MetaData <- read.csv(text = as.character(MetaData),
stringsAsFactors = FALSE,
na.strings = "")
# Call to export Meta Data (Data Dictionary) for specific fields
fields <- vectorToApiBodyList(vector = c("row_purpose",
"prereq_radio"),
parameter_name = "fields")
MetaData <-
makeApiCall(rcon = rcon,
body = c(list(content = "metadata",
format = "csv",
returnFormat = "csv"),
fields))
MetaData <- read.csv(text = as.character(MetaData),
stringsAsFactors = FALSE,
na.strings = "")
# Basic call to export records
Records <- makeApiCall(rcon = rcon,
body = list(content = "record",
format = "csv",
returnFormat = "csv",
type = "flat"))
Records <- read.csv(text = as.character(Records),
stringsAsFactors = FALSE,
na.strings = "")
# Call to export records for a single form.
# Note that even though we are interested in a single form, the
# API requires an array, so we use vectorToApiBodyList
export_form <- vectorToApiBodyList("branching_logic",
parameter_name = "forms")
Records <- makeApiCall(rcon = rcon,
body = c(list(content = "record",
format = "csv",
returnFormat = "csv",
type = "flat"),
export_form))
Records <- read.csv(text = as.character(Records),
stringsAsFactors = FALSE,
na.strings = "")
# Call to export records with a pipe delimiter.
Records <- makeApiCall(rcon = rcon,
body = list(content = "record",
format = "csv",
returnFormat = "csv",
type = "flat",
csvDelimiter = "|"))
Records <- read.csv(text = as.character(Records),
stringsAsFactors = FALSE,
na.strings = "",
sep = "|")
# Call to export records created/modified after 25 Dec 2022 14:00.
Records <- makeApiCall(rcon = rcon,
body = list(content = "record",
format = "csv",
returnFormat = "csv",
type = "flat",
dateRangeBegin = "2022-12-25 14:00:00"))
Records <- read.csv(text = as.character(Records),
stringsAsFactors = FALSE,
na.strings = "")
}
Run the code above in your browser using DataLab