The JavaScript SDK of Trust Vision API
<script src="https://unpkg.com/@tsocial/trustvision-sdk@2.5.0/dist/trustvision-sdk.umd.js"></script>
<script>
// create and instance of API client with provided access key, secret key and environment
// environment values should be testing, staging, production or the API URL
const apiClient = new trustvisionSdk.default(
'access key', // access key
'secret key', // secret key
'testing', // environment (testing, staging, production) or API URL
);
// start using services
apiClient
.clientSettings()
.then((result) => {
// result contains information about card types and other settings
})
.catch((error) => {
});
</script>
// import API Client class
import TrustVisionAPI from '@tsocial/trustvision-sdk';
// create and instance of API client with provided access key, secret key and environment
// environment values should be testing, staging, production or the API URL
const apiClient = new TrustVisionAPI(
'access key', // access key
'secret key', // secret key
'testing', // environment (testing, staging, production) or API URL
);
// start using services
apiClient
.clientSettings()
.then((result) => {
// result contains information about card types and other settings
})
.catch((error) => {
});
apiClient
.clientSettings()
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.uploadImage({
file: imageFile, // file object
imageLabel: 'portrait', // image label
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.compareFaces({
image1: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
},
image2: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.verifyFaceLiveness({
images: [{
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}, {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}],
gestures: ['<image 1 gesture>', '<image 1 gesture>'], //array of expected gestures of the face in each image, optional
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.readIDCard({
card_type: 'card type', // card type of image
image1: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
},
image2: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}, // optional
qr1_images: [{
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}], // array of uploaded back qr code, optional
qr2_images: [{
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}], // array of uploaded front qr code, optional
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.requestVerifyIDCard({
card_type: 'card type', // card type of image
image1: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
},
image2: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.requestVerifyPortrait({
image: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
}
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.searchFaces({
image: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
},
collection: "", // index faces to this collection, optional
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
Example: Download an image and display it on a img HTML tag
const $img = document.getElementById('result'); // select an image tag with id result <img id="result" />
const imageId = 'd70b3fd3-253d-4e35-b2f7-fad564a36443';
apiClient.downloadImage(imageId)
.then((dataURL) => $img.setAttribute('src', result));
apiClient
.indexFaces({
image: {
id: '', //ID of the image in DB
base64: '', //Base64 encoded text of image1 data
label: '', //label of the image as described at Upload Image API
metadata: {}, //any key-value metadata to save with the image, both key and value should be string
},
collection: "", // index faces to this collection, optional
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});
apiClient
.updateMetadata({
"metadata": {} // any key-value metadata to save with the image, both key and value should be string,
"label": '', //label of the image
"override": true, // boolean flag to allow override old metadata or not,
})
.then((result) => {
// please refer to API document for response's format
})
.catch((error) => {
});