Presentation is loading. Please wait.

Presentation is loading. Please wait.

U SING T HE REDC AP API (SAS, R, PHP…) By Kevan Essmyer.

Similar presentations


Presentation on theme: "U SING T HE REDC AP API (SAS, R, PHP…) By Kevan Essmyer."— Presentation transcript:

1 U SING T HE REDC AP API (SAS, R, PHP…) By Kevan Essmyer

2 REDC AP API What’s an API? What Data Can the API Extract/Import Who Can Use the API? Where Can You Use the API? Examples

3 W HAT ’ S AN API? API – Application Program Interface Defines the rules, protocols, and tools for interacting with a system or application. REDCap “Limited” API/Service Import/Export data via structured method Activity captured in project logging Adheres to system access constraints API development through Biostat Consulting Services.

4 REDC AP ’ S API REST like service Programming Language Neutral Web Based – uses existing REDCap URLs to access the system. Functional response determined by request parameters Supported Functions/Actions Import/Export Records (Data) Uploaded File Delete Uploaded File Export Only Metadata / Data Dictionary Event names Study Arms (Longitudinal) Form-Event Mappings Project Users

5 W HO C AN U SE T HE API User Rights Project Manager grants API Rights Separate import and export rights API Token Holders Request token after being granted API User Rights Token Hash represents (API) project user/name password Revoke or regenerate

6 API U SER R IGHTS

7 File Server Host Server WEB Server Uploaded Files Installation Files Web Server WUCON Sidedoor Server https://redcapsurvey.wustl.edu... REDCap Survey Data Entry /Admin MySQL Server MySQL Slave Server Data Sync Biostatistics Secure Domain Authenticated Access Public HTTPS Access API

8 W HERE C AN Y OU U SE THE API? REDCap Server Project Administrative Access WUCON Connection to REDCap Web Server Sidedoor Secure Proxy Server Access Extra procedures involved in SSL certificate authentication Access forbidden through the Public Survey Server No project administrative access API feature disabled. Global access from an authenticated internet connection Third party venders or other data systems. (Clinportal) Research Collaborators Clinics/Lab information systems Bridge multiple REDCap projects

9 API F EATURES AND D OCUMENTATION

10 U SING THE API Authorization Token – keep in a safe place. Parameters (Import records) Required Token – User assigned token content – record (…file,metadata,event,arm,formeventMapping,user) Format-- csv, json, xml [default] Type— flat,eav overwriteBehavior normal [default], overwrite Data the formatted data to be imported EAV XML: Flat XML: 1 12 M event1 Optional returnContent– ids, count[default], nothing returnFormat-- csv, json, xml [default]

11 API R ETURN XML D ATA F ORMATS EAV XML: 1 id 1 event_1 1 age 12 event_1 1 sex M event1 Flat XML: 1 12 M event1

12 U SING THE API Authorization Token – keep in a safe place. Parameters (Export records) Required Token – User assigned token content – record (…file,metadata,event,arm,formeventMapping,user) Format-- csv, json, xml [default] Type— flat,eav Optional Records– subset of Study ID Fields— variable names Forms Events rawOrLabel—raw, label eventName returnFormat-- csv, json, xml [default] exportSurveyFields-- true, false exportDataAccessGroups

13 EXAMPLES

14 R EXAMPLE library(bitops) library(RCurl) library(Hmisc) library(xtable) # Set secret token specific to your REDCap project secret_token = '8E7BD5E3AD2A9AFF25D10EE ' # Set the url to the api (ex. https://YOUR_REDCAP_INSTALLATION/api/) api_url = 'https://redcap.biostat.lan/redcap/srvrs/debug_v3_1_0_001/redcap/api/' # If in R for Linux # --> Code to "export" data from REDCap y <- postForm(api_url, token = secret_token, content = 'record', format = 'csv', type = 'flat') # Use the output from postForm() to create a data frame of the exported data x <- read.table(file = textConnection(y), header = TRUE, sep = ",", na.strings = "", stringsAsFactors = FALSE) rm(secret_token, y)

15 PHP REDC AP API UTILITY CLASS require_once('RestCallRequest.php'); Wrapper class for cURL Free Software library Supports multitude of protocols including (HTTPS). Supported on most OS platforms Reduces the amount of manual data manipulation steps.

16 PHP E XPORT E XAMPLE 'record', 'type' => 'flat', 'format' => 'csv', 'records' => $records, 'events' => $events, 'fields' => $fields, 'forms' => $forms, 'exportSurveyFields'=>'false', 'exportDataAccessGroups'=>'false', 'token' => 'YOUR_TOKEN'); # create a new API request object $request = new RestCallRequest("API_URL", 'POST', $data); # initiate the API request $request->execute(); $filename = './dataout.txt'; file_put_contents($filename, $request->getResponseBody());

17 PHP I MPORT E XAMPLE 'record', 'type' => 'flat', 'format' => 'csv', 'token' => 'YOUR_TOKEN', 'data' => $YOUR_DATA); # create a new API request object $request = new RestCallRequest("API_URL", 'POST', $data); # initiate the API request $request->execute(); # print the output from the API echo $request->getResponseBody();

18 C URL E XAMPLE ### Uses curl. Please make sure you have the module # Set secret token specific to your REDCap project TOKEN="YOUR_TOKEN" # Set the url to the api (ex. https://YOUR_REDCAP_INSTALLATION/api/) SERVICE="YOUR_API_URL" # DOWNLOAD all records curl -F token=${TOKEN} -F content=record -F format=csv -F type=flat ${SERVICE}

19 SAS B UILTIN P ROC HTTP M ETHOD filename in "./in.txt"; filename out "./out.txt"; data _null_; file in; input; put _infile_; datalines4; 'token='||"&_token."||'&content=record&format=xml&type=flat&fields=sitpif_idn' ;;;; proc http in=in out=out url="&_xurl" method="post“ ct="application/x-www-form-urlencoded"; run; quit;

21 T IPS AND R EMINDERS Import Template correct field name Start with small batches Check the project logs Data type artifacts need to be handled via code Keep token secure Keep track of which token is which Technical support available if you get stuck

22 Q UESTIONS ?


Download ppt "U SING T HE REDC AP API (SAS, R, PHP…) By Kevan Essmyer."

Similar presentations


Ads by Google