# Custom webhooks

Choose which Returning.AI events to receive, then look up the payload and retry behavior for each destination. Start with the event you need or [set up a receiver](#set-up).

## What you can receive

| Type | Events | Sent |
| --- | --- | --- |
| [Milestone](#milestone) | A trader completes a milestone stage or a whole milestone group, or loses a completed stage. | One request per trader and stage or group in Singular mode. |
| [Streak](#streak) | `streak_changed` (a period earned or taken back) and `streak_reset` (a missed period reset the count to 0). | One request per trader and change. |
| [Match Prediction](#match-prediction) | `prediction_made` and `game_settled`. | One request per prediction, and one per participant when a match settles. |
| [Gamification](#gamification) | Total XP, Total Coins, Tier and Level changes. | One or more requests per UTC interval, with optional per-trader histories. |
| [Raffle](#raffle) | Raffle run ended or Community Goal prize claimed. | One request per run or fulfilled claim. |
| [Mystery Box](#mystery-box) | Event ended, collection completed or prize fulfilled. | One or more requests per occurrence. |
| [Store order status](#order-status) | An order moves to a different status. | From Integration > Webhooks. |
| [Salesforce](#salesforce) | Selected reward events, including milestone transitions and [custom-field changes](#salesforce-custom-fields). | Records upserted in Salesforce. |
| [Workflow results](https://docs.returning.ai/broker-integrations/workflow-webhooks.md#bulk-update-callback) | A Data Workflow bulk update finishes. | To the callback URL configured for the workflow. |

For trader events, store the platform `userId` returned by [Create User](https://docs.returning.ai/api-reference/users/create-user.md) to link payloads to your customer records.

## Set one up

In the dashboard, open Settings > Quests > Custom Webhooks. Community owners and admins can create, edit and delete the webhooks configured on this screen.

1. Next to the type you want, select Create Custom Webhook.
2. Give it a name. The name is sent in the body as `event.name`.
3. Select the events and targets for that webhook type. For Gamification, also choose the schedule.
4. Set the HTTP request: method, Webhook URL, headers and JSON body.
5. Select Test Webhook (Send Test for Gamification) to send a request with sample data to your URL.
6. Switch on Active and select Save Changes. A new webhook stays paused, and sends nothing, until you do.

| Setting | What it does |
| --- | --- |
| Name | Up to 100 characters. Sent as `event.name` (`payload.event.name` in Gamification batches). |
| Active | Activate the webhook to collect new events. For Gamification, see [the schedule](#gamification). |
| Events and targets | Select the events and targets that should send requests. Add newly created targets to the selection when you want to include them. |
| HTTP method | `POST` (the default), `PUT`, `PATCH`, `DELETE` or `GET`. A `GET` sends no body. For Gamification, use `POST`, `PUT`, `PATCH` or `DELETE`. |
| Webhook URL | An `https://` address on port 443, up to 2,048 characters, with no username, password or `#` fragment. Saving fails if the host name resolves to a private, loopback or other non-public IP address. It is checked again on every send. |
| Headers | Up to 50 headers, sent as saved. Values are single-line and together at most 8 KiB. `Host`, `Content-Length`, `Connection`, `Transfer-Encoding`, `Keep-Alive`, `TE`, `Trailer`, `Upgrade` and `Proxy-Authenticate` are set by the server and can't be added. |
| JSON body | A JSON template filled in with the event's values; see [Design the body](#body). Up to 256 KiB before rendering. Start with the body supplied by the editor and use Variables to customize it. |
| Outbound rate limit | Match Prediction only; see [Pace match prediction deliveries](#rate-limit). |

Deleting a webhook stops new deliveries and keeps its delivery history. You can create several webhooks of the same type, for example one per system; each one that matches an event sends its own request.

## The request

For webhooks set up under Custom Webhooks, Returning.AI sends the method, URL and headers you saved, and the body built from your template. The default is `Content-Type: application/json`. You can set your own `Content-Type` header.

`custom-webhook-request.http`

```
POST /hooks/returning-ai/9f3c1b7e HTTP/1.1
Host: hooks.example.com
Content-Type: application/json
Authorization: Bearer <WEBHOOK_SECRET>

{ ...the JSON body you designed, filled in for this event... }
```

> Authenticate incoming requests
>
> Custom Webhooks rely on the headers you set for receiver authentication. Add a header with a shared secret, such as `Authorization: Bearer <WEBHOOK_SECRET>`, reject requests without it. For anything that moves money, confirm the fact with the API before you act. For a trader balance, use [Get User Data](https://docs.returning.ai/api-reference/users/get-user-data.md).

Other headers, such as `User-Agent` and `Accept`, may change without notice. Don't depend on them.

## Design the body

The JSON body is a template. Each `{{variable}}` is replaced with a value from the event; select Variables in the editor to insert one. The sections below list each type's variables, which are the paths of the default body.

- A variable on its own as a JSON value keeps its type: numbers stay numbers, `true` and `null` stay as they are, and objects and arrays are inserted whole. Don't put quotes around it.
- A variable inside a quoted string is inserted as text, and `null` becomes an empty string. Objects and arrays can't be used inside a string.
- Saving fails if the template uses a variable the type doesn't have, or doesn't produce valid JSON with the test data.
- When a value doesn't exist for an event, such as `milestone.completionCriteria` for a stage without one, its key is left out of the body.

`milestone-template.json`

```json
{
  "type": {{event.type}},
  "eventId": {{event.id}},
  "stage": {{milestone.stage.name}},
  "traderId": {{trader.id}},
  "email": {{trader.email}},
  "xpAwarded": {{reward.xp}},
  "note": "Stage {{milestone.stage.name}} reached by {{trader.displayname}}"
}
```

For a stage upgrade, that template sends:

`milestone-rendered.json`

```json
{
  "type": "milestone_transition",
  "eventId": "66f000000000000000000001:3247779:66f000000000000000000501:stage:66f000000000000000000502:upgrade:2026-10-01T09:15:04.120Z",
  "stage": "First deposit",
  "traderId": "3247779",
  "email": "trader@example.com",
  "xpAwarded": 100,
  "note": "Stage First deposit reached by Sample Trader"
}
```

### Trader fields

Milestone, Streak and Match Prediction bodies can include these trader fields. The event examples show the trader ID and email.

`trader.json`

```json
{
  "id": "3247779",
  "firstName": "Sample",
  "lastName": "Trader",
  "name": "Sample Trader",
  "avatar": "https://cdn.example.com/avatars/sample.png",
  "email": "trader@example.com",
  "nicename": "sample_trader",
  "displayname": "Sample Trader",
  "phoneNumber": null,
  "country": null,
  "language": null
}
```

| Variable | Meaning |
| --- | --- |
| `trader.id` | The trader's platform user ID, as a string. It is the `userId` from Create User and the `platform_user_id` identifier in the API. |
| `trader.email` | The trader's email, or `null`. |
| `trader.firstName`, `trader.lastName`, `trader.name` | Names from the trader's profile. `name` is the first and last name together when no full name is stored. Each can be `null`. |
| `trader.nicename`, `trader.displayname` | The username and the name shown in the community. Either can be `null`. |
| `trader.avatar`, `trader.phoneNumber`, `trader.country`, `trader.language` | Profile details, each `null` when not set. |

The examples for these three event types also include `community.id` and `community.name`.

## Milestone

For Singular delivery, under Milestone Events, select groups and stages. Selecting a group by its checkbox selects the group and all of its stages; you can also pick the group alone or single stages.

- **Stage upgrade** (`targetType: stage`): a trader meets a stage's conditions.
- **Group upgrade** (`targetType: group`): a trader completes the group and its rewards are granted. When the last stage completes a group, a webhook that selects both sends two requests.
- **Downgrade** (`direction: downgrade`): a trader who no longer meets a completed stage loses it. The Downgrade option appears only when you select a stage in a group with downgrade switched on. `reward.xp` and `reward.currency` are `0`, and roles or tags that were removed are listed under `remove`.

`milestone-stage-upgrade.json`

```json
{
  "event": {
    "id": "66f000000000000000000001:3247779:66f000000000000000000501:stage:66f000000000000000000502:upgrade:2026-10-01T09:15:04.120Z",
    "name": "CRM milestones",
    "type": "milestone_transition",
    "direction": "upgrade",
    "targetType": "stage",
    "occurredAt": "2026-10-01T09:15:04.120Z",
    "isTest": false
  },
  "community": {
    "id": "66f000000000000000000001",
    "name": "Example Community"
  },
  "milestone": {
    "group": { "id": "66f000000000000000000501", "name": "Getting started" },
    "stage": { "id": "66f000000000000000000502", "name": "First deposit" },
    "completionCriteria": "Deposits: more than 250/100"
  },
  "trader": { "id": "3247779", "email": "trader@example.com" },
  "reward": { "xp": 100, "currency": 50 },
  "roleChange": {
    "overwrite": [],
    "add": [{ "id": "66f000000000000000000806", "name": "Funded" }],
    "remove": []
  },
  "tagChange": { "overwrite": [], "add": [], "remove": [] }
}
```

| Variable | Meaning |
| --- | --- |
| `event.id` | Unique for each transition: community, trader, group, target and direction, and the time. Use it to spot repeats. |
| `event.type` | Always `milestone_transition`. |
| `event.direction` | `upgrade` or `downgrade`. |
| `event.targetType` | `stage` or `group`. |
| `event.occurredAt` | When the stage or group was completed or lost, ISO 8601 UTC. |
| `event.isTest` | `true` only for test requests. |
| `milestone.group.id`, `milestone.group.name` | The milestone group. |
| `milestone.stage.id`, `milestone.stage.name` | The stage. Both are `null` in a group event. |
| `milestone.completionCriteria` | A readable summary of the conditions and the trader's values. A group event repeats its last stage's summary. Left out when there is none. Show it to people; don't parse it. |
| `reward.xp`, `reward.currency` | The XP and coins this stage or group granted; `0` when it has none, and on a downgrade. |
| `roleChange`, `tagChange` | Roles and tags changed by the milestone, each split into `overwrite`, `add` and `remove` lists of `{ id, name }`. Empty lists when nothing changed. |

## Streak

Under Streaks, select one or more streaks, then Streak changed, Streak reset or both.

- **`streak_changed`, `changeType: earned`**: a trader completes the streak's requirement for the current period, and the count goes up by 1.
- **`streak_changed`, `changeType: revoked`**: a completion is taken back in the same period, for example because XP was deducted, and the count goes down by 1.
- **`streak_reset`**: a period ended without a completion, so a count above 0 was reset to 0. It is sent after that period closes.

A count changed by hand in the dashboard, and progress that doesn't complete a period, send nothing.

`streak-earned.json`

```json
{
  "event": {
    "id": "streak:66f000000000000000000001:66f000000000000000000611",
    "name": "CRM streaks",
    "type": "streak",
    "action": "streak_changed",
    "targetType": "streak",
    "targetId": "66f000000000000000000601",
    "targetName": "Daily trader",
    "occurredAt": "2026-10-01T09:20:11.482Z",
    "isTest": false
  },
  "community": {
    "id": "66f000000000000000000001",
    "name": "Example Community"
  },
  "trader": { "id": "3247779", "email": "trader@example.com" },
  "streak": {
    "id": "66f000000000000000000601",
    "name": "Daily trader",
    "changeType": "earned",
    "previousCount": 4,
    "currentCount": 5,
    "delta": 1,
    "reason": "requirements_completed",
    "timeframe": { "value": "daily", "count": null },
    "timezone": "utc_gmt"
  }
}
```

| Variable | Meaning |
| --- | --- |
| `event.id` | `streak:<communityId>:<streakLogId>`, unique for each change. |
| `event.action` | `streak_changed` or `streak_reset`. |
| `event.targetId`, `event.targetName` | The streak's ID and name, the same as `streak.id` and `streak.name`. |
| `event.occurredAt` | When the change happened, ISO 8601 UTC. For a reset, the end of the missed period. |
| `streak.changeType` | `earned`, `revoked` or `reset`. |
| `streak.previousCount`, `streak.currentCount`, `streak.delta` | The count before and after, and the difference: `1`, `-1`, or minus the old count on a reset. |
| `streak.reason` | `requirements_completed`, `requirements_revoked` or `timeframe_expired`. |
| `streak.timeframe.value`, `streak.timeframe.count` | `daily` with `count: null`, or `every` with the period length in hours. |
| `streak.timezone` | The streak's time zone setting, such as `utc_gmt`. |

## Match Prediction

Under Match Prediction Games, select the games, then Prediction Made, Game Settled or both.

- **`prediction_made`**: a trader submits a prediction. A submission that fails sends nothing. `finalScore`, `settledAt`, `resultTier` and `reward` are `null`.
- **`game_settled`**: after [Settle match prediction](https://docs.returning.ai/api-reference/gamification-match-predictions/settle-match-prediction.md) finishes and rewards are paid, one request for each trader who predicted, including those who missed.
- Voiding a match sends nothing.

`matchPrediction.id` is the match's ID without the `mp_` prefix the API uses: for `6abd000000000000000000aa`, call the API with `mp_6abd000000000000000000aa`.

`match-prediction-settled.json`

```json
{
  "event": {
    "id": "match_prediction:66f000000000000000000001:66f000000000000000000801:game_settled:66f000000000000000000811:2026-10-10T21:05:00.000Z",
    "name": "CRM match predictions",
    "type": "match_prediction",
    "action": "game_settled",
    "targetType": "game",
    "targetId": "66f000000000000000000801",
    "targetName": "Australia vs New Zealand",
    "occurredAt": "2026-10-10T21:05:00.000Z",
    "isTest": false
  },
  "community": {
    "id": "66f000000000000000000001",
    "name": "Example Community"
  },
  "matchPrediction": {
    "id": "66f000000000000000000801",
    "name": "Australia vs New Zealand",
    "title": "Australia vs New Zealand",
    "teamA": {
      "name": "Australia",
      "imageUrl": "https://cdn.example.com/teams/australia.png"
    },
    "teamB": { "name": "New Zealand", "imageUrl": null },
    "finalScore": { "teamA": 2, "teamB": 1 }
  },
  "trader": { "id": "3247779", "email": "trader@example.com" },
  "prediction": {
    "attemptId": "66f000000000000000000811",
    "pick": "teamA",
    "predictedScore": { "teamA": 2, "teamB": 1 },
    "submittedAt": "2026-10-09T14:02:37.910Z",
    "settledAt": "2026-10-10T21:05:00.084Z",
    "resultTier": "exact_score"
  },
  "reward": {
    "coins": 300,
    "xp": 150,
    "customFields": [],
    "entryCostReturned": 0
  }
}
```

| Variable | Meaning |
| --- | --- |
| `event.id` | `match_prediction:<communityId>:<matchId>:prediction_made:<attemptId>`, or for a settlement the same with `game_settled` and the settlement time added. |
| `event.action` | `prediction_made` or `game_settled`. |
| `event.targetId`, `event.targetName` | The match's ID and name. |
| `event.occurredAt` | When the prediction was submitted, or when the match was settled. |
| `matchPrediction` | `id`, `name`, `title`, `teamA` and `teamB` (`name` and `imageUrl`, which can be `null`), and `finalScore` (`teamA`, `teamB`) once settled. |
| `prediction.attemptId` | The trader's prediction. A trader has one per match. |
| `prediction.pick`, `prediction.predictedScore` | `teamA`, `draw` or `teamB`, and the score the trader called. |
| `prediction.submittedAt`, `prediction.settledAt` | When the trader predicted, and when the prediction was settled (`null` before). |
| `prediction.resultTier` | `exact_score`, `correct_result` or `missed`; `null` before settlement. |
| `reward` | What the trader received: `coins`, `xp`, `customFields` (each with `fieldId`, `fieldName`, `label` and `value`) and `entryCostReturned`. The reward object is `null` for `prediction_made`. |

### Pace match prediction deliveries

A settlement sends one request per participant, all at once. If your endpoint has a request limit, switch on Outbound rate limit and set Maximum requests (1 to 100) per Every (seconds) (1 to 3,600). Requests over the limit are scheduled for later delivery. Test requests and manual retries bypass pacing.

## Gamification

A Gamification webhook sends batches on a schedule instead of one request per event. Choose:

- **Gamification events**: Total XP, Total Coins, Tier, Level, or several. A trader is in a batch when any selected value changed.
- **Batch schedule (UTC)**: 1 hour, 2 hours, Daily (00:00 UTC), Weekly (Monday 00:00 UTC) or Monthly (the 1st, 00:00 UTC).
- **Maximum users per request**: 1 to 1,000 (the default). A larger batch is split into several requests, and so is one that would exceed the size limit.

At each boundary Returning.AI collects traders whose selected values changed during the interval that just ended. Nothing is sent for an interval with no changes. The first batch covers the whole interval in which you switched the webhook on. Pausing, resuming or editing an active webhook starts collecting again from the start of the current interval, so changes in intervals that ended while it was paused are never sent.

### The batch template

The body must contain exactly one `{{#each batch.items}}` ... `{{/each}}` loop, placed where array elements go. Inside the loop, use the `payload` variables below; outside it, only `batch.item_count`, the number of traders in this request. The default body is a JSON array with one object per trader.

`gamification-template.json`

```json
{
  "count": {{batch.item_count}},
  "items": [
    {{#each batch.items}}
    {
      "eventId": "{{payload.event.id}}",
      "traderId": "{{payload.user_id}}",
      "email": {{payload.user_email}},
      "changedAt": "{{payload.occurred_at}}",
      "xpChange": {{payload.xp_change}},
      "xpTotal": {{payload.xp_after}},
      "coinChange": {{payload.coin_change}},
      "coinTotal": {{payload.coins_after}}
    }
    {{/each}}
  ]
}
```

With Total XP and Total Coins selected, a batch with two traders sends:

`gamification-batch.json`

```json
{
  "count": 2,
  "items": [
    {
      "eventId": "3c0f6f0d2a9e4b7c8d1e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f7a8",
      "traderId": "3247779",
      "email": "trader@example.com",
      "changedAt": "2026-10-01T09:34:07.212Z",
      "xpChange": 5,
      "xpTotal": 1205,
      "coinChange": 7,
      "coinTotal": 430
    },
    {
      "eventId": "9a8b7c6d5e4f30211f2e3d4c5b6a79880f1e2d3c4b5a69788796a5b4c3d2e1f0",
      "traderId": "3247780",
      "email": null,
      "changedAt": "2026-10-01T09:52:36.004Z",
      "xpChange": 3,
      "xpTotal": 3,
      "coinChange": 0,
      "coinTotal": 0
    }
  ]
}
```

| Variable | Meaning |
| --- | --- |
| `payload.event.id` | An ID for this trader in this interval and webhook. A resent batch carries the same IDs, so use it to spot repeats. |
| `payload.event.name` | The webhook's name. |
| `payload.community_id` | Your community ID. |
| `payload.user_id` | The trader's platform user ID, as a string. |
| `payload.user_email` | The trader's email, or `null`. Place it without quotes so `null` stays `null`. |
| `payload.occurred_at` | The trader's latest selected change in the interval, ISO 8601 UTC. |
| `payload.xp_change`, `payload.xp_after` | Total XP only. The net XP change in the interval, counted from the last time XP was overwritten if it was, and the trader's XP total when the batch is built. |
| `payload.coin_change`, `payload.coins_after` | Total Coins only. The same for coins. Premium currency is not included. |
| `payload.tier`, `payload.level` | Tier and Level only. The trader's current tier name and level, such as `Level 12`. |
| `batch.item_count` | The number of traders in this request. Outside the loop only. |

Totals are read when the batch is built, so they can include changes made after the boundary. A trader with no XP or coin balance yet gets `0`. Variables for events you didn't select can't be used.

### Per-trader XP and coin history

Select Total XP and Total Coins and include `{{payload.histories}}` as an unquoted value inside the `{{#each batch.items}}` loop. New default templates include it. Add it explicitly to an existing summary-only template. Each `histories` array carries that trader's complete selected history for the UTC interval, oldest first.

`gamification-history.json`

```json
[
  {
    "event": {
      "id": "3c0f6f0d2a9e4b7c8d1e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f7a8"
    },
    "user_id": "3247779",
    "histories": [
      {
        "event_id": "4dd4439763f0449751ce2671078b3722ed1d3ec3b48ec36199db0a8eb15957c8",
        "resource_type": "xp",
        "action": "adjust xps",
        "action_details": "adjust xps",
        "operation": "overwrite",
        "value": 1200,
        "occurred_at": "2026-11-20T09:34:07.212Z"
      },
      {
        "event_id": "254d1b5aabc8742d41d20e01506efcc9198c9703766dbd67e7edcd8c9184d81b",
        "resource_type": "coin",
        "action": "overwrite",
        "action_details": "overwrite",
        "operation": "overwrite",
        "value": 430,
        "occurred_at": "2026-11-20T09:52:36.004Z"
      }
    ]
  }
]
```

Apply each entry's `operation` to interpret `value`. For `add` and `subtract`, it is a positive amount. For `overwrite`, it is the replacement value. Deduplicate retried items by `payload.event.id` and individual changes by `histories[].event_id`.

A request can split between traders. If one trader's history is invalid or too large to send whole, History records a failed delivery for that trader with zero HTTP attempts. The receiver gets no partial history for that trader, and batches continue for others. Use the affected user and interval in Delivery results to reconcile the gap against [Search user gamification logs](https://docs.returning.ai/api-reference/gamification/search-user-gamification-logs.md). Retry is for a delivery that reached the send stage and can be replayed from its saved request.

## Raffle

Choose Raffle in Custom Webhooks, select the raffles, then choose Raffle Run Ended (`raffle_run_ended`) or Community Goal Prize Claimed (`raffle_prize_claimed`). To receive claim events, also select the final prizes to track.

For a run end, `{{winners}}` inserts an array in the body. Each entry shows `position`, `winner`, `ticket`, `communityGoal`, `prize` and the `claim` status at the time the event was prepared. A trader who wins twice appears twice. Older queued run-end events that have no winner snapshot send `[]`, so an empty array can also mean the list was unavailable.

`raffle-run-ended-template.json`

```json
{
  "event": { "id": {{event.id}}, "action": {{event.action}} },
  "run": { "id": {{run.id}}, "endedAt": {{run.endedAt}} },
  "winners": {{winners}}
}
```

The standard Run Ended template includes the array, and older standard templates are updated automatically. Add the variable to a customized template to receive it. The rendered request limit is 480,000 bytes including the URL and headers. If the complete request exceeds that limit, the delivery fails without sending a truncated list or splitting it across requests. A template that leaves out `winners` sends a smaller body.

The prize-claimed event goes out after a selected Community Goal prize is fulfilled. Use `fulfilment.claimId`, `fulfilment.ticketId` and `winner.id` to link the claim to the winning ticket and trader. For both events, deduplicate by `event.id`.

## Mystery Box

Choose Mystery Box and select the events to track. Mystery Box Event Ended / Collection Completed sends `mystery_box_completed`. Mystery Box Prize Awarded sends `mystery_box_prize_awarded` when one of the prizes you selected is fulfilled.

For a scheduled end, `completion.reason` is `event_ended` and `completion.participant` is `null`. A participant completing a collection without an end date gets a separate occurrence with `collection_completed` and their identity in `completion.participant`. This completion example shows selected fields from the first of multiple requests.

`mystery-box-completion.json`

```json
{
  "event": {
    "id": "3a6b81f255864db538d9cc9af63c9264c0bdf190cbecce05ed0dd3573c334a76",
    "occurrenceId": "6df11bdee6ed94b16660543200daf7f034256d6c078db31148aa8e82b585b55b",
    "action": "mystery_box_completed",
    "targetId": "66f000000000000000000911"
  },
  "completion": {
    "reason": "event_ended",
    "participant": null,
    "boxesEarned": null,
    "capacity": 5
  },
  "participants": [{
    "id": "3247779",
    "username": "sample_trader",
    "email": "trader@example.com",
    "roles": [],
    "boxesEarned": 0,
    "rewards": []
  }],
  "chunk": {
    "id": "3a6b81f255864db538d9cc9af63c9264c0bdf190cbecce05ed0dd3573c334a76",
    "index": 0,
    "participantCount": 1,
    "totalParticipants": 2,
    "hasMore": true
  }
}
```

For prize fulfilment, `fulfilment` identifies the participant, box, collection and prize, with the granted reward and any claim responses. `fulfilment.source` is `automatic` or `manual`. This example shows selected fields for an automatic award.

`mystery-box-prize-awarded.json`

```json
{
  "event": {
    "id": "2b9a557de14bc3eb222b42cfcf963fc4719731d6c3a8866510876890799f4b2e",
    "occurrenceId": "ce3f3c6d120f0d98bf66f07af5267f010e11c212fd80506279df1528836d482b",
    "action": "mystery_box_prize_awarded",
    "targetType": "claim",
    "targetId": "66f000000000000000000912"
  },
  "fulfilment": {
    "boxId": "66f000000000000000000913",
    "boxNumber": 1,
    "collection": { "id": "66f000000000000000000914", "name": "Welcome" },
    "prize": {
      "id": "66f000000000000000000915",
      "name": "100 coins",
      "tier": "regular"
    },
    "reward": { "coins": 100, "xp": 0, "inventory": [] },
    "benefit": { "multiplier": 1, "premiumBoost": 1, "streakDay": 0 },
    "status": "fulfilled",
    "fulfilledAt": "2026-11-20T09:15:04.120Z",
    "participant": {
      "id": "3247779",
      "username": "sample_trader",
      "email": "trader@example.com",
      "roles": []
    },
    "source": "automatic",
    "claimResponses": []
  }
}
```

Keep `event.occurrenceId` to group requests from the same completion or award. Deduplicate individual requests by `event.id`, which equals `chunk.id` and stays stable on a retry. The same occurrence can contain several different chunk IDs.

Track zero-based `chunk.index` within each destination and use `chunk.hasMore` to identify the final chunk. Chunks can arrive out of order. Use the indexes and participant counts to check completeness. A participant that cannot fit in one request gets a failure in History, so receiving the final chunk alone does not prove that the full participant list arrived.

## Responding, retries and duplicates

These rules apply to deliveries from Settings > Quests > Custom Webhooks.

- Save the event or enqueue it durably before returning `2xx` within 10 seconds, then do heavier processing. A slower answer counts as a timeout and can trigger a retry. The first 256 KiB of your response is kept in the delivery history.
- A `408`, `425`, `429`, `500`, `502`, `503` or `504`, a timeout, or a connection or DNS failure is retried, for at most 3 attempts: the second about 1 second after the first and the third about 2 seconds after the second. A `Retry-After` header of up to 900 seconds (in seconds or as a date) sets the wait instead.
- Any other status, such as `400`, `401` or `404`, and TLS errors, are final at once. Every attempt sends the same body and headers.
- Up to 3 redirects are followed. A `301` or `302` turns a `POST` into a `GET` without a body, a `303` turns any method into `GET`, and a redirect to another host drops your headers. Use the final URL.
- After the last attempt the delivery is marked Failed and the webhook is flagged in the list. It stays active and keeps sending new events; nothing switches it off.
- Store the ID as part of the durable write, using a unique key. Use `event.id` for a singular event or Mystery Box chunk and each item's `payload.event.id` for Gamification. Return `2xx` for an ID you already accepted, so a retry has no second effect.
- Requests are not ordered. Use `event.occurredAt`, and for streaks the counts, rather than arrival order.

## Test, history and manual retry

Test Webhook sends one request with sample data, using the settings in the editor, saved or not. The values are fixed samples such as `test_trader_001` and `test_community_001`, and `event.isTest` is `true` (Gamification test items have `test_gamification_event_001` as their event ID instead). For Match Prediction and Streak you pick which event to test. Testing a webhook that was never saved saves it first, paused. A test is retried like a real delivery, and you can send up to 10 a minute.

The History tab lists every delivery with its status, attempts, the request sent and your response, and can be searched. Header values are masked; the community owner can reveal them. When Retry is available for a failed delivery, it resends the recorded request.

## Store order status changes

In Settings > Integration > Webhooks, add an outgoing webhook and select Order Status Change. This event sends a fixed payload by `POST`. The example shows JSON with encryption turned off. An update to the same status ID can appear in order history but sends no status-change event.

`order-status-change.json`

```json
{
  "event": "Order Status Change",
  "eventKey": "order_status_change",
  "eventId": "0f7b4563-b1ee-4f8a-a0a4-986bab0e236b",
  "date": "2026-11-20T09:15:04.120Z",
  "server": {
    "id": "66f000000000000000000001",
    "name": "Example Community"
  },
  "order": {
    "id": "66f000000000000000000401",
    "purchaseId": "ORD20269268300418273"
  },
  "previousStatus": {
    "id": "66f000000000000000000402",
    "name": "In progress",
    "category": "in_progress"
  },
  "newStatus": {
    "id": "66f000000000000000000403",
    "name": "Completed",
    "category": "completed"
  },
  "changedBy": {
    "type": "api_key",
    "id": "66f000000000000000000404",
    "name": null,
    "username": null
  },
  "source": "api"
}
```

| Field | Meaning |
| --- | --- |
| `eventId` | Unique ID for this status change. Store it with your receipt and use it to deduplicate redelivery. |
| `date` | When the order status changed, in UTC. |
| `order.id`, `order.purchaseId` | The internal order ID and the purchase ID. If no purchase ID is saved, both fields carry the internal ID. Use the `ORD...` purchase ID as `transactionId` when updating the status. |
| `previousStatus`, `newStatus` | Each has `id`, `name` and `category`. The previous status can have null ID and name and category `unknown`. |
| `source` | `order_history`, `api`, `automatic_refund`, `refund_approval`, `status_replacement` or `internal`. |
| `changedBy` | The actor's `type` (`user`, `api_key` or `system`) and `id`, plus nullable `name` and `username`. |

Save the receipt and enqueue processing durably before returning `2xx`. Use the same acknowledgment for an `eventId` you already accepted. Use the order ID to find the order and the event ID to distinguish separate transitions on that order. To reconcile a missed or out-of-order delivery, [read order status history](https://docs.returning.ai/api-reference/rewards-and-redemptions/get-redemption-order-status-history.md).

## Salesforce milestone reward events

In Salesforce, provision the `Returning_Reward_Event__c` object with an auto-number name and `Returning_Event_Id__c` as a unique Text(255) external ID. Give the integration user API access and permission to read, create and update the object and required fields.

The base mapping uses Text(255) fields `Event_Type__c`, `Community_Id__c`, `Returning_User_Id__c`, `Source_Record_Id__c`, `Source_System__c` and `Payload_Hash__c`, Date/Time field `Occurred_At__c`, and Number field `Schema_Version__c`.

In the Returning.AI dashboard, open Salesforce > Reward Event Settings, turn on Export reward events to Salesforce, select Milestones under Reward event types, and save once prerequisites pass.

The integration upserts each future transition using `Returning_Event_Id__c` (`<communityId>:<eventId>`). `Event_Type__c` identifies `MILESTONE_STAGE_COMPLETED`, `MILESTONE_STAGE_REVOKED`, `MILESTONE_GROUP_COMPLETED` or `MILESTONE_GROUP_REVOKED`. To include an Account association, select the Account lookup and identifier text fields under Link reward events to Account.

| Salesforce fields | Value |
| --- | --- |
| `Milestone_Id__c`, `Milestone_Name__c` | Milestone ID and name. |
| `Milestone_Group_Id__c`, `Milestone_Group_Name__c` | Group ID and name. |
| `Milestone_Stage_Id__c`, `Milestone_Stage_Name__c` | Stage ID and name, present for stage events. |

Make all six milestone fields writable Text(255) fields. Group completion records a transition when all stages have active awards, even if the group has no prize. Stage revocation follows the milestone group's downgrade setting.

Look up `Returning_Event_Id__c` in Salesforce to confirm delivery. If a record is missing, your success manager can check whether it is paused, waiting for an automatic retry, or failed. Re-enabling an event type resumes queued records. Transient errors retry with backoff, and terminal errors require correcting the cause before replay. Each retry uses the same external ID, so it updates the same record if the first attempt reached Salesforce.

## Salesforce custom-field changes

Salesforce exports writes to selected community custom fields, including writes from Data Workflows and bulk updates, starting when the selection takes effect. Allow up to a minute for a newly selected field to start exporting.

In `Returning_Reward_Event__c`, provision the writable fields below alongside the base reward event fields. Allow negative and decimal values in `Delta__c`. If `Event_Type__c` is a restricted picklist, add `CUSTOM_FIELD_CHANGED`.

| Salesforce field and type | Value |
| --- | --- |
| `Custom_Field_Key__c` Text(255) | Community custom field key. |
| `Custom_Field_Value__c` Long Text Area (32,768) | Value recorded for the write, stored as text. |
| `Custom_Field_Operation__c` Text(255) | `overwrite`, `increment` or `decrement`. |
| `Delta__c` Number | Positive increment or negative decrement. Omitted for overwrites. |

In the Returning.AI dashboard, open Salesforce > Reward Event Settings and turn on Export reward events to Salesforce. Under Custom field changes, select the fields to export and save once the setup checks pass. This selection works independently of Milestones. If you enable Link reward events to Account, the export uses the trader's active custom identifier mapped to Account.

To confirm delivery, look up the event by `Returning_Event_Id__c` in Salesforce and check for `CUSTOM_FIELD_CHANGED` in `Event_Type__c`. Retries upsert the same record using the same external ID and recorded field value. Separate writes have separate event IDs, even when they produce the same value. Incrementing or decrementing by zero produces no event.

If a record is missing, your success manager can check its delivery status. Removing a field from the selection pauses its queued deliveries. Selecting it again resumes them. Temporary errors retry with backoff, with at most 12 delivery attempts. For failed deliveries, correct the cause, such as Salesforce field permissions or a value that exceeds the field limit, before requesting replay.

## Other outbound deliveries

Use Settings > Integration > Webhooks for community activity such as member joins, new messages and Store purchases. Select the event in that screen and check the payload your receiver gets. For Data Workflow bulk updates, see the [bulk update results callback](https://docs.returning.ai/broker-integrations/workflow-webhooks.md#bulk-update-callback).

## Next steps

Store each trader's platform user ID when you [enroll them](https://docs.returning.ai/broker-integrations/users.md), so webhook payloads map to your customers. Then add your endpoint to the [launch checklist](https://docs.returning.ai/broker-integrations/launch-checklist.md).
