Node.js SDK for Ayushman Bharat Digital Mission (ABDM) API. This SDK provides a simple and type-safe way to interact with ABDM's healthcare APIs.
- TypeScript Support: Full TypeScript support with type definitions
- Comprehensive API Coverage: Covers all major ABDM APIs
- Promise-based: All API calls return Promises
- Configurable: Customize HTTP client and other options
- Well-tested: Comprehensive test suite
- Production-ready: Used in production by Nirmitee
# Using npm
npm install @nirmitee/abdm-sdk-node
# Using yarn
yarn add @nirmitee/abdm-sdk-node
# Using pnpm
pnpm add @nirmitee/abdm-sdk-node- Node.js 16.0.0 or higher
- TypeScript 4.0.0 or higher (for TypeScript projects)
- Valid ABDM API credentials
import { ABDMClient } from '@nirmitee/abdm-sdk-node';
const client = new ABDMClient({
clientId: 'your-client-id',
clientSecret: 'your-client-secret'
});
async function generateAndVerifyAadhaarOTP() {
try {
// Step 1: Generate Aadhaar OTP
const generateResponse = await client.generateAadhaarOTP({
aadhaar: '123456789012',
txnId: '' // Leave blank or omit; will be generated by the API if not provided
});
console.log('Aadhaar OTP sent:', generateResponse);
// Extract txnId from the response
const txnId = generateResponse?.data?.txnId; // Adjust based on actual response structure
// Step 2: Prompt user to enter the OTP received on their mobile and the mobile number used for Aadhaar
const otp = '123456'; // TODO: Replace with actual OTP input from user
const mobile = '9876543210'; // TODO: Replace with the mobile number used for Aadhaar authentication
// Step 3: Verify Aadhaar OTP
const verifyResponse = await client.verifyAadhaarOTP({
txnId, // Use txnId from generateAadhaarOTP response
otp,
mobile // Mobile number must be entered by the user
});
console.log('Aadhaar OTP verified:', verifyResponse);
return verifyResponse;
} catch (error) {
console.error('Error in Aadhaar OTP flow:', error);
throw error;
}
}
generateAndVerifyAadhaarOTP();-
auth: Authentication and user managementgenerateAadhaarOTP(): Generate OTP for Aadhaar authenticationverifyAadhaarOTP(): Verify Aadhaar OTPgenerateMobileOTP(): Generate OTP for mobile authenticationverifyMobileOTP(): Verify mobile OTPgetAuthToken(): Get authentication token
-
consent: Consent managementcreateConsent(): Create a new consentgetConsentStatus(): Get consent statusrevokeConsent(): Revoke consent
-
health: Health record and facility servicesaddUpdateHealthFacilityServices(data): Add or update health facility servicesgetHealthFacility(facilityId): Get health facility detailslistHealthFacilities(): List all health facilitiesupdateHealthFacilityStatus(facilityId, active): Update health facility status (active/inactive)getHealthRecords(patientId, token, options): Fetch health recordsgetHealthRecord(recordId, token): Get health record by IDgetABHAProfile(abhaNumber, token): Get ABHA profileupdateABHAProfile(profileData, token): Update ABHA profilegetLinkedAddresses(abhaNumber, token): Get linked ABHA addressescreateConsent(consentRequest, token): Create a new consent requestgetConsent(consentId, token): Get consent details
interface ABDMConfig {
clientId: string;
clientSecret: string;
// baseUrl: string;
timeout?: number; // Request timeout in milliseconds (default: 30000)
maxRetries?: number; // Maximum retry attempts (default: 3)
retryDelay?: number; // Delay between retries in ms (default: 1000)
debug?: boolean; // Enable debug logging (default: false)
}import { ABDMClient } from '@nirmitee/abdm-sdk-node';
const client = new ABDMClient({
clientId: 'your-client-id',
clientSecret: 'your-client-secret'
});
async function addOrUpdateFacility() {
try {
const data = {
// Fill with HealthFacilityRequest fields
};
const response = await client.health.addUpdateHealthFacilityServices(data);
console.log('Facility add/update response:', response);
} catch (error) {
console.error('Error adding/updating facility:', error);
}
}
addOrUpdateFacility();-
Clone the repository
git clone https://github.com/Nirmitee-tech/abdm-sdk-node.git cd abdm-sdk-node -
Install dependencies
npm install
-
Build the project
npm run build
-
Run tests
# Run all tests npm test # Run unit tests npm run test:unit # Run integration tests npm run test:integration # Run tests with coverage npm run test:coverage
-
Lint and format code
# Lint code npm run lint # Format code npm run format
- Node.js 16.0.0 or higher is required.
- OpenSSL 1.x or 3.x is required (Node.js uses OpenSSL under the hood).
-
Encryption failed: unsupported or Failed to create public key object: Your Node.js or OpenSSL version may be too old or incompatible. Upgrade Node.js to the latest LTS version.
-
OpenSSL legacy provider required: On Node.js 17+ with OpenSSL 3, you may need to run your app with:
node --openssl-legacy-provider your-app.js
-
Insecure SSL warning in production: Never set
NODE_TLS_REJECT_UNAUTHORIZED=0or userejectUnauthorized: falsein production. This is only for sandbox/testing.
- Check your Node.js version:
node -v - Check your OpenSSL version:
node -p "process.versions.openssl" - If you see errors, upgrade Node.js or consult the SDK documentation/issues.
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Nirmitee - https://nirmitee.io/get-in-touch/
Project Link: https://github.com/Nirmitee-tech/abdm-sdk-node