Integration Guide

Overview of flow

Web SDK integration flow

Integration Steps

Create Client

A client represents the individual for whom you need to perform various KYC checks. A client is required to generate an SDK token. This must be done in your backend server.

Example request

cURL
Node.js
Python
PHP
.NET
1
curl -X POST https://api.complycube.com/v1/clients \
2
-H 'Authorization: <YOUR_API_KEY>' \
3
-H 'Content-Type: application/json' \
4
-d '{
5
"type": "person",
6
"email": "[email protected]",
7
"personDetails":{
8
"firstName": "John",
9
"lastName" :"Doe"
10
}
11
}'
Copied!
1
const { ComplyCube } = require("@complycube/api");
2
3
const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });
4
5
const client = await complycube.client.create({
6
type: "person",
7
8
personDetails: {
9
firstName: "John",
10
lastName: "Doe"
11
}
12
});
Copied!
1
from complycube import ComplyCubeClient
2
cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')
3
4
new_client = {
5
'type':'person',
6
'email':'[email protected]',
7
'personDetails': {
8
'firstName':'John',
9
'lastName':'Doe'
10
}
11
}
12
13
client = cc_api.clients.create(**new_client)
Copied!
1
use ComplyCube\ComplyCubeClient;
2
3
$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');
4
$result = $ccapi->clients()->create(['type' => 'person',
5
'email' => '[email protected]',
6
'personDetails' => ['firstName' => 'John',
7
'lastName' => 'Doe']]);
Copied!
1
using ComplyCube.Net;
2
using ComplyCube.Net.Resources.Clients;
3
4
var clientApi = new ClientApi(new ComplyCubeClient("<YOUR_API_KEY>"));
5
var newClient = new ClientRequest {
6
type = "person",
7
email = "[email protected]",
8
personDetails = new PersonDetails {
9
firstName = "John",
10
lastName = "Doe"
11
}
12
}
13
14
var client = await clientApi.CreateAsync(newclientRequest);
Copied!

Example response

The response will contain an id (the Client ID). It is required for the next step.
1
{
2
"id": "5eb04fcd0f3e360008035eb1",
3
"type": "person",
4
"email": "[email protected]",
5
"personDetails": {
6
"firstName": "John",
7
"lastName": "Doe",
8
},
9
"createdAt": "2020-01-04T17:24:29.146Z",
10
"updatedAt": "2020-01-04T17:24:29.146Z"
11
}
Copied!

Generate SDK token

SDK Tokens enable clients to securely send personal data from your web application's frontend to ComplyCube.
You must generate a new token each time you initialise the ComplyCube Web SDK.

Example request

cURL
Node.js
Python
PHP
.NET
1
curl -X POST https://api.complycube.com/v1/tokens \
2
-H 'Authorization: <YOUR_API_KEY>' \
3
-H 'Content-Type: application/json' \
4
-d '{
5
"clientId":"CLIENT_ID",
6
"referrer": "https://www.example.com/*"
7
}'
Copied!
1
const { ComplyCube } = require("@complycube/api");
2
3
const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });
4
5
const token = await complycube.token.generate("CLIENT_ID", {
6
referrer: "https://www.example.com/*"
7
});
Copied!
1
from complycube import ComplyCubeClient
2
3
cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')
4
5
token = cc_api.tokens.create('CLIENT_ID','https://www.example.com/*')
Copied!
1
use ComplyCube\ComplyCubeClient;
2
3
$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');
4
5
$report = $ccapi->tokens()->generate('CLIENT_ID', 'https://www.example.com/*');
Copied!
1
using ComplyCube.Net;
2
using ComplyCube.Net.Resources.SDKTokens;
3
4
var sdkTokenApi = new SDKTokenApi(new ComplyCubeClient("<YOUR_API_KEY>"));
5
6
var sdkTokenRequest = { clientId = "CLIENT_ID" ,
7
referrer = "https://www.example.com/*" }
8
9
var sdkToken = await sdkTokenApi.GenerateToken(sdkTokenRequest);
Copied!

Example response

1
{
2
"token": "<CLIENT_TOKEN>"
3
}
Copied!

Import the SDK

To import our Web SDK, you need to include it in your target page as follows:
1
<!DOCTYPE html>
2
<html>
3
<head>
4
...
5
<!-- Importing the Javascript library -->
6
<script src="complycube.min.js"></script>
7
8
<!-- Importing the default CSS -->
9
<link rel="stylesheet" href="style.css" />
10
</head>
11
<body>
12
<!-- This is where the Web SDK will be mounted -->
13
<div id="complycube-mount"></div>
14
</body>
15
</html>
16
Copied!
The links to complycube.min.js and style.css can be found in your developers portal.

Mount the SDK

