# SDK REST endpoints

> The HTTP endpoints the SDK calls, with headers, schemas, limits, status codes and verification modes, and how your backend mints user tokens.

The SDK talks to these Herald endpoints. You do not call them from the app yourself; this page is for backend engineers, security reviewers and anyone debugging traffic. Your backend mints user tokens (below) and calls the [Server API](/docs/reference/server-api).

All paths are relative to your Herald base URL, the `endpoint` you pass to `configure`. Every response body is JSON: `{ "data": ... }` on success, `{ "error": "..." }` on failure.

## Authentication

| Header | Sent on | Value |
|---|---|---|
| `x-herald-app-key` | Every SDK request | The connection's app key (its publishable key). Public: it identifies the connection and grants no secret access. |
| `x-herald-user-token` | Requests that name a user, when the SDK has a token | Hex HMAC-SHA256 of the External ID, keyed with the SHA-256 hex digest of the connection's ingest token |

The app key must belong to an active Herald sending connection. Any other key gets `401 Invalid app key`.

### Getting the keys

Both keys live on the app's connection, under **Settings → Sending & SDK**:

- **App key.** Open the app and select **Generate app key** on the **Mobile SDK** card. It goes in the app.
- **Ingest token** (`nx_ingest_…`). Open the app and select **Rotate** next to **Ingest token**. Herald shows the token once, so copy it into your backend's secret store then. It signs user tokens and authorizes server calls as `Authorization: Bearer <ingest token>`. Rotating it again invalidates the old token at once: see [Rotating the ingest token](/docs/data-and-privacy/security-and-identity-verification#rotating-the-ingest-token).

### Verification modes

Set on the connection's **Mobile SDK** card. A connection without a setting uses **Required**.

| Mode | Request names a user, valid token | Names a user, no token | Names a user, wrong token | Names no user |
|---|---|---|---|---|
| `required` | Verified | `401 Invalid user token` | `401 Invalid user token` | Anonymous |
| `optional` | Verified | Processed as anonymous | `401 Invalid user token` | Anonymous |
| `off` | Trusted as sent | Trusted as sent | Trusted as sent (not checked) | Anonymous |

A batch names a user through its `userId` field, or, when that is empty, the `userId` of its first `identify` event. A message fetch names a user through its `userId` query parameter. A token sent on a request that names no user is ignored.

:::warning Off is for development only
With verification off, anyone with your app key can send data as any user and read their messages. Use it only for testing.
:::

## POST /api/v1/sdk/batch

Uploads queued events. Native clients only, so no CORS.

### Request

| Header | Required | Value |
|---|---|---|
| `Content-Type` | Yes | `application/json` |
| `x-herald-app-key` | Yes | App key |
| `x-herald-user-token` | Depends on the mode | User token |

