# Contact Consent

> Read and record a contact's opt-in or opt-out for email, SMS, WhatsApp and voice

URL: https://docs.lemuai.com/api-reference/contacts/consents

Each contact has a consent status for every channel. LemuAI checks it before a journey or campaign sends a message or places a call, so recording opt-ins and opt-outs from your own system (a signup form, a preference center, a support ticket) keeps your messages within what each person agreed to.

## How consent works

Every channel has one of three states:

| Status | Meaning |
|---|---|
| `subscribed` | The person opted in to this channel. |
| `unsubscribed` | The person opted out of this channel. On WhatsApp this stops marketing: replies in a chat they start, utility templates and authentication codes still go. |
| `null` (unknown) | Nothing has been recorded for this channel yet. |

What happens when the status is unknown depends on the channel:

| Channel | Unknown means |
|---|---|
| `voice` | Allowed |
| `whatsapp` | Allowed |
| `email` | Not allowed for marketing email |
| `sms` | Not allowed |

The contact's `opted_out` flag is a separate "do not contact" switch. When it is `true`, no channel is allowed, whatever the per-channel status says. Recording a channel status with this API doesn't change `opted_out`.

Each response includes `can_contact` for every channel, which applies all of these rules for you.

**Note:** For marketing email, your workspace's email settings can also allow sending when consent is unknown. Transactional email (order and account updates sent with [Send a transactional email](https://docs.lemuai.com/api-reference/email/send)) doesn't need consent, but is never sent to an address on your suppression list, for example after a hard bounce, a spam complaint or an unsubscribe.

## Get a contact's consent

Returns the consent state for all four channels, including channels with nothing recorded.

**Endpoint:** `GET /api/v1/contacts/{contact_id}/consents`

### Headers

| Name | Required | Description |
|---|---|---|
| `X-API-Key` | Yes | An API key from your organization. See [Authentication](https://docs.lemuai.com/api-reference/authentication). |

### Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `contact_id` | integer | Yes | The contact's `id`, from [List contacts](https://docs.lemuai.com/api-reference/contacts/list) or an upsert response. |

**Example request:**

**cURL**

```bash
curl https://app.lemuai.com/api/v1/contacts/901/consents \
  -H "X-API-Key: lemu_your_api_key"
```

**JavaScript**

```js
const res = await fetch("https://app.lemuai.com/api/v1/contacts/901/consents", {
  method: "GET",
  headers: {
    "X-API-Key": process.env.LEMU_API_KEY,
  },
});
if (!res.ok) throw new Error(`LemuAI API ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data);
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://app.lemuai.com/api/v1/contacts/901/consents",
    headers={
        "X-API-Key": os.environ["LEMU_API_KEY"],
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

### Response

**`200`**
```json
{
  "contact_id": 901,
  "opted_out": false,
  "consents": [
    {
      "channel": "email",
      "status": "subscribed",
      "source": "signup_form",
      "source_detail": { "form": "footer-newsletter" },
      "updated_at": "2026-10-20T08:12:44Z",
      "can_contact": true
    },
    {
      "channel": "sms",
      "status": null,
      "source": null,
      "source_detail": {},
      "updated_at": null,
      "can_contact": false
    },
    {
      "channel": "whatsapp",
      "status": "unsubscribed",
      "source": "manual",
      "source_detail": {},
      "updated_at": "2026-10-22T11:03:10Z",
      "can_contact": false
    },
    {
      "channel": "voice",
      "status": null,
      "source": null,
      "source_detail": {},
      "updated_at": null,
      "can_contact": true
    }
  ]
}
```

| Field | Type | Description |
|---|---|---|
| `contact_id` | integer | The contact. |
| `opted_out` | boolean | The contact's "do not contact" switch. When `true`, `can_contact` is `false` for every channel. |
| `consents` | array | One entry per channel: `email`, `sms`, `whatsapp` and `voice`. |
| `consents[].channel` | string | The channel. |
| `consents[].status` | string or null | `subscribed`, `unsubscribed`, or `null` when nothing has been recorded. |
| `consents[].source` | string or null | Where the latest status came from, as sent when it was recorded (for example `manual`, `signup_form` or `checkout`). |
| `consents[].source_detail` | object | Any extra details sent with the latest status. |
| `consents[].updated_at` | string or null | When the status was last recorded, in ISO 8601 (UTC). |
| `consents[].can_contact` | boolean | Whether a message or call on this channel may go to this contact right now. |

## Record consent for one channel

Sets the status for one channel. Every change is also kept in the contact's consent history.

**Endpoint:** `PUT /api/v1/contacts/{contact_id}/consents/{channel}`

### Headers (record)

| Name | Required | Description |
|---|---|---|
| `X-API-Key` | Yes | An API key from your organization. See [Authentication](https://docs.lemuai.com/api-reference/authentication). |
| `Content-Type` | Yes | `application/json` |

### Path parameters (record)

| Name | Type | Required | Description |
|---|---|---|---|
| `contact_id` | integer | Yes | The contact's `id`. |
| `channel` | string | Yes | `email`, `sms`, `whatsapp` or `voice`. |

### Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `status` | string | Yes | `subscribed` or `unsubscribed`. |
| `source` | string | No | Where the decision came from, 1 to 64 characters, for example `signup_form`, `checkout` or `support`. Default `manual`. |
| `source_detail` | object | No | Any extra details you want kept with the decision, such as a form name or the text the person agreed to. |

**Example request:**

**cURL**

```bash
curl -X PUT https://app.lemuai.com/api/v1/contacts/901/consents/whatsapp \
  -H "X-API-Key: lemu_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "subscribed",
    "source": "checkout",
    "source_detail": { "order_id": "SO-10422", "checkbox": "Send me order updates on WhatsApp" }
  }'
```

**JavaScript**

```js
const res = await fetch("https://app.lemuai.com/api/v1/contacts/901/consents/whatsapp", {
  method: "PUT",
  headers: {
    "X-API-Key": process.env.LEMU_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "status": "subscribed",
    "source": "checkout",
    "source_detail": {
      "order_id": "SO-10422",
      "checkbox": "Send me order updates on WhatsApp"
    }
  }),
});
if (!res.ok) throw new Error(`LemuAI API ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data);
```

**Python**

```python
import os

import requests

response = requests.put(
    "https://app.lemuai.com/api/v1/contacts/901/consents/whatsapp",
    headers={
        "X-API-Key": os.environ["LEMU_API_KEY"],
    },
    json={
        "status": "subscribed",
        "source": "checkout",
        "source_detail": {
            "order_id": "SO-10422",
            "checkbox": "Send me order updates on WhatsApp",
        },
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

### Response (record)

**`200`**: the full consent state for the contact, in the same shape as [Get a contact's consent](#get-a-contacts-consent).

### Errors

| Status | When |
|---|---|
| `401` | The API key is missing or not valid. |
| `404` | No contact with this id in your organization. |
| `422` | `channel` isn't one of the four channels, `status` isn't `subscribed` or `unsubscribed`, or `source` is empty or too long. |

See [Errors](https://docs.lemuai.com/api-reference/errors) for the error format.
