<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>redcap | Andreas Ebbehoj</title><link>https://www.ebbehoej.dk/tag/redcap/</link><atom:link href="https://www.ebbehoej.dk/tag/redcap/index.xml" rel="self" type="application/rss+xml"/><description>redcap</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Sat, 23 May 2020 19:42:50 +0000</lastBuildDate><image><url>https://www.ebbehoej.dk/images/icon_hu0b7a4cb9992c9ac0e91bd28ffd38dd00_9727_512x512_fill_lanczos_center_2.png</url><title>redcap</title><link>https://www.ebbehoej.dk/tag/redcap/</link></image><item><title>Automating data import from REDCap</title><link>https://www.ebbehoej.dk/post/automating-data-import-from-redcap/</link><pubDate>Sat, 23 May 2020 19:42:50 +0000</pubDate><guid>https://www.ebbehoej.dk/post/automating-data-import-from-redcap/</guid><description>&lt;h2>Table of Contents&lt;/h2>
&lt;nav id="TableOfContents">
&lt;ul>
&lt;li>
&lt;ul>
&lt;li>&lt;a href="#introduction">Introduction&lt;/a>&lt;/li>
&lt;li>&lt;a href="#setup">Setup&lt;/a>&lt;/li>
&lt;li>&lt;a href="#in-stata">In Stata&lt;/a>&lt;/li>
&lt;li>&lt;a href="#final-remarks">Final remarks&lt;/a>&lt;/li>
&lt;li>&lt;a href="#troubleshooting">Troubleshooting&lt;/a>&lt;/li>
&lt;li>&lt;a href="#download-specific-records-with-filter-logic">Download specific records with filter logic&lt;/a>&lt;/li>
&lt;li>&lt;a href="#download-specific-variables">Download specific variables&lt;/a>&lt;/li>
&lt;li>&lt;a href="#sources">Sources&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/nav>
&lt;h3 id="introduction">Introduction&lt;/h3>
&lt;p>Most (sane) researchers probably use Redcap to collect and store their valuable research data. The advances of using REDCap are plentiful: Reproducibility, automatic backups, data safety, GCP-compliant logging, etc. If you still organize your hard-earned data in an Excel spreadsheet (yikes!) then return here when you have seen the REDCap light.&lt;/p>
&lt;p>While REDCap is amazing, is does has one minor disadvantage. Everytime you add a new record, correct an error or change anything in REDCap, you need to download your data again to your computer before you can re-run your analysis. And since each file you export from REDCap has a new an unique name, you also to update your Stata do-file. This my friend is repetitive and boring monkey work. And nobody likes monkey work.&lt;/p>
&lt;p>Luckily, you can automate the process of downloading data directly within Stata. All it takes is five minutes and a few lines of code in your do-file.&lt;/p>
&lt;h5 id="tldr">TL;DR&lt;/h5>
&lt;p>If you are the impatient &amp;ldquo;I saw the Harry Potter movies but never read the books&amp;rdquo;-type, then you can
&lt;a href="https://github.com/andreasebbehoj/stata-examples/tree/master/Redcap%20API" target="_blank" rel="noopener">download the Stata do file here&lt;/a>. If you are the type that want all the nitty-gritty details, then read on.&lt;/p>
&lt;h5 id="what-is-api">What is API?&lt;/h5>
&lt;p>API stands for &lt;em>Application Program Interface&lt;/em>. It is basically a programming language that computer programs use to communicate with each other.&lt;/p>
&lt;p>Let&amp;rsquo;s use the Facebook app as an example. What happens when you check your newsfeed?:&lt;/p>
&lt;ol>
&lt;li>The app sends an &lt;em>API request&lt;/em> via the internet to Facebook&amp;rsquo;s server along with a confidential &lt;em>API key&lt;/em> or password. The API request is a description of what data the app wants the server to send. The API key is a unique password that lets the server know who you are and what data you should have access to.&lt;/li>
&lt;li>Once the server has confirmed who you are, it processes the request to find the data you need.&lt;/li>
&lt;li>The server then sends back an &lt;em>API response&lt;/em>, containing the data that the app requested. In this case, the response would contain your notifications, the latest cat pictures on your newsfeed, and tons of ads.&lt;/li>
&lt;/ol>
&lt;p>You can also picture the API as the waiter on a restaurant. You request some food, the waiter carriers the request to the kitchen, the kitchen process the request, and sends the waiter back with a response in form of a nice enchilada.&lt;/p>
&lt;p>Enough with the theory. Time to put it to use.&lt;/p>
&lt;h3 id="setup">Setup&lt;/h3>
&lt;p>In REDCap, the API is deactivated by default for security purposes, so you need to active it.&lt;/p>
&lt;h5 id="redcap-settings">REDCap settings&lt;/h5>
&lt;p>To enable API, navigate to &amp;ldquo;User Rights&amp;rdquo;, click on your username, click &amp;ldquo;Edit user privileges&amp;rdquo;, tick &amp;ldquo;API Export&amp;rdquo; and save changes:
&lt;figure >
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-edit-user-privileges_hu676259acaaaa12141c0778e276db0238_11671_2000x2000_fit_lanczos_2.PNG" >
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-edit-user-privileges_hu676259acaaaa12141c0778e276db0238_11671_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="364" height="283">
&lt;/a>
&lt;/figure>
Only the project administrator can give you permission to use API. If you are project administrator but cannot find API in settings, then your institution probably restricted access to APIs and you need to contact the institution&amp;rsquo;s REDCap super admin.&lt;/p>
&lt;p>Once you has access, update the page. You should see a new &amp;ldquo;API&amp;rdquo; app in menu to the left:
&lt;figure >
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-api-menu_hu2e3a0af84019b19a52390cc470da6ca0_27519_2000x2000_fit_lanczos_2.PNG" >
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-api-menu_hu2e3a0af84019b19a52390cc470da6ca0_27519_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="329" height="342">
&lt;/a>
&lt;/figure>
If you see this, then the API is active.&lt;/p>
&lt;p>Note: Unless you know what you are doing or you are just playing around with a test database, I advice strongly against checking the &amp;ldquo;API Import/Update&amp;rdquo;. If you fool around with the API import function, you can in theory overwrite your entire database.&lt;/p>
&lt;h5 id="getting-the-api-key">Getting the API key&lt;/h5>
&lt;p>Click the API menu. Click &amp;ldquo;Generate API token&amp;rdquo;
&lt;figure >
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-generate-token_hu0534c2e0dc0971c0b2f05f416329b6be_59865_2000x2000_fit_lanczos_2.PNG" >
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-generate-token_hu0534c2e0dc0971c0b2f05f416329b6be_59865_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="911" height="430">
&lt;/a>
&lt;/figure>
&lt;/p>
&lt;p>A 32-character text string appears. This is your API key (or API Token in REDCap lingo).&lt;/p>
&lt;p>We need to save it for later. Open Notepad (or TextEdit for MacOS), copy/paste the API token and save it as &amp;ldquo;APIKEY_redcap.txt&amp;rdquo; in your working folder:
&lt;figure >
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/textfile_hube34aee39b65fb606142e9976115dc8a_14052_2000x2000_fit_lanczos_2.PNG" >
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/textfile_hube34aee39b65fb606142e9976115dc8a_14052_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="627" height="331">
&lt;/a>
&lt;/figure>
&lt;/p>
&lt;p>&lt;strong>A word of warning&lt;/strong>: The API key is confidential! Anyone with the API key can download your entire dataset including social security numbers and other patient identifiable data. Treat your API key as you would treat your pin code to your credit card.&lt;/p>
&lt;h5 id="curl">cURL&lt;/h5>
&lt;p>We will use the nifty little program, cURL, to communicate with the API. cURL is short for &lt;em>Client URL&lt;/em>. It is program used for interacting webpages and servers with commands instead of using mouse and keyboard.&lt;/p>
&lt;p>It should be preinstalled on Windows 10 and newer versions of MacOS. To check if it is installed, first open the terminal by pressing the &lt;strong>Windows-key&lt;/strong> and search for &amp;ldquo;Command Prompt&amp;rdquo; (in MacOS: press &lt;strong>Cmd&lt;/strong> + &lt;strong>spacebar&lt;/strong> and search for &amp;ldquo;Terminal&amp;rdquo;). Once in the terminal, type &lt;code>curl --V&lt;/code> (MacOS: curl &amp;ndash;version). If the output looks something like this, you&amp;rsquo;re good to go:
&lt;figure >
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/curl-preinstalled_hu53bffb7330807dabe2316d5c664166a4_5856_2000x2000_fit_lanczos_2.PNG" >
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/curl-preinstalled_hu53bffb7330807dabe2316d5c664166a4_5856_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="709" height="78">
&lt;/a>
&lt;/figure>
&lt;/p>
&lt;p>If cURL is not installed, follow
&lt;a href="https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux" target="_blank" rel="noopener">this guide&lt;/a>.&lt;/p>
&lt;h3 id="in-stata">In Stata&lt;/h3>
&lt;p>Time to open Stata. We will use Stata&amp;rsquo;s &lt;code>shell&lt;/code> function to run cURL and interact with the REDCap API. You can copy/paste the step-by-step guide below into your own do file or download the entire code
&lt;a href="https://github.com/andreasebbehoj/stata-examples/tree/master/Redcap%20API" target="_blank" rel="noopener">here&lt;/a>.&lt;/p>
&lt;h5 id="define-settings-for-curl">Define settings for cURL&lt;/h5>
&lt;p>First we need to supply the settings that cURL needs to communicate with REDCap:&lt;/p>
&lt;pre>&lt;code class="language-stata">***** Redcap_API.do *****
version 15
clear
file close _all
set more off
*** Import secret API key
file open text using APIKEY_redcap.txt, read text // Txt file containing API key
file read text token // Store API key as local 'token'
*** cURL Settings (update to match your system and REDCap)
local curlpath &amp;quot;C:/Windows/System32/curl.exe&amp;quot; // Folder where cURL is installed (MacOS: &amp;quot;/usr/bin/curl&amp;quot;)
local apiurl &amp;quot;https://redcap.au.dk/api/&amp;quot; // Link to REDCap database
local outfile &amp;quot;redcap_export&amp;quot; // Name of the output file
&lt;/code>&lt;/pre>
&lt;p>The first part imports the secret API key from the text file we saved previously. We could also just add the key directly in the do file by typing &lt;code>local token = &amp;quot;1234567890ABCDE...&amp;quot;&lt;/code>. But if you did that and shared your do file or log with somebody, you&amp;rsquo;ve had to remember to remove the API key beforehand. Storing the API key in a separate file is safer. You&amp;rsquo;ve wouldn&amp;rsquo;t keep your pin code in your wallet next to your credit card either, &lt;em>right&lt;/em>?&lt;/p>
&lt;p>The second part stores the location where cURL is installed and the link to your institution&amp;rsquo;s REDCap database. Update both &lt;em>curlpath&lt;/em> and &lt;em>apiurl&lt;/em> to match your system and REDCap database. You can also change the name of the final output file if you want.&lt;/p>
&lt;p>Note: Stata deletes the content of all locals as soon as it has run the do file until the end. Therefore, you need to run the entire do file from the top to bottom for this code to work. Otherwise, Stata will just throw angry red errors in your face.&lt;/p>
&lt;h5 id="run-curl">Run cURL&lt;/h5>
&lt;p>Now it is time to run cURL:&lt;/p>
&lt;pre>&lt;code class="language-stata">*** Run cURL command
shell `curlpath' ///
--output `outfile'.csv ///
--form token=`token' ///
--form content=record ///
--form format=csv ///
--form type=flat ///
`apiurl'
&lt;/code>&lt;/pre>
&lt;p>The code might seem a bit complex, but basically &lt;code>shell&lt;/code> is Stata&amp;rsquo;s way of asking Windows (or MacOS) to run a program on the compute. In this case, the program is curl.exe, which we previously stored in the local &lt;em>curlpath&lt;/em>.&lt;/p>
&lt;p>The next two lines specify that cURL should save the output with the name stored in the local &lt;em>outfile&lt;/em> and that the API key is found in the local &lt;em>token&lt;/em>, which we both defined above.&lt;/p>
&lt;p>The four lines beginning with &lt;code>--form&lt;/code> specify what kind of data we want. In this case, we want to download all records (&lt;code>token=record&lt;/code>), we want the data in csv format (&lt;code>format=csv&lt;/code>), and each observation should be on a separate row (&lt;code>type=flat&lt;/code>).&lt;/p>
&lt;p>The last line specify that REDCap can be found in URL provided in the local &lt;em>apiurl&lt;/em>.&lt;/p>
&lt;p>Now, run the entire do file. A window should pop up, and after a few seconds, data should appear as a csv file in your folder. &lt;em>Accio data&lt;/em>. It&amp;rsquo;s freaking magic!&lt;/p>
&lt;h5 id="import-to-stata-and-add-value-label">Import to Stata and add value label&lt;/h5>
&lt;p>You&amp;rsquo;ve downloaded the data but it is still in a &amp;ldquo;raw&amp;rdquo; csv file. You&amp;rsquo;ll want to convert it to Stata format and then add all those lovely value labels that you spent so much time writing in your REDCap database.&lt;/p>
&lt;p>Importing first:&lt;/p>
&lt;pre>&lt;code class="language-stata">*** Convert CSV file to Stata format
import delimited `outfile', ///
bindquote(strict) /// Fix quotes in text fields
stringcols(2) // Import second variable as string (Optional. Relevant if 2nd var is an ID var with leading zeroes such as SSN, CPR or similar study ID)
erase `outfile'.csv // Delete csv file
&lt;/code>&lt;/pre>
&lt;p>If you&amp;rsquo;ve used &lt;code>import delimited&lt;/code> before, this part should be pretty straight forward. Note, that in my databases, the second variable is usually some unique study ID like a social security numbers. Since these IDs often contain leading zeroes (&amp;ldquo;0123456789&amp;rdquo;), I force Stata to import the second variable as a string with the option &lt;code>stringcols(2)&lt;/code>, so Stata doesn&amp;rsquo;t think that they are numbers and remove the first zero (&amp;ldquo;123456789&amp;rdquo;). To keep my computer neat&amp;rsquo;n tidy, I also ask Stata to &lt;code>erase&lt;/code> the csv file.&lt;/p>
&lt;p>Last thing we need is to add the value labels from REDCap. You&amp;rsquo;ll need to download the labels manually from REDCap:
&lt;figure id="figure-click-export-data">
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-1_hu0a4f92d836222c48b50e0e3f591d633b_20784_2000x2000_fit_lanczos_2.PNG" data-caption="Click Export Data">
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-1_hu0a4f92d836222c48b50e0e3f591d633b_20784_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="1060" height="251">
&lt;/a>
&lt;figcaption>
Click Export Data
&lt;/figcaption>
&lt;/figure>
&lt;figure id="figure-select-stata-and-click-export-data">
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-2_hu224e1fc60266ceca57b849d40d12cdc0_102230_2000x2000_fit_lanczos_2.PNG" data-caption="Select Stata and Click Export Data">
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-2_hu224e1fc60266ceca57b849d40d12cdc0_102230_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="1135" height="563">
&lt;/a>
&lt;figcaption>
Select Stata and Click Export Data
&lt;/figcaption>
&lt;/figure>
&lt;figure id="figure-right-click-the-stata-logo-and-select-save-file-as">
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-3_hue627640ae8bd78dcb60b1666582a9c60_16780_2000x2000_fit_lanczos_2.PNG" data-caption="Right-click the Stata logo and select Save File As">
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-3_hue627640ae8bd78dcb60b1666582a9c60_16780_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="739" height="152">
&lt;/a>
&lt;figcaption>
Right-click the Stata logo and select Save File As
&lt;/figcaption>
&lt;/figure>
&lt;figure id="figure-save-in-working-folder-and-rename-it-redcapvaluelabeldo">
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-4_hud69166ea1beaf5f6c25385ec6d821169_6782_2000x2000_fit_lanczos_2.PNG" data-caption="Save in working folder and rename it RedcapValuelabel.do">
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-4_hud69166ea1beaf5f6c25385ec6d821169_6782_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="607" height="121">
&lt;/a>
&lt;figcaption>
Save in working folder and rename it RedcapValuelabel.do
&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>Open RedcapValuelabel.do and delete the first 7 lines of code, so it doesn&amp;rsquo;t interfere with our do file:
&lt;figure >
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-5_hu46ea26fdf017d3e73de47e063396ebec_49971_2000x2000_fit_lanczos_2.PNG" >
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-export-5_hu46ea26fdf017d3e73de47e063396ebec_49971_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="957" height="382">
&lt;/a>
&lt;/figure>
&lt;/p>
&lt;p>Save the changes and go back to your main do file. Note, that you need to do this every time you make changes to your REDCap database.&lt;/p>
&lt;p>Now you only need to add a few lines of code to add the value labels and save the final output:&lt;/p>
&lt;pre>&lt;code class="language-stata">** Apply value labels (Optional).
do RedcapValuelabel.do, nostop
** Save
save `outfile'.dta, replace
&lt;/code>&lt;/pre>
&lt;p>The &lt;code>nostop&lt;/code> option forces Stata to run the do file until the end, even if it encounters an error along the way. While this option is generally &lt;strong>not recommended&lt;/strong>, it is practical in this specific setting, since you might later ask cURL to only download specific variables from REDCap (See below). If you were to only download some specific variables (&lt;em>included&lt;/em> and &lt;em>disease&lt;/em> for example), then RedcapValuelabel.do would produce an error and stop, when trying to label all the other variables that haven&amp;rsquo;t been downloaded. Nostop prevents that.&lt;/p>
&lt;h3 id="final-remarks">Final remarks&lt;/h3>
&lt;p>And now you are done! Congratulations on becoming your office&amp;rsquo;s resident API wizard. Hopefully, it all worked like a charm. See the sections below for troubleshooting and tips on other API features.&lt;/p>
&lt;h3 id="troubleshooting">Troubleshooting&lt;/h3>
&lt;p>If the code doesn&amp;rsquo;t work, make sure you&amp;rsquo;ve specified the correct &lt;em>apikey&lt;/em> and &lt;em>apiurl&lt;/em>, and that you run the entire do file from top to bottom. If that doesn&amp;rsquo;t do it, try downloading my do file
&lt;a href="https://github.com/andreasebbehoj/stata-examples/tree/master/Redcap%20API" target="_blank" rel="noopener">from Github&lt;/a> and see if you&amp;rsquo;ve made a typo. If it still doesn&amp;rsquo;t work, then don&amp;rsquo;t hesitate writing to me.&lt;/p>
&lt;h5 id="error-message-you-do-not-have-permissions-to-use-the-api">Error message: You do not have permissions to use the API&lt;/h5>
&lt;p>I&amp;rsquo;ve received a few emails from people getting this error in their CSV file instead of the lovely data they expected.
&lt;figure id="figure-redcap-you-do-not-have-permission-to-use-the-api">
&lt;a data-fancybox="" href="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-error-no-permission_huad7935a395c295cfca7124a8f8b2d7f0_15817_2000x2000_fit_lanczos_2.PNG" data-caption="REDCap You do not have permission to use the API">
&lt;img data-src="https://www.ebbehoej.dk/post/automating-data-import-from-redcap/redcap-error-no-permission_huad7935a395c295cfca7124a8f8b2d7f0_15817_2000x2000_fit_lanczos_2.PNG" class="lazyload" alt="" width="536" height="332">
&lt;/a>
&lt;figcaption>
REDCap You do not have permission to use the API
&lt;/figcaption>
&lt;/figure>
First, go back and check that you have the correct API token and all that in the
&lt;a href="#REDCap-settings">beginning of this guide&lt;/a>. If it doesn&amp;rsquo;t solve the issue, Google tells me it is probably because the URL has been misspecified so &lt;em>carefully&lt;/em> check that you haven&amp;rsquo;t made a typo. Maybe you wrote &amp;ldquo;http://&amp;rdquo; instead of &amp;ldquo;https://&amp;quot;. Or maybe you have written the wrong version name in the URL (e.g. &amp;ldquo;&lt;a href="https://redcap.institutionname.edu/api/7.1.1%22)">https://redcap.institutionname.edu/api/7.1.1&amp;quot;)&lt;/a>. Try simply removing the version to see if it fixes the issue (&lt;a href="https://redcap.institutionname.edu/api/)">https://redcap.institutionname.edu/api/)&lt;/a>.&lt;/p>
&lt;h5 id="readwrite-issues-with-stata-and-mac-computers">Read/write issues with Stata and Mac computers&lt;/h5>
&lt;p>If you are a Mac user, then you might have issues with read/write access in the folder you are trying to download the csv file into.&lt;/p>
&lt;p>Maybe you have accidentally changed the working directory to some weird folder in your system which contains stuff you really should not be messing with. Your can check your current working folder by typing &lt;code>cd&lt;/code>. You can change working folder to the project folder by typing &lt;code>cd &amp;quot;pathtoprojectfolder&amp;quot;&lt;/code>.&lt;/p>
&lt;p>If you are in the correct working folder then you probably need to change your access from &amp;ldquo;read only&amp;rdquo; to &amp;ldquo;read/write access&amp;rdquo;. A guide on how to do this can be found
&lt;a href="https://www.stata.com/support/faqs/mac/cannot-write-in-directory/" target="_blank" rel="noopener">here&lt;/a>. Thanks to Jeniffer Nagudi (University of the Witwatersrand, South Africa) for pointing this out to me.&lt;/p>
&lt;h3 id="download-specific-records-with-filter-logic">Download specific records with filter logic&lt;/h3>
&lt;p>If you only need specific patients (records), you can use REDCap&amp;rsquo;s filter logic to specify which records the API should to download. This can make downloading a lot faster if you have a large database. For example, you might only need the patients that were included in your study (included=1) and got the disease you are interested in (disease=1). To select these records, you only need to add a single line to the &lt;code>shell&lt;/code> command:&lt;/p>
&lt;pre>&lt;code class="language-stata">shell `curlpath' ///
--output `outfile'.csv ///
--form token=`token' ///
--form content=record ///
--form format=csv ///
--form type=flat ///
--form filterLogic=&amp;quot;[included]='1' and [disease]='1'&amp;quot; ///
`apiurl'
&lt;/code>&lt;/pre>
&lt;h3 id="download-specific-variables">Download specific variables&lt;/h3>
&lt;p>Similarly to the example above, you might not want to download all variables. This could be relevant if only want inclusion status and disease status but don&amp;rsquo;t want to download patient identifiable data like social security numbers etc. You can then specify the variables you want to download by adding the &lt;code>--form fields[]=varname&lt;/code> option:&lt;/p>
&lt;pre>&lt;code class="language-stata">shell `curlpath' ///
--output `outfile'.csv ///
--form token=`token' ///
--form content=record ///
--form format=csv ///
--form type=flat ///
--form fields[]=included ///
--form fields[]=disease ///
`apiurl'
&lt;/code>&lt;/pre>
&lt;p>There are tons of options like this. Check sources for more inspiration.&lt;/p>
&lt;h3 id="sources">Sources&lt;/h3>
&lt;p>Most of this code is &lt;em>heavily&lt;/em> inspired by (i.e. copy-pasted from) this magnificent
&lt;a href="https://github.com/lsgs/REDCap-API-and-Stata" target="_blank" rel="noopener">code posted on Github&lt;/a>. It is written by &amp;ldquo;Luke&amp;rdquo; who appears to be REDCap&amp;rsquo;s version of Dumbledore. Thanks Luke!&lt;/p>
&lt;p>He has also writting a bunch do files for doing more complex stuff with the API that you should check out, if you want to download metadata, download specific data forms, reports etc, or if you want to learn how to upload data.&lt;/p></description></item></channel></rss>