Skip to main content

Callbacks

ID Bolt provides callbacks to handle session completion and cancellation, allowing your application to respond appropriately to user actions and scan results.

Completion Callback

The onCompletion callback is invoked when the user has successfully scanned their ID and passed all validations. This is where you'll receive the extracted data.

const idBoltSession = IdBoltSession.create(ID_BOLT_URL, {
// other options...
onCompletion: (result) => {
if (result.capturedId) {
console.log('Document type:', result.capturedId.documentType);
console.log('Full name:', result.capturedId.fullName);
console.log('Document number:', result.capturedId.documentNumber);
// Process the scanned ID data
}
}
});

CompletionResult Object

The onCompletion callback receives a CompletionResult object containing:

PropertyTypeDescription
capturedIdCapturedIdThe scanned document data. Will be null if no data was returned based on the returnDataMode.

Cancellation Callback

The onCancellation callback is invoked when the user closes the ID Bolt pop-up without completing the scanning process or when the service fails to start.

const idBoltSession = IdBoltSession.create(ID_BOLT_URL, {
// other options...
onCancellation: (reason) => {
switch (reason) {
case CancellationReason.UserClosed:
console.log("User closed the scanning window");
// Handle user cancellation
break;
case CancellationReason.ServiceStartFailure:
console.log("ID Bolt service failed to start");
// Handle service failure
break;
}
}
});

CancellationReason Enum

The onCancellation callback receives a CancellationReason enum value:

ValueDescription
CancellationReason.UserClosedThe user closed the ID Bolt pop-up before completing the scanning process
CancellationReason.ServiceStartFailureThe ID Bolt service failed to start

Captured ID Data

The CapturedId object contains the extracted data from the scanned document. The available data depends on the document type and quality of the scan.

CapturedId Properties

PropertyTypeDescription
firstNamestringFirst name of the document holder
lastNamestringLast name of the document holder
fullNamestringFull name of the document holder
sexstringSex/gender of the document holder
nationalitystringNationality of the document holder
addressstringAddress of the document holder
issuingCountryRegionThe ISO (Alpha-3 code) abbreviation of the issuing country
documentNumberstringUnique identifier assigned to the document
documentAdditionalNumberstringSecondary identification number if present
personalIdNumberstringPersonal identification number of the document holder
dateOfBirthDateResultDate of birth of the document holder
agenumberCalculated age based on date of birth
dateOfExpiryDateResultExpiration date of the document
isExpiredbooleanWhether the document is expired
dateOfIssueDateResultDate when the document was issued
documentTypeDocumentTypeType of document ("Passport", "IDCard", or "DriverLicense")
capturedResultTypesstring[]Types of data that were captured
imagesImageDataObject containing base64 encoded images (if requested)
mrzResult{capturedMrz: string | null} | nullCaptured MRZ raw data

DateResult Object

Date values are represented as DateResult objects:

PropertyTypeDescription
daynumberDay of the month (1-31)
monthnumberMonth (1-12)
yearnumberFour-digit year

ImageData Object

If you've used ReturnDataMode.FullWithImages, the images property will contain:

PropertyTypeDescription
fullFramestring[]Raw captured frames used for detection (base64 encoded JPG images)
croppedstring[]Cropped face and ID images, if available (base64 encoded JPG images)

Example: Complete Callback Usage

const idBoltSession = IdBoltSession.create(ID_BOLT_URL, {
licenseKey: LICENSE_KEY,
documentSelection: DocumentSelection.create({
accepted: [new Passport(Region.Any)]
}),
returnDataMode: ReturnDataMode.FullWithImages,
onCompletion: (result) => {
if (result.capturedId) {
// Extract basic information
const { fullName, documentNumber, documentType, issuingCountry } = result.capturedId;
console.log("Full Name:", fullName);
console.log("Document Number:", documentNumber);
console.log("Document Type:", documentType);
console.log("Issuing Country:", issuingCountry);
}
},
onCancellation: (reason) => {
switch (reason) {
case CancellationReason.UserClosed: {
console.log("User cancelled the scanning process");
// Show alternative flow
return;
}
case CancellationReason.ServiceStartFailure: {
console.log("Service failed to start");
// Show alternative flow
return;
}
default: {
console.log("Other cancellation reason");
// Reserved for future cancellation reasons
}
}
}
});