# Segment, RudderStack and webhooks

> Send users and events to Herald from Segment, RudderStack or any tool that can post a signed webhook, with the mapping and signature for each.

:::note Built and tested against each vendor's documented API; tell us if anything differs in your account.:::

These integrations push users and events to a webhook URL. Herald translates each body and ingests it exactly like the server API (`POST /api/v1/users` and `POST /api/v1/events`).

## What you'll need

- An admin of the account. Integrations are set up in **Settings → Integrations**.
- **Segment:** a Webhooks or Webhooks (Actions) destination you can edit.
- **RudderStack:** a Webhook destination you can edit.
- **Signed webhook:** a tool or script that can compute an HMAC-SHA256 signature.
- Your own user id on every user and event, the same id your app passes to `identify`.

## Connect

1. In **Settings → Integrations**, pick the app, choose the provider and name it.
2. Copy the webhook URL and the secret. The secret is shown once.
3. Paste both into the sending tool, as below.
4. Choose **Send test** to run a signed sample through the checks. It writes nothing.

The URL looks like `https://app.runherald.com/api/v1/integrations/<provider>/<integrationId>`.

## Answers

| Answer | When |
|---|---|
| `200` with `accepted`, `duplicates`, `skipped` | The body was translated and ingested. `accepted` is users upserted plus new events. |
| `401` | Unknown integration, a different provider in the path, a paused integration, or a bad or missing signature |
| `400` | A body that cannot be translated. Shown as the integration's last error. |
| `413` | More than 1,000 users or 1,000 events, or a body over 4.5 MB |
| `403` | The app is disabled |

## Segment

In Segment, add a **Webhooks** destination (or **Webhooks (Actions)**). Paste the URL. Set the shared secret to the secret from the console. For Actions, add the header `Authorization: Bearer <secret>` instead.

Accepted signatures: `X-Signature: <hex HMAC-SHA1(secret, raw body)>`, or `Authorization: Bearer <secret>`.

Segment's Spec messages, sent one per request or batched as `{ "batch": [ ... ] }`, map like this:

| Segment | In Herald |
|---|---|
| `identify` | A user upsert: `userId`; `traits` become attributes (strings, numbers, booleans and string arrays; nested objects are dropped); `traits.email` becomes the email contact; `traits.createdAt` becomes the signup date |
| `track` | An event named `event`, with `properties` |
| `page` | The event `page_viewed`, with `properties` plus `name` |
| `screen` | The event `screen_viewed`, with `properties` plus `name` |
| `alias`, `group` | Skipped, counted in `skipped` |
| A message without `userId` | Skipped: people are keyed on your own user id, not `anonymousId` |
| Event id | `segment:<messageId>`. A message without `messageId` is skipped. |
| Event time | `timestamp`, else `receivedAt`, else the time the webhook arrived |

A message with a value the server API would refuse (an event name over 255 characters, a `userId` over 200) is skipped instead of failing the batch. An invalid email is dropped and the user is still upserted.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `Unauthorized` | `401`: the secret or signature doesn't match, the integration is paused, or the URL names another provider | Copy the URL and secret from the console again, and resume the integration |
| `batch must be an array` | `400`: `batch` is not a list | Send one message, or `{ "batch": [ ... ] }` |
| `At most 1000 messages per request` | `400`: the batch holds more | Lower the destination's batch size |
| `At most 1,000 users and 1,000 events per request` | `413`: the request holds more | Send smaller batches |

### Send decisions to Segment (optional)

Turn on **Send decisions to Segment** when you connect. In Segment, add an **HTTP API** source and paste its write key, and pick the region (US or EU). The key is sealed with the integration's secret and never shown again.

The hourly sync sends each decision changed since the last send as Segment `track` calls to `/v1/batch`. The first run covers the last 24 hours. Every destination connected to that source receives them: your warehouse, Amplitude, an ad platform.

| Event | When | Properties |
|---|---|---|
| `herald_message_sent` | Every decision | `agent`, `agent_id`, `variant`, `variant_id`, `channel`, `decision_id`, `holdout` (always false) |
| `herald_message_converted` | The decision converted | The same, plus `conversion_event` and `conversion_value` |

`userId` is the person's External ID and `messageId` is `herald:<decision id>:sent` (or `:converted`), which Segment uses to drop duplicates. The cursor moves only after Segment accepts the batch.

| Message | Cause | Fix |
|---|---|---|
| `Set the Segment write key` | Shown as the last error: the key is missing | Add the write key on the integration |
| `segment export HTTP <status>` | Shown as the last error: Segment refused the batch | Check the write key and region; the next run retries |
| `segment network error` | Shown as the last error: Segment couldn't be reached | None: the next run retries |

## RudderStack

In RudderStack, add a **Webhook** destination. Paste the URL, set the method to POST, and add the header `Authorization: Bearer <secret>`. That is the only accepted signature.

RudderStack sends the same Spec payload as Segment, so the Segment table applies. Event ids are `rudderstack:<messageId>`.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `Unauthorized` | `401`: the header isn't `Authorization: Bearer <secret>`, the integration is paused, or the URL names another provider | Set the header exactly, and resume the integration |
| `batch must be an array` | `400`: `batch` is not a list | Send one message, or `{ "batch": [ ... ] }` |
| `At most 1000 messages per request` | `400`: the batch holds more | Lower the destination's batch size |
| `At most 1,000 users and 1,000 events per request` | `413`: the request holds more | Send smaller batches |

## Signed webhook

For anything else: Zapier, Make, n8n, a cron job or your own code.

The body is `{ "users"?: [...], "events"?: [...] }`, with the shapes of `POST /api/v1/users` and `POST /api/v1/events`. Either key may be absent, not both. Users are applied before events.

Sign the exact bytes you send with HMAC-SHA256 and put the result in `X-Herald-Signature: sha256=<hex>`:

```bash
BODY='{"events":[{"id":"evt-1","userId":"u1","name":"signup","timestamp":"2026-11-20T12:00:00Z"}]}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.* //')
curl -X POST "$WEBHOOK_URL" -H 'Content-Type: application/json' -H "X-Herald-Signature: sha256=$SIG" -d "$BODY"
```

Validation is the server API's: an invalid item fails the whole request with a `400` that names it.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `Unauthorized` | `401`: `X-Herald-Signature` doesn't match the exact bytes sent, or the integration is paused | Sign the raw body you send, after any serialization |
| `Send users, events or both` | `400`: the body has neither `users` nor `events` | Add one of them |
| `Invalid users payload: ...` or `Invalid events payload: ...` | `400`: an item breaks the server API's rules; the message names it | Fix that item and resend the request |
| `Invalid JSON` or `Expected a JSON object` | `400`: the body isn't a JSON object | Send JSON |
| `At most 1,000 users and 1,000 events per request` | `413`: the request holds more | Send smaller batches |

## Troubleshooting

- **Every request answers 401.** The secret does not match, the integration is paused, or the URL names a different provider.
- **Everything is skipped.** Messages without a `userId` are skipped. Send your own user id.
- **A retry created duplicates.** It should not: event ids are deterministic, so a retried delivery counts as a duplicate. Check the `duplicates` count in the answer.
