# Broadcast API - V2

URL: https://developers.cuedesk.com/api/broadcasts/broadcasts_api_v2

> Send WhatsApp template broadcasts from a tabular payload, with per-recipient variables and fallbacks.

The V2 Broadcasts API uses a **payload-variable** model. You supply a tabular `payload` (like a CSV) where each row is a recipient, and the `template` object maps column names to template variable slots via `payload_variable` fields with optional `fallback` values.

See the [authentication](/api/authentication) page for how to obtain a bearer token.

## Create a Broadcast [#create-a-broadcast]

```text
POST https://api.cuedesk.com/v2/broadcasts
Authorization: Bearer <token>
Content-Type: application/json
```

### Examples [#examples]

<Tabs items={["Standard Template","Carousel Template","Using a Contact List"]}>
<Tab value="Standard Template">

```json
{
  "name": "Holiday Sale",
  "from": "447576209857",
  "scheduled_at": "2024-06-15T10:00:00Z",
  "valid_until": "2024-12-31T23:59:59Z",
  "client_unique_identifier": "abe120b4-048c-4d00-9c1a-0b01d34c583c",
  "template": {
    "name": "holiday_sale_template",
    "locale": "en",
    "header": {
      "type": "image",
      "payload_variable": "header_image_url",
      "fallback": "https://www.example.com/default-sale.jpg"
    },
    "body": {
      "payload_variables": ["first_name", "discount_code", "expiry_date"],
      "fallbacks": ["Customer", "SALE2024", "31 Dec"]
    },
    "buttons": [
      {
        "index": 0,
        "type": "URL",
        "payload_variable": "tracking_url_suffix",
        "fallback": "default"
      }
    ]
  },
  "payload": [
    {
      "identifier": "447592850122",
      "client_reference": "order-abc-123",
      "first_name": "Alex",
      "discount_code": "ALEX20",
      "expiry_date": "25 Dec",
      "header_image_url": "https://www.example.com/alex-promo.jpg",
      "tracking_url_suffix": "alex-campaign"
    },
    {
      "identifier": "27827134468",
      "client_reference": "order-def-456",
      "first_name": "Jordan",
      "discount_code": "JORDAN15",
      "expiry_date": "30 Dec"
    }
  ]
}
```

In this example, the second recipient does not have `header_image_url` or `tracking_url_suffix` in their payload row, so the `fallback` values from the template definition will be used instead.

</Tab>
<Tab value="Carousel Template">

```json
{
  "name": "Product Showcase",
  "from": "447576209857",
  "scheduled_at": "2024-06-15T10:00:00Z",
  "template": {
    "name": "product_carousel_template",
    "locale": "en",
    "body": {
      "payload_variables": ["first_name"],
      "fallbacks": ["Customer"]
    },
    "cards": [
      {
        "index": 0,
        "header": {
          "type": "image",
          "payload_variable": "card_1_image",
          "fallback": "https://www.example.com/product1.jpg"
        },
        "body": {
          "payload_variables": ["card_1_product_name", "card_1_price"],
          "fallbacks": ["Product 1", "$99.00"]
        },
        "buttons": [
          {
            "index": 0,
            "type": "URL",
            "payload_variable": "card_1_url_suffix",
            "fallback": "product-1"
          }
        ]
      },
      {
        "index": 1,
        "header": {
          "type": "image",
          "payload_variable": "card_2_image",
          "fallback": "https://www.example.com/product2.jpg"
        },
        "body": {
          "payload_variables": ["card_2_product_name", "card_2_price"],
          "fallbacks": ["Product 2", "$79.00"]
        },
        "buttons": [
          {
            "index": 0,
            "type": "URL",
            "payload_variable": "card_2_url_suffix",
            "fallback": "product-2"
          }
        ]
      }
    ]
  },
  "payload": [
    {
      "identifier": "447592850122",
      "first_name": "Alex",
      "card_1_product_name": "Running Shoes",
      "card_1_price": "$99.00",
      "card_1_url_suffix": "running-shoes-123",
      "card_2_product_name": "Casual Sneakers",
      "card_2_price": "$79.00",
      "card_2_url_suffix": "casual-sneakers-456"
    },
    {
      "identifier": "27827134468",
      "first_name": "Jordan",
      "card_1_product_name": "Trail Boots",
      "card_1_price": "$120.00",
      "card_1_url_suffix": "trail-boots-789",
      "card_2_product_name": "Slip-Ons",
      "card_2_price": "$49.00",
      "card_2_url_suffix": "slip-ons-012"
    }
  ]
}
```

</Tab>
<Tab value="Using a Contact List">

Instead of providing recipients inline via `payload`, you can reference a pre-uploaded contact list by UUID:

```json
{
  "name": "Monthly Newsletter",
  "from": "447576209857",
  "template": {
    "name": "monthly_newsletter",
    "locale": "en",
    "body": {
      "payload_variables": ["first_name"],
      "fallbacks": ["Subscriber"]
    }
  },
  "contact_list_uuid": "f47ac10b-58cc-4372-a567-0e02b2c3d479"
}
```

