rc_api_call: Execute a call to the REDCap API

View source: R/rc_api_call.R

rc_api_callR Documentation

Execute a call to the REDCap API

Description

This is a generic API function. It is intended to provide a more flexible interface to the API than rc_import and rc_export while still improving usability. It is also a barebones type function by natures and does not have the same level of checks and other embellishments as other package functions.

Usage

rc_api_call(
  url = getOption("redcap_bundle")$redcap_url,
  token = getOption("redcap_token"),
  content = "version",
  action = "export",
  return_as = "dataframe",
  ...,
  arms = NULL,
  fields = NULL,
  forms = NULL,
  events = NULL,
  records = NULL,
  dags = NULL,
  beginTime = "",
  csvDelimiter = "",
  dag = "",
  data = NULL,
  dateRangeBegin = "",
  dateRangeEnd = "",
  endTime = "",
  event = "",
  exportCheckboxLabel = "false",
  exportDataAccessGroups = "false",
  exportSurveyFields = "false",
  file_field = "",
  file = "path/to/file",
  filterLogic = "",
  forceAutoNumber = "false",
  logtype = "",
  overWriteBehavior = "normal",
  rawOrLabel = "raw",
  rawOrLabelHeaders = "raw",
  record = "",
  report_id = "",
  returnContent = "count",
  returnMetadataOnly = "false",
  type = "flat",
  user = "",
  format = "csv",
  returnFormat = "csv",
  encode = "form"
)

Arguments

url

URL of the REDCap API

token

Project API token

content

API endpoint. The options are 'arm', 'dag', 'event', 'exportFieldNames', 'file', 'formEventMapping', 'generateNextRecordName', 'instrument', 'log', 'metadata', 'participantList', 'pdf', 'project', 'project_settings', 'project_xml', 'record', 'repeatingFormsEvents', 'report', 'surveyLink', 'surveyReturnCode', 'surveyQueueLink', 'user', 'userDagMapping', 'userRole', 'userRoleMapping', and 'version'

action

Action to perform when calling the endpoint. Either 'import', 'export', 'delete', 'rename', or 'switch'

return_as

Determines how the server response will be returned from this function. This is mostly useful for returning the raw response when needed. Options are 'raw', 'text', and 'dataframe'. 'raw' returns raw byte data, 'text' converts it to character, and 'dataframe' returns a data.frame.

...

Additional arguments to be passed to the API

arms

Vector of arm numbers

fields

Vector of field names

forms

Vector of form names

events

Vector of event names

records

Vector of record IDs

dags

Vector of data access groups

beginTime

Filter for log exports. Format is 'YYYY-MM-DD HH:MM'

csvDelimiter

Operator to delimit csv exports with. For exporting records and reports. Options are ',', 'tab', ';', '|', and '^'

dag

Specifies a data access group to switch to

data

Data to import

dateRangeBegin

Optional date filter for records exports. Use format 'YYYY-MM-DD HH:MM:SS'

dateRangeEnd

Optional date filter for records exports. Use format 'YYYY-MM-DD HH:MM:SS'

endTime

Filter for log exports. Format is 'YYYY-MM-DD HH:MM'

event

Event name. For file import/export

exportCheckboxLabel

Logical. Will use the choice label or NA to fill fields instead of Checked or Unchecked. Requires rawOrLabel to be set to 'true', otherwise does nothing.

exportDataAccessGroups

Logical

exportSurveyFields

Logical

file_field

Field name for file import/export

file

Path to file for import

filterLogic

Optional logic filter for record exports. Use REDCap style syntax- ie. similar to branching logic, calculations, etc.

forceAutoNumber

Logical. For importing records

logtype

Unknown

overWriteBehavior

Determines whether import data will overwrite existing data. Options are 'normal or 'overwrite'. Pay careful attention to NA values when using this option, as they will overwrite existing values. In normal mode, existing values cannot be replaced with another value or NA.

rawOrLabel

For choice fields such as radio and drop-down. 'raw' will fill the data using the choice numbers while 'label' will use the choice labels.

rawOrLabelHeaders

Determines whether to use field names or field labels for column names

record

Specify record ID for file import/export or log filtering

report_id

ID number of report for export. May be supplied as either character or numeric.

returnContent

Specify response type when importing records. Options are 'count', 'ids', 'auto_ids', 'raw', and 'nothing'. 'count' returns the number of records which were updated. 'ids' returns a list of updated IDs. 'auto_ids' is not properly supported yet and currently is the same as 'count'? 'raw' returns the response object as recieved from the server for debugging. 'nothing' returns NULL.

returnMetadataOnly

Logical. For 'project_xml' export.

type

For record imports/exports. Options are 'flat' and 'eav'

user

Specify a user for log exports

format

Specify format of imported or exported data. Options are 'csv', 'json', or 'xml'

returnFormat

Specify format for errors. Options are 'csv', 'json', or 'xml'

encode

Encoding format to be passed to httr::POST(). Options are 'form', 'multipart', or 'identity'

Author(s)

Marcus Lehr


chillywings/rctools documentation built on Aug. 9, 2024, 11:52 p.m.