With the SDK token you generated earlier, the Web SDK can be initialised in your frontend using the following Javascript code:
1
ComplyCube.mount({
2
token: '<YOUR_WEB_SDK_TOKEN>',
3
containerId: 'complycube-mount',
4
stages: [
5
'intro',
6
'documentCapture',
7
{
8
name: 'faceCapture',
9
options: {
10
mode: "video"
11
},
12
},
13
'completion'
14
],
15
onComplete: function(data) {
16
// Using the data attributes returned, request your
17
// backend server to perform the necessary ComplyCube checks
18
console.info("Capture complete")
19
},
20
onModalClose: function() {
21
// Handle the modal closure attempt
22
ComplyCube.updateSettings({ isModalOpen: false })
23
},
24
onError: function ({ type, message }) {
25
if (type === 'token_expired')
26
// Request a new SDK token
27
} else {
28
// Handle other errors
29
console.err(message)
30
}
31
},
32
});
Copied!
The SDK mount parameters are described in the SDK Settings section below.

Perform Checks

Using the data returned by the SDK, via the onComplete callback, you can now instruct your backend server to run the appropriate checks using the create a check endpoint. For instance, use:
If you have set up webhooks as described in our webhooks guide, you will be notified once a check completes.
To retrieve the check results, you can perform a get check request.

Example request

cURL
Node.js
Python
PHP
.NET
1
curl -X GET https://api.complycube.com/v1/checks/{:checkId} \
2
-H 'Authorization: <YOUR_API_KEY>'
Copied!
1
const { ComplyCube } = require("@complycube/api");
2
3
const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });
4
5
const check = await complycube.check.get("CHECK_ID");
Copied!
1
from complycube import ComplyCubeClient
2
3
cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')
4
5
check = cc_api.checks.get('CHECK_ID')
Copied!
1
use ComplyCube\ComplyCubeClient;
2
3
$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');
4
5
$check = $ccapi->checks()->get('CHECK_ID');
Copied!
1
using ComplyCube.Net;
2
using ComplyCube.Net.Resources.Checks;
3
4
var checkApi = new CheckApi(new ComplyCubeClient("<YOUR_API_KEY>"));
5
6
var check = await checkApi.GetAsync("CHECK_ID");
Copied!

Miscellaneous

SDK Settings

Attribute
Description
token
Your client's SDK token. This is a required attribute.
language
The UI language. Valid values include:
  1. 1.
    en
  2. 2.
    de
  3. 3.
    es
  4. 4.
    fr
  5. 5.
    it
  6. 6.
    nl
  7. 7.
    no
  8. 8.
    pl
Default value: en
containerId
A string containing the ID of the container element that the Web SDK will mount to.
This must be an empty element.
Default value: complycube-mount
stages
This is the array of verification stages your clients will go through. Stages can be provided as string values which include : intro, userConsentCapture faceCapture, documentCapture, poaCapture, and completion.
Stages can be also provided as objects to enable customisations, as explained on the customisations page.
Default value: ['intro', 'faceCapture, 'documentCapture', 'completion']
onComplete
This callback function executes after the client completes the SDK flow. You could then use a function to trigger a check creation on your backend server.
Depending on the stages provided, data may include the following attributes:
  • documentCapture
    • documentId: the uploaded identity document unique reference generated by ComplyCube.
    • documentType: the type of document uploaded.
  • faceCapture
    • liveVideoId: the captured video unique reference number generated by ComplyCube, OR;
    • livePhotoId: the captured photo unique reference number generated by ComplyCube.
  • poaCapture
    • documentId: the uploaded ID document unique reference generated by ComplyCube.
    • documentType: the type of document uploaded.
onModalClose
This callback executes when your client tries to close the modal. You can then decide whether to close the modal or not by toggling the isModalOpenattribute using the updateSettingsmethod, as shown below.
onError
This callback executes when an error occurs. The error object has two attributes:
  • type: this can be either:
    • exception
    • token_expired : indicates the SDK token provided has expired. When this occurs, a new SDK toke must be provided, as shown below.
      • message: a descriptive message of the error that has occurred.
onExit
This callback executes when your client exits the SDK verification flow prior to completion. The callback returns the exit reason e.g. USER_CONSENT_NOT_GRANTED

Updating SDK Settings

A number of settings can be updated at runtime as follows:
1
complycube = ComplyCube.mount({...})
2
3
// Replace the SDK token
4
complycube.updateSettings({ token: "NEW_SDK_TOKEN" });
5
...
6
// Open the modal
7
complycube.updateSettings({ isModalOpen: true });
8
9
//Close the modal
10
complycube.updateSettings({ isModalOpen: false });
11
Copied!

Unmounting the SDK

If you are using the SDK within a Single Page Application (SPA), you can call unmount function to remove the SDK and reset its state.
1
complycube = ComplyCube.mount({...})
2
...
3
complycube.unmount()
Copied!