<Callout type="info">
When using `contact_list_uuid`, the `payload` field should be omitted. The contact list provides the recipient identifiers and any payload variables associated with each contact.
</Callout>

</Tab>
</Tabs>

### Request Body [#request-body]

| Field                      | Type     | Required | Description                                                                      |
| -------------------------- | -------- | -------- | -------------------------------------------------------------------------------- |
| `name`                     | string   | No       | Name of the broadcast (for your reference)                                       |
| `from`                     | string   | Yes      | Phone number or channel identifier used as the sender                            |
| `scheduled_at`             | datetime | No       | ISO 8601 timestamp for when to send. Sends immediately if omitted                |
| `valid_until`              | datetime | No       | ISO 8601 timestamp after which undelivered messages expire. No expiry if omitted |
| `template`                 | object   | Yes      | Template definition with payload variable mappings                               |
| `payload`                  | array    | No       | Array of recipient rows (max 50,000). Each row is a key-value map                |
| `contact_list_uuid`        | UUID     | No       | UUID of a pre-uploaded contact list. Alternative to `payload`                    |
| `client_unique_identifier` | string   | No       | Idempotency key. See [Retries and timeouts](#retries-and-timeouts)               |

### Template Object [#template-object]

The `template` object defines which template to use and how payload columns map to template variable slots.

| Field     | Type   | Required | Description                             |
| --------- | ------ | -------- | --------------------------------------- |
| `name`    | string | Yes      | Name of the approved WhatsApp template  |
| `locale`  | string | Yes      | Language code (e.g. `en`, `pt_BR`)      |
| `header`  | object | No       | Header variable mapping                 |
| `body`    | object | No       | Body variable mappings                  |
| `buttons` | array  | No       | Button variable mappings                |
| `cards`   | array  | No       | Card definitions for carousel templates |

### Header [#header]

| Field              | Type   | Required | Description                                                                            |
| ------------------ | ------ | -------- | -------------------------------------------------------------------------------------- |
| `type`             | string | No       | Header media type: `image`, `video`, `document`, or `text`                             |
| `payload_variable` | string | No       | Payload column name containing the header value (URL for media, text for text headers) |
| `fallback`         | string | No       | Default value used when `payload_variable` is missing from a recipient's row           |
| `filename`         | string | No       | Filename for `document` type headers                                                   |

<Callout type="warn" title="Media hosting requirements">
When a header (or `fallback`) points at a media URL, WhatsApp fetches the file directly from your server for each recipient. Because a broadcast can deliver to thousands of recipients in a short period, the server hosting the media must be able to handle a high volume of concurrent requests to the media resource. We recommend serving media from a CDN or object storage service built to deliver files at scale. If you use a CDN or web application firewall, make sure it won't flag this burst of requests as bot traffic and block or rate-limit WhatsApp's fetches.
</Callout>

### Body [#body]

| Field               | Type          | Required | Description                                                                                        |
| ------------------- | ------------- | -------- | -------------------------------------------------------------------------------------------------- |
| `payload_variables` | array[string] | No       | Ordered list of payload column names. Position 0 maps to `{{1}}`, position 1 maps to `{{2}}`, etc. |
| `fallbacks`         | array[string] | No       | Positional fallback values. Must be the same length as `payload_variables` if provided             |

### Buttons [#buttons]

| Field              | Type    | Required | Description                                        |
| ------------------ | ------- | -------- | -------------------------------------------------- |
| `index`            | integer | Yes      | Zero-based position of the button in the template  |
| `type`             | string  | No       | Button type: `URL`, `OTP`, `QUICK_REPLY`           |
| `payload_variable` | string  | No       | Payload column name for the button's dynamic value |
| `fallback`         | string  | No       | Default value when `payload_variable` is missing   |

### Cards [#cards]

| Field     | Type    | Required | Description                                                 |
| --------- | ------- | -------- | ----------------------------------------------------------- |
| `index`   | integer | Yes      | Zero-based card position. Fully static cards can be omitted |
| `header`  | object  | No       | Card-level header (same structure as above)                 |
| `body`    | object  | No       | Card-level body (same structure as above)                   |
| `buttons` | array   | No       | Card-level buttons (same structure as above)                |

### Payload [#payload]

The `payload` is an array of objects where each object represents one recipient. Every row must contain an `identifier` key with the recipient's phone number. All other keys are custom column names referenced by `payload_variable` in the template definition.

| Key                | Type   | Required | Description                                                                                |
| ------------------ | ------ | -------- | ------------------------------------------------------------------------------------------ |
| `identifier`       | string | Yes      | Recipient phone number with country code (no leading `+`)                                  |
| `client_reference` | string | No       | Custom reference ID for this recipient, returned in webhook status updates (max 255 chars) |
| _(custom keys)_    | string | No       | Values for payload variables referenced in the template                                    |

<Callout type="warn">
If a recipient row is missing a column referenced by a `payload_variable` and no `fallback` is defined, a warning will be generated for that recipient.
</Callout>

### Response [#response]

#### 200 OK [#200-ok]

```json
{
  "broadcast": {
    "uuid": "d3b3b3b3-3b3b-3b3b-3b3b-3b3b3b3b3b3b",
    "name": "Holiday Sale",
    "scheduled_at": "2024-06-15T10:00:00Z",
    "status": "scheduled",
    "created_at": "2024-06-01T12:00:00Z",
    "recipients": 19750
  },
  "warnings": [
    {
      "identifier": "6563546436",
      "errors": [
        "Missing payload variable 'discount_code' with no fallback defined"
      ]
    }
  ]
}
```

| Field                    | Type          | Description                                                           |
| ------------------------ | ------------- | --------------------------------------------------------------------- |
| `broadcast.uuid`         | UUID          | Unique identifier of the created broadcast                            |
| `broadcast.name`         | string        | Broadcast name                                                        |
| `broadcast.scheduled_at` | datetime      | Scheduled send time (null if immediate)                               |
| `broadcast.status`       | string        | Broadcast status: `scheduled`, `processing`, `completed`, `cancelled` |
| `broadcast.created_at`   | datetime      | When the broadcast was created                                        |
| `broadcast.recipients`   | integer       | Total number of valid recipients                                      |
| `warnings`               | array         | Per-recipient warnings for validation issues                          |
| `warnings[].identifier`  | string        | Recipient phone number                                                |
| `warnings[].errors`      | array[string] | Warning messages for this recipient                                   |

#### Error Responses [#error-responses]

**400 Bad Request:**

```json
{
  "message": "Broadcast could not be created",
  "details": "Template 'holiday_sale_template' not found or not approved"
}
```

**403 Forbidden:**

```json
{
  "message": "Forbidden",
  "details": "Channel does not belong to your workspace"
}
```

**422 Unprocessable Entity:**

```json
{
  "error": {
    "message": "Validation failed",
    "details": "Template parameter count mismatch",
    "violations": [
      {
        "field": "template.body.payload_variables",
        "rule": "PARAMETER_COUNT_MISMATCH",
        "message": "Template expects 3 body parameters but 2 were provided"
      }
    ]
  }
}
```

**504 Gateway Timeout:**

```json
{
  "detail": "The broadcast service did not answer in time. The broadcast may still have been created and sent, so do not create it again. Repeat this request with the same client_unique_identifier to check: an existing broadcast is reported, never sent again."
}
```

The broadcast may exist. See [Retries and timeouts](#retries-and-timeouts) before you send the request again.

## Retries and Timeouts [#retries-and-timeouts]

The API answers a create request only after it has saved every recipient, so a large request can take tens of seconds. Set the timeout of your HTTP client to at least 90 seconds.

### Send a `client_unique_identifier` with every create request [#send-a-client_unique_identifier-with-every-create-request]

`client_unique_identifier` is an idempotency key. Use a new value for each broadcast (a UUID, for example) and keep it until you have a response.

When you repeat a request with a `client_unique_identifier` that your workspace has already used, the API does not create or send a second broadcast. It returns `200 OK` with the broadcast that already exists, with the same `broadcast.uuid`. This also applies while the first request is still being processed.

- Only the identifier is compared, not the rest of the request. A different request with a used identifier returns the earlier broadcast.
- If two requests with the same identifier arrive at almost the same moment, the second one can get `409 Conflict`. Wait a few seconds and repeat it.
- A request without a `client_unique_identifier` has no such protection: each request creates a new broadcast.

### When a create request fails or times out [#when-a-create-request-fails-or-times-out]

A `5xx` response, or a timeout in your HTTP client, does not mean that the broadcast was not created. The broadcast can exist and be sent.

1. Do not create the broadcast again as a new request, and do not change the `client_unique_identifier`.
2. Repeat the same request with the same `client_unique_identifier`.
3. A `200 OK` response contains the broadcast: the one that the first request created, or a new one if the first request created nothing. In both cases only one broadcast exists.
4. Use `broadcast.uuid` with [Get Broadcast Details](/api/broadcasts/broadcasts_api_v1#get-broadcast-details) to see its status.

If the request had no `client_unique_identifier`, do not repeat it. Check the broadcasts in your workspace first.

### 504 Gateway Timeout [#504-gateway-timeout]

The API returns `504 Gateway Timeout` when a create request takes longer than 60 seconds. The `detail` field says what is known:

- `The broadcast service did not answer in time. The broadcast may still have been created and sent, so do not create it again.` The result is unknown. Follow the steps above.
- `The broadcast service could not be reached in time. No broadcast was created, so it is safe to send this request again.` Nothing was created.

A repeat with the same `client_unique_identifier` is safe in both cases.
