> For the complete documentation index, see [llms.txt](https://docs.complycube.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.complycube.com/documentation/sdks/web-integrations/web-sdk-quick-guide/web-sdk-quick-guide.md).

# Workflow Integration

Integrate KYC workflows in your web app using the ComplyCube Web SDK.

## Overview

This guide walks you through integrating the Web SDK with ComplyCube [workflows](/documentation/product-guides/compliance-studio/workflows.md).

{% hint style="info" %}
For a quick copy-paste example, use our [integration assistant](https://portal.complycube.com/developers).
{% endhint %}

## Integration flow

The Web SDK runs as part of your frontend but relies on your backend to create **secure tokens**. Here’s how it works:

{% stepper %}
{% step %}

#### **Create a client**

Register a new **client** (i.e. customer) using the ComplyCube API
{% endstep %}

{% step %}

#### **Generate an SDK token**

Your backend requests a **JWT token** tied to that client.
{% endstep %}

{% step %}

#### **Import and mount the SDK**

Add the JS and CSS files, then mount the SDK in your web app.
{% endstep %}

{% step %}

#### Capture documents, videos, and selfies

The SDK guides your customer through the required steps.
{% endstep %}

{% step %}

#### Perform verification checks

Captured data is securely sent to ComplyCube for verification checks, and results are delivered in real time through the API or webhooks.
{% endstep %}
{% endstepper %}

<figure><img src="https://648014528-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Flv7UhJvTbxeq4s3KwQpn%2Fuploads%2F27Bdqoog1QcehV7SqoZw%2Fdocumentation-Web%20SDK%20(WF).png?alt=media&amp;token=ad02b9fa-42ba-472d-9c0e-c915cb6bbf50" alt=""><figcaption><p>Web SDK Integration via Workflows Guide</p></figcaption></figure>

## Integration guide

{% stepper %}
{% step %}

#### Create a client

Every verification flow starts with a **client** (i.e. customer). Use the API to [create the client](/documentation/api-reference/core-resources/clients/create-a-client.md).

**Example request**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.complycube.com/v1/clients \
     -H 'Authorization: <YOUR_API_KEY>' \
     -H 'Content-Type: application/json' \
     -d '{
          "type": "person",
          "email": "john.doe@example.com",
          "personDetails":{
               "firstName": "John",
               "lastName" :"Doe"
          }
        }'
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { ComplyCube } = require("@complycube/api");

const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });

const client = await complycube.client.create({
  type: "person",
  email: "john.doe@example.com",
  personDetails: {
    firstName: "John",
    lastName: "Doe"
  }
});
```

{% endtab %}

{% tab title="Python" %}

```python
from complycube import ComplyCubeClient
cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')

new_client = {
    'type':'person',
    'email':'john.doe@example.com',
    'personDetails': {
        'firstName':'John',
        'lastName':'Doe'
    }
}

client = cc_api.clients.create(**new_client)
```

{% endtab %}

{% tab title="PHP" %}

```php
use ComplyCube\ComplyCubeClient;

$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');

$result = $ccapi->clients()->create([
    'type' => 'person',
    'email' => 'john@doe.com',
    'personDetails' => [
        'firstName' => 'John',
        'lastName' => 'Doe'
    ]
]);
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using ComplyCube.Net;
using ComplyCube.Net.Resources.Clients;

var clientApi = new ClientApi(new ComplyCubeClient("<YOUR_API_KEY>"));
var newClient = new ClientRequest {
  type = "person",
  email = "john@doe.com",
  personDetails = new PersonDetails {
    firstName = "John",
    lastName = "Doe"
  }
}

