Skip to main content

CustomFields API

Tenant-defined fields attached to contacts and conversations Base path: /api/v1/custom-fields Endpoint count: 10

title: “Errors worth branching on” description: “Per-endpoint failure templates matching the envelope — what actually fires, what to retry, what to surface to the operator.”

Errors worth branching on

These five failures cover the custom-field create (POST /api/v1/custom-fields), which every form-builder save flows through. Each block below is a full { error, meta } envelope as the API returns it, and the matrix at the bottom answers retry vs surface for the same five classes. For the platform-wide decision table these branches plug into, see the error handling guide.

401 — Unauthorized

A 401 on this page is the bearer key failing before the route ran — it never means the resource is wrong. Rotate the key or re-mint the scoped token; retrying the same request changes nothing.

403 — Forbidden

A 403 means the key authenticated but the operation is gated by scope — check the key’s scopes on the developer page; a 403 is never a data-not-found shape.

422 — Schema

A 422 means the payload did not match the request schema — branch on error.details.field and resend with an allowed name (letters/digits/hyphens/underscores) instead of blind-retrying the same body.

429 — Rate

The Retry-After header and error.details.retry_after are both set on every 429 — resend the SAME request after the lower of the two.

409 — Conflict

Retry with PATCH against the existing field — do not rename-and-forget.

60-second retry matrix

Worked request and response samples

Copy the request as written, substitute your own ids, and compare the response envelope — a success in the same shape the numbered error sections spell out.

Define a custom field

POST /api/v1/custom-fields
Schema-safe extensions to a contact record — the field lands on the explorer once created and honors dependencies. Request

Worked sequences — field lifecycle

The blocks below walk one field through its whole life, end to end: define it, list and inspect it in the schema, edit what stays editable, retire it safely, and push values onto contacts. Each sample is a full request or response envelope you can copy; substitute your own ids. The error matrix above stays the branch table for every step.

1 — Define a field (with an enum variant)

The select create above is the common shape. For a closed vocabulary of values, declare type: enum with the allowed values inline in enum_values — values written to contacts are rejected at the door if they are not in the list.
201

2 — List the schema and diff one field

List every definition the tenant has, then read one field back for the full validator set. The schema-diff check before a PATCH or DELETE is: GET list → GET {id} → GET {id}/dependencies (blast radius) or {id}/explorer (usage + redacted samples).
200

3 — Update what is editable; skip what is immutable

PATCH rewrites the label, description, options, default value, the required / searchable flags, and validators (validator_regex, min_len, max_len, enum_values). The key and type are frozen — send them in the body and they are ignored; a rename of values already stored on contacts is how you orphan data. Passing null for a validator or default_value clears it.
200
The key (vip_band) and type (select) come back unchanged — that is your confirmation the immutable pair survived the PATCH.

4 — Retire a field: dependency gate, then force-delete

DELETE is the archive path. Run it without force first: if any segment, campaign, drip enrollment, or flow still references the field you get a 409 carrying the full dependency snapshot — that is the undo-safe version of the call, nothing was removed. Once the dependents are cleaned up (or deliberately abandoned), re-send with ?force=true; dependents are flagged broken and the definition plus every stored value is stripped from contacts.
204 No Content — the field is archived and its key stripped from every contact.

5 — Backfill a segment, then read it back through Contacts

Values land on a contact through PUT /api/v1/custom-fields/values, one field per call, validated against the definition. Backfill a segment by iterating contact ids — the same call idempotent per contact — and confirm the write by reading the contact back through GET /api/v1/contacts/{id}.
200 — write accepted
200 — read-back through Contacts
For a bulk segment backfill, run the PUT per contact id; a rejected value returns 422 with error.details.field set to the failing key, matching the 422 branch in the matrix above.

List custom field definitions

GET /api/v1/custom-fields
List every custom-field definition configured for the current tenant, in display order. Populates the Settings › Custom Fields table and the field pickers in the segment builder and contact detail. Returns an empty list for a freshly-provisioned tenant.

Get a custom field definition

GET /api/v1/custom-fields/{id}
Fetch a single custom-field definition by id, including its type, options, default value, validators (regex / min_len / max_len / enum_values) and required/searchable flags. Returns 404 if no definition with that id exists for the tenant.
string
required
—

Scan dependents (segments / campaigns / flows / contacts)

GET /api/v1/custom-fields/{id}/dependencies
Scan every surface that references this custom field — contacts holding a value, plus segments, campaigns, drip enrollments and flows filtering on it — and return the counts, so the UI can preview the blast radius before a force-delete. Returns zeroed counts when the field is unused; 404 if the definition does not exist.
string
required
—

Schema-explorer payload: definition + usage counts + last-10 PII-redacted sample values

GET /api/v1/custom-fields/{id}/explorer
Return the schema-explorer payload for one field: its definition, usage counts across contacts / segments / campaigns / drip enrollments / flows, and up to ten of the most recent distinct, PII-redacted sample values stored under the field key. Powers the field drill-down panel. Returns 404 if the definition does not exist.
string
required
—

Create a custom field definition

POST /api/v1/custom-fields
Create a custom-field definition for the tenant. The key and type are immutable once set; select / multiselect fields require options, and enum_values / min_len / max_len apply per type. Returns 201 with the created definition and rejects invalid payloads with 422.

Reorder custom field definitions

POST /api/v1/custom-fields/reorder
Persist a new top-to-bottom display order for the tenant’s custom-field definitions from a list of definition ids. Unknown ids are ignored and omitted ids keep their current order; duplicate ids are rejected with 422. Returns the refreshed, reordered definition list.
string[]
required
Custom-field definition ids in the desired top-to-bottom display order (1–500 ids). Unknown ids are ignored and any definitions omitted from the list keep their current order.

Propose a custom field definition from a description

POST /api/v1/custom-fields/suggest
Turn a plain-language description (“a dropdown for subscription tier with options Basic, Pro, Enterprise”) into a draft field definition — type, key, options, required/searchable — matching what the manual dialog captures. Returns a DRAFT only; nothing is created until the admin saves it through POST /custom-fields. The type is chosen from the platform’s fixed list; a description implying another type resolves to the closest one.

Set a custom-field value on a contact

PUT /api/v1/custom-fields/values
Set a single custom-field value on one contact, validated against the field definition, and persist it to the contact’s custom_attributes. Invalidates the contact-detail cache so the next read reflects the write. Returns the contact id, key and an ok flag.
string
required
Id of the contact whose custom-field value is being set (1–128 characters).
string
required
Machine key of the custom-field definition to write, in snake_case (up to 40 characters).
string | number | boolean | string[] | null
required
Value to store for this field. Its JSON type must match the field’s declared type — a string for text / select, a number for number, a boolean for boolean, an ISO-8601 string for date, or an array of strings for multiselect.

Update a custom field definition

PATCH /api/v1/custom-fields/{id}
Update a custom-field definition’s editable attributes (name, description, options, default value, required / searchable flags and validators). The key and type stay frozen so stored values are never orphaned; passing null clears a validator or the default. Returns 404 if the definition does not exist.
string
required
—

Delete a custom field definition

DELETE /api/v1/custom-fields/{id}
Delete a custom-field definition and strip its key from every contact. Without force=true, a field still referenced by any segment, campaign, drip enrollment or flow returns 409 with the full dependency snapshot; with force=true, dependents are flagged broken and the field is removed. Returns 204 on success.
string
required
—
Response: 204 No Content