# Custom fields

Read and write the fields your organisation added to projects, customers, contacts, users, work items and agenda events, and look up what each field takes.

An organisation can add its own fields to its record types under **Settings > Modules > Custom fields** in plnnrly. Over the API, those values sit in one object on the record, `custom_fields`, keyed by each field's `code`. These resources carry it:

| Resource      | Read                              | Write                                                                         |
| ------------- | --------------------------------- | ----------------------------------------------------------------------------- |
| Projects      | `GET /projects/{project}`         | `POST /projects`, `PATCH /projects/{project}`                                 |
| Customers     | `GET /customers/{customer}`       | `POST /customers`, `PATCH /customers/{customer}`                              |
| Contacts      | `GET /contacts/{contact}`         | `POST /contacts`, `PATCH /contacts/{contact}`, for a customer's contacts only |
| Users         | `GET /users/{user}` and `GET /me` | not over the API                                                              |
| Work items    | `GET /work-items/{work_item}`     | `POST /work-items`, `PATCH /work-items/{work_item}`                           |
| Agenda events | `GET /events/{event}`             | `POST /events`, `PATCH /events/{event}`                                       |

> **Note:**
> Custom fields are there only while your organisation has added the Custom fields module and switched it on. Without it, `GET /custom-fields` answers `404` [endpoint-not-found](https://developers.plnnrly.com/en/docs/api/v2/guides/errors/#endpoint-not-found) and every record's `custom_fields` is `{}`.

## Reading values

`custom_fields` is part of a record's detail view: one record (`GET /customers/{customer}`) or a list with `view=detail`. It lists every active field of that record type, with `null` for a field that has no value:

```json
{
  "id": 3107,
  "name": "Acme Logistics",
  "custom_fields": {
    "licence_plate": "AB-12-CD",
    "fleet_size": 4,
    "fuel_type": 12,
    "regions": [31, 33],
    "contract_value": "12500.00",
    "renewal_date": "2027-01-31",
    "notes": null
  }
}
```

Each value has the shape of its field's `type`:

| `type`                                                | Value                                                      |
| ----------------------------------------------------- | ---------------------------------------------------------- |
| `text`, `textarea`, `color-picker`, `markdown-editor` | a string                                                   |
| `rich-editor`                                         | HTML, sanitised the way plnnrly shows it                   |
| `email`, `phone`, `link`, `tags-input`                | a list of strings                                          |
| `number`                                              | an integer                                                 |
| `currency`                                            | a decimal string, such as `"12500.00"`                     |
| `date`                                                | `YYYY-MM-DD`                                               |
| `date-time`                                           | a UTC date-time with a `Z`, such as `2026-11-04T09:30:00Z` |
| `checkbox`, `toggle`                                  | `true` or `false`                                          |
| `select`, `radio`, `toggle-buttons`                   | the id of the chosen option                                |
| `multi-select`, `checkbox-list`                       | a list of option ids                                       |

A contact only takes custom fields while it belongs to a customer: a user's emergency contact always has `{}`. On a recurring agenda event, the values belong to the whole series. An occurrence that was edited on its own keeps its own copy, so a later change to the series does not reach it.

## What each field means

`GET /custom-fields` lists the active fields, and `GET /custom-fields/{custom_field}` reads one. Narrow the list to one record type with `filter[entity_type]=customer`:

```json
{
  "id": 41,
  "code": "fuel_type",
  "name": "Fuel type",
  "description": "What most of the fleet runs on.",
  "type": "select",
  "entity_type": "customer",
  "section": { "id": 6, "name": "Fleet" },
  "required": false,
  "api_writable": true,
  "sort_order": 3,
  "options": [
    { "id": 12, "name": "Diesel" },
    { "id": 13, "name": "Electric" }
  ]
}
```

- **The code** is the key in `custom_fields`. It never changes once the field exists, so store `code` rather than `name`.
- **Options** are the ids a choice takes, in order, in `options`. A value is always an option id, never its name.
- **A required field** (`required` is `true`) may be left out of a write, but not cleared.
- **A read-only field** has `api_writable` set to `false`: the API cannot set it.
- `entity_type` is one of `project`, `customer`, `contact`, `user`, `work_item` and `event`.

You only see the fields of record types you may read, with a token that reaches them. The endpoints need no permission of their own, and any token with a read ability reaches them.

## Writing values

Send `custom_fields` with a record's `POST` or `PATCH`, holding only the codes you change. A code you leave out keeps its value, and `null` clears one:

```http
PATCH /api/v2/customers/3107
Content-Type: application/json

{
  "custom_fields": {
    "fleet_size": 5,
    "notes": null
  }
}
```

This sets `fleet_size`, clears `notes` and leaves `licence_plate`, `fuel_type` and the others as they were. The record's `updated_at` and `ETag` move even when only custom fields changed, so [conditional requests](https://developers.plnnrly.com/en/docs/api/v2/guides/concurrency-and-etags/) and [sync](https://developers.plnnrly.com/en/docs/api/v2/guides/syncing-data/) see the change. On a work item, a changed value raises `version` once, together with any other field in the same `PATCH`.

A write is refused with `422` [validation-failed](https://developers.plnnrly.com/en/docs/api/v2/guides/errors/#validation-failed), its error pointing at the field, such as `/custom_fields/fuel_type`, when:

- the code is not an active field of that record type, or the field is not `api_writable` (`prohibited`);
- the value does not fit the field, such as an option id of another field, or a date in another format;
- a `required` field is sent as `null` (`required`);
- the organisation does not use custom fields, or the record takes none, such as a user's emergency contact, and `custom_fields` is not empty (`prohibited`).

## What is not supported yet

- **No filtering or sorting by a custom field.** Lists cannot be narrowed or ordered by a value in `custom_fields`. Read the records and filter them yourself.
- **Fields are managed in plnnrly only.** The API reads field definitions but cannot add, change or remove them.

See [What the API cannot do](https://developers.plnnrly.com/en/docs/api/v2/guides/known-limitations/) for the rest.
