# Channels

`crm.channels` — `/v1/channels`

The connections an account sends and receives on: a WhatsApp number, an RCS
agent, a webchat widget.

A channel is **provisioned by onboarding, not by this API**. There is no
`create` and no `delete` here: `disable` retires one for good, keeping the row
its billing, wallet and activity history hang off. Connecting a new one is
`crm.channelOnboarding`, which walks the account holder through Meta's signup
dialog -- **[connecting a channel](onboarding.md)**.

Anything that lives with the provider rather than on the channel document — the
business profile, the QR code, media uploads, number registration — moves
through `getProp` and `setProp`, documented on their own page:
**[channel properties](channel-props.md)**.

| Action | Route | Scope |
| --- | --- | --- |
| [`list`](#list) | `GET /v1/channels` | `channels:read` |
| [`get`](#get) | `GET /v1/channels/:id` | `channels:read` |
| [`updateDetails`](#updatedetails) | `PUT /v1/channels/:id` | `channels:write` |
| [`disable`](#disable) | `POST /v1/channels/:id/disable` | `channels:write` |
| [`rotateToken`](#rotatetoken) | `DELETE /v1/channels/:id/token` | `channels:write` |
| [`getProp`](channel-props.md) | `GET /v1/channels/:id/:prop` | `channels:read` |
| [`setProp`](channel-props.md) | `POST /v1/channels/:id/:prop` | `channels:write` |

**Permissions** — there is no single `CRM.CHANNEL` key. The catalogue has one
feature per channel type, because each sits behind its own plan option:
`CRM.CHANNEL.WHATSAPP`, `CRM.CHANNEL.SMS`, `CRM.CHANNEL.RCS`. So the key for a
request depends on the **type of the channel being addressed**, which is a field
on the row — the check runs in the handler, not as route middleware.

| Action | Verb |
| --- | --- |
| `list` | `LIST` — see below |
| `get` | `READ` |
| `updateDetails` | `UPDATE` |
| `disable` | `DELETE` (a channel is never deleted; disabling retires it) |
| `rotateToken` | **`CREDENTIAL`** |
| `getProp` / `setProp` | depends on the prop — see [channel properties](channel-props.md) |

`rotateToken` is `CREDENTIAL` rather than `UPDATE` because it replaces the same
provider access token the `token` prop reads. Three verbs exist for that reason:
`CREDENTIAL` for the token, `REGISTER` for the number lifecycle, and `ANALYTICS`
for the analytics reads — none of which belong beside a business-profile edit.

`list` spans every type the account owns, so it cannot be one key: it is
**filtered** rather than refused. A member holding only
`CRM.CHANNEL.WHATSAPP.LIST` sees the WhatsApp channels and no others, and asking
for `?type=sms` without `CRM.CHANNEL.SMS.LIST` returns an empty page rather than
somebody else's channels.

Not every verb exists on every type: SMS reaches no properties at all, so it has
no `CREDENTIAL`, `REGISTER` or `ANALYTICS`, and asking for one is refused rather
than ignored.

## The channel object

Credentials and the private auth block are stripped from every response; what
remains is safe to hand a console.

```ts
interface Channel {
  id: string;
  member?: string;                  // the team member who connected it; absent when the account holder did
  active: boolean;                  // enabled by the owner — NOT the connection state
  ecom?: { store_status: boolean; store?: string };
  basic_details: { name: string; color_code: string; channel_identity: string };
  meta: {
    category: string;               // whatsapp | sms | email | rcs | webchat
    provider: string;               // BSP or integration, e.g. EMBEDDED_PNCL_BILLING
    support_template: boolean;
    show_template: boolean;
    bypass_webhook_verification: boolean;
  };
  wallet: { balance: number | 'NULL'; currency: string };
  campaign_tps: number;             // messages/second the campaign runner may push; default 10
  upgraded_webhook_listener: boolean;
  cloud: ChannelCloud;              // provider identifiers, flattened
  api_only: boolean;
  crm_only: boolean;
  mm_lite_enabled: boolean;
  access_token: string;             // short-lived encrypted handle, minted per response
  [key: string]: unknown;
}

interface ChannelCloud {
  instagram_id: string;
  is_instagram_business_login: boolean;
  waba_id: string;
  business: string;                 // Meta business id
  phone_number_id: string;
  is_on_biz_app: boolean;
  version: string;                  // Graph API version
  auto_read_receipt: number;
  upgrade_eligibility: boolean;
  wa_biz_registration: 'pending' | 'completed';
}
```

`basic_details.channel_identity` is the channel's address: the phone number, the
handle, the widget id.

**Wallet balances are divided down for display.** They are stored as
ten-thousandths; `channel.wallet.balance` is the value to four decimal places.
`'NULL'` means the agency has hidden the wallet from this caller. The
[wallet ledger](wallet.md) reports the raw stored values instead.

---

## list

```ts
crm.channels.list(query?: Partial<ListChannelsQuery>): Promise<Paginated<Channel>>
```

`GET /v1/channels` · `channels:read` · **200**

Newest first.

| Field | Type | Default | Notes |
| --- | --- | --- | --- |
| `page` | number | `1` | 1-based. |
| `rows` | number | `25` | 1–100. |
| `search` | string | — | 1–120 chars. Matches the channel **name and identity**. |
| `type` | `'whatsapp' \| 'sms' \| 'email' \| 'rcs' \| 'webchat'` | — | Quick filter on the category. |
| `active` | boolean | — | Quick filter: enabled/disabled by the owner. |
| `status` | `'connected' \| 'disconnected' \| 'error'` | — | Quick filter on connection health. |

```ts
const { data } = await crm.channels.list({ type: 'whatsapp', active: true });
```

---

## get

```ts
crm.channels.get(id: string): Promise<ChannelResponse>
```

`GET /v1/channels/:id` · `channels:read` · **200**

**Wrapped, and never a 404.** The payload is `{ data }`, and when nothing
matches it is `{ data: {} }` rather than an error:

```ts
const { data } = await crm.channels.get(id);
if (!('id' in data)) throw new Error('no such channel');
```

---

## updateDetails

```ts
crm.channels.updateDetails(id: string, input: UpdateChannelDetailsInput): Promise<ChannelResponse>
```

`PUT /v1/channels/:id` · `channels:write` · **200**, wrapped as `{ data }`

Renames or recolours a channel, and moves its billing currency. **At least one
field is required** — an empty body is a `422`.

| Field | Type | Notes |
| --- | --- | --- |
| `name` | string | 1–120 chars. |
| `color` | string | Hex, `#075E54` or `#fff`. |
| `currency` | `'USD' \| 'EUR' \| 'INR' \| 'IDR'` | See below. |

Currency is the one field with consequences: it decides how every conversation
is priced, so it only moves on a **WhatsApp channel with an empty wallet** — a
balance carried across a switch would be worth a different amount on the other
side. A non-empty wallet is `409 wallet_not_empty`, with the current currency in
`details`. Asking for the currency the channel already bills in changes nothing
and is not an error.

```ts
await crm.channels.updateDetails(id, { name: 'Support', color: '#075E54' });
```

---

## disable

```ts
crm.channels.disable(id: string): Promise<{ success: true }>
```

`POST /v1/channels/:id/disable` · `channels:write` · **200**

Retires a channel for good. It stops delivering, drops out of every listing, and
**cannot be brought back**. The row stays so its billing, wallet and activity
history remain readable.

A negative wallet balance blocks it with `409 negative_wallet_balance`: that is
money owed that nothing would collect afterwards. Settle the balance first.

A webchat channel has its widget subscription removed first — left behind, the
panel would keep posting into a dead inbox, and nothing would be able to reach
the widget to remove it afterwards.

---

## rotateToken

```ts
crm.channels.rotateToken(id: string): Promise<{ success: true }>
```

`DELETE /v1/channels/:id/token` · `channels:write` · **200**

Issues a new inbound API token and discards the old one, which **stops working
immediately**. Anything using it starts failing on the next request.

The new value is not in the response. Read it back with:

```ts
await crm.channels.rotateToken(id);
const { data: token } = await crm.channels.getProp<string>(id, 'token');
```

---

## Properties

`getProp` and `setProp` cover everything else a channel can do — the business
profile, QR codes, media uploads, number registration and migration, the message
queue, conversation automation. Each property, with its query and body, is on
**[channel properties](channel-props.md)**.
