The startDeviceScan function
Call
To use the Device Scan module you must call the startDeviceScan function, which takes the following positional parameters:
await startDeviceScan(
token,
document_number,
session_id,
event_id,
event_type,
environment
);
| Parameter | Type | Purpose | Required |
|---|---|---|---|
| token | string | Temporary authentication token obtained through a server-to-server request to the Device Scan API. It must be generated with the same session_id passed to this function. | Yes. |
| document_number | string | The user's document number (CPF/CNPJ without dots, dashes and slashes). | Yes. |
| session_id | string | Key that identifies the session the collected data comes from. It must be sent in lowercase. | Yes. |
| event_id | string | An identifier of the event being reported. | Yes. |
| event_type | string | An enum defining the type of event being reported (e.g. 'onboarding'). Please take care that very similar events are reported with the same enum, so that intelligence can be built on top of this data. | Yes. |
| environment | CAAS_ENVIRONMENT | Enum used to set the execution environment to SANDBOX or PRODUCTION. | Yes. |
Warning
Parameter order matters. Note that session_id comes before event_id and event_type in the function signature, even though the native module internally receives the values in a different order.
CAAS_ENVIRONMENT
enum CAAS_ENVIRONMENT {
PRODUCTION = 'production',
SANDBOX = 'sandbox',
}
Return values
The function returns a Promise resolved with a string indicating the success of the collection.
Success
Success collecting device scan data
Error
The Promise is rejected when the collection fails:
There was an error collecting DeviceScan data
When the native module is not correctly linked, the call throws:
The package '@qitech/react-native-device-scan' doesn't seem to be linked. Make sure:
- You have run 'pod install'
- You rebuilt the app after installing the package
- You are not using Expo managed workflow
Example
try {
const result = await startDeviceScan(
token,
'<CPF_NUMBER>',
'<SESSION_ID>',
'1',
'onboarding',
CAAS_ENVIRONMENT.SANDBOX
);
console.log(result); // "Success collecting device scan data"
} catch (error) {
console.log('Error executing device scan: ' + error);
}
Using the full package
If your application uses @qitech/react-native-caas, the startDeviceScan function has exactly the same signature and behavior — only the import path changes:
import { CAAS_ENVIRONMENT, startDeviceScan } from '@qitech/react-native-caas';