| Field | Type | Rules |
|---|---|---|
| `sdk.name` | string | 1 to 64 characters (`herald-ios`, `herald-android`) |
| `sdk.version` | string | 1 to 32 characters |
| `deviceId` | string | 1 to 128 characters |
| `userId` | string or null | 1 to 200 characters; null or absent for an anonymous batch |
| `sentAt` | string | ISO 8601 date-time with offset |
| `dropped` | integer | 0 or more; events the device dropped (a full queue, over 32 KB, or queued more than 30 days). Default 0. |
| `context` | object | Device data; see [Event payload spec](/docs/reference/event-payload#context) |
| `events` | array | Up to 100 events; see [Event payload spec](/docs/reference/event-payload) |

```json
{
  "sdk": { "name": "herald-ios", "version": "0.4.0" },
  "deviceId": "6c1f2a9e-0b7d-4a8e-9f61-1b2c3d4e5f60",
  "userId": "u_123",
  "sentAt": "2026-11-09T14:00:00Z",
  "dropped": 0,
  "context": {
    "app": { "name": "Lumen", "version": "4.2.0", "build": "812", "namespace": "com.lumen.app" },
    "os": { "name": "iOS", "version": "18.1" },
    "region": "US"
  },
  "events": [
    { "id": "a1b2", "type": "track", "timestamp": "2026-11-09T13:59:58Z", "sessionId": "1731160800000",
      "name": "workout_completed", "properties": { "minutes": 32 } }
  ]
}
```

### Limits

- 512 KB per request body. Checked against `Content-Length` and the body itself.
- 100 events per request.
- 32 KB per event, as JSON. The SDKs drop a larger event on the device and count it in `dropped`.
- Each event is checked on its own: an invalid one is rejected and the rest are stored. Only a problem with the batch itself (JSON, `sdk`, `deviceId`, `userId`, `sentAt`, `dropped`, `context`, the `events` array) fails it with a 400. The SDKs check every call on the device, so rejects are rare in normal use.
- Event time: Herald corrects each event's `timestamp` for the device's clock, using `sentAt` and the time the batch arrived, and rejects events more than 30 days old. See [Clock correction](/docs/concepts/batching-and-offline#clock-correction).

### Response

```json
{ "data": { "accepted": 1, "duplicates": 0, "heraldId": "7K3M-9QXA" } }
```

`accepted` counts new events stored. `duplicates` counts event IDs this connection already had; they are skipped, so a retried batch is safe. `heraldId` is the batch user's User ID (see [Support ID](/docs/concepts/users-and-identity#support-id)), sent for the user the batch is verified as once their profile exists: with a valid user token under Required or Optional, and for any claimed user under Off. Anonymous batches and Optional batches without a token leave it out. It isn't secret. When events were rejected, `rejected` lists them, and `accepted` and `duplicates` count only the valid ones:

```json
{ "data": { "accepted": 1, "duplicates": 0,
  "rejected": [{ "id": "e2", "index": 1, "reason": "too_old", "detail": "timestamp is more than 30 days old" }] } }
```

Each entry has the event's `id` (null when it has no usable one), its `index` in `events`, a `reason` code and a short `detail`. The codes are listed under [Rejected events](/docs/reference/error-codes#rejected-events).

### Status codes

| Status | Body `error` | Cause | What the SDK does |
|---|---|---|---|
| 200 | | Stored, except any events listed in `rejected` | Removes the batch from its queue; logs each rejected event at debug level and never retries it |
| 400 | `Invalid JSON` | Body is not JSON | Drops the batch, logs an error |
| 400 | Path and message, such as `deviceId: Too small: expected string to have >=1 characters` | The batch breaks the schema | Drops the batch, logs an error |
| 401 | `Invalid app key` | Missing, unknown or inactive app key | Keeps every queued event, logs an error, and sends nothing more until the app launches again |
| 401 | `Invalid user token` | See the verification table | Keeps that user's events until the app calls `setUserToken`, logs a warning; anonymous events keep flowing |
| 413 | `Batch exceeds 512 KB` or `Batch exceeds 100 events` | Too large | Drops the batch, logs an error |
| 500 | `Internal server error` | Server failure | Keeps the batch and retries with backoff |

The SDKs also retry 408, 429 and any 5xx, and honor a `Retry-After` header (seconds or HTTP date) or a `retryAfterSeconds` body field, capped at one hour. Herald itself does not return 429 today; a proxy or firewall in front of it may.

### What the server does with a batch

- **Device record.** Creates or updates the device, with its platform, context and region. Region comes from the country of the request's IP address when the hosting platform supplies it, else from `context.region`.
- **Verified user.** Only the verified user gets writes: attributes, email and phone contacts, push tokens, subscriptions, message state and outcome credit. Events that claim any other user are stored with no user, and the claim is kept in the stored payload.
- **Sign-out.** A batch with no user unbinds the device from its previous user and deletes that user's push tokens for this device.
- **Time zone.** A verified user's time zone is filled from `context.timezone` only when the profile has none.
- **Idempotency.** Events are stored once per `(connection, id)`.

## POST /api/v1/sdk/diagnostics

Uploads crash and hang reports from the iOS SDK, when `crashReports` is on. Native clients only, so no CORS. The request carries no user or device id.

| Header | Required | Value |
|---|---|---|
| `Content-Type` | Yes | `application/json` |
| `x-herald-app-key` | Yes | App key |

A request holds 1 to 20 reports and is at most 256 KB.

## GET /api/v1/sdk/config

SDK 0.6.0+. Returns the app's remote SDK settings, set in the console under Settings, SDK settings. Native clients only.

| Header | Required | Value |
|---|---|---|
| `x-herald-app-key` | Yes | App key |
| `If-None-Match` | No | The `ETag` of the last response |

```json
{ "data": { "version": "3f9c2a7b1d4e6f80", "settings": { "enabled": true, "flushIntervalSeconds": 30, "dataCollection": "minimal" } } }
```

`version` is opaque and changes on every save; it is `"0"` with empty `settings` until the first save. Every setting is optional, and an absent one means the value built into the app:

| Setting | Values |
|---|---|
| `enabled` | `true` or `false`. `false` stops all collection and sending in the SDK and clears its queue (push tokens and subscriptions wait and go out when it is back on) |
| `flushIntervalSeconds` | 5 to 300 |
| `foregroundSessionTimeoutSeconds`, `backgroundSessionTimeoutSeconds` | 60 to 86400, a multiple of 60 (whole minutes) |
| `dataCollection` | `standard` or `minimal` |
| `trackLifecycleEvents`, `trackExternalPushes`, `trackDeepLinks` | `true` or `false` |
| `geofences` | `true` or `false`. SDK 0.7.0+. `false` stops geofence monitoring on every device; see [Geofences](/docs/concepts/geofences) |

The response carries `ETag` (the quoted version) and `Cache-Control: private, no-cache`. A matching `If-None-Match` returns 304 with no body. A bad app key returns 401 `Invalid app key`. The SDKs fetch it at launch and on a foreground at most once an hour; see [iOS API](/docs/reference/ios-api#remote-config) and [Android API](/docs/reference/android-api#remote-config).

## GET /api/v1/sdk/geofences

SDK 0.7.0+. Not released yet. Returns the app's whole geofence list, set in the console under Settings, Geofences, for the `HeraldGeofence` (iOS) and `herald-geofence` (Android) modules. The request carries no location: the device picks the regions to monitor itself. Native clients only.

| Header | Required | Value |
|---|---|---|
| `x-herald-app-key` | Yes | App key |
| `If-None-Match` | No | The `ETag` of the last response |

```json
{ "data": { "enabled": true, "geofences": [ { "id": "4f1c2b9e-7a3d-4e8b-9c51-2d6f0a8b3e17", "name": "Store 12", "latitude": 40.7484, "longitude": -73.9857, "radiusMeters": 200 } ] } }
```

`enabled` is the app's **Geofences** SDK setting (`geofences` in [GET /api/v1/sdk/config](#get-api-v1-sdk-config)); it is `true` unless an admin set it to Off, and then `geofences` is empty and the SDK stops monitoring. Geofences are listed oldest first, at most 100. The response carries a strong `ETag` over the body and `Cache-Control: private, no-cache`; a matching `If-None-Match` returns 304 with no body. A bad app key returns 401 `Invalid app key`. See [Geofences](/docs/concepts/geofences).

## GET /api/v1/sdk/messages

Returns the content cards and in-app messages for the SDK's user.

### Request

| Query parameter | Required | Rules |
|---|---|---|
| `deviceId` | Yes | 1 to 128 characters |
| `userId` | No | 1 to 200 characters; omit for an anonymous device |

| Header | Required | Value |
|---|---|---|
| `x-herald-app-key` | Yes | App key |
| `x-herald-user-token` | Depends on the mode | User token |
| `If-None-Match` | No | The `ETag` of the last response |

### Response

```json
{ "data": {
  "syncedAt": "2026-11-09T14:00:00.000Z",
  "contentCards": [
    { "id": "msg_1", "type": "captioned_image", "title": "Your 7 AM session, upgraded", "body": "Try Plus free for 7 days.",
      "imageUrl": "https://cdn.example.com/plus.jpg", "cta": "Try Plus", "url": "lumen://plus", "extras": {},
      "pinned": false, "dismissible": true, "categories": [], "createdAt": "2026-11-09T13:00:00.000Z",
      "expiresAt": null, "viewed": false, "clicked": false, "dismissed": false, "decisionId": "dec_1" }
  ],
  "inAppMessages": [
    { "id": "msg_2", "type": "modal", "priority": 0,
      "trigger": { "type": "session_start" }, "reEligibility": { "mode": "once" }, "expiresAt": null,
      "content": { "header": "Nice work, Maya", "body": "You logged 5 workouts this week.", "imageUrl": null,
        "buttons": [{ "id": "primary", "text": "See Plus", "action": { "type": "deeplink", "value": "lumen://plus" } }],
        "html": null, "slideFrom": null, "dismissAfterSeconds": null },
      "style": { "backgroundColor": null, "textColor": null, "buttonColor": null, "buttonTextColor": null, "cornerRadius": null },
      "decisionId": "dec_2" }
  ]
} }
```

| Field | Values |
|---|---|
| Card `type` | `classic`, `captioned_image`, `image_only` |
| Message `type` | `slideup`, `modal`, `full`, `html` |
| `trigger.type` | `session_start`, `push_open`, `event` (with `event` and optional `propertyFilters`) |
| `propertyFilters[].op` | `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains`, `exists` |
| `reEligibility.mode` | `once`, `after_hours` (with `hours`, greater than 0) |
| Button `action.type` | `deeplink`, `url`, `close` |
| `slideFrom` | `top`, `bottom`, null |
| Style fields | Hex color strings or null; null means use the app theme |

Rules:

- Only active, unexpired, undismissed messages are returned, newest first: up to 100 content cards and 50 in-app messages.
- An anonymous or unverified caller gets empty lists.
- The response carries a strong `ETag` and `Cache-Control: private, no-cache`. A matching `If-None-Match` returns 304 with no body. The ETag changes when any card or message changes, including its viewed or clicked state.
- The SDKs skip an item they cannot read (for example a type from a newer version) and keep the rest.

### Status codes

| Status | Body `error` | Cause |
|---|---|---|
| 200 | | The lists |
| 304 | | Nothing changed since the ETag you sent |
| 400 | Parameter and message, such as `deviceId: Required` | Bad query |
| 401 | `Invalid app key` or `Invalid user token` | See the verification table |
| 500 | `Internal server error` | Server failure |

On any failure the SDK keeps showing its cached cards and messages.

## Backend: minting user tokens

There is no endpoint for this: your backend computes the token. It needs the connection's ingest token, which **Rotate ingest token** on the connection page shows once. Keep the ingest token on your server only.

```javascript
// Node.js. HERALD_INGEST_TOKEN is the connection's ingest token.
import { createHash, createHmac } from "node:crypto";

const key = createHash("sha256").update(process.env.HERALD_INGEST_TOKEN).digest("hex");
const userToken = createHmac("sha256", key).update(userId).digest("hex");
```

```sh
key=$(printf %s "$HERALD_INGEST_TOKEN" | openssl dgst -sha256 -r | cut -d' ' -f1)
printf %s "u_123" | openssl dgst -sha256 -hmac "$key" -r | cut -d' ' -f1
```

The token does not expire. Rotating the ingest token invalidates every user token at once, so re-mint after a rotation.

## Backend endpoints

Your backend's own calls, authorized with the ingest token, are on [Server API](/docs/reference/server-api): users, events, decide, the decisions and holdout exports, contacts and user deletion.

## Related

- [Event payload spec](/docs/reference/event-payload)
- [Error codes](/docs/reference/error-codes)
- [Server API](/docs/reference/server-api)
- [Security and identity verification](/docs/data-and-privacy/security-and-identity-verification)
- [Importing push tokens and users](/docs/migration/importing-tokens-and-users)
