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:

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

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:

ValueDescriptionSince
CancellationReason.UserClosedThe user closed the ID Bolt pop-up before completing the scanning process1.1
CancellationReason.ServiceStartFailureThe ID Bolt service failed to start1.1

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

PropertyTypeDescriptionSince
firstNamestringFirst name of the document holder1.0
lastNamestringLast name of the document holder1.0
fullNamestringFull name of the document holder1.0
sexstringSex/gender of the document holder1.0
nationalitystringNationality of the document holder1.0
addressstringAddress of the document holder1.0
issuingCountryRegionThe ISO (Alpha-3 code) abbreviation of the issuing country1.0
documentNumberstringUnique identifier assigned to the document1.0
documentAdditionalNumberstringSecondary identification number if present1.0
personalIdNumberstringPersonal identification number of the document holder1.3
dateOfBirthDateResultDate of birth of the document holder1.0
agenumberCalculated age based on date of birth1.0
dateOfExpiryDateResultExpiration date of the document1.0
isExpiredbooleanWhether the document is expired1.0
dateOfIssueDateResultDate when the document was issued1.0
documentTypeDocumentTypeType of document (e.g. "Passport", "IdCard", "DriverLicense", "VisaIcao", "ResidencePermit", "HealthInsuranceCard", "RegionSpecific")1.0
documentSubtypestring | nullSubtype of the document, if applicable2.1
capturedResultTypesstring[]Types of data that were captured1.0
nationalityISOstring | nullISO code of the nationality2.1
isCitizenPassportbooleanWhether the document is a citizen passport2.1
imagesobject | nullObject containing base64 encoded images (if requested)1.0
mrzResultMrzResult | nullRaw extracted data from Machine Readable Zone (MRZ)1.6
vizResultVizResult | nullRaw extracted data from Visual Inspection Zone (VIZ)1.11
barcodeResultBarcodeResult | nullRaw extracted data from barcode2.1
anonymizedFieldsIdFieldType[]List of fields that were anonymized for this document2.2

DateResult Object

Date values are represented as DateResult objects:

PropertyTypeDescriptionSince
daynumberDay of the month (1-31)1.0
monthnumberMonth (1-12)1.0
yearnumberFour-digit year1.0

Images Object

If you've used ReturnDataMode.FullWithImages, the images property will contain front and back image sets:

images: {
front: ImageSet;
back: ImageSet;
} | null

Each ImageSet contains:

PropertyTypeDescriptionSince
facestring | nullCropped face image extracted from the document (base64 encoded)2.0
croppedDocumentstring | nullCropped image of the document, only available when the visual inspection zone is scanned (base64 encoded)2.0
framestring | nullFull frame image of the captured document (base64 encoded)2.0

In version 1.x, images has a different structure:

PropertyTypeDescriptionSince
croppedstring[]Cropped images of the ID in the order they were captured (only available when VIZ is scanned)1.0
fullFramestring[]Full frame images in the order they were captured1.0

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
}
}
},
});