# Custom fields

`crm.customFields` — `/v1/audience/custom-fields`

The per-account schema for contacts. A field's `slug` is the key its values are
stored under in `contact.custom_field_hash`, and the `field_id` the
[contact filter](../contact-filter.md) addresses it by.

**Every route takes either the field's id or its slug**, so a caller that knows
the schema never has to look an id up first. A value that reads as a 24-hex id
is looked up as one; anything else is read as a slug.

| Action | Route | Scope |
| --- | --- | --- |
| [`list`](#list) | `GET /v1/audience/custom-fields` | `custom_fields:read` |
| [`get`](#get) | `GET /v1/audience/custom-fields/:ref` | `custom_fields:read` |
| [`create`](#create) | `POST /v1/audience/custom-fields` | `custom_fields:write` |
| [`update`](#update) | `PATCH /v1/audience/custom-fields/:ref` | `custom_fields:write` |
| [`delete`](#delete) | `DELETE /v1/audience/custom-fields/:ref` | `custom_fields:write` |

**Permissions** — the feature is `CRM.CONTACT.FIELD`, which is its own feature
and not a verb of `CRM.CONTACT`. A team member needs the key; an owner does not.

| Action | Key |
| --- | --- |
| `list`, `get` | `CRM.CONTACT.FIELD.LIST` |
| `create` | `CRM.CONTACT.FIELD.CREATE` |
| `update` | `CRM.CONTACT.FIELD.UPDATE` |
| `delete` | `CRM.CONTACT.FIELD.DELETE` |

Reading one field uses `LIST`: the feature publishes no `READ` verb.

The schema is account-level, so there is nothing for a role's `data_scope` to
narrow — a field definition is not assigned to anybody, and a member seeing half
a schema would see half of every contact. A member either reaches custom fields
or does not.

`teamAccess` on a field (`restricted` / `open_to_all`) is **stored and
filterable, not enforced**: passing `?teamAccess=restricted` filters the list,
and nothing restricts a member to `open_to_all` fields. If per-field visibility
is meant to be real, that is a separate change from the key above.


## The field object

```ts
interface CustomField {
  id: string;
  slug: string;                  // machine name, unique per account
  name?: string;                 // label
  caption?: string;              // helper text
  type: 'system' | 'user';       // who owns it — NOT the data type
  dataType?: CustomFieldType;    // the data type
  default: Record<string, unknown>;
  props: Record<string, unknown>;  // type-specific config: dropdown options, precision, …
  required: boolean;
  displayInPanel: boolean;
  showInSidebar: boolean;
  showAsLabel: boolean;
  isBoard: boolean;
  teamAccess: 'restricted' | 'open_to_all';
  createdAt: string;
  updatedAt: string;
}
```

`type` and `dataType` are easy to confuse. `type` says **who owns the field** —
`system` for platform-provisioned, `user` for the account's own. `dataType` is
what it holds.

### Data types

`text` `textarea` `url` `email` `phone` `dial_code` `country` `language`
`timezone` `date` `timestamp` `periodic_time` `number` `decimal` `amount`
`percent` `address` `location` `attachment` `checkbox` `dropdown`
`multi_select`

---

## list

```ts
crm.customFields.list(query?: Partial<ListCustomFieldsQuery>): Promise<Paginated<CustomField>>
```

`GET /v1/audience/custom-fields` · `custom_fields:read` · **200**

### Query

| Field | Type | Default | Notes |
| --- | --- | --- | --- |
| `page` | number | `1` | 1-based. |
| `rows` | number | `25` | 1–100. |
| `search` | string | — | 1–120 chars. Matches the **slug, the label and the caption**. |
| `dataType` | `CustomFieldType` | — | Quick filter. |
| `type` | `'system' \| 'user'` | — | Quick filter: platform-provisioned or the account's own. |
| `teamAccess` | `'restricted' \| 'open_to_all'` | — | Quick filter. |

```ts
const fields = await crm.customFields.list({ type: 'user', dataType: 'dropdown' });
```

---

## get

```ts
crm.customFields.get(ref: string): Promise<CustomField>
```

`GET /v1/audience/custom-fields/:ref` · `custom_fields:read` · **200**

`ref` is the field's id **or** its slug.

```ts
await crm.customFields.get('lead_score');                  // by slug
await crm.customFields.get('65f0a1b2c3d4e5f6a7b8c9d0');    // by id
```

---

## create

```ts
crm.customFields.create(input: CreateCustomFieldInput): Promise<CustomField>
```

`POST /v1/audience/custom-fields` · `custom_fields:write` · **201**

### Body

| Field | Type | Required | Default | Notes |
| --- | --- | --- | --- | --- |
| `slug` | string | yes | — | `^[a-z][a-z0-9_]{0,63}$`, and not reserved. Immutable once created. |
| `name` | string | yes | — | 1–120 chars. The label. |
| `caption` | string | no | — | Up to 240 chars. |
| `dataType` | `CustomFieldType` | yes | — | See the list above. |
| `default` | object | no | `{}` | Default value, shaped by `dataType`. |
| `props` | object | no | `{}` | Type-specific config — dropdown options, number precision, and so on. |
| `required` | boolean | no | `false` | |
| `displayInPanel` | boolean | no | `false` | |
| `showInSidebar` | boolean | no | `false` | |
| `showAsLabel` | boolean | no | `false` | |
| `isBoard` | boolean | no | `false` | |
| `teamAccess` | `'restricted' \| 'open_to_all'` | no | `'open_to_all'` | |

### Reserved slugs

A slug that would shadow something else is rejected with `422`. Three groups:

- **Contact document paths** — `id` `_id` `__v` `user` `business` `name`
  `profile` `custom_field_hash` `custom_fields` `chat_metadata` `bot` `order`
  `last_seen` `last_icm_timestamp` `last_interaction_props` `agent` `team`
  `lead_source` `status` `privacy_status` `tags` `createdat` `updatedat`
- **Channel keys**, which `profile` is keyed by — `waba` `whatsapp` `facebook`
  `instagram` `telegram` `email` `rcs` `webchat`
- **Built-in filter fields** — `referral_id` `system_last_seen`
  `system_created_on` `system_identifier` `system_profile_name`

The check is case-insensitive. A slug already in use on the account is a
`409 conflict`.

```ts
const field = await crm.customFields.create({
  slug: 'lead_score',
  name: 'Lead score',
  dataType: 'number',
  required: true,
  showInSidebar: true,
});
```

---

## update

```ts
crm.customFields.update(ref: string, input: UpdateCustomFieldInput): Promise<CustomField>
```

`PATCH /v1/audience/custom-fields/:ref` · `custom_fields:write` · **200**

Every field from `create` except `slug`, all optional. The slug is not updatable:
values already stored under it would be orphaned.

---

## delete

```ts
crm.customFields.delete(ref: string): Promise<void>
```

`DELETE /v1/audience/custom-fields/:ref` · `custom_fields:write` · **204**, no body.

Deleting the definition does not rewrite the contacts that hold values under its
slug; those values stay in `custom_field_hash` and simply stop being described.
