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

# Kommo plugin

> CRM with Kommo - manage leads, contacts, companies and tasks, and read the pipelines with their stages, the account users and the account itself.

Use **Kommo** through Corsair: one client, typed API calls.

Create a private integration in Kommo, then generate a long-lived token under its Keys and scopes tab. A token lasts from one day to five years, and only an account administrator can create one. It is sent as a bearer token. A long-lived token has no refresh token: once it expires, every call answers 401 until a new token is generated and stored.

Two things are needed before the first call:

* **The account subdomain.** Every account is served from its own host: `acme` for `acme.kommo.com`, under `/api/v4`. Connect delivers it as the `subdomain` credential; the plugin option of the same name overrides it. A call with neither throws before any request is sent.
* **A pipeline and stage.** A lead's `pipeline_id` and `status_id` come from `pipelines.list`. A lead created without them lands in the first stage of the main pipeline.

Things to know before you call:

* **Timestamps are Unix seconds.** `created_at`, `updated_at`, `closed_at`, `closest_task_at` and a task's `complete_till` are integers counting seconds, not ISO strings. The plugin passes them through as Kommo sends them.
* **Paging is by page number.** A list takes `page` and `limit` (250 at most) and returns a `_page` and `_links` block. The plugin adds `next_page`, which is null on the last page. Kommo answers an empty list with 204 No Content, which the plugin returns as an empty page.
* **Filters are bracketed query keys.** `pipeline_id` and the date filters become `filter[pipeline_id][]` and `filter[created_at][from]` on the wire, which is how Kommo documents them. The date filters take Unix seconds. A stage filter is `status_id` together with its `pipeline_id`, sent as `filter[statuses][0][...]`; Kommo allows only one stage in one pipeline per request.
* **A write takes an array.** `leads.create`, `contacts.create` and `tasks.create` post up to 250 entities at once, and the update routes are PATCH with each entity carrying its `id`. A field left out of an update is untouched.
* **Custom field values go by `field_id` or `field_code`.** The plugin refuses a value that names neither, because Kommo would reject it. A value's type follows its `field_type`, so a `date_time` field takes a Unix timestamp.
* **A new contact needs a name.** `name`, or `first_name` and `last_name`; a contact created with neither is refused before the call. An update can change any one field.
* **A task needs a deadline.** `complete_till` is required, in Unix seconds.
* **Rate limits.** Kommo allows seven requests a second and answers 429 past that, with `Retry-After`, which the plugin honours before backing off. A 402 means the account's paid or trial period has ended, and is not retried. Only reads are replayed after a 5xx, because a retried lead create would make a second lead.
* **Webhooks.** Kommo does send webhooks, but this plugin does not receive them; that is a separate integration surface.

**What you get:**

* 14 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/kommo better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/kommo better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/kommo better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/kommo better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { kommo } from '@corsair-dev/kommo';

export const corsair = createCorsair({
	plugins: [
		kommo(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Kommo API key before the first call: `pnpm corsair setup --plugin=kommo --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> kommo()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'kommo',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**List the first page of leads**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.kommo.api.leads.list({
	limit: 50,
	with: ['contacts'],
});
```

**Create a lead**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.kommo.api.leads.create({
	leads: [{ name: 'Acme renewal', price: 5000 }],
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/kommo/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/kommo/api.md)
>
> Every `kommo.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


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