Created
February 8, 2021 11:07
-
-
Save tertek/80607e3843abd8da3cfc97c3543b1e1f to your computer and use it in GitHub Desktop.
Example of using REDCap API for exporting record data and importing into Stata via Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python: | |
#!/usr/bin/env python | |
import requests | |
data = { | |
'token': '<PLEASE INSERT API TOKEN HERE>', | |
'content': 'record', | |
'format': 'csv', | |
'type': 'flat', | |
'csvDelimiter': '', | |
'records[0]': '1', | |
'forms[0]': 'contact_information', | |
'rawOrLabel': 'raw', | |
'rawOrLabelHeaders': 'raw', | |
'exportCheckboxLabel': 'false', | |
'exportSurveyFields': 'false', | |
'exportDataAccessGroups': 'false', | |
'returnFormat': 'json' | |
} | |
# Send Post Request to Redcap API | |
r = requests.post('https://redcap-dev.swisstph.ch/redcap/api/',data=data) | |
# Write request contents into temporary file | |
f = open("import.csv", "w") | |
f.write(r.text) | |
f.close() | |
end | |
import delimited import.csv, clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment