This guide explains how to create an Ayushman Bharat Health Account (ABHA) using Aadhaar through the ABDM-ruby
gem.
Before you begin the ABHA creation process, ensure that:
- You have installed and configured the
ABDM-ruby
gem. (Refer to the Installation Guide for details). - You have a valid Aadhaar number and a mobile number linked to your Aadhaar.
- You are familiar with how the gem handles Responses and Exceptions, to effectively manage API responses and errors.
Creating an ABHA via Aadhaar requires a series of API calls. The @client
object manages the flow by storing essential response values like txnId
, session_token
, and others, which are reused in subsequent API calls.
Start by creating an instance of the ABDM::Abha
class:
@client = ABDM::Abha.new
The first step is to generate an OTP for Aadhaar verification.
aadhaar_number
: String - The Aadhaar number for which the OTP will be generated.
generate_aadhaar_otp(aadhaar_number: )
@client.generate_aadhaar_otp(aadhaar_number: '123456789012')
{
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb",
"message": "OTP sent to Aadhaar registered mobile number ending with ******0704"
}
The
txnId
from the response is automatically stored in@client.transaction_id
and will be used in subsequent API calls.
If the OTP was not received or has expired, you can resend the OTP using the same method as in Step 1.
aadhaar_number
: String - The Aadhaar number for which the OTP will be regenerated.
resend_aadhaar_otp(aadhaar_number: )
@client.resend_aadhaar_otp(aadhaar_number: '123456789012')
{
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb",
"message": "OTP resent to Aadhaar registered mobile number ending with ******0704"
}
After successfully verifying the Aadhaar OTP, the next step is to enrol and create the ABHA ID from the previous steps.
otp_value
: String (required) - The OTP value received on your Aadhaar-registered mobile number.mobile_number
: String (required) - The primary mobile number to be used for ABHA enrolment, which may be different from the Aadhaar-linked mobile number.
enrol_abha(
otp_value:,
mobile_number:
)
@client.enrol_abha(otp_value: '123456', mobile_number: '9876543210')
{
"message": "Account created successfully",
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb"
}
After enrolling an ABHA, you need to verify the mobile number provided during enrolment. If the mobile number is different from the Aadhaar-linked mobile number, you must send an OTP for verification.
- If the primary mobile number matches the Aadhaar-linked mobile number, it is saved in the database.
- If the primary mobile number is different from the Aadhaar-linked mobile number, it is not saved, and its value is set to
null
.
mobile_number
: String (required) - The mobile number that was provided during the ABHA enrolment. This is used to send a verification OTP.
send_mobile_otp(mobile_number: )
@client.send_mobile_otp(mobile_number: '9876543210')
{
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb",
"message": "OTP sent to the mobile number ending with ******3210"
}
After receiving the OTP on the mobile number, you need to verify it to complete the mobile number verification process.
otp_value
: String (required) - The OTP received on the mobile number.
verify_mobile_otp(otp_value: )
@client.verify_mobile_otp(otp_value: '123456')
{
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb",
"authResult": "success",
"message": "OTP verified successfully"
}
After completing the ABHA enrolment and mobile verification, you need to verify the email address.
email_id
: String (required) - The email address for which the verification link will be sent. This should be RSA encrypted.
send_email_verification_link(email_id:)
@client.send_email_verification_link(email_id: '[email protected]')
No response body is provided. check with this
@client.response_code
This API call retrieves suggestions for ABHA addresses based on the current transaction. It helps users find available ABHA addresses.
- No parameters are required for this method.
get_abha_address_suggestion()
@client.get_abha_address_suggestion
{
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb",
"abhaAddressList": [
"bikash1",
"bikash1997",
"bikash.choudhury",
"bikash228",
"choudhury228"
]
}
This API call is used to create a custom ABHA address for the user. You need to provide the desired custom ABHA address.
abha_address
: String (required) - The custom ABHA address that the user wants to create.preferred
: Integer (optional) - Indicates if the custom ABHA address should be set as the preferred address. Accepted value is1
.
create_custom_abha_address(
abha_address:,
preferred:
)
@client.create_custom_abha_address(
abha_address: 'bikash22',
preferred: 1
)
{
"txnId": "bace3e1e-b09e-4506-b80d-d98fd16f1acb",
"healthIdNumber": "91-6285-4575-XXXX",
"preferredAbhaAddress": "bikash22"
}
This guide provides a overview of the ABHA creation process via Aadhaar using the ABDM-ruby
gem. By following these steps, you can successfully create and manage an Ayushman Bharat Health Account, including generating OTPs, verifying mobile numbers and emails, and setting up custom ABHA addresses.
For those interested in creating an ABHA via Driving License, please refer to the ABHA Creation via Driving License Guide.