var client = await clientApi.CreateAsync(newClient);
```

{% endtab %}
{% endtabs %}

**Example response**

The response will contain an `id` (the Client ID). It is required for the next step.

```json
{
    "id": "5eb04fcd0f3e360008035eb1",
    "type": "person",
    "email": "john.doe@example.com",
    "personDetails": {
        "firstName": "John",
        "lastName": "Doe"
    },
    "createdAt": "2020-01-04T17:24:29.146Z",
    "updatedAt": "2020-01-04T17:24:29.146Z"
}
```

{% hint style="info" %}
See [Clients API Reference](/documentation/api-reference/core-resources/clients.md) to learn more.
{% endhint %}
{% endstep %}

{% step %}

#### Generate an SDK token

Your backend must create an **SDK token** for each new flow. This token links the SDK session to the client. Tokens are short-lived and must not be reused.

**Example request**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.complycube.com/v1/tokens \
     -H 'Authorization: <YOUR_API_KEY>' \
     -H 'Content-Type: application/json' \
     -d '{
          "clientId":"CLIENT_ID",
          "referrer": "https://www.example.com/*"
        }'
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { ComplyCube } = require("@complycube/api");

const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });

const token = await complycube.token.generate("CLIENT_ID", {
    referrer: "https://www.example.com/*"
});
```

{% endtab %}

{% tab title="Python" %}

```python
from complycube import ComplyCubeClient

cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')

token = cc_api.tokens.create('CLIENT_ID','https://www.example.com/*')
```

{% endtab %}

{% tab title="PHP" %}

```php
 use ComplyCube\ComplyCubeClient;

$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');

$report = $ccapi->tokens()->generate('CLIENT_ID', 'https://www.example.com/*');
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using ComplyCube.Net;
using ComplyCube.Net.Resources.SDKTokens;

var sdkTokenApi = new SDKTokenApi(new ComplyCubeClient("<YOUR_API_KEY>"));

var sdkTokenRequest = {
  clientId = "CLIENT_ID",
  referrer = "https://www.example.com/*"
}

var sdkToken = await sdkTokenApi.GenerateToken(sdkTokenRequest);
```

{% endtab %}
{% endtabs %}

**Example response**

```json
{
    "token": "<CLIENT_TOKEN>"
}
```

{% hint style="info" %}
See [SDK Token API Reference](/documentation/api-reference/other-resources/tokens.md) to learn more.
{% endhint %}
{% endstep %}

{% step %}

#### Import the SDK

To import our Web SDK, you need to include it in your target page HTML:

```html
<!DOCTYPE html>
<html>
  <head>
    ...
    <!-- Importing the Javascript library -->
    <script src="complycube.min.js"></script>

    <!-- Importing the default CSS -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
     <!-- This is where the Web SDK will be mounted -->
    <div id="complycube-mount"></div>
  </body>
</html>
```

<details>

<summary><strong>Loading the SDK with Integrity</strong> <em>(Optional)</em></summary>

For additional security, you can optionally load the ComplyCube Web SDK using **Subresource Integrity (SRI)**. This allows the browser to verify that the JavaScript and CSS files have not been modified by validating them against cryptographic checksums.

#### **Retrieve the latest SDK integrity values**

To ensure you always use the latest supported SDK version and integrity hashes, retrieve the asset metadata from the Web SDK info endpoint.

**Example request**

```bash
curl -X POST https://api.complycube.com/v1/webSdk/latest \
     -H 'Authorization: <YOUR_API_KEY>'
```

**Example response**

The response includes the URLs and corresponding integrity values for both the JavaScript and CSS assets.

{% code overflow="wrap" %}

```json
{
  "js": {
    "url": "<JAVASCRIPT_ASSET_URL>/complycube.min.js",
    "integrity": "sha384-<INTEGRITY_HASH_1> sha384-<INTEGRITY_HASH_2>"
  },
  "css": {
    "url": "<CSS_ASSET_URL>/style.css",
    "integrity": "sha384-<INTEGRITY_HASH_1> sha384-<INTEGRITY_HASH_2>"
  }
}
```

{% endcode %}

#### **Import the SDK using integrity attributes**

Use the returned values to load the SDK in your HTML with `integrity` and `crossorigin` attributes:

```html
<!DOCTYPE html>
<html>
  ...
  <head>
    <!-- Importing the Javascript library -->
    <script
      src="<JAVASCRIPT_ASSET_URL>/sdk.min.js"
      integrity="sha384-<INTEGRITY_HASH_1> sha384-<INTEGRITY_HASH_2>"
      crossorigin="anonymous">
    </script>

    <!-- Importing the default CSS -->
    <link
      rel="stylesheet"
      href="<CSS_ASSET_URL>/style.css"
      integrity="sha384-<INTEGRITY_HASH_1> sha384-<INTEGRITY_HASH_2>"
      crossorigin="anonymous">
  </link>
  </head>
  
  <!-- This is where the Web SDK will be mounted -->
  <body>
    <div id="complycube-mount"></div>
  </body>
</html>
```

