# Send API

> Send push, web push, email, SMS, in-app messages and content cards from your backend to named people or a segment, now or on a schedule, with scoped API keys, hourly limits and idempotency.

:::prereq
- An app whose connection sends through Herald. The Send API refuses other connections with a 400.
- An API key for that app with the scopes you need. See [Authentication](#authentication).
- For email: a verified sending domain on the connection.
:::

The Send API sends every channel Herald delivers to people you name or to a segment, immediately or on a schedule, with the message content in the request. Each send shows in the console's campaign list. It uses the same scheduling, local time, quiet hours, suppression and unsubscribe checks as a campaign.

## Authentication

Send `Authorization: Bearer hk_…` with every request. Create keys under **Settings → Sending**, the app, then **API keys**. Herald shows a key once.

A key belongs to one app. Its scopes, optional IP allowlist and optional expiry are fixed when you create it; to change them, create a new key and revoke the old one.

| Scope | Allows |
|---|---|
| `messages.send` | `POST /api/v1/messages/send` |
| `messages.schedule` | A send with `schedule` (together with `messages.send`), and changing or cancelling a scheduled send |
| `messages.read` | Reading one send and listing sends |
| `exports.read` | The [decisions CSV](/docs/reference/server-api#get-api-v1-exports-decisions-csv) |
| `journeys.enter` | [Adding people to a journey](/docs/reference/server-api#post-api-v1-journeys-id-enter) |
| `mcp.read`, `mcp.write` | The [MCP server](/docs/integrations/ai-assistants) |

A missing, unknown, revoked or expired key gets `401 Invalid API key`. A key without a scope gets `403 This API key lacks the <scope> scope`. The ingest token and the app key can never send, and an API key can't call the ingest or console endpoints.

## Base URL

`https://app.runherald.com`. Requests and responses are JSON: `{ "data": ... }` on success and `{ "error": "..." }` on failure.

## Rate limits

Each app has hourly pools, counted per UTC clock hour. A request charges every pool it touches at once: if any would go over, nothing is charged and the response is `429` naming the pool.

| Pool | Counts | Default per hour |
|---|---|---|
| `api.requests` | Any request made with an API key | 36,000 |
| `messages.push` | Recipients | 250,000 |
| `messages.web_push` | Recipients | 250,000 |
| `messages.email` | Recipients | 100,000 |
| `messages.sms` | Recipients | 2,000 |
| `messages.in_app` | Recipients | 250,000 |
| `messages.content_card` | Recipients | 250,000 |
| `messages.broadcast` | Broadcast requests | 25 |
| `messages.schedule` | Change or cancel requests | 1,000 |
| `messages.read` | Status or list requests | 3,600 |

A send charges each channel's pool once per recipient. A broadcast charges `messages.broadcast` once, since its audience size isn't known until it goes out. A `dry_run` charges only `api.requests`. Every response carries the rate-limit headers; see [API errors](/docs/reference/api-errors#rate-limits).

Send API pushes count toward the app's [push limit](/docs/push-notifications/pushes-your-app-sends#the-push-limit) but are never skipped by it.

## Idempotency

Send `Idempotency-Key` (1 to 255 characters) on `POST /api/v1/messages/send` so a retry can't send twice. Keys are per app and kept for 24 hours.

- The same key and the same body (key order doesn't matter) return the first response again, with nothing sent.
- The same key with a different body gets `409 This Idempotency-Key was used with a different request`.
- While the first request is still running, the key gets `409 A request with this Idempotency-Key is still in progress`. A claim unfinished after 2 minutes is treated as abandoned.
- A failed request releases its key, so you can retry with it.
- A `dry_run` never uses the key.

## POST /api/v1/messages/send

Scope `messages.send`, plus `messages.schedule` when the body has `schedule`.

### Request

| Field | Rules |
|---|---|
| `name` | Optional, 1 to 80 characters. Default `API send <time>` |
| `recipients` | 1 to 50 people, each `{ "external_user_id": "...", "properties": { ... } }`. IDs are 1 to 255 characters and unique. `properties` holds strings, numbers or booleans for personalization |
| `broadcast`, `segment` | Instead of `recipients`: `"broadcast": true` and a segment name. Never both |
| `messages` | At least one channel: `push`, `web_push`, `email`, `sms`, `in_app`, `content_card`. See [Channel content](#channel-content) |
| `schedule` | Optional; absent means now. `{ "time": "2026-12-01T09:00:00Z" }` is that instant. `{ "time": "2026-12-01T09:00:00", "in_local_time": true }` (no offset) is each person's local wall time, or the app's time zone when theirs is unknown. In the future and at most 30 days ahead |
| `quiet_hours` | Optional `skip`, `wait` or `off`. Default `off` for recipients (transactional) and `skip` for broadcasts |
| `category` | Optional category key, such as `transactional`, `lifecycle`, `engagement` or `promotions`. An unknown key is a 400. With a category the message follows that category's budget rules (transactional is exempt; in Enforce mode, others can be held or deferred like a campaign). Without one it is never held and counts toward the channel limit only. Pass one. See [Message priority](/docs/concepts/message-priority) |
| `dry_run` | Optional `true`: validate and count without storing or sending |

**Personalization.** Any string field can hold `{{key}}` or `{{key|fallback}}`, filled from each recipient's `properties`. Every placeholder without a fallback must exist for every recipient, or the request fails with 400. Values are HTML-escaped in email HTML. Broadcasts have no properties, so only placeholders with a fallback work there.

People this app can't reach (an unknown `external_user_id`, or one with no reachable contact or device) are skipped, never created, and listed in `unknown_recipients`. If none of the recipients exist, the request fails with 400.

:::tabs
::tab curl
```shell
curl -X POST "https://app.runherald.com/api/v1/messages/send" \
  -H "Authorization: Bearer $HERALD_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-A-991-shipped" \
  -d '{
    "name": "Order shipped",
    "recipients": [
      { "external_user_id": "u_123", "properties": { "first_name": "Ana", "order": "A-991" } }
    ],
    "messages": {
      "push": { "title": "Hi {{first_name}}", "body": "Order {{order}} shipped", "deeplink": "myapp://orders" }
    }
  }'
```
::tab node
```javascript
const res = await fetch("https://app.runherald.com/api/v1/messages/send", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.HERALD_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "order-A-991-shipped",
  },
  body: JSON.stringify({
    name: "Order shipped",
    recipients: [{ external_user_id: "u_123", properties: { first_name: "Ana", order: "A-991" } }],
    messages: { push: { title: "Hi {{first_name}}", body: "Order {{order}} shipped", deeplink: "myapp://orders" } },
  }),
});
const { data, error } = await res.json();
```
:::

### Response

`202` with the send:

| Field | Value |
|---|---|
| `send_id` | The send's ID, for status, change and cancel |
| `name` | The send's name |
| `status` | `scheduled` |
| `scheduled_for` | When it goes out: an instant, or a wall time with no offset when `in_local_time` |
| `in_local_time` | Whether `scheduled_for` is each person's local time |
| `created_at` | When the send was created |
| `recipients` | People it will reach (for a broadcast, the segment's current count) |
| `unknown_recipients` | External IDs that were skipped |
| `channels` | The channels in the send |

```json
{ "data": { "send_id": "cmh…", "name": "Order shipped", "status": "scheduled",
  "scheduled_for": "2026-11-24T18:00:00.000Z", "in_local_time": false, "created_at": "2026-11-24T18:00:00.000Z",
  "recipients": 1, "unknown_recipients": [], "channels": ["push"] } }
```

A `dry_run` answers `200` with `{ "valid": true, "recipients", "unknown_recipients", "channels", "charges" }`, where `charges` maps each pool to what a real send would charge.

### Channel content

| Channel | Fields |
|---|---|
| `push` | `title` (1 to 65), `body` (1 to 240), optional `imageUrl`, `deeplink`, `story` (see [Push stories](#push-stories)) |
| `web_push` | `title` (1 to 65), `body` (1 to 240), optional `url`, `iconUrl` |
| `email` | `fromName` (1 to 60, no `<`, `>` or quotes), `fromDomainId` (a verified sending domain), `subject` (1 to 120), optional `preheader` (up to 140), and exactly one of `html` or `templateId` |
| `sms` | `body` (1 to 1,600) |
| `in_app` | `layout` (`modal` or `slideup`), `title` (up to 60), `body` (up to 240), optional `imageUrl`, `buttons` (up to 2, each `label` up to 24 and optional `deeplink`), optional `trigger` (`{ "kind": "next_open" }` or `{ "kind": "event", "name": "..." }`) |
| `content_card` | `title` (up to 60), `body` (up to 240), `pinned` (true or false), optional `imageUrl`, `link`, `expiresAt` (UTC, ending in `Z`) |

Lengths count characters. Links must be `http(s)` URLs or app links such as `myapp://path`.

### Push stories

A push can be a story: 2 to 10 pages the person flips through. Add `story` to `messages.push`:

```json
{
  "push": {
    "story": {
      "pages": [
        { "imageUrl": "https://cdn.example.com/plans.jpg", "title": "New plans", "subtitle": "Start one today", "deeplink": "myapp://plans" },
        { "imageUrl": "https://cdn.example.com/streak.jpg", "title": "Streaks", "subtitle": "Keep yours going" }
      ]
    }
  }
}
```

- Each page has `imageUrl` (an `https` URL, required), `title` (1 to 65), `subtitle` (1 to 240) and an optional `deeplink`. A page without a `deeplink` opens the app.
- `title`, `body`, `imageUrl` and `deeplink` on the push are optional with a story and are replaced by the first page's (its subtitle becomes the body), so a device without story support shows the first page as a normal push.
- The pages (as compact JSON) plus the first page's title, subtitle, image URL and link must fit in 3,400 bytes, because the first page is sent twice; Apple and Google cap a push at 4 KB.
- A story takes no `media`.
- Errors start with `messages.push: story: `, for example `messages.push: story: page 2 needs an https image URL`.

See [Push stories](/docs/push-notifications/push-stories) for what the apps need.

## GET /api/v1/messages/{id}

Scope `messages.read`. Returns one send this app created through the API.

:::tabs
::tab curl
```shell
curl "https://app.runherald.com/api/v1/messages/SEND_ID" \
  -H "Authorization: Bearer $HERALD_API_KEY"
```
::tab node
```javascript
const res = await fetch(`https://app.runherald.com/api/v1/messages/${sendId}`, {
  headers: { Authorization: `Bearer ${process.env.HERALD_API_KEY}` },
});
const { data } = await res.json();
```
:::

| Field | Value |
|---|---|
| `send_id`, `name`, `scheduled_for`, `in_local_time`, `created_at` | As in the send response |
| `status` | `scheduled`, `expanding`, `sending`, `sent`, `partly_sent`, `cancelled` or `failed` |
| `channels` | Per channel: `targeted`, `error` (why the channel failed, else null), and counts by status: `queued`, `sending`, `sent`, `failed`, `suppressed`, `cancelled`. In-app messages and content cards report `delivered` instead |

Status lookups are meant for occasional checks; they count toward `messages.read`.

## GET /api/v1/messages

Scope `messages.read`. Lists this app's API sends, newest first.

| Query parameter | Rules |
|---|---|
| `status` | Optional; one of the statuses above |
| `limit` | Optional, 1 to 100; default 50 |
| `cursor` | Optional; the `next_cursor` of the previous page |

:::tabs
::tab curl
```shell
curl "https://app.runherald.com/api/v1/messages?status=scheduled&limit=20" \
  -H "Authorization: Bearer $HERALD_API_KEY"
```
::tab node
```javascript
const res = await fetch("https://app.runherald.com/api/v1/messages?status=scheduled&limit=20", {
  headers: { Authorization: `Bearer ${process.env.HERALD_API_KEY}` },
});
const { data } = await res.json(); // { sends, next_cursor }
```
:::

The response is `{ "data": { "sends": [...], "next_cursor": "..." } }`. Each send has the fields of the send response plus `channels`. `next_cursor` is null on the last page.

## PATCH /api/v1/messages/{id}

Scope `messages.schedule`. Changes a scheduled send. The body takes any of `schedule`, `messages` and `name`, with the same rules as the send. `messages` replaces the content of the channels it names; it can't add or remove channels. `schedule: null` is refused; leave it out to keep the current time.

A send can change only while its status is `scheduled` and more than 5 minutes before it goes out. Otherwise the answer is `409 This send has already started`.

:::tabs
::tab curl
```shell
curl -X PATCH "https://app.runherald.com/api/v1/messages/SEND_ID" \
  -H "Authorization: Bearer $HERALD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "schedule": { "time": "2026-12-02T09:00:00", "in_local_time": true } }'
```
::tab node
```javascript
const res = await fetch(`https://app.runherald.com/api/v1/messages/${sendId}`, {
  method: "PATCH",
  headers: { Authorization: `Bearer ${process.env.HERALD_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ schedule: { time: "2026-12-02T09:00:00", in_local_time: true } }),
});
```
:::

The response is the send's summary with its `channels`.

## DELETE /api/v1/messages/{id}

Scope `messages.schedule`. Cancels a scheduled send; messages not yet delivered are cancelled. A send that has started gets `409 This send has already started`.

:::tabs
::tab curl
```shell
curl -X DELETE "https://app.runherald.com/api/v1/messages/SEND_ID" \
  -H "Authorization: Bearer $HERALD_API_KEY"
```
::tab node
```javascript
await fetch(`https://app.runherald.com/api/v1/messages/${sendId}`, {
  method: "DELETE",
  headers: { Authorization: `Bearer ${process.env.HERALD_API_KEY}` },
});
```
:::

It returns `{ "data": { "send_id": "...", "status": "cancelled" } }`.

## Errors

| Status | Body `error` | Cause |
|---|---|---|
| 400 | `Invalid JSON body` or `Body must be a JSON object` | The body is not a JSON object |
| 400 | A rule and its field, such as `recipients must have 1 to 50 entries`, `messages.push: ...` or `schedule must be in the future` | The request breaks a rule above |
| 400 | `Recipient "u_123" has no "first_name" property for messages.push` | A placeholder without a fallback has no value |
| 400 | `category must be one of: <keys>` | `category` isn't a category key of this app |
| 400 | `None of the recipients exist` | No recipient is known to this app |
| 400 | `Pick a verified sending domain` | `email` has no `fromDomainId`, or it isn't a verified domain of this connection |
| 400 | `The Send API needs a connection that sends through Herald` | The key's app sends through another tool |
| 400 | `Idempotency-Key must be 1 to 255 characters` | Bad header |
| 401 | `Invalid API key` | Missing, unknown, revoked or expired key |
| 403 | `This API key lacks the <scope> scope` | Wrong scopes |
| 403 | `This API key's app is disabled` | The app is turned off |
| 403 | `This IP address isn't allowed for this API key` | The key has an IP allowlist |
| 404 | `Send not found` | No such send created through this app's API keys |
| 409 | `This send has already started` | Change or cancel too late |
| 409 | `This Idempotency-Key was used with a different request`, or `A request with this Idempotency-Key is still in progress` | See [Idempotency](#idempotency) |
| 429 | `Rate limit exceeded for <pool>: <limit> per hour` | Over a pool's hourly limit; wait for `Retry-After` |
| 500 | `Internal server error` | Server failure |

See [API errors](/docs/reference/api-errors) for status meanings, retries and headers.

## Held messages

A send with a `category` can be held by the person's attention budget. The message is recorded as suppressed with the error `budget:budget_full`, `budget:category_cap`, `budget:reserved` or `budget:expired`; see [Message priority](/docs/concepts/message-priority#when-a-message-is-held).

## Not in this version

Status webhooks, per-person frequency caps for API sends without a `category` (quiet hours apply; agent caps don't), per-key rate limits (limits are per app), optimal-time sends and Live Activities.

## Related

- [Server API](/docs/reference/server-api)
- [API errors](/docs/reference/api-errors)
- [How delivery works](/docs/concepts/how-delivery-works)
