Learn R Programming

redcapAPI (version 2.5.0)

redcapConnection: Connect to a REDCap Database

Description

Creates an object of class redcapApiConnection for using the REDCap API

Usage

redcapConnection(
  url = getOption("redcap_api_url"),
  token,
  config = httr::config()
)

# S3 method for redcapApiConnection print(x, ...)

Arguments

url

URL for a REDCap database API. Check your institution's REDCap documentation for this address. Either url or conn must be specified.

token

REDCap API token

config

A list to be passed to httr::POST. This allows the user to set additional configurations for the API calls, such as certificates, ssl version, etc. For the majority of users, this does not need to be altered. See Details for more about this argument's purpose and the redcapAPI wiki for specifics on its use.

x

redcapConnection object to be printed

...

arguments to pass to other methods

Author

Jeffrey Horner

Details

redcapConnection objects will retrieve and cache various forms of project information. This can make metadata, arms, events, fieldnames, arm-event mappings, users, version, and project information available directly from the redcapConnection object. Take note that the retrieval of these objects uses the default values of the respective export functions.

For each of these objects, there are four methods that can be called from the redcapConnection object: the get method (called via rcon$metadata(), for example); the has method (rcon$has_metadata), which returns a logical indicating if the metadata has been cached; the flush method (rcon$flush_metadata), which removes the cached value; and the refresh method (rcon$refresh_metadata), which replaces the current value with a new call to the API. There is also a flush_all and refresh_all method.

For convenience, you may consider using options(redcap_api_url=[your URL here]) in your RProfile. To obtain an API token for a project, do the following:
Enter the 'User Rights' section of a project
Select a user
Check the box for 'API Data Export' or 'API Data Import,' as appropriate. A full tutorial on configuring REDCap to use the API can be found at https://github.com/vubiostat/redcapAPI/wiki

Tokens are specific to a project, and a token must be created for each project for which you wish to use the API.

The config argument is passed to the httr::POST argument of the same name. The most likely reason for using this argument is that the certificate files bundled in httr have fallen out of date. Hadley Wickham is pretty good about keeping those certificates up to date, so most of the time this problem can be resolved by updating httr to the most recent version. If that doesn't work, a certificate file can be manually passed via the config argument. The redcapAPI wiki has a more detailed tutorial on how to find and pass an SSL certificate to the API call (https://github.com/vubiostat/redcapAPI/wiki/Manually-Setting-an-SSL-Certificate-File).

Additional Curl option can be set in the config argument. See the documentation for httr::config and httr:httr_options for more Curl options.