13 Feb REDCap API 101
The REDCap Application Programming Interface (or API) has been made more accessible for users with limited programming experience. An API is generally used to automate activities between two different systems. Review the details below to learn how you can use the API to improve your REDCap experience.
Uses for the REDCap API
REDCap’s API is generally used for three different things:
-
Pushing data into REDCap (Importing)
API can be used to populate data into REDCap from other systems, such as electronic medical records, other REDCap projects, web-servers, and statistical programs like R (https://www.r-project.org/). Complete projects in REDCap can be created and populated with data by using the API. Note: creating projects via the API require special privileges, talk to your REDCap administrator if you are interested in that type of project.
-
Pulling data from REDCap (Exporting)
Exporting data manually from REDCap is relatively easy. However, you may want to setup an automatic export for data analysis or dashboards. A common use of the API export is for statisticians using R to pull data directly from REDCap into R. This saves time and enables instantaneous reflection of the most up-to-date data.
-
Communication between a REDCap server and the REDCap Mobile App
Using the API with the REDCap mobile app is the simplest way for users to get acquainted with the API. All you would need is an API token (instructions below). The communication between server and app is completely automated; all the necessary code is included with the REDCap mobile app.
Getting Started with the API
1. User rights
First, you must obtain the appropriate user rights. API user rights are turned off by default for most users. There is a separate user right for each of the main API uses (import, export, and mobile app). Navigate to the user rights menu and check the appropriate boxes for your own user account.
If you do not have access to the user rights menu, ask a user on the project who does have access to grant you these user rights.
2. Getting an API token
Once you have the correct user rights, you should see the “API”, “API playground” and “REDCap mobile App” menus appear under the applications section.
Begin with the “API” menu. REDCap will prompt you to get an API token. Depending on the policies of your local REDCap installation, you can either create one yourself or request an API token from the administrator. Most REDCap administrators will approve an API token relatively quickly if not automatically.
3. Learn about the API “Methods”
API “Methods” is an IT term for ‘things you can do with the API’. The current version of REDCap (v7.6.6) has about 20 different methods. They range from “importing data” to “exporting project information” and “setting up arms”.
There are two ways to learn more about the API methods.
- REDCap API Documentation
API Documentation is similar to a traditional technical instruction manual. If you have programming experience you may be familiar with this style of documentation. - API Playground
This feature allows you to test the various API methods to see what they do.
You can set different parameters for each method and run the resulting code to see the results. In the playground, REDCap generates the appropriate code for a given method in seven different programming languages (PHP, Perl, Python, Ruby, Java, R and cURL) based on your selection. The code can then be copied and pasted into the program of your choice.
4. Start using the API code
After learning about the possibilities of the REDCap API, it’s time to use it!
We recommend you start by downloading a free version of R and running an R API method directly from R. Once that is working, you are well on your way to becoming a REDCap API expert. Potential uses of API are limited only by your imagination.