# Audiences & contacts

- Page: https://bytesms.com/docs/audiences (markdown: https://bytesms.com/docs/audiences.md)
- API base URL: https://api.bytesms.com/api (public resources under /api/v1)
- Auth: `Authorization: Bearer tp_live_…` — an API key from Dashboard → API Keys; keep it server-side (e.g. `BYTESMS_API_KEY`)
- All docs in one file: https://bytesms.com/llms-full.txt · OpenAPI 3.1: https://bytesms.com/openapi.json

Manage Bytesms audiences and the contacts you send marketing broadcasts to, including unsubscribe state.

An audience is a list of contacts you send [broadcasts](https://bytesms.com/docs/broadcasts) to. Contacts belong to one audience; the same email address can be a contact in several audiences. All endpoints require a `full_access` key.

## Create an audience

`POST https://api.bytesms.com/api/v1/audiences`

**Body**

- `name` (string, required): 1–200 characters.

**cURL**

```bash
# Create an audience
curl -X POST 'https://api.bytesms.com/api/v1/audiences' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"name":"Newsletter"}'
```

**Node.js**

```js
// Create an audience
const res = await fetch("https://api.bytesms.com/api/v1/audiences", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "Newsletter"
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Create an audience
res = requests.post(
    "https://api.bytesms.com/api/v1/audiences",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "name": "Newsletter"
    },
)
print(res.json())
```

**Response**

```json
{
  "object": "audience",
  "id": "cmg4p3v1e0006l8v9k8d2m5nb",
  "name": "Newsletter"
}
```

The number of audiences is limited on the free Marketing plan (`403 plan_limit_exceeded`, `code: segment_limit_reached`).

### List, retrieve and delete audiences

`GET https://api.bytesms.com/api/v1/audiences`

`GET https://api.bytesms.com/api/v1/audiences/{audience_id}`

`DELETE https://api.bytesms.com/api/v1/audiences/{audience_id}`

**GET /v1/audiences**

```json
{
  "object": "list",
  "has_more": false,
  "data": [
    {
      "object": "audience",
      "id": "cmg4p3v1e0006l8v9k8d2m5nb",
      "name": "Newsletter",
      "created_at": "2026-09-28T09:55:00.000Z"
    }
  ]
}
```

**DELETE /v1/audiences/{audience_id}**

```json
{
  "object": "audience",
  "id": "cmg4p3v1e0006l8v9k8d2m5nb",
  "deleted": true
}
```

## Create a contact

`POST https://api.bytesms.com/api/v1/audiences/{audience_id}/contacts`

**Body**

- `email` (string, required): A valid email address (stored lower-cased). Unique per audience.
- `first_name` (string, optional): ≤ 200 characters.
- `last_name` (string, optional): ≤ 200 characters.
- `unsubscribed` (boolean, optional, default `false`): Unsubscribed contacts are skipped when a broadcast is sent.
- `properties` (object, optional): Custom fields for personalisation, e.g. `{ "plan": "pro" }`. Values are strings (truncated to 1,000 characters), numbers or booleans; at most 100 per contact. Keys are normalised to lower-case `snake_case` and registered as workspace contact properties.

**cURL**

```bash
# Create a contact
curl -X POST 'https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"email":"jane@example.com","first_name":"Jane","last_name":"Doe","properties":{"plan":"pro","seats":5}}'
```

**Node.js**

```js
// Create a contact
const res = await fetch("https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "email": "jane@example.com",
    "first_name": "Jane",
    "last_name": "Doe",
    "properties": {
      "plan": "pro",
      "seats": 5
    }
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Create a contact
res = requests.post(
    "https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "email": "jane@example.com",
        "first_name": "Jane",
        "last_name": "Doe",
        "properties": {
            "plan": "pro",
            "seats": 5
        }
    },
)
print(res.json())
```

**Response**

```json
{
  "object": "contact",
  "id": "cmg4p7x4f0007l8v9t6a9q1zc"
}
```

A duplicate email is `409 validation_error`. Contacts are limited by your Marketing plan (`403 plan_limit_exceeded`, `code: contact_limit_reached`).

## Retrieve a contact

`GET https://api.bytesms.com/api/v1/audiences/{audience_id}/contacts/{contact_id_or_email}`

Look a contact up by id or by email address.

**cURL**

```bash
# Retrieve a contact
curl -X GET 'https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts/jane@example.com' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx'
```

**Node.js**

```js
// Retrieve a contact
const res = await fetch("https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts/jane@example.com", {
  method: "GET",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
  },
});
console.log(await res.json());
```

**Python**

```python
import requests

# Retrieve a contact
res = requests.get(
    "https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts/jane@example.com",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
)
print(res.json())
```

**Response**

```json
{
  "object": "contact",
  "id": "cmg4p7x4f0007l8v9t6a9q1zc",
  "audience_id": "cmg4p3v1e0006l8v9k8d2m5nb",
  "email": "jane@example.com",
  "first_name": "Jane",
  "last_name": "Doe",
  "unsubscribed": false,
  "properties": {
    "plan": "pro",
    "seats": 5
  },
  "created_at": "2026-09-28T10:00:00.000Z",
  "updated_at": "2026-09-28T10:00:00.000Z"
}
```

## List contacts

`GET https://api.bytesms.com/api/v1/audiences/{audience_id}/contacts`

**Query**

- `limit` (integer, optional, default `100`): Page size, 1–500.
- `page` (integer, optional, default `1`): Page number (newest first). `has_more` tells you if there is another page.

**cURL**

```bash
# List contacts
curl -X GET 'https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts?limit=100&page=1' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx'
```

**Node.js**

```js
// List contacts
const res = await fetch("https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts?limit=100&page=1", {
  method: "GET",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
  },
});
console.log(await res.json());
```

**Python**

```python
import requests

# List contacts
res = requests.get(
    "https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts?limit=100&page=1",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
)
print(res.json())
```

**Response**

```json
{
  "object": "list",
  "has_more": false,
  "data": [
    {
      "object": "contact",
      "id": "cmg4p7x4f0007l8v9t6a9q1zc",
      "audience_id": "cmg4p3v1e0006l8v9k8d2m5nb",
      "email": "jane@example.com",
      "first_name": "Jane",
      "last_name": "Doe",
      "unsubscribed": false,
      "properties": {
        "plan": "pro",
        "seats": 5
      },
      "created_at": "2026-09-28T10:00:00.000Z",
      "updated_at": "2026-09-28T10:00:00.000Z"
    }
  ]
}
```

## Update a contact

`PATCH https://api.bytesms.com/api/v1/audiences/{audience_id}/contacts/{contact_id_or_email}`

Same fields as create, all optional. `properties` are merged into the existing ones. Returns `{ object: "contact", id }`.

**cURL**

```bash
# Unsubscribe a contact
curl -X PATCH 'https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts/jane@example.com' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"unsubscribed":true}'
```

**Node.js**

```js
// Unsubscribe a contact
const res = await fetch("https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts/jane@example.com", {
  method: "PATCH",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "unsubscribed": true
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Unsubscribe a contact
res = requests.patch(
    "https://api.bytesms.com/api/v1/audiences/cmg4p3v1e0006l8v9k8d2m5nb/contacts/jane@example.com",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "unsubscribed": True
    },
)
print(res.json())
```

## Delete a contact

`DELETE https://api.bytesms.com/api/v1/audiences/{audience_id}/contacts/{contact_id_or_email}`

**Response**

```json
{
  "object": "contact",
  "contact": "cmg4p7x4f0007l8v9t6a9q1zc",
  "deleted": true
}
```

> **Note: CSV import**
>
> Bulk import from CSV (up to 5 MB) is available in the dashboard under Audience → Import.
