RedcapAPI 2.0.0
dotnet add package RedcapAPI --version 2.0.0
NuGet\Install-Package RedcapAPI -Version 2.0.0
<PackageReference Include="RedcapAPI" Version="2.0.0" />
<PackageVersion Include="RedcapAPI" Version="2.0.0" />
<PackageReference Include="RedcapAPI" />
paket add RedcapAPI --version 2.0.0
#r "nuget: RedcapAPI, 2.0.0"
#:package RedcapAPI@2.0.0
#addin nuget:?package=RedcapAPI&version=2.0.0
#tool nuget:?package=RedcapAPI&version=2.0.0
REDCap API Library for .NET
The REDCap Api Library provides the ability to interact with REDCap programmatically using various .NET languages(C#,F#,VB.NET);
What's New in 2.0.0
Version 2.0.0 is a cleanup and parity release focused on bringing the library in line with documented REDCap API behavior while modernizing the repository structure.
- Added
ExportSurveyAccessCodeAsync - Added interface coverage for randomization and user role mapping endpoints
- Added
combineCheckboxOptionssupport for record export methods - Added
delete_loggingsupport for record deletion methods - Added ODM format support where REDCap supports it
- Expanded
Contentcoverage for newer REDCap content values - Fixed
ExportProjectXmlAsyncdefault content mapping - Reorganized the repository into conventional
.NETfolders:src,tests, anddemo
Prerequisites
- Local redcap instance installed (visit https://project-redcap.org) if you need to download files(assuming you have access)
- Create a new project with "Demographics" for the template; this gives you a basic project to work with.
- Create an api token for yourself, replace that with the tokens you see on the "RedcapApiTests.cs" files, and others
- You may need to add a field type of "file_upload" so that you can test the file upload interface of the API
- Build the solution, then run the demo project to see the results.
Highlights
- Export and import records, metadata, users, roles, DAGs, events, instruments, reports, and files
- Project export, project XML export, project settings import, and next record name generation
- Survey link, survey queue link, survey return code, survey participants, and survey access code support
- File repository create/list/export/import/delete support
- Repeating instruments/events import and export support
- Randomize record support
Usage:
dotnet restore
Add a reference to the package or project
Add "using Redcap" namespace
Add "using Redcap.Models" for convenience
Use the sample data dictionary in
src/RedcapApi/Docsif you want a quick test project setupThe repository is organized as follows:
src/RedcapApi- library sourcetests/RedcapApi.Tests- test projectdemo/RedcapApiDemo- demo console app
Feel free to contribute
Sample / Example
using Newtonsoft.Json;
using Redcap;
namespace RedcapApiDemo
{
internal class Program
{
static async Task<int> Main(string[] args)
{
var apiToken = "3D57A7FA57C8A43F6C8803A84BB3957B";
var redcap_api = new RedcapApi("http://localhost/redcap/api/");
var result = await redcap_api.ExportRecordsAsync(apiToken);
var records = JsonConvert.DeserializeObject(result);
Console.WriteLine(records);
Console.ReadLine();
return 0;
}
}
}
Install directly in Package Manager Console or Command Line Interface
Package Manager
Install-Package RedcapAPI -Version 2.0.0
.NET CLI
dotnet add package RedcapAPI --version 2.0.0
Paket CLI
paket add RedcapAPI --version 2.0.0
Example Project
A console project has been included with the source code to get started. Some examples of method usage. You can use this to get started potentially.
Demo Prerequisites (RedcapApiDemo)
Before running the demo app in demo/RedcapApiDemo, verify all of the following:
- REDCap instance is reachable and API endpoint resolves.
- Example base URI:
https://localhost - Effective API URL used by demo:
<base-uri>/api/
- Example base URI:
- You have a valid project API token with rights for records, metadata, files, users, and project setup actions used in the demo.
- REDCap project setup exists:
- Demographics instrument exists.
- Longitudinal event
event_1_arm_1exists. - File upload field
file_uploadexists.
- Local demo file exists:
demo/RedcapApiDemo/Docs/Demographics_TestProject_DataDictionary.csv
- Local download folder is writable:
C:\redcap_download_files
Run the demo:
dotnet run --project demo/RedcapApiDemo/RedcapApiDemo.csproj
The demo now prints a startup checklist and validates local artifacts before API calls begin.
Developer Local Settings (Tokens)
For local testing, you can provide defaults using a local config file in demo/RedcapApiDemo.
- Copy
demo/RedcapApiDemo/appsettings.Development.example.jsontodemo/RedcapApiDemo/appsettings.Development.json. - Fill in your local values:
{
"RedcapDemo": {
"BaseUri": "http://localhost",
"ProjectToken": "YOUR_PROJECT_TOKEN",
"SuperToken": "YOUR_SUPER_TOKEN"
}
}
appsettings.Development.json is git-ignored in the demo project so local secrets are not committed.
If values are present in this file, pressing Enter at demo prompts will use them.
Developer Environment Variables
You can configure demo defaults via environment variables instead of a local settings file.
Supported variables:
REDCAP_DEMO_BASE_URIREDCAP_DEMO_PROJECT_TOKENREDCAP_DEMO_SUPER_TOKEN
Alternative .NET-style names are also supported:
RedcapDemo__BaseUriRedcapDemo__ProjectTokenRedcapDemo__SuperToken
PowerShell example:
$env:REDCAP_DEMO_BASE_URI = "http://localhost"
$env:REDCAP_DEMO_PROJECT_TOKEN = "YOUR_PROJECT_TOKEN"
$env:REDCAP_DEMO_SUPER_TOKEN = "YOUR_SUPER_TOKEN"
dotnet run --project demo/RedcapApiDemo/RedcapApiDemo.csproj -- -m ImportRecordsAsync
Configuration precedence is:
- Environment variables
appsettings.Development.json- In-code defaults
Run One Method Only
You can run a single demo method by name:
dotnet run --project demo/RedcapApiDemo/RedcapApiDemo.csproj -- -m ImportRecordsAsync
dotnet run --project demo/RedcapApiDemo/RedcapApiDemo.csproj -- -m ExportRecordsAsync
Supported selectors include method names and short aliases, e.g. ImportRecordsAsync/import, ExportRecordsAsync/export.
Test Project
A project with associated test cases is included. Make sure to change the api token
Testing and Coverage
The repository includes transport-focused unit tests that validate payload composition for API methods and overload variants without requiring a live REDCap instance.
Run tests:
dotnet test tests/RedcapApi.Tests/RedcapApi.Tests.csproj --verbosity minimal
Run tests with coverage:
dotnet test tests/RedcapApi.Tests/RedcapApi.Tests.csproj --collect:"XPlat Code Coverage" --verbosity minimal
Latest local baseline (2026-04-19):
- Test count:
128 - Passing:
128 - Failing:
0 - Line coverage:
80.26%(2310/2878) - Branch coverage:
59.49%(445/748)
Recent coverage work focused on:
- Overload parity across API method variants
- Multipart and dictionary payload branch paths
- File and file-repository request behavior
- Survey/report/record export optional parameter handling
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Newtonsoft.Json (>= 13.0.3)
- Serilog (>= 4.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 112 | 4/19/2026 |
| 1.3.7 | 18,267 | 11/7/2024 |
| 1.3.6 | 2,045 | 7/16/2024 |
| 1.3.5 | 1,334 | 5/9/2024 |
| 1.3.4 | 508 | 5/8/2024 |
| 1.3.3 | 2,282 | 10/13/2023 |
| 1.3.2 | 921 | 5/20/2023 |
| 1.3.1 | 1,706 | 1/9/2023 |
| 1.3.0 | 1,072 | 1/7/2023 |
| 1.1.0 | 2,595 | 2/5/2021 |
| 1.0.9 | 1,443 | 10/3/2020 |
| 1.0.8 | 2,958 | 1/27/2020 |
| 1.0.7 | 1,538 | 2/24/2019 |
| 1.0.6 | 1,150 | 2/13/2019 |
| 1.0.5 | 1,090 | 2/12/2019 |
2.0.0 release highlights:
- parity refresh against documented REDCap 17.0.2 endpoints
- added ExportSurveyAccessCodeAsync
- added randomization and user role mapping interface coverage
- added combineCheckboxOptions and delete_logging parameter support
- added ODM format support
- reorganized the repository into src/tests/demo