> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neobiz.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Neobiz Inbox API v1

> Connect your application to Inbox conversations, replies and signed webhook events.

Use the Inbox API to receive conversation events, read public transcripts, reply to customers and assign work across WhatsApp, Instagram and Messenger. Set `NEOBIZ_API` to the HTTPS base URL for the provisioned environment.

See the [object reference](https://docs.neobiz.id/api-reference/inbox-objects.md) for JSON examples, field types, nullable values and customer identity.

## Authentication and tokens

| Who calls whom | Credential | How to use it |
| - | - | - |
| Tenant owner → Neobiz | Staff access token (JWT) with the `Owner` role | Send `Authorization: Bearer <accessToken>` to manage `/v1/inbox/subscriptions`. The owner keeps the access and refresh tokens. |
| Your application → Neobiz | Integration API key (`neo_…`) | Send `X-Neobiz-Api-Key: <apiKey>` on every conversation, message, assignee and action request. The key has no scheduled expiry or refresh exchange. Key replacement or subscription revocation disables it. |
| Neobiz → your webhook | Signing secret (`whsec_…`) | Keep the secret on your receiver. Use it to verify the `X-Neobiz-Signature` header over the raw request body as shown in section 2. |

### Request limits and retries

An API key has two independent one-minute budgets for the partner Inbox endpoints. The default is **120 reads** across conversation, message and assignee lookups and **30 writes** across replies and conversation actions. Each page of a list consumes one read. Applications sharing a key share its budgets. Replacing a key keeps its existing budgets. Owner subscription management and outbound webhook deliveries have separate request paths.

When a budget runs out, Neobiz returns HTTP `429` with `{"error":"RATE_LIMIT_EXCEEDED"}` and a `Retry-After` header in whole seconds. The handler has not executed. Pause the affected requests for at least that long, then resume gradually. Retry a reply with the same `requestId`, conversation and body. A higher ingress limit can also return 429 before authentication when many calls come from the same network peer. During a Redis outage, conversation, message and assignee reads continue with a smaller per-key allowance on each API host. Exhausting that allowance returns 429. Replies and conversation actions return `503` with `RATE_LIMIT_UNAVAILABLE` and `Retry-After` until the host can check the shared budget. Authentication and scope checks continue on every request.

**For operators.** Set `ReadsPerMinute`, `WritesPerMinute` and `IngressPerMinute` in the `PartnerApi:RateLimits` section on every API replica. Each value must be a positive integer. The ingress default is 1,200 attempts per minute per peer bucket on each host. Peers can share a bucket, particularly behind a reverse proxy. Configure the same `ConnectionStrings:Redis` and tenant database on all replicas to share credential counters. A single-host installation without Redis uses in-memory counters that reset on restart. Set `MaxReplicas` to the maximum number of API hosts that can serve partner traffic concurrently, including deployment overlap. The default of four gives each host 30 fallback reads per key per minute at the default 120-read limit. The allowance is `floor(ReadsPerMinute / MaxReplicas)`. A zero allowance returns 503 for reads during an outage. Local and Redis windows can overlap during transitions, and restarting a host resets its local allowance.

While Redis is unavailable, each host waits five seconds before letting one partner request retry the shared quota check. Concurrent requests keep their outage limits while that check runs. A response from Redis restores shared enforcement, including when Redis reports the key is already over quota. Monitor the per-host gauge `neobiz.partner_api.quota.degraded` on the `Neobiz.PartnerApi` meter (1 during fallback, 0 otherwise).

Credential `LastUsedAt` is an approximate UTC time of successful authentication. The first use records it, and subsequent authentications refresh it at most once every five minutes. Revocation and permission checks still run on every request. An authenticated request can count as use even if its operation subsequently returns 429.

### Set up an integration in the dashboard

Sign in as a tenant owner and open **Settings → Integrations → API keys → Create API key**. Give the application a name, expand each module and select its permissions. Each header shows the selections for that module. Inbox grants take effect when saved. Other module selections persist for future use and grant no API or webhook access today. Choose an **Acting staff member** when granting an Inbox write permission. Copy the key when issued. A read-only key can operate without a staff identity or a webhook.

To receive events, open **Webhooks → Add webhook**, choose an active key with **Read conversations**, enter its public HTTPS endpoint, and select the Inbox events to receive. Each key supports one endpoint. Copy the signing secret when issued. Removing Read conversations stops subsequent deliveries, including queued retries. Restoring access enables future matching events.

Use **API keys** to replace a lost key or revoke the integration. Revocation disables both API access and webhook delivery. Use **Webhooks** to edit the endpoint, send a test event or rotate its signing secret. Existing API keys are stored as hashes and cannot be displayed again. Replacing a key invalidates its predecessor immediately. Dashboard and API changes manage the same subscriptions.

[API keys screenshot](./screenshots/api-keys.png) · [Webhooks screenshot](./screenshots/webhooks.png) · [Inbox permissions](./screenshots/inbox-permissions.png) · [Inventory permissions](./screenshots/module-permissions.png) · [Webhook event picker](./screenshots/inbox-webhook-events.png)

### Obtain or renew the owner token

An owner with a current Neobiz staff access token can go straight to registration. For a new staff session, the API exposes the following flow. **Initial sign-in limitation:** the staff OTP request currently creates a challenge without delivering the code to the owner. A fresh self-service sign-in depends on staff OTP delivery being available in the target environment.

| Step | Request | Response and next action |
| - | - | - |
| Request a one-time code | `POST /auth/staff/otp/request` with `{"tenantId":"<tenant UUID>","principal":"<owner identity user UUID>"}` | Save `sessionToken` and observe `expiresAt`. The principal is the owner’s `AspNetUserId`. |
| Verify the code | `POST /auth/staff/otp/verify` with `{"tenantId":"<tenant UUID>","sessionToken":"<sessionToken>","code":"<OTP>"}` | The response includes `accessToken`, `refreshToken`, `staffId` and `role`. Use the access token as `OWNER_TOKEN` below when the role is `Owner`. |
| Renew the session | `POST /auth/staff/refresh` with `{"tenantId":"<tenant UUID>","refreshToken":"<current refreshToken>"}` | Replace both stored tokens with the returned pair. The access token lasts 15 minutes. Each refresh token is single-use and its session expires after 30 days. Refresh once at a time because reusing a rotated token revokes its session family. |

Send these request bodies as `application/json`. Once registration is complete, the integration can read and write using its API key independently of the owner’s session.

## 1 Register and test your webhook endpoint

For write permissions, choose an active Neobiz staff account to represent your integration. Neobiz attributes API replies and claims to this account. A dedicated account makes it easier to recognize replies sent by your application. The owner grants access across the tenant’s customer Inbox, including all locations and all three channels.

```sh theme={null}
curl -X POST "$NEOBIZ_API/v1/inbox/subscriptions" \
  -H "Authorization: Bearer $OWNER_TOKEN" -H 'Content-Type: application/json' \
  -d '{"displayName":"Support integration","permissions":["inbox:read","inbox:reply"],"eventTypes":["message.created","conversation.updated"],"actingStaffId":"762f2c1e-a072-4174-9087-26cf49789dd5","webhookUrl":"https://support.example.com/webhooks/neobiz"}'
```

A successful registration returns HTTP 201 with `subscriptionId`, `apiKey` and `webhookSecret`. Give the integration backend the API key (shown below as `INBOX_API_KEY`) and the webhook receiver the signing secret. Store each in its respective secret store. Neobiz returns the plaintext values once. The callback destination must be a publicly reachable HTTPS endpoint. Use a different subscription for each environment.

| Owner operation | Method and path | Result |
| - | - | - |
| List subscriptions | `GET /v1/inbox/subscriptions` | IDs, names, destinations and activation state |
| Test a subscription | `POST /v1/inbox/subscriptions/{id}/test` | 202 and an event ID. Match this against a signed `subscription.test` at your receiver to confirm delivery. |
| Change permissions | `PUT /v1/inbox/subscriptions/{id}/permissions` with `permissions` and optional `actingStaffId` | 204. Replaces the active grants. Include `configuredPermissions` to replace saved future selections as well. |
| Add or update webhook | `PUT /v1/inbox/subscriptions/{id}/webhook` with `{"webhookUrl":"https://example.com/inbox"}` | First attachment returns 200 and the one-time signing secret. Updates return 204. Supply optional `eventTypes` to replace the event selection. |
| Replace API key | `POST /v1/inbox/subscriptions/{id}/rotate-key` | 200 and a one-time `apiKey`. Switch the calling application to this value. |
| Rotate signing secret | `POST /v1/inbox/subscriptions/{id}/rotate` | 200 and the new secret. Configure the receiver immediately. Subsequent attempts use the current secret. |
| Revoke subscription and API key | `DELETE /v1/inbox/subscriptions/{id}` | 204. New requests with that key return 401. Queued events are checked again before dispatch. |

For a cutover with overlapping keys, register a second subscription, switch the integration, and revoke the original. Both destinations can receive events during the overlap. For an immediate replacement, use `/rotate-key`.

## 2 Receive and authenticate events

Neobiz POSTs JSON to your registered URL. Read the raw HTTP body before parsing it. Compute HMAC-SHA256 with the UTF-8 signing secret as the key and the original body bytes as the input. Compare the lowercase hexadecimal digest, prefixed with `sha256=`, with the `X-Neobiz-Signature` header using a constant-time comparison. The signed body contains the event type. `X-Neobiz-Event` repeats it for routing.

```js theme={null}
import { createHmac, timingSafeEqual } from "node:crypto";

export function validSignature(rawBody, header, secret) {
  if (typeof header !== "string" || !/^sha256=[0-9a-f]{64}$/.test(header)) return false;
  const expected = createHmac("sha256", secret).update(rawBody).digest();
  return timingSafeEqual(expected, Buffer.from(header.slice(7), "hex"));
}
```

Example of a customer message event:

```json theme={null}
{
  "version": 1,
  "eventId": "2a52f865-3ccb-4931-9f3d-1f89ec0465c6",
  "eventType": "message.created",
  "occurredAt": "2026-12-02T08:40:00+00:00",
  "tenantId": "80824bf2-5278-4b69-a65b-fdd207fb8db4",
  "conversationId": "945ade15-9428-4da9-93bb-7d63c3f2b0d0",
  "messageId": "0cbd7774-7b47-44a3-a654-39903614a106",
  "authorType": "customer",
  "channel": "WhatsApp"
}
```

| Event type | What your application should do |
| - | - |
| `message.created` | A live customer message was recorded, or Neobiz recorded the first provider acceptance for an outbound message, including a successful retry after an earlier failure or uncertain outcome. Later delivery and read receipts keep the same message ID. `authorType` distinguishes `customer`, `human`, `ai` and `automation`. A staff reply from the dashboard or a merchant’s phone is human. A Neo reply is AI. A transactional notification can be automation. Fetch the referenced message for its text. |
| `message.updated` | Re-read the message for the latest recorded content, withdrawal or delivery status. A receipt depends on what the channel reports. |
| `message.failed` | Neobiz recorded a failed outbound attempt. For a reply sent in parts, this event can follow `message.created` if the customer received the first part and a later part failed. The message status remains `Failed` even if the customer reads the delivered part. Review the transcript before sending a replacement. |
| `conversation.updated` | Fetch the conversation to refresh assignment, status or snooze state. The message ID and author type are null for this event. |
| `subscription.test` | Record the event ID and acknowledge. Conversation, message, channel and author fields are null. |

The Read conversations permission grants access to eligible history, including conversations and messages from before the key was issued. Webhooks start when the endpoint is activated. Adding an endpoint to an existing key, changing its destination, or restoring its read permission starts a new delivery window. Rotating the signing secret preserves that window. A new receipt or edit on an older message can produce `message.updated`. Historical messages are never replayed as `message.created`.

Hosts learn about enrollment through the backplane. A host that misses an enrollment change can continue serving chat using its last confirmed subscriptions until it reconnects. To reconcile a gap, list conversations and fetch their current transcripts. Webhooks resume for new activity once the host has refreshed its subscriptions.

Webhook payloads contain references. Fetching message content separately returns the latest edit or withdrawal. Private notes, staff operations threads and preview chats are excluded. Imported history and campaign snapshot rows are available through public transcript reads but do not create live message triggers.

**Receiver behavior.** Verify the signature, durably enqueue the event keyed by `eventId`, then return any 2xx within 10 seconds. A repeated event ID should also receive 2xx. Events may arrive more than once or out of order. Neobiz retries timeouts, connection failures, 408, 429 and 5xx up to five total dispatches. Retries become eligible after 15, 30, 60 and 120 seconds respectively. During each delay Neobiz pauses the affected tenant’s queued callbacks so other tenants can receive theirs. Other unsuccessful HTTP responses end delivery to that subscription. For an outage exceeding retries, reconcile the conversation list and public transcripts. Checking current state also handles callbacks received in reverse order.

## 3 Read conversations and messages

To check the API key after registration, request the first page of conversations. A 200 response, including an empty `items` list, confirms the key can read the Inbox.

```sh theme={null}
curl --fail-with-body "$NEOBIZ_API/v1/inbox/conversations" \
  -H "X-Neobiz-Api-Key: $INBOX_API_KEY"
```

Scopes are checked for each request. A write also requires an active operator with the appropriate Inbox and outlet access.

| Scope | Access |
| - | - |
| `inbox:read` | Conversations, customer summaries, public messages and eligibility to select Inbox webhook events |
| `inbox:read-assignees` | Staff directory for assignment |
| `inbox:reply` | Send replies |
| `inbox:assign` | Claim or assign conversations |
| `inbox:handoff` | Hand off to the team or Neo |
| `inbox:manage-status` | Snooze or resolve conversations |

Legacy registrations that omit both `permissions` and `configuredPermissions` require both a webhook URL and an operator and retain the original read/write scope bundle. Explicit grants reject unsupported scopes. Omit `webhookUrl` to create a key only.

| Method and path | Result |
| - | - |
| `GET /v1/inbox/conversations` | A page of conversation headers. Optional `updatedSince` is an inclusive ISO 8601 timestamp on the conversation header. |
| `GET /v1/inbox/conversations/{id}` | One channel thread, including a `customer` object with `memberId` and `displayName`, plus location, status, assignee, snooze time and reply windows. |
| `GET /v1/inbox/conversations/{id}/messages` | Public messages in storage creation order. Use `sentAt` for the historical send time. |
| `GET /v1/inbox/conversations/{id}/messages/{messageId}` | One message. Text is in `body`; a withdrawn message has `withdrawn: true` and `body: null`. Media is identified by content type. |
| `GET /v1/inbox/assignees` | Active staff IDs, first and last names when available, and primary location IDs. |

For the fields returned by these endpoints, see [Conversation](https://docs.neobiz.id/api-reference/inbox-objects.md#conversation-chat), [Customer identity](https://docs.neobiz.id/api-reference/inbox-objects.md#customer-identity), [Message](https://docs.neobiz.id/api-reference/inbox-objects.md#message) and [Assignee](https://docs.neobiz.id/api-reference/inbox-objects.md#assignee).

Both list endpoints for conversations and messages return `{"items":[...],"next":null}` with up to 100 items. If `next` is present, send it as `?after=<next>` and keep any filters. Continue until `next` is null. For a full reconciliation, enumerate all conversation IDs and page their transcripts. A header’s update time alone cannot identify every edit or delivery receipt. Use the underlying conversation ID for each channel, including when the dashboard combines a member’s threads.

## 4 Send a reply and manage a chat

```sh theme={null}
curl -X POST "$NEOBIZ_API/v1/inbox/conversations/$CHAT_ID/replies" \
  -H "X-Neobiz-Api-Key: $INBOX_API_KEY" -H 'Content-Type: application/json' \
  -d '{"requestId":"4a46709f-5f1d-47ba-9284-22f33649f311","body":"I can help with that order."}'
```

Generate one UUID per intended message. After a timeout, repeat the same request ID, conversation and exact text with the same credential. The reply is plain text, up to 4,096 characters. Success returns 200 with `messageId` and `status`. A replay can return 202 with `Pending` while the provider outcome is unknown. Retrieve the message to reconcile. If the transcript is edited, replay the original request text. Reusing the same request ID with changed text or a different conversation returns 409. Correlate the returned message ID with callbacks for your own writes to avoid feedback loops. Route automatic replies only from the customer events you intend to answer.

Neobiz applies the dashboard’s channel reply window, WhatsApp credit checks and human takeover behavior. The social channels’ extended human-agent window is for replies authored by people. This endpoint sends as the designated human operator. Use `handoffToNeo` to let Neo resume its own automated replies.

All commands below use `POST /v1/inbox/conversations/{id}/actions` and return 204 on success.

| Action body | Effect |
| - | - |
| `{"action":"claim"}` | Claim as the integration’s designated staff account. A competing owner yields 409. |
| `{"action":"assign","staffId":"<active staff UUID>"}` | Assign to an active operator who has Inbox viewing permission and access to the conversation’s location. |
| `{"action":"handoffToTeam"}` | Return to the human team’s unassigned queue. |
| `{"action":"handoffToNeo"}` | Return handling to Neo. A persistent manual mute or paused social channel yields 409 with `NEO_PAUSED`. |
| `{"action":"snooze","until":"2027-01-15T09:00:00Z"}` | Snooze until a future timestamp. The staff timeline records the designated operator and deadline. |
| `{"action":"resolve"}` | Resolve the conversation. |

**Errors.** 400 indicates an invalid input, including a cursor or assignee. 401 means the key is missing, invalid or revoked. 403 indicates insufficient scope or an inactive designated operator on a write. 404 means the requested public resource is unavailable to this tenant. 409 covers a conflicting owner, concurrent update, closed messaging window, insufficient credit or failed send. Read the response’s `error` field where supplied. Refresh the resource after a conflict. Keep the same request ID when checking an uncertain send.

## 5 Verify the integration together

1. Register a test subscription in the agreed Neobiz environment and confirm its signed test event.
2. Send a customer message and let Neo answer. Check that your receiver gets two distinct message IDs for the same conversation with author types `customer` and `ai`.
3. Claim the conversation, send one API reply twice with the same request ID and confirm a single human message in the customer’s channel. Assign it to a second operator and check the conversation update.
4. Add a private dashboard note. Verify that it is absent from both the callback stream and the public transcript.
5. Return 503 once, then acknowledge the retry. Confirm the event ID is stable. Rotate the secret, send another test, then revoke the test subscription and confirm that the old API key returns 401.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.