ID Validation
Validate ID images wih Incode API
Introduction
There's 3 steps to an ID Validation, depending on which type of document you are validating:
- Add front side of ID
/omni/add/front-id/v2
- Add back side of ID
/omni/add/back-id/v2
- Process Id
/omni/process/id
Some documents, like passports, only have 1 side (front), as such, adding the back side is not necessary. Also sequence matters. Ensure front and back sides are uploaded before calling Process Id.
After calling
/omni/process/id
, you can't re-process the Id.If you wish to call the
/omni/process/id
endpoint again, you will need to first add the front and back sides of the ID again.
Requirements
x-api-key
header is required with it's value set to your Api Keyapi-version
header is required and must be set to 1.0X-Incode-Hardware-Id
header is required with it's value set to our Session Token. Obtained when we started our onboarding session.- Always call the endpoints in the mentioned order ( front -> back -> process)
- Images need to be provided as a base64 encoded string
Image Requirements
- Images should be at least 1000 pixels on one dimension, width or height.
- Make sure the request doesn't exceed the 10mb mentioned in the limitations of the API
- ID's should be fully visible in the image without edges or corners removed
- There should be some padding between the image edges and the ID edge
Image | Description |
---|---|
Valid image. There's a clear padding between the ID and the image borders. Id is fully visible | |
Invalid image. The ID is cropped and not fully visible | |
Invalid image. While the ID is fully visible, there's no padding with the image borders. |
The Image requirements above apply to both, front and back ID images.
Sample Code
For these samples, make sure to set your X-Incode-Hardware-Id
header to the token
you got from the start onboarding session step.
Front Id
curl --location 'https://demo-api.incodesmile.com/omni/add/front-id/v2' \
--header 'Content-Type: application/json' \
--header 'api-version: 1.0' \
--header 'x-api-key: <your_api_key>' \
--header 'X-Incode-Hardware-Id: <your_session_token>' \
--data '{
"base64Image": ""
}'
const axios = require('axios');
const fs = require('fs');
// Read your image file and encode as base64
const imageFilePath = 'path/to/your/image.jpg';
const base64 = fs.readFileSync(imageFilePath, { encoding: 'base64' });
const data = JSON.stringify({
base64Image: base64
});
const config = {
method: 'post',
url: 'https://demo-api.incodesmile.com/omni/add/front-id/v2',
headers: {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
},
data : data
};
axios(config)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
var client = HttpClient.newHttpClient();
// Read your image file and encode as base64
Path imagePath = Path.of("path/to/your/image.jpg");
String base64 = Base64.getEncoder().encodeToString(Files.readAllBytes(imagePath));
var request = HttpRequest.newBuilder()
.uri(URI.create("https://demo-api.incodesmile.com/omni/add/front-id/v2"))
.header("Content-Type", "application/json")
.header("api-version", "1.0")
.header("x-api-key", "<your_api_key>")
.header("X-Incode-Hardware-Id", "<your_session_token>")
.POST(BodyPublishers.ofString("{\"base64Image\":\"" + base64 + "\"}"))
.build();
var response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body());
using var client = new HttpClient();
// Read your image file and encode as base64
var imageFilePath = "path/to/your/image.jpg";
var base64 = Convert.ToBase64String(File.ReadAllBytes(imageFilePath));
var json = "{\"base64Image\":\"" + base64 + "\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("api-version", "1.0");
client.DefaultRequestHeaders.Add("x-api-key", "<your_api_key>");
client.DefaultRequestHeaders.Add("X-Incode-Hardware-Id", "<your_session_token>");
var response = await client.PostAsync("https://demo-api.incodesmile.com/omni/add/front-id/v2", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
import requests
import base64
# Read your image file and encode as base64
image_file_path = 'path/to/your/image.jpg'
with open(image_file_path, "rb") as image_file:
base64 = base64.b64encode(image_file.read()).decode('utf-8')
url = "https://demo-api.incodesmile.com/omni/add/front-id/v2"
payload = {
"base64Image": base64
}
headers = {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
You don't really need to store anything from the response. You can see more details about it here: Add front side of ID
Back Id
curl --location 'https://demo-api.incodesmile.com/omni/add/back-id/v2' \
--header 'Content-Type: application/json' \
--header 'api-version: 1.0' \
--header 'x-api-key: <your_api_key>' \
--header 'X-Incode-Hardware-Id: <your_session_token>' \
--data '{
"base64Image": ""
}'
const axios = require('axios');
const fs = require('fs');
// Read your image file and encode as base64
const imageFilePath = 'path/to/your/image.jpg';
const base64 = fs.readFileSync(imageFilePath, { encoding: 'base64' });
const data = JSON.stringify({
base64Image: base64
});
const config = {
method: 'post',
url: 'https://demo-api.incodesmile.com/omni/add/back-id/v2',
headers: {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
},
data : data
};
axios(config).then(function (response) {
console.log(response.data);
});
var client = HttpClient.newHttpClient();
// Read your image file and encode as base64
Path imagePath = Path.of("path/to/your/image.jpg");
String base64 = Base64.getEncoder().encodeToString(Files.readAllBytes(imagePath));
var request = HttpRequest.newBuilder()
.uri(URI.create("https://demo-api.incodesmile.com/omni/add/back-id/v2"))
.header("Content-Type", "application/json")
.header("api-version", "1.0")
.header("x-api-key", "<your_api_key>")
.header("X-Incode-Hardware-Id", "<your_session_token>")
.POST(BodyPublishers.ofString("{\"base64Image\":\"" + base64 + "\"}"))
.build();
var response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body());
using var client = new HttpClient();
// Read your image file and encode as base64
var imageFilePath = "path/to/your/image.jpg";
var base64 = Convert.ToBase64String(File.ReadAllBytes(imageFilePath));
var json = "{\"base64Image\":\"" + base64 + "\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("api-version", "1.0");
client.DefaultRequestHeaders.Add("x-api-key", "<your_api_key>");
client.DefaultRequestHeaders.Add("X-Incode-Hardware-Id", "<your_session_token>");
var response = await client.PostAsync("https://demo-api.incodesmile.com/omni/add/back-id/v2", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
import requests
import base64
# Read your image file and encode as base64
image_file_path = 'path/to/your/image.jpg'
with open(image_file_path, "rb") as image_file:
base64 = base64.b64encode(image_file.read()).decode('utf-8')
url = "https://demo-api.incodesmile.com/omni/add/back-id/v2"
payload = {
"base64Image": base64
}
headers = {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
As with the front ID, you don't really need to store anything from the response.
More details about the response here: Add back side of ID
Process Id
curl --location 'https://demo-api.incodesmile.com/omni/process/id' \
--header 'Content-Type: application/json' \
--header 'api-version: 1.0' \
--header 'x-api-key: <your_api_key>' \
--header 'X-Incode-Hardware-Id: <your_session_token>' \
--data '{}'
const axios = require('axios');
const config = {
method: 'post',
url: 'https://demo-api.incodesmile.com/omni/process/id',
headers: {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
}
};
axios(config).then(function (response) {
console.log(response.data);
});
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://demo-api.incodesmile.com/omni/process/id"))
.header("Content-Type", "application/json")
.header("api-version", "1.0")
.header("x-api-key", "<your_api_key>")
.header("X-Incode-Hardware-Id", "<your_session_token>")
.POST(BodyPublishers.ofString("{}"))
.build();
var response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body());
using var client = new HttpClient();
var content = new StringContent("{}", Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("api-version", "1.0");
client.DefaultRequestHeaders.Add("x-api-key", "<your_api_key>");
client.DefaultRequestHeaders.Add("X-Incode-Hardware-Id", "<your_session_token>");
var response = await client.PostAsync("https://demo-api.incodesmile.com/omni/process/id", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
import requests
url = "https://demo-api.incodesmile.com/omni/process/id"
headers = {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
}
response = requests.post(url, json={}, headers=headers)
print(response.text)
This is the final step for ID Validation. After this step is done, you will be able to see in your dashboard the score for the ID section. You can also review them via the fetch scores api (which is also part of the foundations section, but we will do that later in this guide.
Make sure to do proper error handling and validations in your application.
The provided sample code is for learning purposes. It only contains the basics
Updated about 2 months ago