Skip to main content

Method Signature

FAD_SDK.startCaptureId(
  configuration?: Configuration
): Promise<CaptureIdResponse>

Description

The startCaptureId() method initiates a basic document capture module for capturing identification documents and extracting OCR data. This method provides a simpler alternative to Regula and Acuant for basic ID capture needs.

Parameters

configuration
Configuration
Optional configuration object for customizing the module’s behavior and appearance

Returns

CaptureIdResponse
Promise<object>
A promise that resolves with the capture ID module response

Code Example

import FadSDK from '@fad-producto/fad-sdk';

const TOKEN = 'YOUR_FAD_TOKEN';

const CONFIGURATION = {
  views: {
    instructions: false,
    preview: false,
  },
  customization: {
    fadCustomization: {
      colors: {
        primary: '#0066CC',
      },
      buttons: {
        primary: {
          backgroundColor: '#0066CC',
          labelColor: '#ffffff',
        },
      },
      fonts: {
        title: {
          fontSize: '25px',
          fontFamily: 'system-ui',
        },
        subtitle: {
          fontSize: '17px',
          fontFamily: 'system-ui',
        },
      },
    },
    moduleCustomization: {
      legends: {
        title: 'Identification',
        detection: {
          noDocument: 'Place document in the frame',
          goodDocument: 'Hold still',
          bigDocument: 'Move away',
          smallDocument: 'Move closer',
          blurryDocument: 'Document not readable',
        },
        subtitle: {
          front: 'Front',
          back: 'Back',
        },
      },
      style: {
        outerBackgroundColor: '#2b2b2b66',
        detectionBorder: {
          initial: {
            color: '#FFFFFF',
            style: 'solid',
            width: '4px',
          },
          warning: {
            color: '#FFDC45',
            style: 'solid',
            width: '4px',
          },
          detected: {
            color: '#009895',
            style: 'solid',
            width: '4px',
          },
        },
      },
    },
  },
};

async function captureId() {
  const options = {
    environment: FadSDK.getFadEnvironments().UATHA
  };

  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    const captureIdResponse = await FAD_SDK.startCaptureId(CONFIGURATION);

    // Process the results
    console.log('ID captured successfully');
    console.log('Front image:', captureIdResponse.data.image.front.data);
    
    if (captureIdResponse.data.image?.back?.data) {
      console.log('Back image:', captureIdResponse.data.image.back.data);
    }
    
    console.log('OCR data:', captureIdResponse.data.ocr);

    // Display in HTML elements
    // document.getElementById('image-id-front').src = captureIdResponse.data.image.front.data;
    // if (captureIdResponse.data.image?.back?.data) {
    //   document.getElementById('image-id-back').src = captureIdResponse.data.image.back.data;
    // }

  } catch (error) {
    if (error.code === FadSDK.Errors.CaptureId.NOT_READABLE_CAMERA) {
      console.error('Camera is being used by another application');
    } else if (error.code === FadSDK.Errors.CaptureId.SERVICE_ERROR) {
      console.error('Service error occurred');
    } else if (error.code === FadSDK.Errors.CaptureId.VIDEO_PLAYING_ERROR) {
      console.error('Video playing error');
    } else if (error.code === FadSDK.Errors.CaptureId.MODEL_FAILED) {
      console.error('Model failed to load');
    } else if (error.code === FadSDK.Errors.CaptureId.TF_LITE_ERROR) {
      console.error('TensorFlow Lite error');
    } else {
      console.error('Error:', error);
    }
  } finally {
    FAD_SDK.end();
  }
}

Error Handling

The method may throw errors that can be identified using FadSDK.Errors.CaptureId:
  • NOT_READABLE_CAMERA - Camera is being used by another application
  • SERVICE_ERROR - Service error occurred
  • VIDEO_PLAYING_ERROR - Error playing video stream
  • MODEL_FAILED - ML model failed to load
  • TF_LITE_ERROR - TensorFlow Lite error
This method provides basic document capture. For advanced document verification with authentication features, use startRegula() or startAcuant().
Always call FAD_SDK.end() in a finally block to properly clean up resources after the module completes or fails.

Build docs developers (and LLMs) love