> ## Documentation Index
> Fetch the complete documentation index at: https://idto.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Web SDK

> Open the idto verification flow in any web app with one script tag. No bundler, npm install or CSS file needed.

The Web SDK is a single script that opens the idto verification flow over your page. It renders inside a shadow root, so your page styles never reach the flow and the flow's styles never reach your page. It works with any frontend stack, React included, because it is a plain script tag.

![Verification overview screen listing the workflow steps](https://idto-sdk-usage-demo-bucket.s3.ap-south-1.amazonaws.com/docs/v1/img/sdk-overview.png)

The flow opens with an overview of the steps in your workflow.

## Before you start

You need:

* A `client_id` and `client_secret` from the idto dashboard. The secret stays on your server.
* A `workflow_template_id`: the UUID of the workflow that decides which steps run and in what order.
* A backend route that mints a short-lived client token. See [Authentication](https://idto.mintlify.site/authentication.md) and the [Node and Express recipe](https://idto.mintlify.site/recipes/sdk-token-node-express.md).

## Install

Add the script tag once, on any page that opens the flow:

```html theme={null}
<script src="https://idto-sdk-bucket.s3.ap-south-1.amazonaws.com/sdk/prod/idto.js"></script>
```

The script defines `window.IDtoSDK` with two methods, `open(config)` and `close()`.

## Quick start

**1. Mint a client token on your server**

Call `POST /auth/sdk/token` with your `client_id` and `client_secret`. The response carries `access_token` (the client token) and `expires_in` in seconds. Return only the token to the browser.

```js theme={null}
app.post("/api/idto-token", async (req, res) => {
  const r = await fetch("https://prod.idto.ai/auth/sdk/token", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      client_id: process.env.IDTO_CLIENT_ID,
      client_secret: process.env.IDTO_API_KEY,
    }),
  });
  const { access_token } = await r.json();
  res.json({ client_token: access_token });
});
```

**2. Open the flow**

```html theme={null}
<button id="verify">Verify your identity</button>
<script>
  document.getElementById("verify").addEventListener("click", async () => {
    const r = await fetch("/api/idto-token", { method: "POST" });
    const { client_token } = await r.json();
    IDtoSDK.open({
      client_token,
      workflow_template_id: "your-workflow-template-uuid",
      businessName: "Sample Traders",
      getToken: async () => (await (await fetch("/api/idto-token", { method: "POST" })).json()).client_token,
      onStepComplete: (d) => console.log("step done", d.step),
      onWorkflowComplete: (d) => fetch("/api/idto-confirm", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ session_token: d.session_token }),
      }),
      onError: (d) => console.error("idto error", d.step, d.error),
      onAbandon: (d) => console.warn("abandoned at", d.at_step),
      onClose: () => console.log("closed"),
    });
  });
</script>
```

**3. Confirm the result on your server**

Browser callbacks drive your UI only. Before you grant access, confirm the session from your server with the [session result recipe](https://idto.mintlify.site/recipes/confirm-session-result.md) or a signed [webhook](https://idto.mintlify.site/concepts/webhooks.md).

![PAN card capture screen](https://idto-sdk-usage-demo-bucket.s3.ap-south-1.amazonaws.com/docs/v1/img/sdk-pan-capture.png)

A PAN capture step inside the flow.

## Environments

| `env` | API host | Use for |
| - | - | - |
| `"production"` (default) | `https://prod.idto.ai` | Live traffic |
| `"development"` | `https://dev.idto.ai` | Staging, with staging credentials |

The token must come from the same environment the flow points at. Staging runs real checks, see [Environments](https://idto.mintlify.site/environments.md).

## Configuration

### Required

**client\_token** `string` *required*

The `access_token` your server minted from `POST /auth/sdk/token`.

**workflow\_template\_id** `string` *required*

UUID of the workflow to run.

### Session and user

| Field | Type | Purpose |
| - | - | - |
| `getToken` | `() => Promise<string>` | Returns a fresh client token when the current one expires. |
| `session_token` | `string` | Resume an earlier session instead of starting a new one. |
| `start_fresh` | `boolean` | Start a new session even if one is in progress for this browser. |
| `merchant_user_id` | `string` | Your own id for this user, returned with the session. |
| `phone` | `string` | Prefills the mobile number step. |
| `pre_verified` | `Record<string, boolean>` | Module slugs you already verified, keyed `true`, which the flow skips. |
| `skippable` | `string[]` | Module slugs the user may skip and finish later. See [Modules](https://idto.mintlify.site/sdks/modules.md). |
| `accumulated_data` | `object` | Data you already hold, passed into the session. |

### Matching

| Field | Type | Purpose |
| - | - | - |
| `reference_name` | `string` | Name every document name is matched against. |
| `nameMatchConfig` | `object` | `threshold` (number), `decision_mode` (`"all"` or `"any"`), `extra_honorifics` (string array), `aliases` (object), `compare_pairs` (any of `"aadhaar_vs_pan"`, `"aadhaar_vs_dl"`, `"aadhaar_vs_bank"`, `"pan_vs_bank"`). |
| `faceMatchReferenceImage` | `string` | Reference photo the live selfie is compared with. |
| `faceMatchConfig` | `object` | `skipLiveness` (boolean), `threshold` (number), `livenessFailurePolicy` (`"fail_open"`, `"fail_closed"` or `"needs_review"`). |
| `aadhaarConfig` | `object` | `digilockerMaxFailures` (`1` or `2`), `okycEnabled` (boolean). |
| `panConfig` | `object` | `skipContextScreen` (boolean). |

### Branding and display

| Field | Type | Purpose |
| - | - | - |
| `businessName` | `string` | Your name, shown in the flow header. |
| `logo` | `string` | URL of your logo. |
| `language` | `"en"` or `"hi"` | Language of the flow copy. |
| `theme` | `"light"` or `"dark"` | Colour scheme. |
| `colors` | `object` | `background`, `text`, `text2`, `border`, `primary`, `secondary`, `buttonTextColor_primary`, `buttonTextColor_secondary`. |
| `displayMode` | `"full_screen"` or `"bottom_sheet"` | Layout on small screens. |
| `desktopModal` | `object` | `width`, `height`, `breakpoint` for the centred modal on wide screens. |
| `bottomSheet` | `object` | `minHeight`, `maxHeight` for bottom sheet mode. |
| `env` | `"production"` or `"development"` | API environment. Default `"production"`. |
| `baseUrl` | `string` | Overrides the API host. Takes precedence over `env`. |

## Callbacks

**onStepComplete(data)** `function`

Fires after each step finishes.

**data**

**step** `string`

Slug of the step that finished.

**result** `object`

That step's result.

**accumulated\_data** `object`

Everything collected so far, keyed by slug.

**session\_token** `string`

The session token.

**credits\_deducted** `number`

Credits charged for this step.

**balance\_remaining** `number`

Your credit balance after this step.

**onWorkflowComplete(data)** `function`

Fires once when every step is done.

**data**

**all\_steps** `object[]`

One entry per step, each with its `slug` and result fields.

**accumulated\_data** `object`

Everything collected, keyed by slug.

**session\_token** `string`

Send this to your server to confirm the result.

**onError(data)** `function`

Fires when a step or the session start fails.

**data**

**step** `string`

Slug of the active step, or `"init"` when the session could not start.

**error** `string`

A readable message. Log it; do not match on its text.

**session\_token** `string`

The session token. Empty when `step` is `"init"`.

**onAbandon(data)** `function`

Fires when the user leaves the flow from an error screen.

**data**

**at\_step** `string`

Slug of the step the user was on.

**reason** `string`

Why the session ended, for example `"error"`.

**session\_token** `string`

The session token.

**onClose()** `function`

Fires when the flow closes, with no payload.

![Workflow complete screen](https://idto-sdk-usage-demo-bucket.s3.ap-south-1.amazonaws.com/docs/v1/img/sdk-workflow-complete.png)

The completion screen shown after the last step.

## Methods

| Method | Behaviour |
| - | - |
| `IDtoSDK.open(config)` | Opens the flow. Calling it while a flow is open closes that one and opens a new one. |
| `IDtoSDK.close()` | Closes the flow. `onClose` fires when it has gone. |

## See it run

<video controls width="100%" src="https://idto-sdk-usage-demo-bucket.s3.ap-south-1.amazonaws.com/docs/v1/video/flow-pan.mp4" poster="https://idto-sdk-usage-demo-bucket.s3.ap-south-1.amazonaws.com/docs/v1/video/flow-pan.jpg" />

Was this page helpful? Email us at [tech@idto.ai](mailto:tech@idto.ai?subject=Docs%20feedback%3A%20Web%20SDK) with the page link.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.