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

# Custom contact data

> Discover each organization's fields, then read and write contact values with the keys, types, and error behavior that organization actually uses.

Every organization defines its own contact fields. A payload that works for one account fails or silently drops keys in another. Read the field list first, then write with the machine names you just received.

> [!NOTE]
>
> New to the envelope, team scope, and HTTP `200` failures? Read [API conventions](https://developers.conveyour.com/guides/api-conventions.md) first. The endpoint pages are [List fields](https://developers.conveyour.com/api-reference/fields/list-fields.md), [List contacts](https://developers.conveyour.com/api-reference/contacts/list-contacts.md), [Get a contact](https://developers.conveyour.com/api-reference/contacts/get-a-contact.md), [Create a contact](https://developers.conveyour.com/api-reference/contacts/create-a-contact.md), and [Update a contact](https://developers.conveyour.com/api-reference/contacts/update-a-contact.md).

## Discover the fields first

Call [`GET /api/fields`](https://developers.conveyour.com/api-reference/fields/list-fields) for the organization you are about to write. The list is grouped into buckets. Inside a bucket, each field is keyed by its machine `name` and includes:

| Property | Use it to |
| - | - |
| `name` | Send and read the value. This is the key on a default contact list. |
| `label` | Match what a person sees in the product. Labels are unique across the organization, except the label `name`, which is allowed to repeat. |
| `type` | Choose the value shape. The full list is in [Field types and formats](https://developers.conveyour.com/guides/contact-field-types.md). |
| `editable` | Decide whether an update may change it. A false value means an update of that field is rejected. |
| `format` | Expect validation and normalization on update, not a display hint. |
| `values` and `values_enabled` | When values are enabled, a write must match one allowed option exactly, including case. |
| `visible` | A field the caller cannot see is omitted from contact list and get responses. The `name` field is always visible. |

[`POST /api/fields/validate`](https://developers.conveyour.com/api-reference/fields/validate-a-field) checks a **field definition** (whether that field can be created). It does not check a contact's value.

When an import creates a field, the machine name is the label trimmed, lowercased, with every character outside `a-z`, `0-9`, and `_` replaced by `_`. A name or label that is already taken gets a numeric suffix (`2`, `3`, …). The label `name` is left unchanged.

## Names and labels

Send machine names to [`POST /api/contacts`](https://developers.conveyour.com/api-reference/contacts/create-a-contact) and [`PUT /api/contacts/{id}`](https://developers.conveyour.com/api-reference/contacts/update-a-contact). A label that is not also the machine name is an unknown key.

* **Create** rejects the whole request when any key is unknown. The message is `The field {key} is invalid`. Nothing is saved.
* **Update** skips unknown keys and saves the rest.

[`POST /api/analytics/identify`](https://developers.conveyour.com/api-reference/analytics/identify-a-contact) is a different write. It accepts a machine name or a label, and a key that matches nothing **creates a field**. It is queued, so `status: ok` does not mean the contact was saved. Use it when you mean that browser-style identify call. Use the contacts endpoints when you need a saved contact and a real error.

The default contact list is flat and keyed by machine name. Pass `format=v1` on [`GET /api/contacts`](https://developers.conveyour.com/api-reference/contacts/list-contacts) when you need that same flat list keyed by label.

## Check the field, then write

Before you send a value:

1. Confirm `name`. Copy it from `GET /api/fields`.
2. Confirm `editable` is true when you are updating.
3. Confirm `type`, and `format` if it is set. Formats run on update.
4. When `values_enabled` is true, send one of `values` exactly. `Yes` does not match `yes`. An empty string and null skip this check.

On update, a field you cannot edit fails the request with `field {name} is not editable`. Create does not apply that editable check.

A related custom object field also requires `custom_objects`, `manage_custom_objects`, or `manage_custom_records` on update. Without one of those, the update fails with the same not-editable message.

## Sample payloads

> [!WARNING]
>
> `crew_role`, `hire_date`, and `site` below belong to a **sample organization**. They are not built-in fields. Replace them with `name` values from your own `GET /api/fields` response.

Create the contact. `first_name` and `last_name` are required. `email` is optional. When you do send `email`, it is stored lowercased.

```bash theme={null}
curl -X POST "https://<your-subdomain>.conveyour.com/api/contacts" \
  -H "x-conveyour-token: YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "Jane",
    "last_name": "Doe",
    "email": "jane@example.com",
    "crew_role": "Installer",
    "hire_date": "2024-06-15"
  }'
```

Update one field. Keys you omit stay as they are. This call does not create a contact when the id is missing.

```bash theme={null}
curl -X PUT "https://<your-subdomain>.conveyour.com/api/contacts/CONTACT_ID" \
  -H "x-conveyour-token: YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "crew_role": "Lead" }'
```

## Validation and errors

Branch on `status`. Create and update do not report failure the same way, and there is no upsert: `POST /api/contacts` only creates, and `PUT` with an unknown id returns HTTP `404` and `Contact not found`.

| | Create | Update |
| - | - | - |
| Required | `first_name` and `last_name`, after field checks pass | No required name fields |
| Unknown key | Fails the whole request | Skipped |
| How many errors | Every field error in that request | The first error only |
| HTTP status | `200` with `status: "failed"` | `400` when a field value fails. `404` when the contact is missing |
| Message | `failed to create contact` | `The contact can not be edited` |

Create collects field errors first. The required-name rules run only when those field errors are empty, so a bad key hides a missing `last_name` until you fix the key.

A failed create looks like this. `data` is a one-element list. The inner `messages` object is keyed by the **request field name**. The `format` value is the literal string `:message`.

```json theme={null}
{
  "status": "failed",
  "message": "failed to create contact",
  "data": [
    {
      "messages": {
        "last_name": ["The last_name field is required."]
      },
      "format": ":message"
    }
  ]
}
```

A failed update uses the message `The contact can not be edited` and HTTP `400`. The `data` key is not one shape:

* A bad type or a format failure is keyed by the field **label**.
* A value outside `values` is keyed by the bucket id, `_<bucketId>`.
* A field that is not editable is a string in the list, `field {name} is not editable`.
* `email`, `mobile`, or an `iskey` field already used on another contact is under `con_keys`, with the message `email, mobile, or key field already in use in another contact`.

```json theme={null}
{
  "status": "failed",
  "message": "The contact can not be edited",
  "data": [
    {
      "messages": {
        "Badge Number": ["The field Badge Number should be of type text"]
      }
    }
  ]
}
```

If the save fails and the editor recorded no field error, update returns that same message with HTTP `200` and `"data": []`.

Deleting a missing contact, or a contact this organization does not own, is HTTP `200`, `status: "failed"`, message `The contact can not be deleted`. Getting a missing contact is HTTP `200` and `Cannot find contact`.

Uniqueness of `email`, `mobile`, and `iskey` is checked on the default bucket. A phone number that can be parsed is stored on the uniqueness index in E.164. The `mobile` value saved on the contact is the validated string you sent, not a rewritten E.164 value. Search uses the same split: a value that parses as a phone matches that E.164 index, a value that matches an email matches the lowercased email index, and anything else is a quoted text search.

What an unknown `filters[...]` key does on list is not specified. Send keys you read from `GET /api/fields`.

## Flat list and bucketed get

[`GET /api/contacts`](https://developers.conveyour.com/api-reference/contacts/list-contacts) returns a flat object per contact. Custom fields sit next to `first_name` under their machine names. [`GET /api/contacts/{id}`](https://developers.conveyour.com/api-reference/contacts/get-a-contact) with the internal id returns buckets. Each bucket has a `fields` map, and each field includes its metadata plus `value`.

```json theme={null}
{
  "1165": {
    "title": "Profile",
    "fields": {
      "crew_role": {
        "label": "Crew role",
        "type": "string",
        "name": "crew_role",
        "editable": true,
        "value": "Installer"
      }
    }
  },
  "con_id": "6a1445f03af9bb089d10e1ad",
  "supervisor_child_cnt": 1
}
```

> [!NOTE]
>
> Bucket id `1165` and `crew_role` are sample data. Your bucket ids and field names come from `GET /api/fields`.

A few read rules apply to both calls:

* Fields the caller cannot see are omitted.
* On the **flat list only**, when two buckets share a machine name and the value already stored is a string, the later value is appended with a space. The bucketed get keeps each bucket separate.
* The `fields` projection drops any name that is not a field. You get no error.
* Each related-contacts field adds `{name}_child_cnt` (an integer, `0` when empty). On the list it sits on the flat contact. On get it sits on the root, beside the bucket ids.
* `created_at`, `last_seen`, `last_reply`, and any field whose suffix is `First` or `Last`, are Unix timestamps. Other `date` values are `Y-m-d`. `time` values are ISO 8601.
* A `secret` field comes back encrypted. [`GET /api/contacts/{id}/reveal-secret`](https://developers.conveyour.com/api-reference/contacts/reveal-a-secret-field) returns the plaintext `field_value`. Pass `public_key` when the org requires one.

A 10-character id on get is the public portal id. That response is only `{ "con_id": "..." }` and the message `Contact ID Found`.

## Related values

Related contacts and related custom objects use different keys and different failure rules. The shapes, the 50-link cap, and the list `add` / `remove` behavior are in [Field types and formats](https://developers.conveyour.com/guides/contact-field-types.md).

Form submissions for one person take `con_id` on [`GET /api/form/submissions`](https://developers.conveyour.com/api-reference/forms/list-submissions). The filter is applied when `con_id` is a valid ObjectId, from the query string or the JSON body. The submissions controller uses that same scope for the other submission actions that load records through it.


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