-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path6_Import.do
36 lines (28 loc) · 1.21 KB
/
6_Import.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
Using the REDCap API with Stata
Luke Stevens, Murdoch Childrens Research Institute
20-Jun-2017
6. Import_Records.do
Illustrating data import - API is not just for export.
(This example toggles the gender of first record 1 <-> 2)
Ensure that you (your role) has "API Import" permission.
*/
version 12
set more off
clear
local token "<insert your token here>"
local outfile "exported_data.csv"
local fileforimport "data_for_import.csv"
shell c:\curl\curl.exe --output `outfile' --form token=`token' --form content=record --form format=csv --form type=flat --form fields[]=record_id --form fields[]=gender "https://redcap.mcri.edu.au/api/"
import delimited `outfile'
keep if _n==1
replace gender=1+(!(gender-1)) // toggle gender 1 <-> 2
export delimited using `fileforimport', nolabel replace
local cmd="c:\curl\curl.exe" ///
+ " --form token=`token'" ///
+ " --form content=record" ///
+ " --form format=csv" ///
+ " --form type=flat" ///
+ " --form data="+char(34)+"<`fileforimport'"+char(34) /// The < is critical! It causes curl to read the contents of the file, not just send the file name.
+ " https://redcap.mcri.edu.au/api/"
shell `cmd'