{% hint style="info" %}

#### Notes

* Using SRI is ***optional***, but recommended for environments with stricter security requirements.
* The crossorigin="anonymous" attribute is required when using SRI with assets served from a different origin.
* Integrity values may change when the SDK is updated. Always retrieve the latest values from the endpoint.
  {% endhint %}

</details>

{% hint style="info" %}
The links to `complycube.min.js` and `style.css` can be found in your [developers portal](https://portal.complycube.com/developers/webSdk).
{% endhint %}
{% endstep %}

{% step %}

#### Mount the SDK

As part of mounting the Web SDK, you are required to specify a [workflow template ID](https://portal.complycube.com/workflowTemplates). The SDK will automatically run the **active** version of the selected workflow.

Once the verification flow is complete, customers are redirected back to the return URL you specify.

With the generated token, the Web SDK can be initialized in your frontend using the following JavaScript code:

```javascript
ComplyCube.mount({
  token: '<YOUR_WEB_SDK_TOKEN>',
  containerId: 'complycube-mount',
  workflowTemplateId: "WORKFLOW_TEMPLATE_ID",
  onComplete: function(data) {    
    // Have your backend notify ComplyCube once the workflow is complete
    // to trigger the verification checks
    console.info('Capture complete');
  },
  onModalClose: function() {
    // Handle the modal closure attempt
  },
  onError: function ({ type, message }) {
    if (type === 'token_expired') {
      // Request a new SDK token
    } else {
      // Handle other errors
      console.error(message);
    }
  }
});
```

{% hint style="info" %}
The SDK mount parameters are described in the [SDK Settings](#settings) section below.
{% endhint %}

{% hint style="info" %}

#### Referrer policy

To enable successful communication between the SDK and our servers, your web page's **Referrer Policy** header should be set to `strict-origin-when-cross-origin`. This ensures that the referrer information is securely transmitted during HTTP requests.

You can either do it programmatically or add it directly to the web page as follows:\
`<meta name="referrer" content="strict-origin-when-cross-origin">`
{% endhint %}
{% endstep %}

{% step %}

#### Perform verification checks

Once your customer starts the flow, a [workflow session](/documentation/product-guides/compliance-studio/workflows.md#workflow-session) is automatically created. This session contains all captured data (documents, images, and videos) as well as progress tracking. You can view all of them through the [workflow sessions page](https://portal.complycube.com/workflowSessions) on the portal or through the API.

When the flow finishes, the SDK triggers the `onComplete` callback. The callback provides a `data` object that includes the `workflowSessionId`. Your backend should use this ID to notify ComplyCube that the [workflow has completed](/documentation/api-reference/core-resources/workflow-sessions/complete-a-workflow-session.md), which in turn runs the verification checks defined in the workflow.

If you have [set up webhooks ](https://docs.complycube.com/api-reference/other-resources/webhooks/create-a-webhook)as described in our [webhooks guide](https://docs.complycube.com/documentation/guides/webhooks), you will be notified once a workflow session completes.

You can retrieve the details of a workflow session by calling the [retrieve workflow session request](/documentation/api-reference/core-resources/workflow-sessions/get-a-workflow-session.md).

**Example of a complete workflow session request**

{% tabs %}
{% tab title="cURL" %}

```javascript
curl -X POST https://api.complycube.com/v1/workflowSessions/{:wfSessionId}/complete \
     -H 'Authorization: <YOUR_API_KEY>' \
     -H 'Content-Type: application/json'
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { ComplyCube } = require("@complycube/api");

const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });

const wfSession = await complycube.workflowSession.complete("WORKFLOW_SESSION_ID");
```

{% endtab %}

{% tab title="Python" %}

```python
from complycube import ComplyCubeClient

cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')

workflow_session = cc_api.workflowsessions.complete('WORKFLOW_SESSION_ID')
```

{% endtab %}

{% tab title="PHP" %}

```php
use ComplyCube\ComplyCubeClient;

$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');

$workflowSession = $ccapi->workflowSessions()->complete('WORKFLOW_SESSION_ID');
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using ComplyCube.Net;
using ComplyCube.Net.Resources.WorkflowSessions;

var wfSessionApi = new WorkflowSessionApi(new ComplyCubeClient("<YOUR_API_KEY>"));

var workflowSession = await wfSessionApi.CompleteAsync("WORKFLOW_SESSION_ID");
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

## SDK reference

This section describes all configurable settings, callbacks, lifecycle methods, and branding options available in the ComplyCube Web SDK.

### Settings

<table><thead><tr><th width="218.09765625">Option</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td>The SDK token generated by your backend. This is <strong>required</strong>.<br><br><strong>Type</strong>: <code>string</code></td></tr><tr><td><code>workflowTemplateId</code></td><td><p>The ID of the <a href="https://portal.complycube.com/workflowTemplates">workflow template</a> to load for this the session. This is <strong>required</strong>.</p><p><strong>Type:</strong> <code>string</code></p></td></tr><tr><td><code>containerId</code></td><td><p>The ID of the container element where the SDK mounts. This must be an empty element.</p><p><strong>Type:</strong> <code>string</code><br><strong>Default value</strong>: <code>complycube-mount</code></p></td></tr><tr><td><code>useModal</code></td><td>This defines whether the UI screens load into a modal instead of inline.<br><br><strong>Type:</strong> <code>boolean</code><br><strong>Default value</strong>: <code>true</code></td></tr><tr><td><code>useFullScreen</code></td><td>This defines whether the SDK loads in full-screen mode.<br><br><strong>Type:</strong> <code>boolean</code><br><strong>Default value</strong>: <code>false</code></td></tr><tr><td><code>disableClientAnalytics</code></td><td><p>This defines whether we track client analytics or not.<br></p><p><strong>Type:</strong> <code>boolean</code><br><strong>Default value</strong>: <code>false</code></p></td></tr></tbody></table>

### Callback

Callbacks let you respond to SDK lifecycle events.

<table><thead><tr><th width="218.0234375">Option</th><th>Description</th></tr></thead><tbody><tr><td><code>onComplete</code></td><td>Triggered after the customer completes the verification flow. This is used to invoke a <a href="/documentation/api-reference/core-resources/workflow-sessions/complete-a-workflow-session.md">workflow session complete request</a>.</td></tr><tr><td><code>onError</code></td><td><p>Triggered when an error occurs. The error object has two attributes:</p><ul><li><p><code>type</code>: This can be:</p><ul><li><code>exception</code></li><li><code>token_expired</code> : indicates the token has expired. When this occurs, a new <strong>SDK token must be provided</strong>.</li></ul></li><li><code>message</code>: Description of the error.</li></ul></td></tr><tr><td><code>onExit</code></td><td>This callback is triggered when your client exits before completing the flow. It will return the exit reason, e.g., <code>USER_CONSENT_NOT_GRANTED</code>.</td></tr><tr><td><code>onModalClose</code></td><td>Triggered when the customer tries to close the modal. You can allow or prevent closure by updating the <code>isModalOpen</code> attribute using <a href="#updating-settings">updateSettings</a>.</td></tr></tbody></table>

### Updating settings

A number of settings can be updated at runtime as follows:

```javascript
complycube = ComplyCube.mount({...});

// Replace the SDK token
complycube.updateSettings({ token: "NEW_SDK_TOKEN" });
...
// Open the modal
complycube.updateSettings({ isModalOpen: true });

//Close the modal
complycube.updateSettings({ isModalOpen: false });

```

### Unmounting the SDK

If you are using the SDK in a Single Page Application (SPA), you can call the unmount function to remove the SDK and reset its state.

```javascript
complycube = ComplyCube.mount({...});
...
complycube.unmount()
```

## Branding

You can customise colours, logos, and other branding elements through the [branding settings page](https://portal.complycube.com/settings/branding), if available on your plan.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.complycube.com/documentation/sdks/web-integrations/web-sdk-quick-guide/web-sdk-quick-guide.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
