# Reference Architecture (/build/architecture.md) # Reference Architecture [#reference-architecture] Before any code, get the shape right. A production Sent integration is small but has a few distinct responsibilities that are worth separating. Keeping them apart is what makes the integration testable, safe to scale, and easy to reason about when something fails at 3 AM. ## The layers [#the-layers] A production Sent integration is organized the same way, regardless of language: CF[Per-request client factory] CF --> SVC[Sent service layer] SVC --> R[Routes / controllers] R --> APP[HTTP app] WR[Webhook receiver] --> APP VER[Signature verifier] --> WR WR --> STORE[(State store)] MGMT[Webhook management] --> SVC classDef edge fill:#eef,stroke:#88a `} /> *In plain English: config loads first, builds a per-request client, which the service layer uses to talk to Sent; routes call the service layer; a separate webhook receiver (with its own verifier) writes to the same state store. Read top to bottom.* | Layer | Responsibility | Why it's separate | |---|---|---| | **Config & validation** | Parse and validate environment/config at startup; fail fast on misconfiguration. | Nothing downstream should defend against missing config. | | **Per-request client factory** | Turn the caller's `Authorization: Bearer` key into an SDK client for *this* request. | The key is a request credential, not global state. See [Authentication](/build/authentication). | | **Sent service layer** | A thin wrapper over the SDK: one method per business operation, snake→camel mapping, error translation. | Keeps SDK types out of your controllers and makes everything mockable in tests. | | **Routes / controllers** | HTTP surface, request validation, response shaping. | Thin. All logic lives in the service layer. | | **Webhook receiver** | Verify → acknowledge → process inbound events. | It's a public, state-mutating endpoint; it needs its own security discipline. | | **Signature verifier** | The HMAC verification primitive, isolated and unit-tested. | Security-critical and identical across every route that needs it. | | **State store** | Track message status from webhook events; hold webhook secrets; track idempotency/dedupe keys. | The only stateful part, and the part you swap for Redis/DB in production. | This isn't heavyweight. In most languages each layer is one small file. The point is that "call the SDK" and "receive a webhook" never bleed into each other, and neither one reaches directly for global credentials. ## Flow 1: Outbound (you call Sent) [#flow-1-outbound-you-call-sent] A client hits your API; you build a Sent client from the request's credential, call the service layer, and map the response back to your own contract. >R: POST /api/messages (Authorization: Bearer ) R->>F: build client for this request F-->>R: SDK client (scoped to the key) R->>S: send({ to, channel, template, sandbox }) S->>API: messages.send(...) API-->>S: { data: { status, recipients[] } } S-->>R: mapped { status, recipients:[{ id, to, channel }] } R-->>C: 200 { status, recipients } `} /> *In plain English: read each arrow top to bottom as one step in order. Your route builds a client, hands off to the service layer, which calls Sent and maps the response back. The `200` you return only means "accepted," not "delivered."* The message now exists on Sent's side in a non-terminal state (`QUEUED`). Its final outcome arrives later, asynchronously, over a webhook. That's Flow 2. ## Flow 2: Inbound (Sent calls you) [#flow-2-inbound-sent-calls-you] As the message progresses, Sent `POST`s signed events to an endpoint you registered. Your receiver verifies, acknowledges immediately, then updates state. >W: POST /webhooks/sent (signature headers, raw body) W->>V: verify(raw body, headers, secret) alt invalid signature or stale timestamp V-->>W: reject W-->>API: 401 else valid V-->>W: ok W-->>API: 200 { received: true } Note over W,DB: acknowledge first, then process W->>DB: updateStatus(message_id, message_status) end `} /> *In plain English: the `alt`/`else` box is an if/else. If the signature is bad or the timestamp is stale, reject with `401`; otherwise acknowledge with `200` immediately, and only then update your own state store.* Two independent flows, one shared service layer. Everything else in this guide is filling in these boxes correctly. ## The HTTP surface your integration exposes [#the-http-surface-your-integration-exposes] This guide standardizes on one contract so the pattern applies unchanged regardless of your backend. You don't have to expose exactly this, but it's a well-tested starting point and the rest of the guide uses these paths. | Method | Path | Purpose | |---|---|---| | `GET` | `/health` | Liveness. | | `POST` | `/api/auth/verify` | Validate a key against `GET /v3/me`. | | `POST` | `/api/messages` | Send a templated message. | | `GET` | `/api/messages/:id` | Read a tracked message's current status. | | `GET` / `POST` | `/api/contacts` | List / create contacts. | | `DELETE` | `/api/contacts/:id` | Delete a contact. | | `GET` | `/api/templates` (`/:id`) | List / fetch templates. | | `POST` | `/webhooks/sent` | **Receive** signed webhook events. | | `GET` / `POST` | `/api/webhooks` | List / register webhook endpoints. | | `PATCH` | `/api/webhooks/:id/toggle` | Turn an endpoint on / off. | | `POST` | `/api/webhooks/:id/rotate-secret` | Rotate an endpoint's signing secret. | | `DELETE` | `/api/webhooks/:id` | Remove an endpoint. | Note the two distinct webhook paths. `POST /webhooks/sent` is where Sent delivers events to you (the receiver). The `/api/webhooks*` routes are where *your* client manages which endpoints exist (management, a proxy over the SDK). They are different concerns. See [Endpoint management](/build/endpoint-management). ## Stateful vs stateless [#stateful-vs-stateless] The only stateful pieces are the **message-status store**, the **held webhook secrets**, and the **idempotency/dedupe keys** that guard against duplicate sends and duplicate webhook processing. Starting with all three in-process memory is perfect for a single instance and for learning the pattern. In production you run more than one instance, so all three move to shared storage. This guide builds the in-memory version first and shows the swap in [Scaling & deployment](/build/scaling-and-deployment). **If you're on PHP-FPM, "in-process memory" doesn't mean what it does in Node, Python, or Go.** Those runtimes keep one long-lived process handling many requests, so a plain in-memory map genuinely persists between them. PHP-FPM spins up a fresh process (or reuses one with no memory of prior requests) for every single request. An in-memory store built the same way as the other languages' examples will silently be empty on the very next request. For PHP, treat "in-process" as file-backed (or Redis/DB) from day one, not as an optional later upgrade. ## Next steps [#next-steps] # Authenticating Requests with Per-Request Clients (/build/authentication.md) # Authenticating Requests with Per-Request Clients [#authenticating-requests-with-per-request-clients] This is the foundation everything else in the integration builds on, and it's the one thing most integrations get wrong. This guide shows you how to extract the caller's API key, build a per-request SDK client in seven frameworks, guard protected routes with `401`, verify a key, and keep rotation a non-event. The rule, stated once and precisely: > The Sent API key is a **per-request credential**. It arrives as > `Authorization: Bearer `, and you use it to build an SDK client **for that request**. > It is **never** a boot-time singleton, and it is **never** a stored or required environment > variable. **Do not do this.** The most common mistake in a Sent integration: ```ts // ❌ Anti-pattern: a global client built from an env var at boot. import SentDm from "@sentdm/sentdm"; export const sent = new SentDm({ apiKey: process.env.SENT_DM_API_KEY }); ``` This bakes a single tenant's key into your process, forces a secret into your environment, makes multi-tenant serving impossible, and turns key rotation into a redeploy. There is no `SENT_DM_API_KEY` env var anywhere in this blueprint. Build the client **per request** instead. **Quick path.** If you just need this working: pick your language/framework tab under [The per-request client factory](#the-per-request-client-factory), copy the bearer-extraction function and the 401 guard, and call the factory at the top of every protected route. That's the whole pattern. The rest of this page covers key sources, `401` handling, verification, and rotation; the reasoning behind the rule lives in [About per-request credentials](/build/per-request-credentials). ## The per-request client factory [#the-per-request-client-factory] The pattern is identical in every language: pull the bearer token off the request, reject with `401` if it's missing, and construct a client bound to that key. Nothing is cached across requests; nothing reads a global. ```ts import SentDm from "@sentdm/sentdm"; import type { Request } from "express"; import { ApiError } from "../types"; /** Builds SDK-backed services bound to a specific customer's API key. */ export function servicesForApiKey(apiKey: string): Services { const client = new SentDm({ apiKey }); return { sentService: new SentService(client), /* … */ }; } /** * Resolve the API key for THIS request. The ONLY valid source is * `Authorization: Bearer `. The key is never persisted. */ export function apiKeyFromRequest(req: Request): string | undefined { const header = req.header("authorization"); const bearer = header?.match(/^Bearer\s+(.+)$/i)?.[1]?.trim(); return bearer || undefined; } /** Per-request services — throws 401 when no bearer token is present. */ export function servicesForRequest(req: Request): Services { const apiKey = apiKeyFromRequest(req); if (!apiKey) { throw new ApiError(401, "Unauthorized", "Missing API key — send it as Authorization: Bearer ."); } return servicesForApiKey(apiKey); } ``` ```ts import SentDm from "@sentdm/sentdm"; import type { NextRequest } from "next/server"; export function apiKeyFromRequest(request: NextRequest | Request): string | undefined { const header = request.headers.get("authorization"); const bearer = header?.match(/^Bearer\s+(.+)$/i)?.[1]?.trim(); return bearer || undefined; } export class MissingApiKeyError extends Error { readonly status = 401; readonly code = "Unauthorized"; constructor() { super("Missing API key — send it as Authorization: Bearer ."); } } /** Builds an SDK client bound to a specific customer's key. */ export function clientForApiKey(apiKey: string): SentDm { return new SentDm({ apiKey, maxRetries: 2, timeout: 30_000 }); } /** Per-request client — throws MissingApiKeyError (401) when absent. */ export function clientForRequest(request: NextRequest | Request): SentDm { const apiKey = apiKeyFromRequest(request); if (!apiKey) throw new MissingApiKeyError(); return clientForApiKey(apiKey); } ``` ```python from fastapi import Depends, HTTPException, status from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from sent_dm import AsyncSent security = HTTPBearer(auto_error=False) async def get_optional_token( credentials: HTTPAuthorizationCredentials | None = Depends(security), ) -> str | None: return credentials.credentials if credentials else None def _resolve_api_key(token: str | None) -> str: if not token: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Missing API key — send it as Authorization: Bearer .", ) return token def get_sent_client(token: str | None = Depends(get_optional_token)) -> AsyncSent: """Per-request SDK client bound to the customer's API key.""" api_key = _resolve_api_key(token) return AsyncSent(api_key=api_key) def get_sent_service(client: AsyncSent = Depends(get_sent_client)) -> SentService: return SentService(client) ``` ```go // ClientResolver builds a per-request SentClient from the caller's API key. // The key lives only for the duration of the request. No env fallback. type ClientResolver struct{ logger *zap.Logger } var bearerRE = regexp.MustCompile(`(?i)^Bearer\s+(.+)$`) var ErrMissingAPIKey = &models.HTTPError{ Code: http.StatusUnauthorized, ErrorCode: "UNAUTHORIZED", Message: "Missing API key — send it as Authorization: Bearer .", } func (r *ClientResolver) APIKeyFromRequest(c echo.Context) string { header := c.Request().Header.Get("Authorization") if m := bearerRE.FindStringSubmatch(strings.TrimSpace(header)); m != nil { if key := strings.TrimSpace(m[1]); key != "" { return key } } return "" } // ForRequest → SentClient bound to this request's key, or 401 when absent. func (r *ClientResolver) ForRequest(c echo.Context) (*SentClient, error) { apiKey := r.APIKeyFromRequest(c) if apiKey == "" { return nil, ErrMissingAPIKey } return NewSentClient(apiKey, r.logger), nil } func NewSentClient(apiKey string, logger *zap.Logger) *SentClient { return &SentClient{client: sentdm.NewClient(option.WithAPIKey(apiKey)), logger: logger} } ``` ```php app->singleton(...)`. */ class SentClientFactory { public function forRequest(Request $request): Client { $apiKey = $this->resolveApiKey($request); if (empty($apiKey)) { abort(401, 'Missing API key — send it as Authorization: Bearer .'); } return new Client(apiKey: $apiKey, requestOptions: ['maxRetries' => 2]); } private function resolveApiKey(Request $request): ?string { $header = (string) $request->header('Authorization', ''); if (preg_match('/^Bearer\s+(.+)$/i', $header, $m)) { $bearer = trim($m[1]); return $bearer !== '' ? $bearer : null; } return null; } } ``` **Why not the container?** `$this->app->singleton(Client::class, fn () => new Client(apiKey: config('services.sent.key')))` is the same boot-time-singleton anti-pattern from the top of this page, expressed with Laravel's container. Under standard PHP-FPM it happens to be harmless because the whole process (and the container with it) is thrown away after each request. But under **Laravel Octane**, which reuses the same process across many requests exactly like Node or Python, that singleton would freeze the *first* request's key into every request the worker ever serves after it. Resolve `SentClientFactory` fresh (`app()->bind(...)` at most, never `singleton`) and call `forRequest($request)` explicitly. Don't let the container hold the client itself. ```php /** * Builds the Sent SDK client for THIS request. The API key is a per-customer * RUNTIME value, never required at boot and never persisted. No env fallback. */ class SentClientFactory { public function __construct( private readonly RequestStack $requestStack, private readonly int $maxRetries = 2, ) {} public function create(): Client { $apiKey = $this->resolveApiKey(); if (empty($apiKey)) { throw new HttpException(401, 'Missing API key — send it as Authorization: Bearer .'); } return new Client(apiKey: $apiKey, requestOptions: ['maxRetries' => $this->maxRetries]); } private function resolveApiKey(): ?string { $request = $this->requestStack->getCurrentRequest(); $header = (string) ($request?->headers->get('Authorization') ?? ''); if (preg_match('/^Bearer\s+(.+)$/i', $header, $m)) { $bearer = trim($m[1]); return $bearer !== '' ? $bearer : null; } return null; } } ``` ```ruby class ApplicationController < ActionController::API private # Resolve the customer API key for THIS request. nil when no bearer token. def current_api_key header = request.headers["Authorization"] header&.match(/\ABearer\s+(.+)\z/i)&.captures&.first&.strip.presence end # Guard for protected /api/* routes. 401 when no bearer token is present. def require_api_key! return if current_api_key.present? render json: { error: { code: "UNAUTHORIZED", message: "Missing API key — send it as Authorization: Bearer ." } }, status: :unauthorized end # Per-request SDK client built from the resolved key. def sent_client Sentdm::Client.new(api_key: current_api_key) end end ``` Note the framework-idiomatic shapes: Express uses a plain factory function, FastAPI a `Depends` chain, Go a `ClientResolver`, Laravel a plain service class called explicitly (never container-bound, see the preceding warning), Symfony a DI-injected factory scoped to `RequestStack`, Rails a controller `before_action` guard. They all implement the same contract: build fresh from the request, never cache across one. **One regex, everywhere.** Every backend matches `^Bearer\s+(.+)$` case-insensitively, trims, and treats empty as absent. Keep that parsing in the factory so no controller re-implements it. ## Where the key comes from [#where-the-key-comes-from] The factory needs a key on every request; its source depends on your deployment shape: - **Multi-tenant.** Each customer supplies their own key as `Authorization: Bearer `; extract it exactly as the factories in the preceding section do. Never share a client across tenants. - **Single-tenant.** Your own backend resolves the one key inside each request or job (from your config or secrets manager, never cached into a module-level global at boot) and hands it to the same factory. Never ship the key to a browser or mobile app. For why the pattern works this way, and what it buys you in rotation and tenant isolation, see [About per-request credentials](/build/per-request-credentials). ## No key → 401 [#no-key--401] A protected route with no bearer token must fail closed with `401`, before any SDK call. Every factory in [The per-request client factory](#the-per-request-client-factory) does exactly this. Two things to keep straight: - **Unprotected routes never gate on it.** `GET /health` and the webhook receiver `POST /webhooks/sent` don't build an SDK client, so they never call the factory and never return `401`. (The receiver has its own auth: the [signature](/build/signature-verification).) - **Fail before the network.** Reject the missing key locally; don't send an unauthenticated request to Sent just to bounce a `401` back. ## Verifying a key [#verifying-a-key] Before trusting a key, or to let a user confirm the one they pasted works, validate it against `GET /v3/me`. This is the canonical `POST /api/auth/verify` endpoint: it makes one authenticated call and reports whether the key is good, without leaking upstream error shapes. Two deliberate departures from the rest of this page: the route reads the key from the request body because its whole job is to test a key the user just pasted (it's not yet a trusted credential), and the upstream call sends the key in the `x-api-key` header because it calls the Sent REST API directly. The `Authorization: Bearer` shape on your routes is your API's contract with its own callers. [Sent's API accepts either header](/reference/api/authentication), and the SDKs send `x-api-key`. In the TypeScript sample, `asyncHandler` is one of the [shared helpers](/build/project-setup#shared-helpers) defined in project setup. ```ts router.post("/verify", asyncHandler(async (req, res) => { const { apiKey } = req.body as { apiKey?: string }; if (!apiKey) { return res.status(400).json({ valid: false, error: { status: 400, code: "MissingApiKey", message: "apiKey is required" } }); } const baseUrl = process.env["SENT_BASE_URL"] ?? "https://api.sent.dm"; const response = await fetch(`${baseUrl}/v3/me`, { headers: { "x-api-key": apiKey, "Content-Type": "application/json" }, }); const data = await response.json(); if (response.ok) return res.status(200).json({ valid: true, account: data }); return res.status(200).json({ valid: false, error: { status: response.status, code: data.code ?? "ApiError", message: data.message ?? "Authentication failed" }, }); })); ``` ```python @router.post("/api/auth/verify") async def verify(body: dict): api_key = body.get("apiKey") if not api_key: return {"valid": False, "error": {"status": 400, "code": "MissingApiKey", "message": "apiKey is required"}} base_url = os.getenv("SENT_BASE_URL", "https://api.sent.dm") async with httpx.AsyncClient() as http: resp = await http.get(f"{base_url}/v3/me", headers={"x-api-key": api_key}) data = resp.json() if resp.is_success: return {"valid": True, "account": data} return {"valid": False, "error": {"status": resp.status_code, "code": data.get("code", "ApiError"), "message": data.get("message", "Authentication failed")}} ``` `verify` returns `200` with `{ valid: false, error }` for a bad key rather than propagating the upstream `401`. That's a deliberate UX choice for a "test your key" screen: the request to *your* endpoint succeeded; the *key* is what's invalid. ## Secret hygiene and rotation [#secret-hygiene-and-rotation] The key is a bearer credential: anyone holding it can send on the account. Treat it accordingly. - **Never log it.** Not in request logs, not in error payloads, not in traces. Redact the `Authorization` header at your logging boundary. - **Never persist it.** Keep it out of environment variables, config files, database columns, and disk. It exists only in the request scope. When the request ends, so does the key. The one narrow, deliberate exception is queued/async work, where the key necessarily outlives the original request. See [Errors & resilience](/build/errors-and-resilience#retries-and-exponential-backoff) for the hygiene that exception requires. - **Transport only over TLS.** The bearer token is only as safe as the channel, so require HTTPS end to end. - **Scope who can send it.** In your own front end, the key comes from the authenticated user's session or vault, attached per request, never hard-coded or shipped to the browser. - **Rotation is a non-event.** Because nothing caches the key, a customer rotates in the dashboard and sends the new key on the next request. Your integration needs no redeploy, restart, or coordinated cutover. This is the direct reward for not holding the key in a singleton. If rotating a key would require you to redeploy or restart, that's the singleton anti-pattern leaking back in. In this architecture, rotation should require **zero** changes to your running app. ## Next steps [#next-steps] You can now build an authenticated client for any request. Put it to work on the outbound path. # Managing Contacts & Templates (/build/contacts-and-templates.md) # Managing Contacts & Templates [#managing-contacts--templates] This page shows you how to wrap contacts and templates in your service layer. Both follow the same shape as [sending messages](/build/sending-messages): a thin service method wraps the SDK resource, maps the snake_case response to your camelCase contract, and lets the controller stay dumb. Samples on this page are shown in TypeScript, Python, and Go; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). Concepts first: [contacts](/start/concepts/contacts) and [templates](/start/concepts/templates). Guides: [managing contacts](/start/guides/managing-contacts) and [working with templates](/start/guides/working-with-templates). This page is about *wiring* them into your service layer. ## Contacts [#contacts] Three operations: `contacts.list`, `contacts.create`, `contacts.delete`. The mapping is small but non-negotiable: `phone_number → phoneNumber`, `created_at → createdAt`, and it happens in the service, never in the controller. ```ts // services/sent.service.ts async listContacts(): Promise { const response = await this.client.contacts.list({ page: 1, page_size: 100 }); const contacts = response.data?.contacts ?? []; return contacts.map((c) => ({ id: c.id, phoneNumber: c.phone_number, // ← snake → camel createdAt: c.created_at, })); } async createContact(phoneNumber: string, sandbox?: boolean): Promise { const response = await this.client.contacts.create({ phone_number: phoneNumber, sandbox: sandbox ?? false, }); const c = response.data ?? {}; return { id: c.id, phoneNumber: c.phone_number, createdAt: c.created_at }; } async deleteContact(id: string): Promise { await this.client.contacts.delete(id, {}); } ``` ```python # app/services/sent_service.py async def list_contacts(self) -> CanonicalContactList: response = await self._client.contacts.list(page=1, page_size=100) contacts = response.data.contacts if response.data and response.data.contacts else [] return CanonicalContactList( items=[ CanonicalContact(id=c.id, phoneNumber=c.phone_number, createdAt=c.created_at) for c in contacts ] ) async def create_contact(self, request: CanonicalCreateContactRequest) -> CanonicalContact: response = await self._client.contacts.create( phone_number=request.phoneNumber, sandbox=request.sandbox, ) c = response.data return CanonicalContact( id=getattr(c, "id", None), phoneNumber=getattr(c, "phone_number", None), createdAt=getattr(c, "created_at", None), ) async def delete_contact(self, contact_id: str) -> None: await self._client.contacts.delete(contact_id) ``` ```go // internal/services/sentclient.go func (c *SentClient) CreateContact(ctx context.Context, phoneNumber string, sandbox bool) (*sentdm.APIResponseOfContact, error) { ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() params := sentdm.ContactNewParams{PhoneNumber: phoneNumber} if sandbox { params.Sandbox = sentdm.Bool(true) } return c.client.Contacts.New(ctx, params) } // internal/models/contract.go — map SDK contact → contract shape. func NewContactResponse(c sentdm.ContactResponse) ContactResponse { return ContactResponse{ ID: c.ID, PhoneNumber: c.PhoneNumber, // ← snake → camel at the JSON tag CreatedAt: c.CreatedAt, } } ``` The controller just delegates and picks status codes (`201` on create, `204` on delete). `validateBody` and `asyncHandler` are the [shared helpers](/build/project-setup#shared-helpers) from project setup: ```ts // controllers/contacts.controller.ts router.get('/', asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); res.status(200).json({ items: await sentService.listContacts() }); })); router.post('/', validateBody(CreateContactSchema), asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); const contact = await sentService.createContact(req.body.phoneNumber, req.body.sandbox); res.status(201).json(contact); })); router.delete('/:id', asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); await sentService.deleteContact(String(req.params.id)); res.status(204).send(); })); ``` ## Templates [#templates] Templates are read-only from your integration's side. You list them and retrieve them; you don't create them here (that's a console/approval workflow). Two operations: `templates.list` and `templates.retrieve`. Two mapping gotchas to handle explicitly: - The SDK exposes **`channels`** (an array); your contract wants a single **`channel`**, so take `channels[0]`. - The SDK `Template` model carries **no rendered `body`**, so emit `null` for it. Don't invent it. ```ts // services/sent.service.ts async listTemplates(): Promise { const response = await this.client.templates.list({ page: 1, page_size: 100 }); const templates = response.data?.templates ?? []; return templates.map((t) => ({ id: t.id, name: t.name, channel: t.channels?.[0], // ← channels[] → channel status: t.status, body: null, // ← SDK has no rendered body — always null category: t.category, language: t.language, })); } async getTemplate(id: string): Promise { const response = await this.client.templates.retrieve(id); const t = response.data ?? {}; return { id: t.id, name: t.name, channel: t.channels?.[0], status: t.status, body: null, category: t.category, language: t.language, }; } ``` ```python # app/services/sent_service.py def _channel_from_template(tmpl) -> str | None: channels = getattr(tmpl, "channels", None) return channels[0] if channels else None async def list_templates(self) -> CanonicalTemplateList: response = await self._client.templates.list(page=1, page_size=100) templates = response.data.templates if response.data and response.data.templates else [] return CanonicalTemplateList( items=[ CanonicalTemplate( id=t.id, name=t.name, channel=_channel_from_template(t), # ← channels[] → channel status=t.status, body=None, # ← SDK has no rendered body — always None category=t.category, language=t.language, ) for t in templates ] ) async def get_template(self, template_id: str) -> CanonicalTemplate: response = await self._client.templates.retrieve(template_id) t = response.data return CanonicalTemplate( id=getattr(t, "id", None), name=getattr(t, "name", None), channel=_channel_from_template(t), status=getattr(t, "status", None), body=None, # ← SDK has no rendered body — always None category=getattr(t, "category", None), language=getattr(t, "language", None), ) ``` ```go // internal/models/contract.go — map SDK template → contract shape. func NewTemplateResponse(t sentdm.Template) TemplateResponse { channel := "" if len(t.Channels) > 0 { channel = t.Channels[0] // ← channels[] → channel } return TemplateResponse{ ID: t.ID, Name: t.Name, Channel: channel, Status: t.Status, Body: nil, // ← *string in the contract; SDK has no rendered body — always null Category: t.Category, Language: t.Language, } } ``` ## Looking up templates by id or name [#looking-up-templates-by-id-or-name] The send API accepts a template `id` **or** `name`. You don't need both. Prefer resolving by **name** and letting `templates.list` give you the id when you need it, rather than pasting UUIDs around your codebase. ```ts // Resolve a stable, human-readable name to whatever the current template is. async function resolveTemplate(sent: SentService, name: string): Promise { const templates = await sent.listTemplates(); const match = templates.find((t) => t.name === name); if (!match) throw new ApiError(404, 'TemplateNotFound', `No template named "${name}"`); return match; } ``` Don't ship hard-coded template UUIDs scattered through your business logic. In real code, map a small set of **stable names** (`welcome`, `order_update`) to templates, resolve them at the edge, and let the id float. When a template is re-approved with a new id, nothing in your code changes. Docs snippets inline an id (`templateId: 'welcome-template-id'`) only for brevity. Validate at send time, too: a template must be **approved** for the channel you're sending on. Check `status === "APPROVED"` (and that the resolved `channel` matches your intended channel) before you call `send`, so you fail with a clear error instead of a cryptic API rejection. Budget real time for approval before your go-live date. WhatsApp template approval typically takes **24-48 hours** (see [Create your first template](/start/quickstart/first-template)). SMS templates aren't gated the same way, so if you're SMS-only you can usually send immediately. Build and test against a `sandbox: true` send while waiting; don't let approval latency be a surprise on launch day. `resolveTemplate` as shown makes a full `listTemplates` round trip on every send. Fine for a first pass, but templates change rarely, so a short-TTL cache (30-60s in memory, or your shared store once you're on multiple instances) removes that extra call and its rate-limit cost from your hot send path without meaningfully delaying a template re-approval from taking effect. ## Why the wrapper matters [#why-the-wrapper-matters] Every method here does the same three things: call one SDK resource, map snake→camel, translate errors. That uniformity is the point. - Controllers depend on your service interface, never on SDK types, so the SDK is mockable and swappable in tests. - The contract stays stable even when the SDK's field names or shapes drift. - The client is still built **per request** (`servicesForRequest`) from the bearer key. These reads are just as scoped as the sends. See [Authentication](/build/authentication). ## Next steps [#next-steps] # Managing Webhook Endpoints (/build/endpoint-management.md) # Managing Webhook Endpoints [#managing-webhook-endpoints] The receiver is where Sent *delivers* events. This page is the other side, the surface where your customers *manage which endpoints exist*: register a URL, turn it on or off, rotate its secret, remove it. These are two distinct concerns living at two distinct paths, and it's worth being precise: - **`POST /webhooks/sent`**: the receiver. Sent calls it. Covered in [The webhook receiver](/build/webhook-receiver). - **`/api/webhooks*`**: management. *Your client* calls it. A thin proxy over the SDK's `webhooks` resource. That's this page. The management routes proxy the SDK's `webhooks.list` / `create` / `delete` / `rotateSecret` / `toggleStatus` methods, mapping the SDK's snake_case fields to your camelCase contract. Samples on this page are shown in TypeScript, Python, and Go; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). **Developing locally?** Sent needs a publicly reachable HTTPS URL to deliver to. It can't reach `localhost`. Tunnel your local receiver with a tool like [ngrok](https://ngrok.com) (`ngrok http 3000`) or ngrok's built-in webhook forwarding, register the tunnel's URL as your endpoint, and you'll see real, signed deliveries hit your machine while you develop. Swap in your real production URL before go-live. See the [checklist](/build/going-to-production). ## Per-customer isolation [#per-customer-isolation] Every management call is authenticated by the caller's `Authorization: Bearer `, and the SDK client is built per request from that key (see [Authentication](/build/authentication)). The SDK's `webhooks` resource is scoped to the account behind the key, so a customer only ever sees and manages *their own* endpoints. There's no cross-customer spillage to guard against. The credential boundary handles it, as long as you never build the client from a shared, stored key. ## The born-on-registration secret [#the-born-on-registration-secret] This is the one thing to get right here. The signing secret is **returned exactly once**, on create (and again on rotate). It is not an env var you set, and there is no API to read it back later. If you don't capture it at the moment of creation, you cannot verify that endpoint's deliveries. You'll have to rotate to get a fresh one. So the create handler does two things atomically: register the endpoint via the SDK, and hand the returned `secret` to the store your receiver verifies against. For what that store should be, see [Where the secret lives](#where-the-secret-lives). ## Registering an endpoint [#registering-an-endpoint] In the TypeScript sample, `validateBody`, `asyncHandler`, and `webhookSecretStore` are the [shared helpers](/build/project-setup#shared-helpers) defined in project setup. ```ts router.post("/", validateBody(CreateWebhookSchema), asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); const body = req.body as { url: string; eventTypes?: string[] }; const created = await sentService.createWebhook(body.url, body.eventTypes); // Hold the signing secret in memory, keyed by endpoint id, so the receiver // can look up the right secret for whichever endpoint Sent delivers to. webhookSecretStore.remember(created.id, created.secret); res.status(201).json(created); })); // In the service layer — note the snake_case → camelCase field mapping: async createWebhook(url: string, eventTypes?: string[]) { const response = await this.client.webhooks.create({ endpoint_url: url, // contract `url` → SDK `endpoint_url` event_types: eventTypes, // contract `eventTypes` → SDK `event_types` }); const w = response.data ?? {}; return { id: w.id, url: w.endpoint_url, eventTypes: w.event_types, active: w.is_active, // SDK `is_active` → contract `active` createdAt: w.created_at, secret: w.signing_secret, // SDK `signing_secret` → contract `secret` (ONCE) }; } ``` ```python @router.post("", response_model=CanonicalCreatedWebhook, status_code=201) async def create_webhook(request: Request, body: CanonicalCreateWebhookRequest, client=Depends(get_sent_client)): service = SentService(client) created = await service.create_webhook(body.url, body.eventTypes) # Hold the signing secret in memory, keyed by endpoint id, so the receiver # can look up the right secret for whichever endpoint Sent delivers to. webhook_secret_store.remember(created.id, created.secret) return created # In the service layer — snake_case (SDK) ↔ camelCase (contract): # url → endpoint_url is_active → active # eventTypes → event_types signing_secret → secret (returned ONCE) ``` ```go func (h *WebhookAdminHandler) Create(c echo.Context) error { var req models.CreateWebhookRequest // { URL, EventTypes } if err := c.Bind(&req); err != nil { return models.BindValidationError(err) } client, err := h.resolver.ForRequest(c) // per-request, key-scoped client if err != nil { return err } resp, err := client.WebhookCreate(c.Request().Context(), req.URL, req.EventTypes) if err != nil { return err } created := models.NewWebhookResponse(resp.Data) // maps endpoint_url→url, is_active→active… created.Secret = resp.Data.SigningSecret // signing_secret → secret (ONCE) // Hold the signing secret in memory, keyed by endpoint id, so the receiver // can look up the right secret for whichever endpoint Sent delivers to. h.secrets.Remember(resp.Data.ID, resp.Data.SigningSecret) return c.JSON(http.StatusCreated, created) } ``` ### Field mapping [#field-mapping] The SDK / v3 API uses snake_case; your app's contract will likely use camelCase. Map at the edge: | Contract field | SDK / v3 source | |---|---| | `url` | `endpoint_url` | | `eventTypes` | `event_types` | | `active` | `is_active` | | `createdAt` | `created_at` | | `secret` | `signing_secret` | ## Listing, toggling, deleting [#listing-toggling-deleting] The rest of the surface is a straight pass-through to the SDK. List returns the caller's endpoints (never the secret; that's create/rotate only). Toggle flips `is_active` to turn off an endpoint without deleting it. Delete removes it. ```ts router.get("/", asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); res.json({ items: await sentService.listWebhooks() }); })); router.patch("/:id/toggle", asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); res.json(await sentService.toggleWebhook(String(req.params.id))); })); router.delete("/:id", asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); await sentService.deleteWebhook(String(req.params.id)); res.status(204).send(); })); ``` ```python @router.get("", response_model=CanonicalWebhookList) async def list_webhooks(request: Request, client=Depends(get_sent_client)): return await SentService(client).list_webhooks() @router.patch("/{webhook_id}/toggle", response_model=CanonicalWebhook) async def toggle_webhook(request: Request, webhook_id: str, client=Depends(get_sent_client)): return await SentService(client).toggle_webhook(webhook_id) @router.delete("/{webhook_id}", status_code=204) async def delete_webhook(request: Request, webhook_id: str, client=Depends(get_sent_client)): await SentService(client).delete_webhook(webhook_id) return Response(status_code=204) ``` ```go func (h *WebhookAdminHandler) Register(e *echo.Echo) { e.GET("/api/webhooks", h.List) e.POST("/api/webhooks", h.Create) e.PATCH("/api/webhooks/:id/toggle", h.Toggle) e.POST("/api/webhooks/:id/rotate-secret", h.RotateSecret) e.DELETE("/api/webhooks/:id", h.Delete) } func (h *WebhookAdminHandler) Toggle(c echo.Context) error { client, err := h.resolver.ForRequest(c) if err != nil { return err } resp, err := client.WebhookToggle(c.Request().Context(), c.Param("id")) if err != nil { return err } return c.JSON(http.StatusOK, models.NewWebhookResponse(resp.Data)) } ``` ## Rotating a secret [#rotating-a-secret] Rotation exists so you can replace a signing secret that may be compromised, or replace it on a routine schedule. On a [version 2](/start/webhooks/event-types#webhook-versions) webhook, deliveries are signed with both the new and the old secret for 24 hours after the rotate call, so a receiver still holding the old secret keeps verifying while you roll the new one out. On a version 1 webhook there is **no overlap window**: the old secret is invalidated the moment the rotate call returns, and Sent signs every subsequent delivery with the new secret only. Treat rotation like a deployment: the faster the new secret reaches the store your receiver verifies against, the fewer deliveries fail in the gap. Call rotate. The SDK returns a **new** `signing_secret` (shown once, like on create). On version 1 the old secret is already invalid; on version 2 it stays valid for 24 hours. **Persist the new secret immediately, in the same handler.** Every delivery from now on is signed with it. On version 1, a delivery checked only against the old secret is rejected. Rejected deliveries aren't lost. Sent retries failed deliveries, so a short gap recovers on its own. But repeated failures count against the endpoint (10 consecutive failures auto-disable it), so treat rotate-and-persist as one atomic move, not two tasks. Retire the old secret from the endpoint's candidate set on your own schedule. On version 1 it never matches again, and on version 2 it stops matching after 24 hours, so leaving it briefly is harmless; remove it once deliveries verify against the new secret. ```ts router.post("/:id/rotate-secret", asyncHandler(async (req, res) => { const { sentService } = servicesForRequest(req); const id = String(req.params.id); const secret = await sentService.rotateWebhookSecret(id); // Persist the new secret immediately — Sent already signs with it. The old // entry in the set is harmless now; retire it once new-secret deliveries verify. webhookSecretStore.remember(id, secret); res.json({ secret }); })); ``` ```python @router.post("/{webhook_id}/rotate-secret", response_model=CanonicalWebhookSecret) async def rotate_webhook_secret(request: Request, webhook_id: str, client=Depends(get_sent_client)): rotated = await SentService(client).rotate_webhook_secret(webhook_id) # Persist the new secret immediately — Sent already signs with it. The old # entry in the set is harmless now; retire it once new-secret deliveries verify. webhook_secret_store.remember(webhook_id, rotated.secret) return rotated ``` ```go func (h *WebhookAdminHandler) RotateSecret(c echo.Context) error { client, err := h.resolver.ForRequest(c) if err != nil { return err } resp, err := client.WebhookRotateSecret(c.Request().Context(), c.Param("id")) if err != nil { return err } // Persist the new secret immediately — Sent already signs with it. The old // entry in the set is harmless now; retire it once new-secret deliveries verify. h.secrets.Remember(c.Param("id"), resp.Data.SigningSecret) return c.JSON(http.StatusOK, models.WebhookSecretResponse{Secret: resp.Data.SigningSecret}) } ``` The verifier holds a *set* of candidate secrets per endpoint so that adding the new secret and retiring the old one don't have to be coordinated in a single step. See the rotation section in [Signature verification](/build/signature-verification). ## Where the secret lives [#where-the-secret-lives] A simple starting point is holding the secret in process memory, except in **PHP**, where each request runs in a fresh FPM worker with no shared process state, so the secret store needs to be **file-backed** on disk instead. Both are stand-ins. In production, persist the secret to your datastore keyed by the endpoint id, and load it per delivery in the receiver. Process memory doesn't survive a restart and isn't shared across instances. A second instance would reject every delivery it can't find a secret for. Never log the secret at any point in this flow. ## Next steps [#next-steps] # Error Handling & Resilience (/build/errors-and-resilience.md) # Error Handling & Resilience [#error-handling--resilience] The SDK throws its own exception types. Your API shouldn't leak them. The pattern is the same everywhere: catch the SDK error in the service layer, translate it into **one internal error type** with a status code and a stable code, and let a single handler at the edge render it as JSON. Then layer on the resilience concerns (retries, rate limits, idempotency, timeouts), most of which the SDK already handles if you let it. The SDK exception types are shown in all seven SDK languages below; the surrounding samples use a representative subset and transfer directly to the other [supported SDK languages](/sdks). Pair this with the [error-handling guide](/start/guides/error-handling) for the catalog of API error codes. This page is about *structuring* your integration to handle them. ## One internal error type [#one-internal-error-type] Define a single `ApiError` (status code + machine code + message + optional details). Every service method catches the SDK exception and rethrows as this. The controllers never deal with it; one error handler renders it. ```ts // types/index.ts export class ApiError extends Error { constructor( public readonly statusCode: number, public readonly code: string, message: string, public readonly details?: Record, ) { super(message); this.name = 'ApiError'; } } ``` ```python # exceptions.py class SentServiceException(Exception): def __init__(self, message: str, status_code: int = 500): self.message = message self.status_code = status_code super().__init__(self.message) ``` ```go // internal/models — a single HTTP-shaped error the edge can render. type HTTPError struct { Code int `json:"-"` ErrorCode string `json:"code"` Message string `json:"message"` } var ErrMissingAPIKey = &HTTPError{ Code: http.StatusUnauthorized, ErrorCode: "UNAUTHORIZED", Message: "Missing API key — send it as Authorization: Bearer .", } ``` ## Catch specific SDK exception types [#catch-specific-sdk-exception-types] Both the TypeScript and Python SDKs expose the same hierarchy: a base `APIError` with typed subclasses per status: `BadRequestError` (400), `AuthenticationError` (401), `NotFoundError` (404), `RateLimitError` (429), and a timeout error (`APIConnectionTimeoutError` in TypeScript, `APITimeoutError` in Python). Catch what you can act on differently; fall through to the base for everything else. These are real SDK-exported types, not app code. See each language's "Error handling" section in the [SDK reference](/sdks) for the full, authoritative hierarchy (Go, Java, C#, PHP, and Ruby each expose their own idiomatic shape, shown in the tabs below). ```ts // services/sent.service.ts — translate the SDK error, don't leak it. import { APIError as SentApiError } from '@sentdm/sentdm'; private toApiError(error: unknown, fallbackMessage: string): ApiError { this.logger.error({ error }, fallbackMessage); if (error instanceof SentApiError) { const e = error as { status?: number; name: string; message: string; headers?: unknown }; // e.name is BadRequestError | AuthenticationError | RateLimitError | … return new ApiError(e.status || 500, e.name, e.message, { headers: e.headers as Record | undefined, }); } return new ApiError(500, 'InternalError', fallbackMessage); } ``` ```python # exceptions.py — one handler maps every SDK APIError to your envelope. from sent_dm import APIError async def sent_api_exception_handler(request: Request, exc: APIError) -> JSONResponse: # The Python SDK exposes `status_code` (not `status`); the class name is the label. status_code = {400: 400, 401: 401, 403: 403, 404: 404, 422: 422, 429: 429}.get( getattr(exc, "status_code", 500), 500 ) return JSONResponse( status_code=status_code, content={ "error": type(exc).__name__, "message": str(exc), "status_code": status_code, }, ) # For per-call handling, catch the typed subclasses: # from sent_dm import BadRequestError, AuthenticationError, RateLimitError, APIError ``` ```go // The SDK returns a typed *sentdm.Error; unwrap it to read StatusCode. result, err := client.Messages.Send(ctx, params) if err != nil { var apiErr *sentdm.Error if errors.As(err, &apiErr) { switch apiErr.StatusCode { case http.StatusTooManyRequests: return &models.HTTPError{Code: 429, ErrorCode: "RATE_LIMITED", Message: apiErr.Error()} case http.StatusUnauthorized: return &models.HTTPError{Code: 401, ErrorCode: "UNAUTHORIZED", Message: apiErr.Error()} } } return fmt.Errorf("failed to send message: %w", err) } ``` ```java // exception/GlobalExceptionHandler.java — @RestControllerAdvice maps the // SDK's exported types (dm.sent.errors.*) to RFC 7807 ProblemDetail. import dm.sent.errors.RateLimitException; import dm.sent.errors.SentException; @ExceptionHandler(RateLimitException.class) // SDK 429 — act on it differently public ResponseEntity handleRateLimit(RateLimitException ex) { ProblemDetail problem = ProblemDetail.forStatus(HttpStatus.TOO_MANY_REQUESTS); problem.setTitle("Rate Limited"); problem.setDetail(ex.getMessage()); return ResponseEntity.status(HttpStatus.TOO_MANY_REQUESTS).body(problem); } @ExceptionHandler(SentException.class) // fall through to the SDK base type public ResponseEntity handleSentException(SentException ex) { ProblemDetail problem = ProblemDetail.forStatus(HttpStatus.BAD_GATEWAY); problem.setTitle("Messaging Provider Error"); problem.setDetail(ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(problem); } ``` ```csharp // Middleware/GlobalExceptionMiddleware.cs — map SentApiException → status. private static (int Status, string Title, string Detail) MapSdkException(SentApiException ex) { var status = ex.StatusCode switch { HttpStatusCode.Unauthorized => StatusCodes.Status401Unauthorized, HttpStatusCode.NotFound => StatusCodes.Status404NotFound, HttpStatusCode.Conflict => StatusCodes.Status409Conflict, HttpStatusCode.UnprocessableEntity=> StatusCodes.Status422UnprocessableEntity, HttpStatusCode.TooManyRequests => StatusCodes.Status429TooManyRequests, _ => StatusCodes.Status502BadGateway, }; return (status, "Sent API Error", ex.Message); } ``` ```php // app/Services/SentDM/SentDMService.php — catch the SDK's typed exceptions, // rethrow your one internal error type; the edge handler renders it as JSON. use SentDm\Core\Exceptions\APIException; use SentDm\Core\Exceptions\BadRequestException; use SentDm\Core\Exceptions\RateLimitException; try { $response = $this->client->messages->send(/* … */); // … map response … } catch (RateLimitException $e) { throw new ApiError(429, 'RATE_LIMITED', $e->getMessage()); // SDK 429 } catch (BadRequestException $e) { throw new ApiError(400, 'INVALID_REQUEST', $e->getMessage()); // SDK 400 } catch (APIException $e) { Log::error('Sent API call failed', ['error' => $e->getMessage()]); throw new ApiError(502, 'UPSTREAM_ERROR', $e->getMessage()); // SDK base } ``` ```ruby # app/services/sent_dm/base_service.rb — rescue the SDK's typed errors # (Sentdm::Errors::*), rethrow your one internal error type. def send_message(params) # … client.messages.send_(**params) … rescue Sentdm::Errors::RateLimitError => e raise ApiError.new(status: 429, code: "RATE_LIMITED", message: e.message) rescue Sentdm::Errors::BadRequestError => e raise ApiError.new(status: 400, code: "INVALID_REQUEST", message: e.message) rescue Sentdm::Errors::APIError => e # fall through to the SDK base type Rails.logger.error "[SentDM] #{e.class}: #{e.message}" raise ApiError.new(status: 502, code: "UPSTREAM_ERROR", message: e.message) end # One edge handler renders it: `rescue_from ApiError` in ApplicationController. ``` ## Validation errors are yours, not the SDK's [#validation-errors-are-yours-not-the-sdks] Reject malformed input *before* it reaches the SDK. Validate the body against a schema and emit a `400`/`422` with field-level detail. This keeps garbage off the wire and gives clients actionable errors. ```ts // middleware/validate.ts if (error instanceof ZodError) { const details = error.errors.map((e) => ({ path: e.path.join('.'), message: e.message })); next(new ApiError(400, 'ValidationError', 'Request validation failed', { errors: details })); } ``` ## Retries and exponential backoff [#retries-and-exponential-backoff] **The SDKs retry transient failures automatically.** Connection errors, timeouts, and `429`/`5xx` responses are retried with exponential backoff out of the box. You configure the ceiling, not the loop. Set `maxRetries` (and a request timeout) when you build the client. The SDK defaults to **2** retries with a **60 s** timeout; tightening the timeout to something like **30 s** is a reasonable choice for a user-facing request path where you'd rather fail fast and let your own retry/queue logic take over. ```ts // lib/sent/client.ts export function clientForApiKey(apiKey: string): SentDm { return new SentDm({ apiKey, maxRetries: 2, timeout: 30 * 1000, }); } ``` ```php // SentClientFactory.php — maxRetries is set via requestOptions (default 2). return new Client( apiKey: $apiKey, requestOptions: ['maxRetries' => $this->maxRetries], ); ``` ```go // Per-call deadline; the SDK handles retry of transient failures internally. ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() response, err := c.client.Messages.Send(ctx, params) ``` For long-running or bulk work, push sends onto a **queue** and let the worker own the retry policy. A Celery task, for example, can retry up to 3 times with backoff and classify errors as retryable vs terminal: A queue worker has no inbound HTTP request to pull a bearer key from, so the per-request rule still applies. It's just the request that moved. Enqueue the caller's API key (or a reference to it) as **task payload** alongside the send parameters, and build `sent_client` from that payload inside the task, never from a boot-time singleton or a worker-wide env var. This is the **one deliberate exception** to "never persist the key" (see [Authentication](/build/authentication#secret-hygiene-and-rotation)): the payload sits in the broker for as long as the job is queued. Treat it accordingly: use a broker that encrypts at rest, keep task payloads out of any queue-monitoring dashboard or DLQ viewer that isn't itself access-controlled, and set a short result/message TTL so failed jobs don't retain the key indefinitely. If a tenant's key rotates, in-flight jobs enqueued with the old key will still use it until they drain; size your retry window and TTL accordingly. ```python # tasks/messages.py — api_key arrives as task payload, not a worker singleton. from sent_dm import APIError, BadRequestError, RateLimitError, Sent, UnprocessableEntityError @shared_task(bind=True, max_retries=3, default_retry_delay=60) def send_single_message(self, api_key, phone_number, template_id, variables=None, channel=None, **_): try: sent_client = Sent(api_key=api_key) # built from this task's payload, per invocation result = sent_client.messages.send(to=[phone_number], template={...}, channel=channel) # … except RateLimitError as exc: retry_after = 60 * (2 ** self.request.retries) # exponential backoff raise self.retry(exc=exc, countdown=retry_after) # 429 → back off, then retry except (BadRequestError, UnprocessableEntityError) as exc: raise NonRetryableError(f"Invalid request: {exc}", "INVALID_REQUEST") from exc # terminal except APIError as exc: raise self.retry(exc=exc) # transient (timeout, 5xx) → bounded retry, then surface ``` Only retry **transient** failures (timeouts, `429`, `5xx`). Never blindly retry a `400`/`422`. The request is malformed and will fail every time. Retrying a bad request just amplifies the error and burns rate-limit budget. ## Rate limits and `Retry-After` [#rate-limits-and-retry-after] A `429` (`RateLimitError`) means back off. The SDK's built-in retry already honors the `Retry-After` header for you. If you surface the `429` to your own client, for example from a queue worker that has exhausted its retries, propagate a `Retry-After` so *they* can back off too, using the same exponential schedule (`60 * 2^attempt`). ## Idempotency for sends [#idempotency-for-sends] Retries (yours or the SDK's) mean a send can be attempted more than once. Guard against duplicate deliveries with an **idempotency key**: a stable key derived from the business event (order id, notification id), stored before you call `send`. If a retry comes in for a key you've already sent, short-circuit and return the recorded result instead of sending again. This is the outbound mirror of the **inbound** dedupe you do on the `webhook-id` header (`X-Webhook-Event-ID` on version 1, not `X-Webhook-ID`; that's the endpoint id, identical on every delivery) in [Status tracking](/build/status-tracking). This key needs the same shared, persistent store as the message-status store. An in-memory map has the identical failure mode: it's lost on restart, and a retry that lands on a *different* instance than the original attempt won't see it, so you send twice anyway. A database unique constraint on the idempotency key, or Redis with a TTL long enough to cover your retry window, both work. See [Idempotency across instances](/build/scaling-and-deployment#idempotency-across-instances). ## Timeouts [#timeouts] Always bound the call: a **30 s** timeout is a reasonable default; in Go, wrap every SDK call in a `context.WithTimeout(ctx, 30*time.Second)`. A timeout surfaces as a retryable connection error (`APIConnectionTimeoutError` in TypeScript, `APITimeoutError` in Python), so the SDK's retry logic picks it up first, until retries are exhausted, at which point it surfaces as the timeout error your handler maps. ## The whole chain [#the-whole-chain] 1. **Validate** input → `400`/`422` before the SDK sees it. 2. **Call** the SDK with a bounded timeout and a `maxRetries` cap. 3. The **SDK retries** transient failures (timeouts, `429`, `5xx`) with backoff, honoring `Retry-After`. 4. **Catch** the typed SDK exception in the service; translate to your `ApiError`. 5. **Render** it once at the edge as consistent JSON. 6. For bulk/async work, do all of the preceding **in a queue worker** with its own retry budget and idempotency keys. ## Next steps [#next-steps] # Going to Production (/build/going-to-production.md) # Going to Production [#going-to-production] Everything in this section, distilled into one gate. Walk it top to bottom before flipping traffic on. Each item links back to the page that explains the "why"; if any line surprises you, read that page first. This is the section-wide checklist. For a webhook-receiver-only pass with copy-paste snippets, the [webhook production checklist](/start/webhooks/production-checklist) drills deeper into that one endpoint. ## Credentials & authentication [#credentials--authentication] - [ ] **API key is per-request.** The SDK client is built from the incoming `Authorization: Bearer ` on every request. No `SENT_DM_API_KEY` env var, no boot-time singleton. See [Authentication](/build/authentication). - [ ] **No bearer token → `401`.** Requests without a valid key never reach the service layer. - [ ] **The key is never logged or persisted.** Not in logs, not in error messages, not in a database. ## Webhook verification & replay protection [#webhook-verification--replay-protection] - [ ] **Every delivery is verified** against the HMAC scheme on the **raw body**, before JSON parsing. See [Signature verification](/build/signature-verification). - [ ] **Constant-time compare** against `X-Webhook-Signature`. - [ ] **Replay window enforced:** reject if `|now − X-Webhook-Timestamp| > 300s`. - [ ] **Rotation ready:** the verifier loads candidate secrets per endpoint at delivery time, so a rotated secret takes effect without a code deploy. Sent signs each delivery with exactly one signature, using the current secret only. - [ ] **The signing secret is never logged.** ## Resilience & idempotency [#resilience--idempotency] - [ ] **Acknowledge fast.** The receiver returns `2xx` within the endpoint's timeout, then processes. See [Webhook receiver](/build/webhook-receiver). - [ ] **Alerting on receiver failures.** You'll know before 10 consecutive failures automatically turn off the endpoint, not after. See [Webhook receiver](/build/webhook-receiver). - [ ] **Idempotent processing.** Dedupe key is the `webhook-id` header on version 2 or `X-Webhook-Event-ID` on version 1, **not** version 1's `X-Webhook-ID` (that's the config UUID) and **not** the timestamp header (that changes between attempts). See [Status tracking](/build/status-tracking). - [ ] **Forward-only status.** Out-of-order and duplicate events can't regress or double-apply status; terminal states lock. - [ ] **Errors are mapped**, not leaked: the service layer translates SDK failures into your own error contract. See [Errors & resilience](/build/errors-and-resilience). ## Stateless deployment [#stateless-deployment] - [ ] **Message-status store is shared** (Redis/DB), not in process memory, so a send on one instance and its webhook on another agree. See [Scaling & deployment](/build/scaling-and-deployment). - [ ] **Webhook secrets are shared and readable by every instance** that can receive a delivery. - [ ] **Inbound dedupe store is shared**, so the same webhook event isn't processed twice across instances. See [Webhook receiver](/build/webhook-receiver). - [ ] **Outbound idempotency-key store is shared**, so a retried send doesn't double-send when the retry lands on a different instance. See [Errors & resilience](/build/errors-and-resilience). - [ ] **Graceful shutdown** on `SIGTERM`/`SIGINT` drains in-flight requests with a hard timeout cap. - [ ] **Health probes wired:** `/live` (pure process check) and `/ready` (checks shared deps) are distinct. ## Security & network [#security--network] - [ ] **HTTPS only.** TLS terminated, `http→https` redirect, HSTS set; webhook URL registered as `https://`. See [Security](/build/security). - [ ] **No leftover local tunnel URL.** If you developed against ngrok or similar, the registered endpoint now points at your real production URL, not a dev tunnel. See [Endpoint management](/build/endpoint-management). - [ ] **Security headers** on (helmet or equivalent). - [ ] **CORS locked** to your own front-end origins (no wildcard in prod), and you're not relying on CORS to protect the receiver. - [ ] **Input validated at the edge** (zod/pydantic); malformed bodies `400`, never reach the SDK. - [ ] **Rate limits configured**: a global limiter plus a stricter one on the receiver; backed by shared storage if you need a hard cap across instances. ## Logging & monitoring [#logging--monitoring] - [ ] **Structured (JSON) logs to stdout**, with a request/correlation ID (`X-Request-Id`) on every line. See [Observability](/build/observability). - [ ] **No secrets or PII in logs**: redact raw headers, raw bodies, and recipient numbers. - [ ] **Levels chosen by outcome** (`2xx`→debug, `4xx`→warn, `5xx`→error). - [ ] **Metrics emitted:** sends, webhooks received/rejected, failures (counters); latencies (histograms); queue depth if applicable. - [ ] **Alerts wired** on error rate and webhook rejection rate; tracing hooks (OpenTelemetry) in place if used. ## Final pre-launch [#final-pre-launch] - [ ] **`sandbox` is OFF for production traffic**. Verify no live path sets `sandbox: true`, and test harnesses that do can't leak in. See [Testing](/build/testing). - [ ] **Test suite green:** service-layer units, route integration tests, and the webhook verifier's known-vector test. - [ ] **Dashboard config confirmed** in the Sent dashboard: correct endpoint URL, selected event types, endpoint enabled, a test delivery succeeds. - [ ] **Rotation runbook exists** (the *Key & secret rotation runbook* section on this page) and the team knows where it is. ## Key & secret rotation runbook [#key--secret-rotation-runbook] Two independent credentials rotate independently. Document both so a 3 AM rotation isn't improvised. **API key (compromised or scheduled)** 1. Issue a new key in the Sent dashboard. 2. Roll it out to callers. Because the key is a per-request credential, this is a client/caller change, **not** a redeploy of your integration. 3. Confirm traffic on the new key (watch auth `401` rates), then revoke the old key. **Webhook signing secret (compromised or scheduled)** {/* "auto-disable" is the Sent product behavior for failing endpoints, not a UI toggle. */} {/* vale Google.WordList = NO */} 1. Rotate via `POST /api/webhooks/:id/rotate-secret`. Sent returns the new secret once. On version 1 the old secret is invalid **immediately** and every subsequent delivery is signed only with the new secret; on version 2 deliveries carry both signatures for 24 hours. See [Endpoint management](/build/endpoint-management). 2. Persist the new secret to shared storage in the same operation, so every instance can verify the very next delivery. Deliveries that land before the new secret is live fail verification; Sent retries them, but 10 consecutive failures auto-disable the endpoint. 3. Retire the old secret from the verifier's candidate set once deliveries verify against the new one. On version 1, leaving it briefly is harmless: it never matches again. On version 2 it stops matching after 24 hours. 4. Never log either secret at any step. {/* vale Google.WordList = YES */} On a version 1 webhook there is no dual-signing overlap (a version 2 webhook is signed with both secrets for 24 hours). Sent signs a version 1 webhook with exactly one secret at a time, and rotation swaps it the moment the call returns, so "rotate, then persist at once" is the only safe order. Every delivery in the gap between those two steps is rejected and retried; keep the gap to seconds, not a deploy cycle. All boxes checked? Enable the endpoint in the dashboard and watch closely for the first 24 hours: auth failures, webhook rejections, and send error rates are your early-warning signals. ## Next steps [#next-steps] # Build with Sent (/build.md) # Build with Sent [#build-with-sent] This is the production blueprint for integrating Sent: the opinionated, end-to-end way to architect and ship a real messaging integration, not a pile of disconnected snippets. Where the [Concepts](/start/concepts) explain *what* Sent is and the [SDK reference](/sdks) documents *every method*, this section shows you how the pieces fit together into an app you'd be comfortable running in production: how to structure the code, handle credentials safely, send messages, receive and verify webhooks, track delivery, and harden the whole thing before go-live. The code samples in these pages are written against the current, official Sent SDKs and the v3 API. The security-critical code (the send call, the signature verifier, the webhook receiver's raw-body handling) is shown in all seven SDK languages: TypeScript, Python, Go, Java, C#, PHP, Ruby. Supporting samples use a representative subset you can adapt to your stack. ## Who this is for [#who-this-is-for] Engineers integrating Sent into a real backend. You know your language and framework; you want the *right* way to wire Sent in (the architecture, the security boundaries, and the failure modes) without rediscovering them the hard way. Everything is framework-agnostic and shown in multiple languages via tabs; apply the pattern to your stack. ## How to read this [#how-to-read-this] The section follows the path you actually build in. Read it straight through the first time, then use it as a reference. } description="The layered architecture, project setup, and per-request API key handling (the part most integrations get wrong)." /> } description="The outbound path: a clean service layer over messages.send, contacts and templates, and resilient error handling." /> } description="The inbound path: a verified receiver, the exact signature scheme, endpoint management, and closing the delivery-status loop." /> } description="Security, observability, scaling a stateless deployment, testing, and a go-live checklist." /> ## The mental model [#the-mental-model] A Sent integration has two independent flows, and most of this guide is about building each one well: - **Outbound**: your app calls Sent to send templated messages. The work is structuring a thin, testable service layer over the SDK and mapping errors into your own API surface. - **Inbound**: Sent calls *you* over webhooks as messages progress (sent → delivered → read / failed) and when recipients reply. The work is verifying those requests are authentic, acknowledging fast, and updating your own state idempotently. S[Sent service layer] W[Webhook receiver] --> ST[(State store)] end S -- "Bearer key, per request" --> API[(Sent API)] API -- "signed webhook events" --> W R -.->|send| S `} /> *In plain English: your app calls Sent to send (top path), and Sent calls your webhook receiver back with delivery events (bottom path). Two separate directions, one shared service layer in between.* ## Three principles this guide is built on [#three-principles-this-guide-is-built-on] } description="Build the SDK client per request from an Authorization: Bearer header. Never bake a key into a boot-time singleton or a stored env var. This is the single most common thing to get wrong. See Authentication." /> } description="It's a public URL that mutates your state. Verify the signature against the raw body before doing anything else, every time." /> } description="Keep per-request and per-event state out of process memory in production so you can scale horizontally. We show the in-memory pattern, then how to productionize it." /> ## Start small, then scale [#start-small-then-scale] This guide shows the full production shape up front so you can see where everything ends up. But that shape is a **ceiling, not a floor**. If you're shipping a single-tenant app on one instance this week, you don't need Redis, a queue, Kubernetes, or distributed tracing to send a correct first message: - **One Sent account, no reseller model?** The per-request client pattern still applies (see [Authentication](/build/authentication) for exactly what it buys you), but you can skip the multi-tenant reasoning. There's no second tenant to isolate. - **One running instance?** In-memory state for message status, webhook secrets, and idempotency/dedupe keys is fine to start and fine to ship with. [Scaling & deployment](/build/scaling-and-deployment) is what you read *before* you add a second instance, not before your first deploy. - **No background jobs yet?** The queue-worker patterns in [Errors & resilience](/build/errors-and-resilience) are for when sends become long-running or bulk. Skip them until you actually have a queue. Everything else (structuring the service layer, verifying webhooks, mapping delivery status) applies from message one and isn't optional. ## Next steps [#next-steps] - Start with the [reference architecture](/build/architecture) to see the whole shape before the details. - New to the platform? Do the [Quickstart](/start/quickstart) first, then come back here. # Instrumenting Logs, Metrics & Traces (/build/observability.md) # Instrumenting Logs, Metrics & Traces [#instrumenting-logs-metrics--traces] When a message doesn't arrive, you need to answer one question fast: *where in the two flows did it stop?* Good observability makes that a single log query. The rules are the usual ones (structured logs, a correlation ID on every request, sensible levels), with one hard constraint specific to this integration: **never log the API key, the signing secret, or message payloads.** Samples on this page are shown in TypeScript and Python; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). ## Structured logging [#structured-logging] Log JSON, not free text. In TypeScript, `pino` is a good default: JSON in production, pretty-printed in development, with a `base` that stamps every line with the pid and environment. ```ts // src/config/logger.ts import pino from 'pino'; import { env } from './env'; export const logger = pino({ level: env.LOG_LEVEL, transport: env.NODE_ENV === 'development' ? { target: 'pino-pretty', options: { colorize: true } } : undefined, // JSON to stdout in production base: { pid: process.pid, env: env.NODE_ENV }, }); ``` ```python # src/app/utils/logging.py import logging from pythonjsonlogger import jsonlogger # pip install python-json-logger def configure_logging(level: str = "INFO") -> None: handler = logging.StreamHandler() # JSON to stdout — no log files handler.setFormatter( jsonlogger.JsonFormatter("%(asctime)s %(name)s %(levelname)s %(message)s") ) logging.basicConfig( level=getattr(logging, level.upper(), logging.INFO), handlers=[handler], ) # Every `extra={...}` field now lands as a queryable JSON key. ``` Write logs to stdout as JSON and let your platform (the container runtime, a log shipper, or your host) collect them. Don't manage log files inside the app. A stateless service shouldn't own local state, including logs. See [Scaling & deployment](/build/scaling-and-deployment). ## Correlation: a request ID on every request [#correlation-a-request-id-on-every-request] Attach a unique ID to each inbound request, echo it back in an `X-Request-Id` header, and include it in every log line for that request. That single field lets you reconstruct a whole request from scattered log lines, and lets a client quote it in a support ticket. ```ts // src/middleware/request-logger.ts export function requestLogger(req, res, next) { const start = Date.now(); const requestId = randomUUID(); res.setHeader('X-Request-Id', requestId); logger.trace( { requestId, method: req.method, path: req.path, ip: req.ip }, 'Incoming request', ); res.on('finish', () => { const logData = { requestId, method: req.method, path: req.path, statusCode: res.statusCode, duration: `${Date.now() - start}ms`, }; // Level chosen from the outcome — see below. if (res.statusCode >= 500) logger.error(logData, 'Request failed'); else if (res.statusCode >= 400) logger.warn(logData, 'Request failed'); else logger.debug(logData, 'Request completed'); }); next(); } ``` ```python # src/app/middleware.py class RequestIdMiddleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): request_id = request.headers.get("X-Request-ID", str(uuid.uuid4())) request.state.request_id = request_id response = await call_next(request) response.headers["X-Request-ID"] = request_id return response class LoggingMiddleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): start = time.time() request_id = getattr(request.state, "request_id", "unknown") response = await call_next(request) logger.info("Request completed", extra={ "request_id": request_id, "method": request.method, "path": request.url.path, "status_code": response.status_code, "duration_ms": round((time.time() - start) * 1000, 2), }) return response ``` Honor an inbound `X-Request-Id` if the caller already set one (as shown in the preceding Python snippet), so the ID flows across service boundaries. Generate a fresh one only when none is present. ## What to log at each level [#what-to-log-at-each-level] Pick the level from the outcome, not the code path. The preceding request logger is the template: `2xx` → `debug`, `4xx` → `warn`, `5xx` → `error`. | Level | Use for | Example | |---|---|---| | `trace` / `debug` | Normal request lifecycle, health checks. | "Incoming request," "Request completed" | | `info` | Business milestones worth keeping. | "Message sent" (with `message_id`), "Webhook endpoint registered" | | `warn` | Handled problems / client errors. | `4xx` responses, an unverified webhook rejected `401` | | `error` | Unhandled failures needing attention. | `5xx` responses, SDK call threw | | `fatal` | Process-ending conditions. | Uncaught exception, unhandled rejection | ## Logging webhook processing (without secrets) [#logging-webhook-processing-without-secrets] The receiver is where observability and security collide. Log enough to trace a delivery, and nothing that leaks. ```ts // Safe: identifiers and outcomes only. logger.info( { requestId, // per-event, same on every attempt: webhook-id (v2) or X-Webhook-Event-ID (v1) eventId: req.headers['webhook-id'] ?? req.headers['x-webhook-event-id'], attempt: req.headers['x-webhook-attempt'], // v1 only: 1 on the first delivery eventType: req.body.event, // e.g. "message.delivered" messageId: payload.message_id, status: payload.message_status, }, 'Webhook processed', ); // NEVER: logger.info(req.headers) → leaks the signature header + secret material // NEVER: logger.debug(req.body) → leaks recipient numbers + message content ``` ```python logger.info("Webhook processed", extra={ "request_id": request_id, # per-event: webhook-id (v2) or X-Webhook-Event-ID (v1) "event_id": request.headers.get("webhook-id") or request.headers.get("x-webhook-event-id"), "attempt": request.headers.get("x-webhook-attempt"), # v1 only "event_type": payload["event"], "message_id": payload["payload"]["message_id"], "status": payload["payload"]["message_status"], }) # Never log request.headers or the raw body. ``` On a version 1 webhook, `X-Webhook-ID` is the webhook **configuration** UUID, not a per-event ID. It's the same across every delivery from one endpoint, so it's useful context but the wrong dedupe key. The per-event ID is `webhook-id` on version 2 and `X-Webhook-Event-ID` on version 1, and logging it (beside `X-Webhook-Attempt` on version 1) is what lets you tell "the same event arrived twice" from "two events arrived" in a log search. See [Status tracking](/build/status-tracking). ## Metrics and tracing [#metrics-and-tracing] Logs tell you what happened to one request; metrics tell you the shape of the system. The [go-live checklist](/build/going-to-production) gates on these baseline metrics, so emit at least: - **Counters:** messages sent, webhooks received, webhooks rejected (bad signature / stale timestamp), send failures. - **Histograms:** SDK call latency, webhook processing duration, request duration (you already compute it in the request logger). - **Gauges:** if you offload webhook work to a queue, its depth. Distributed tracing, unlike the baseline metrics, is optional: skip it until you're actually debugging a cross-service latency problem the preceding logs and metrics can't answer. At that point, instrument with [**OpenTelemetry**](https://opentelemetry.io/), a vendor-neutral standard for recording timed operations (**spans**) and stitching them into one end-to-end **trace** per request, even across services. Both flows here are natural spans: wrap the `messages.send` SDK call in a span on the outbound path, and start a span in the receiver keyed by the correlation ID on the inbound path. Carry the same request/correlation ID as **baggage** (OpenTelemetry's term for a small piece of context attached to a trace and automatically propagated to every span within it), so a log line and a span can be correlated back to each other. Keep instrumentation in middleware and the service layer, not in controllers. The [layered architecture](/build/architecture) means one span around the service method covers every route that calls it. ## Next steps [#next-steps] # About Per-Request Credentials (/build/per-request-credentials.md) # About Per-Request Credentials [#about-per-request-credentials] The [Authentication guide](/build/authentication) is built on one rule: the Sent API key arrives as `Authorization: Bearer `, becomes an SDK client for that request, and is gone when the request ends. It is never a boot-time singleton and never a stored environment variable. This page explains why the pattern exists, who actually sends the bearer key in each deployment shape, and why it makes tenant isolation structural rather than something you remember to enforce. ## Why per-request [#why-per-request] Three concrete payoffs, not dogma: - **Multi-tenant by default.** One deployment can serve many customers, each with their own key, because the credential travels with the request instead of living in the process. - **No secret at rest in your app.** The key is never written to your environment, config, or disk. Your app is a pass-through; it holds the key only for the microseconds a request is in flight. - **Rotation is free.** A customer rotates their key in the dashboard and sends the new one on the next request. Nothing to redeploy, no restart. The underlying idea is not unique to Sent. The key is a [bearer credential](/start/concepts/api-authentication), and a bearer credential in a backend is analogous to a session token in a web app: it travels with each request and is resolved fresh each time, so no request depends on state left behind by an earlier one. A per-request client is what that model looks like inside your own service. ## Who sends the bearer key [#who-sends-the-bearer-key] The `Authorization: Bearer ` used throughout the Authentication guide is the *shape* of the pattern; who supplies the key depends entirely on whether you have one Sent account or many. **Multi-tenant / reseller.** Each of *your* customers has their own Sent account and key. Here, "the caller" is genuinely external (your customer's own backend, or their session in your dashboard), and they legitimately hand you their Sent key on each call because it's theirs. **Single-tenant (the common case).** You have exactly one Sent account, so there is no external party who owns a Sent key, and a key shipped to a browser or mobile app is a key published. "Per-request" here means your *own* backend resolves the one key for each request or job, rather than baking it into a global at boot. In the single-tenant case, what matters is *when* the key is read, not what system it's read from. Reading it from your normal config or env on each request (not cached into a module-level variable at import or boot time) is a perfectly reasonable starting point, and it still delivers the real payoffs: rotation without a redeploy, and no key frozen into a long-lived process. A dedicated secrets manager earns its operational cost when you need cross-service rotation: one place to change a credential that many services read. Until then, per-request resolution from ordinary config gives you the same properties with less machinery. ## Why tenant isolation is structural [#why-tenant-isolation-is-structural] Because the client is constructed from the request's key and discarded when the request ends, there is no shared client and no way for one tenant's calls to go out under another tenant's key. Isolation doesn't depend on every developer remembering to scope every call; the shape of the code makes the failure impossible. A boot-time singleton silently forfeits this: every request goes out under whatever single key the process started with, which makes multi-tenant serving impossible and turns key rotation into a redeploy. The per-request factory is what keeps tenant A's messages from being sent on tenant B's account. Single-tenant apps get the mirror image of the same property: because nothing caches the key across requests, rotating the one key is a configuration change, not a deployment event. ## Where to go from here [#where-to-go-from-here] The pattern itself is a few small functions per framework. To act on this understanding: # Setting Up the Project: SDK, Config, and Folder Layout (/build/project-setup.md) # Setting Up the Project: SDK, Config, and Folder Layout [#setting-up-the-project-sdk-config-and-folder-layout] You've seen the [shape of the integration](/build/architecture). Now stand up a project that realizes it: install the SDK, wire up config that fails fast on startup, and lay out the layers so "call the SDK" and "receive a webhook" never bleed into each other. Everything here is framework-agnostic. Pick your language in the tabs; the pattern is the same. ## Prerequisites [#prerequisites] Before any code, you need three things: **A Sent account.** Sign up and complete onboarding. If you're brand new, run the [Quickstart](/start/quickstart) end-to-end first. This guide assumes you've sent at least one message. **An API key.** Generate one on the [API Keys page in your Sent dashboard](https://app.sent.dm/dashboard/api-keys). Keep it handy, but note that it does **not** go into an env var or a config file. It's a per-request credential, supplied as `Authorization: Bearer `, never read once into a boot-time global or singleton client. Every chapter that follows builds on this convention; it's covered in full in [Authentication](/build/authentication). **At least one approved template.** Sent is template-first: outbound messages reference a template by `id` or `name`. Create and get one approved so you have something to send. See [Templates](/start/concepts/templates). ## Install the SDK [#install-the-sdk] Add the official Sent SDK for your language: ```bash npm install @sentdm/sentdm # or: pnpm add @sentdm/sentdm · yarn add @sentdm/sentdm ``` ```bash pip install sentdm # or: uv add sentdm ``` The SDK exposes both a sync `Sent` and an async `AsyncSent` client. ```bash go get github.com/sentdm/sent-dm-go ``` ```xml dm.sent sent-java ``` ```bash dotnet add package Sentdm ``` ```bash composer require sentdm/sent-dm-php ``` ```bash bundle add sentdm # or: gem install sentdm ``` See the [SDK reference](/sdks) for the full method surface in each language. ## SDK or raw v3 REST? [#sdk-or-raw-v3-rest] Almost every integration should use the SDK. It handles auth headers, retries, the response envelope, and gives you typed methods. Reach for the raw v3 REST API only when you have a specific reason: | Use the **SDK** when… | Use **raw v3 REST** when… | |---|---| | You want typed methods, built-in retries, and less boilerplate. | You're on a runtime with no SDK, or want zero dependencies. | | You're integrating a supported language (all seven in the preceding section). | You need to see exactly what goes over the wire (learning, debugging). | | You want the maintained happy path. | You need a request shape the SDK doesn't expose yet. | The raw path looks like a small typed `fetch` client that sends the key as an `x-api-key` header and unwraps the v3 envelope `{ success, data, error, meta }`. ```ts import SentDm from "@sentdm/sentdm"; // One typed client, per request, bound to the caller's key. const client = new SentDm({ apiKey }); const res = await client.messages.send({ to, template }); ``` ```ts // A hand-rolled client: you own the transport and the envelope. export class SentV3Client { constructor(private opts: { apiKey: string; baseUrl: string }) {} async request(method: string, path: string, body?: unknown): Promise { const res = await fetch(`${this.opts.baseUrl}${path}`, { method, headers: { "x-api-key": this.opts.apiKey, "content-type": "application/json", accept: "application/json", }, body: body === undefined ? undefined : JSON.stringify(body), }); const parsed = JSON.parse(await res.text()); if (!res.ok || !parsed?.success) { throw new SentV3ApiError(parsed?.error?.message ?? res.statusText, res.status); } return parsed.data as T; // unwrap the { success, data, error, meta } envelope } } ``` Both the SDK and the raw v3 client send the key to Sent as `x-api-key`. Sent also accepts it as `Authorization: Bearer`, but either way the header is internal to how you talk to Sent, separate from whatever scheme your own API uses to receive the key from its callers. ## Validate config at startup: fail fast [#validate-config-at-startup-fail-fast] Parse and validate your configuration at boot, and exit immediately if it's wrong. Nothing downstream should have to defend against missing config. But be precise about **what's in config**. Config holds operational knobs: base URL, log level, rate-limit settings, port. It does **not** hold the API key (that's per-request) and it does **not** *require* a webhook signing secret (that's a runtime value born when a customer registers a webhook; see [Endpoint management](/build/endpoint-management)). A `SENT_DM_WEBHOOK_SECRET` may appear only as an optional local/curl convenience, never as a required boot variable. ```ts import { z } from "zod"; const envSchema = z.object({ NODE_ENV: z.enum(["development", "production", "test"]).default("development"), PORT: z.string().transform(Number).default("3001"), // Operational knobs only. NOT the API key (per-request), and the webhook // secret is a runtime value — optional here, not required at boot. SENT_DM_WEBHOOK_SECRET: z.string().min(1).optional(), LOG_LEVEL: z.enum(["trace", "debug", "info", "warn", "error", "fatal"]).default("info"), RATE_LIMIT_WINDOW_MS: z.string().transform(Number).default("900000"), RATE_LIMIT_MAX_REQUESTS: z.string().transform(Number).default("100"), }); const parsed = envSchema.safeParse(process.env); if (!parsed.success) { console.error("Invalid environment variables:", parsed.error.format()); process.exit(1); // fail fast } export const env = parsed.data; ``` ```python from functools import lru_cache from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env", extra="ignore") debug: bool = Field(default=False, alias="DEBUG") # Optional runtime convenience only — not required at boot. sent_dm_webhook_secret: str | None = Field(default=None, alias="SENT_DM_WEBHOOK_SECRET") sent_base_url: str | None = Field(default=None, alias="SENT_BASE_URL") rate_limit: str = Field(default="100/minute", alias="RATE_LIMIT") log_level: str = Field(default="INFO", alias="LOG_LEVEL") @lru_cache def get_settings() -> Settings: return Settings() # pydantic raises on invalid config at first access ``` ```go // Loaded with envconfig (kelseyhightower/envconfig); viper works the same way. type Config struct { Server ServerConfig Sent SentConfig RateLimit RateLimitConfig } type ServerConfig struct { Port string `envconfig:"PORT" default:"3031"` Environment string `envconfig:"ENVIRONMENT" default:"development"` } // Per-customer RUNTIME value, optional env fallback for dev/curl. Never // required to boot the server. type SentConfig struct { WebhookSecret string `envconfig:"SENT_DM_WEBHOOK_SECRET"` } type RateLimitConfig struct { RequestsPerSecond float64 `envconfig:"RATE_LIMIT_RPS" default:"10"` BurstSize int `envconfig:"RATE_LIMIT_BURST" default:"20"` } func Load() (*Config, error) { var cfg Config if err := envconfig.Process("", &cfg); err != nil { return nil, fmt.Errorf("failed to load config: %w", err) // fail fast } return &cfg, nil } ``` ```php // config/sent.php — operational knobs only, sourced from env at boot. return [ 'base_url' => env('SENT_BASE_URL', 'https://api.sent.dm'), // Optional runtime convenience only — never required to boot. 'webhook_secret' => env('SENT_DM_WEBHOOK_SECRET'), 'rate_limit' => env('RATE_LIMIT', '100,1'), // "max,per-minute" ]; ``` ```php ## The folder layout [#the-folder-layout] Realize the [reference architecture's layers](/build/architecture#the-layers) as small, single-responsibility files. Exact filenames vary by framework, but the seams are the same everywhere: ```text src/ ├── config/ # Config & validation — parse + validate env at boot, fail fast │ └── env.(ts|py|go) ├── container/ (or clients/, dependencies) │ └── client.* # Per-request client factory — Bearer key → SDK client ├── services/ # Sent service layer — thin wrappers, snake→camel mapping, errors │ └── sent.service.* ├── controllers/ (or routes/) │ ├── auth.* # POST /api/auth/verify │ ├── messages.* # POST /api/messages, GET /api/messages/:id │ ├── contacts.* # GET/POST /api/contacts, DELETE /api/contacts/:id │ ├── templates.* # GET /api/templates(/:id) │ └── webhooks.* # management: GET/POST /api/webhooks, toggle, rotate, delete ├── middleware/ │ ├── async-handler.* # asyncHandler — route async errors into the error handler │ └── validate.* # validateBody — schema-check req.body, 400 on failure ├── webhooks/ │ ├── receiver.* # POST /webhooks/sent — verify → ack → process │ ├── verifier.* # HMAC signature primitive (unit-tested in isolation) │ └── secret-store.* # in-memory (prod: Redis/DB) └── store/ └── messages.* # message-status store (in-memory; prod: Redis/DB) ``` The two rules that keep this honest: - The **client factory** is the *only* place that reads the request's API key and constructs a client. Controllers ask it for a client; they never read `process.env` or a global. - The **verifier** and **receiver** are isolated from the outbound service layer. A public, state-mutating endpoint deserves its own security discipline. This is deliberately lightweight. In most languages each layer is one small file. ## Shared helpers [#shared-helpers] The TypeScript samples across this guide reuse three small pieces of app code. They are not SDK exports; define them once in [The folder layout](#the-folder-layout) and import them everywhere. Later pages link back here at each symbol's first use. `asyncHandler` forwards a rejected promise from an async route into Express's error middleware, so one edge handler renders every error (see [Errors & resilience](/build/errors-and-resilience#one-internal-error-type)): ```ts // middleware/async-handler.ts import type { NextFunction, Request, RequestHandler, Response } from "express"; export function asyncHandler( fn: (req: Request, res: Response, next: NextFunction) => Promise, ): RequestHandler { return (req, res, next) => { Promise.resolve(fn(req, res, next)).catch(next); }; } ``` `validateBody` checks `req.body` against a Zod schema and rejects invalid input with a `400` before the handler runs. It rethrows as the integration's single `ApiError` type, defined in [Errors & resilience](/build/errors-and-resilience#one-internal-error-type): ```ts // middleware/validate.ts import type { RequestHandler } from "express"; import { ZodError, type ZodSchema } from "zod"; import { ApiError } from "../types"; export function validateBody(schema: ZodSchema): RequestHandler { return (req, _res, next) => { try { req.body = schema.parse(req.body); next(); } catch (error) { if (error instanceof ZodError) { const details = error.errors.map((e) => ({ path: e.path.join("."), message: e.message })); return next(new ApiError(400, "ValidationError", "Request validation failed", { errors: details })); } next(error); } }; } ``` `webhookSecretStore` holds webhook signing secrets in memory as a set of candidates per endpoint id, so the receiver can verify whichever endpoint Sent delivers to and rotation never needs a coordinated swap (see [Endpoint management](/build/endpoint-management)): ```ts // webhooks/secret-store.ts /* * Production note: a real multi-instance service would load the secret per * delivery from its own datastore (keyed by endpoint id), not from process * memory. A version 2 webhook sends no endpoint-id header (its webhook-id is * per message), so give each endpoint its own receiver URL to know which one * Sent is calling. A version 1 webhook also sends it as X-Webhook-ID. */ const secretsByEndpoint = new Map>(); export const webhookSecretStore = { /** Hold a signing secret for an endpoint — on create and on rotate. */ remember(endpointId: string, secret: string): void { const candidates = secretsByEndpoint.get(endpointId) ?? new Set(); candidates.add(secret); secretsByEndpoint.set(endpointId, candidates); }, /** Candidate secrets for one endpoint. */ candidatesFor(endpointId: string): string[] { return [...(secretsByEndpoint.get(endpointId) ?? [])]; }, /** Retire an old secret once deliveries verify against the new one. */ retire(endpointId: string, secret: string): void { secretsByEndpoint.get(endpointId)?.delete(secret); }, }; ``` The Python and Go samples don't need the first two: FastAPI's Pydantic models and dependency injection, and Echo's `Bind` plus centralized error handling, cover the same ground natively. Their secret stores (`webhook_secret_store` in Python, `h.secrets` in Go) mirror `remember`/`candidatesFor`. ## Next steps [#next-steps] The client factory is the heart of this layout, and it hinges on one idea that trips up most integrations. Get it right next. # Scaling & Deploying the Integration (/build/scaling-and-deployment.md) # Scaling & Deploying the Integration [#scaling--deploying-the-integration] The reference backends run beautifully as a single process. To run **more than one instance** (for availability or throughput), there is exactly one change to make: the three pieces of in-process state have to move to shared storage. Everything else (per-request client, service layer, verifier) is already stateless. This page is about that move, plus the deployment mechanics that make horizontal scaling safe. Samples on this page are shown in TypeScript and Python; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). ## The three things that aren't stateless [#the-three-things-that-arent-stateless] By design, the API key is per-request and the SDK client is disposable, so there's no connection state to share. Only three things live in process memory: | In-memory today | Where it lives | Why it must be shared | |---|---|---| | **Message-status store** | `store/message-store.ts` | The send path records a message on instance A; the delivery webhook may land on instance B. B must see A's record to advance it. | | **Held webhook secrets** | `webhooks/secret-store.ts` | Every instance that can receive a delivery must be able to verify it, so every instance needs the current secrets. | | **Idempotency / dedupe keys** | inbound in the receiver, outbound in the send path | Two instances can each see the same retried webhook or the same retried send and both think it's new if they're not checking the same store. See [Idempotency across instances](#idempotency-across-instances) below. | Run two instances behind a load balancer with these stores in memory and you get silent, intermittent bugs: `GET /api/messages/:id` returns "not found" for messages sent by the other instance, webhooks `401` on whichever instance never saw the registration, and a retried webhook or send gets double-processed because the instance that handles the retry never saw the original. It'll look flaky. It's just unshared state. ## Move the message store to Redis/DB [#move-the-message-store-to-redisdb] The store is written against a small interface: record on send, advance forward-only on webhook, read by id. Keep that surface identical and swap the backing map for Redis or your database. The forward-only, idempotent logic doesn't change. The in-memory version (abridged): ```ts // store/message-store.ts — the surface to preserve export class MessageStore { record(input: { id: string; status?: string; /* … */ }): StoredMessage { /* … */ } updateStatus(id: string, next: string): StoredMessage | null { /* forward-only */ } get(id: string): StoredMessage | null { /* … */ } } ``` A Redis-backed implementation keeps the same methods. The one new requirement is that the read-rank-compare-write in `updateStatus` has to be **atomic**: two instances handling concurrent webhooks must not both read the old status, both decide their event is a valid forward move, and both write, each unaware of the other. A Lua script runs atomically inside Redis (Redis executes it as a single, uninterruptible operation), so it's the natural tool here: ```ts // The same RANK/TERMINAL rules from the in-memory version, expressed in Lua so // Redis evaluates read-compare-write as one atomic step, not three round trips. const FORWARD_ONLY_LUA = ` local RANK = { QUEUED=0, ROUTED=1, SENT=2, DELIVERED=3, FAILED=3, READ=4 } local TERMINAL = { READ=true, FAILED=true } local key, next_status, updated_at = KEYS[1], ARGV[1], ARGV[2] local current = redis.call('HGET', key, 'status') if not current then return nil end -- unknown id if TERMINAL[current] then return current end -- locked if RANK[next_status] == nil or RANK[next_status] <= RANK[current] then return current -- no regress / dup end redis.call('HSET', key, 'status', next_status, 'updatedAt', updated_at) return next_status `; // store/redis-message-store.ts — same interface, shared backing export class RedisMessageStore { constructor(private readonly redis: Redis) {} async record(input: { id: string; status?: string; /* … */ }) { const key = `msg:${input.id}`; await this.redis.hset(key, { status: input.status ?? 'QUEUED', createdAt: new Date().toISOString(), /* … */ }); await this.redis.expire(key, 60 * 60 * 24 * 7); // TTL, like the in-memory eviction } // Forward-only advance across instances — see FORWARD_ONLY_LUA above. async updateStatus(id: string, next: string) { return this.redis.eval(FORWARD_ONLY_LUA, 1, `msg:${id}`, next, new Date().toISOString()); } async get(id: string) { const h = await this.redis.hgetall(`msg:${id}`); return Object.keys(h).length ? h : null; } } ``` On a SQL store instead of Redis, the same atomicity comes from a single `UPDATE … WHERE rank < :next`. The database's own row lock does the job a Lua script does in Redis. Same rule, different tool. See [Status tracking](/build/status-tracking) for where `RANK`/`TERMINAL` originally come from. ## Make the signing secret readable by every instance [#make-the-signing-secret-readable-by-every-instance] The in-memory secret store ([a shared helper](/build/project-setup#shared-helpers)) already flags this in its own comment: ```ts // webhooks/secret-store.ts /* * Production note: a real multi-instance service would load the secret per * delivery from its own datastore (keyed by endpoint id), not from process * memory. A version 2 webhook sends no endpoint-id header (its webhook-id is * per message), so give each endpoint its own receiver URL to know which one * Sent is calling. A version 1 webhook also sends it as X-Webhook-ID. */ ``` When a customer registers or rotates an endpoint (`POST /api/webhooks`, `POST /api/webhooks/:id/rotate-secret`), persist the returned secret to shared storage instead of a process-local `Set`. The receiver then loads the current secrets for that endpoint per delivery. - Store secrets encrypted at rest, keyed by webhook config id. A [version 2](/start/webhooks/event-types#webhook-versions) delivery doesn't carry that id in a header, so put it in the endpoint URL you register (for example `/webhooks/sent/{id}`). A version 1 delivery also sends it as `X-Webhook-ID`. - **Never log them.** See [Security](/build/security). - On rotation, persist the new secret immediately. A version 2 webhook is signed with both secrets for 24 hours, so nothing fails while the new one propagates. A version 1 webhook carries a single signature from the current secret only, and the old one is invalid the moment rotate returns; keeping it in the receiver's candidate set is a harmless mitigation, not an overlap Sent honors. See [Endpoint management](/build/endpoint-management). ## Idempotency across instances [#idempotency-across-instances] Acknowledge-fast plus idempotent processing already handles retries on one instance. Across instances the dedupe check must hit a **shared** store. Otherwise the same event processed on A and B both look "new." ```ts // The event's own id: webhook-id on version 2, X-Webhook-Event-ID on version 1 // (version 1's X-Webhook-ID is NOT per-event). const dedupeKey = `evt:${req.headers['webhook-id'] ?? req.headers['x-webhook-event-id']}`; // SET NX = "claim it only if unseen." Atomic and cross-instance. const claimed = await redis.set(dedupeKey, '1', 'EX', 86_400, 'NX'); if (!claimed) return res.status(200).json({ received: true }); // already handled ``` ## Graceful shutdown [#graceful-shutdown] On deploy or scale-down your platform sends `SIGTERM`. Stop accepting new connections, let in-flight requests finish, then exit, with a hard timeout so a stuck request can't hang the rollout. ```ts // src/server.ts const shutdown = (signal: string) => { logger.info({ signal }, 'Shutting down...'); server.close(() => { // stop accepting, drain in-flight logger.info('Server closed'); process.exit(0); }); setTimeout(() => { // hard cap so a stuck request can't block forever logger.error('Forced shutdown'); process.exit(1); }, 10_000); }; process.on('SIGTERM', () => shutdown('SIGTERM')); process.on('SIGINT', () => shutdown('SIGINT')); ``` ```python # ASGI servers (uvicorn/gunicorn) handle SIGTERM draining for you: they stop # accepting, wait for in-flight requests, then exit. Tune the grace period, and # use FastAPI's lifespan to release shared resources (Redis/DB pools) on shutdown. # uvicorn app.main:app --timeout-graceful-shutdown 10 ``` Set your container's `terminationGracePeriodSeconds` (or platform equivalent) **longer** than your app's hard-shutdown timeout, so the orchestrator lets the drain finish instead of `SIGKILL`-ing mid-request. ## Health, readiness, and liveness [#health-readiness-and-liveness] A load balancer and an orchestrator ask different questions. Expose distinct endpoints so a temporary dependency blip doesn't get your pod killed. ```ts // src/controllers/health.controller.ts router.get('/', (_req, res) => res.status(200).json({ status: 'ok', backend: 'typescript', framework: 'express', uptime: process.uptime(), // …timestamp, version elided // No persistent Sent connection to report — the client is per-request. services: { sentdm: 'ready' }, }), ); // /live is a pure process check — never touches a dependency. router.get('/live', (_req, res) => res.status(200).json({ alive: true })); // /ready actually checks the shared dependency. A timed-out or failed PING // means "don't route traffic here" — remove from rotation, don't restart. router.get('/ready', async (_req, res) => { try { await redis.ping(); res.status(200).json({ ready: true }); } catch { res.status(503).json({ ready: false }); } }); ``` ```python # src/app/routers/health.py @router.get("/health") async def health_check(): return {"status": "ok", "backend": "python", "framework": "fastapi"} @router.get("/health/live") async def liveness(): return {"status": "alive"} # pure process check — never touches a dependency @router.get("/health/ready") async def readiness(): try: await redis_client.ping() return {"status": "ready"} except Exception: return JSONResponse({"status": "not_ready"}, status_code=503) ``` | Endpoint | Answers | Consumer | On failure | |---|---|---|---| | `/health` (`/live`) | "Is the process alive?" | Orchestrator liveness probe | Restart the instance | | `/ready` | "Can it serve traffic?" (shared deps reachable) | Load balancer / readiness probe | Remove from rotation, don't restart | Keep the dependency check on `/ready` only, never on `/live`, as shown in the preceding snippets. Coupling liveness to a dependency causes cascading restarts when that dependency has a hiccup. The orchestrator kills and restarts every instance in a loop instead of just routing around the outage, which is exactly what `/ready` returning `503` already accomplishes on its own. ## Containerization notes [#containerization-notes] - **Config comes from the environment, not the image** (the ["twelve-factor app"](https://12factor.net/config) convention). No `SENT_DM_API_KEY`. The key arrives per request. Config that *is* env-based (log level, rate-limit window, Redis/DB URL) comes from the environment; nothing secret goes into the image. - **Logs to stdout** as JSON; the platform collects them. See [Observability](/build/observability). - **One process per container**, scaled by replica count behind a load balancer. - **Honor `SIGTERM`** (see [Graceful shutdown](#graceful-shutdown)). Run as a non-root user; multi-stage build for a lean image. - **Probes** wired to `/live` and `/ready`. ## Next steps [#next-steps] # Securing Your Sent Integration: Secrets, CORS, and PII (/build/security.md) # Securing Your Sent Integration: Secrets, CORS, and PII [#securing-your-sent-integration-secrets-cors-and-pii] A Sent integration touches two credentials, the caller's **API key** and the **webhook signing secret**, and exposes at least one public, state-mutating endpoint. Get the handling of those two secrets right, verify every inbound request, and validate everything at the edge. The rest is defense in depth. Samples on this page are shown in TypeScript and Python; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). Nothing here is Sent-specific magic. It's standard backend hygiene applied to the two secrets and the one public endpoint this integration adds. ## Secrets: hold them for the shortest possible time [#secrets-hold-them-for-the-shortest-possible-time] Two rules cover almost every mistake Sent sees. **The API key is a request credential, not config.** Build the SDK client per request from the incoming `Authorization: Bearer ` header, use it, and throw the client away. Never persist the key, never log it, never bake it into a boot-time singleton or a `SENT_DM_API_KEY` env var. If there's no bearer token, return `401`; see [Authentication](/build/authentication). (Queued/async work is the one scoped exception, with its own hygiene rules; see [Errors & resilience](/build/errors-and-resilience#retries-and-exponential-backoff).) **The webhook signing secret never leaves memory and never gets logged.** It enters the process the moment a customer registers or rotates an endpoint, lives in a store keyed for verification, and is used only to compute HMACs. It is never written to logs, error messages, or responses. The single most common leak is an over-eager logger. `logger.info(req.headers)` or `logger.debug(req.body)` on a webhook route will happily print the signing secret material, the raw signature, and recipient phone numbers. Log identifiers, not payloads. See [Observability](/build/observability). ## HTTPS only [#https-only] Sent delivers webhooks over HTTPS and expects your registered endpoint to be HTTPS. In production: - Terminate TLS at your load balancer or gateway; redirect any `http://` to `https://`. - Register only `https://` webhook URLs. A plaintext endpoint leaks the raw body (recipient numbers, message content) and the signature on the wire. - Set HSTS. `helmet()` (below) does this and a dozen other headers for you. ## Security headers and CORS [#security-headers-and-cors] Wire `helmet()` for sane default headers and a `cors` policy that is strict in production and permissive only for your local dev origins. ```ts // src/app.ts app.use(helmet()); app.use( cors({ origin: env.NODE_ENV === 'production' ? [/\.your-domain\.com$/] // allow-list your own front-ends; no wildcard : ['http://localhost:3000', 'http://localhost:5173'], credentials: true, }), ); ``` ```python # src/app/main.py settings = get_settings() allowed_origins = ( ["https://app.your-domain.com"] # allow-list your own front-ends; no wildcard if not settings.debug # production else ["http://localhost:3000", "http://localhost:5173"] ) app.add_middleware( CORSMiddleware, allow_origins=allowed_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) ``` CORS protects your **browser** clients, not your webhook receiver. Sent's servers don't send an `Origin` header and aren't subject to CORS at all; the receiver's protection is signature verification, not CORS. Never rely on an origin allow-list to secure `/webhooks/sent`. ## Validate at the edge [#validate-at-the-edge] Parse and validate every request body before it reaches your service layer, and reject with a `400` on failure. Use a schema validator (zod in TypeScript, pydantic in Python) so malformed input never becomes a malformed SDK call. ```ts import { z } from 'zod'; const SendSchema = z.object({ to: z.array(z.string().min(3)).min(1), channel: z.array(z.enum(['sms', 'whatsapp', 'rcs'])).optional(), template: z.object({ id: z.string().uuid().optional(), name: z.string().optional(), parameters: z.record(z.string()).optional(), }), sandbox: z.boolean().optional(), }); const parsed = SendSchema.safeParse(req.body); if (!parsed.success) { return res.status(400).json({ error: { code: 'ValidationError', message: 'Invalid request body' }, }); } ``` ```python from pydantic import BaseModel, Field class Template(BaseModel): id: str | None = None name: str | None = None parameters: dict[str, str] | None = None class SendRequest(BaseModel): to: list[str] = Field(min_length=1) channel: list[str] | None = None template: Template sandbox: bool | None = None # FastAPI validates the body against SendRequest and returns 422 on failure. ``` For the webhook receiver, validate the signature on the **raw body first**, then parse JSON. Parsing before verifying hands attacker-controlled input to your JSON parser and, worse, re-serializes the body so the bytes you sign no longer match what Sent signed. See [Signature verification](/build/signature-verification). ## Rate limiting [#rate-limiting] Rate-limit your public surface: apply a global limiter to everything and a **stricter, separate limiter** to the webhook receiver: the receiver is a public URL and should tolerate Sent's legitimate burst while shedding abuse. ```ts // src/app.ts — global limiter const limiter = rateLimit({ windowMs: env.RATE_LIMIT_WINDOW_MS, max: env.RATE_LIMIT_MAX_REQUESTS, standardHeaders: true, legacyHeaders: false, handler: (_req, res) => res.status(429).json({ error: { code: 'RateLimitExceeded', message: 'Too many requests' }, }), }); app.use(limiter); // A tighter limiter just for the receiver. skipSuccessfulRequests means // legitimate, verified deliveries don't count toward the cap — only the // junk (unverified, malformed) does. const webhookLimiter = rateLimit({ windowMs: 60 * 1000, max: 60, skipSuccessfulRequests: true, }); app.use('/webhooks', webhookLimiter, webhooksRouter); ``` ```python # src/app/main.py — global limiter, one bucket per client from slowapi import Limiter from slowapi.middleware import SlowAPIMiddleware from slowapi.util import get_remote_address limiter = Limiter(key_func=get_remote_address, default_limits=["100/minute"]) app.state.limiter = limiter app.add_middleware(SlowAPIMiddleware) ``` ```python # src/app/routers/webhooks.py — stricter limit on the public receiver @router.post("/webhooks/sent") @limiter.limit("60/minute") async def receive_webhook(request: Request): ... ``` In a multi-instance deployment, an in-memory rate-limit counter is per-instance, so your effective limit is `max × instances`. For a hard global cap, back the limiter with Redis (`rate-limit-redis` for express-rate-limit). See [Scaling & deployment](/build/scaling-and-deployment). ## Never log secrets or PII [#never-log-secrets-or-pii] Treat these as never-log values, everywhere: - The API key and any `Authorization` header. - The webhook signing secret and the signature header (`webhook-signature`, or `X-Webhook-Signature` on version 1). - Raw webhook and request **bodies**. They contain recipient phone numbers and message content. Log identifiers and outcomes instead: request ID, `message_id`, event type, status code, duration. If you must log a phone number for support, mask it (`+1******7890`). ## Replay protection (recap) [#replay-protection-recap] Signature verification proves a request is authentic; the timestamp window proves it's *fresh*. A captured, valid request can otherwise be replayed indefinitely. Enforce both: {/* "auto-disable" is the Sent product behavior for failing endpoints, not a UI toggle. */} {/* vale Google.WordList = NO */} - Reject if `|now − timestamp| > 300s` (±5 minutes), reading `webhook-timestamp` (`X-Webhook-Timestamp` on version 1). - On a [version 2](/start/webhooks/event-types#webhook-versions) webhook, the signature header carries a signature from both the old and new secret for 24 hours after a rotation; accept any match. On version 1 it carries exactly **one** signature, and rotation is a hard replace: the old secret is invalid immediately, so update the receiver's stored secret as soon as you rotate. A receiver still verifying with the old secret rejects every delivery, and 10 consecutive failures auto-disable the endpoint. - Verify against the **raw body** with a constant-time compare. {/* vale Google.WordList = YES */} Full implementation and the exact HMAC scheme live in [Signature verification](/build/signature-verification). ## Next steps [#next-steps] # Sending Messages with the Sent SDK: The Outbound Path (/build/sending-messages.md) # Sending Messages with the Sent SDK: The Outbound Path [#sending-messages-with-the-sent-sdk-the-outbound-path] Sending is the first half of your integration: your app calls Sent, Sent hands back a set of recipients, and you record them. The whole outbound path is one SDK call (`messages.send`) wrapped in a thin service method and a controller that does nothing but validate, delegate, and map. Get that seam right and everything downstream (status tracking, error handling, tests) falls out cleanly. Before you send anything, understand the concepts: [sending messages](/start/guides/sending-messages), [channels](/start/concepts/channels), and [templates](/start/concepts/templates). Sent is **template-first**: you send an approved template with parameters, not free-form text. ## The request shape [#the-request-shape] Every backend maps one canonical request to `messages.send`: ```json { "to": ["+14155550123"], "channel": ["sms"], "template": { "name": "order_update", "parameters": { "1": "Ada" } }, "sandbox": false } ``` - **`to`**: an array of E.164 numbers. One call can fan out to many recipients. - **`channel`**: optional array; `sms`, `whatsapp`, or `rcs`. Omit it and Sent picks the channel from the template. See [Channels](/start/concepts/channels). - **`template`**: reference an approved template by **`name`** (as here) or by **`id`** (one selector is enough), plus its **`parameters`**. See [Templates](/start/concepts/templates). - **`sandbox`**: `true` for a dry run that validates and returns a shaped response without actually delivering. Great for wiring up the path end-to-end before going live. ## The service method [#the-service-method] Put the SDK call behind one method. It takes your typed input, calls `messages.send`, and maps the snake_case SDK response into your own camelCase contract, nothing else. Controllers never see an SDK type; tests mock this one method. The critical mapping: the response carries **`data.recipients[]`**, and each recipient's **`message_id`** becomes your `id`. Also lift **`data.status`**, **`data.template_id`**, and **`data.template_name`** to the top level. ```ts // services/sent.service.ts async send(input: SentMessageInput): Promise { try { const response = await this.client.messages.send({ to: input.to, channel: input.channel, template: input.template, sandbox: input.sandbox, }); const data = response.data ?? {}; const recipients = data.recipients ?? []; return { status: data.status, templateId: data.template_id, templateName: data.template_name, recipients: recipients.map((r) => ({ id: r.message_id, // ← message_id → id to: r.to, channel: r.channel, body: r.body, })), }; } catch (error) { throw this.toApiError(error, 'Failed to send message'); } } ``` ```python # app/services/sent_service.py async def send_canonical(self, request: CanonicalSendRequest) -> CanonicalSendResponse: template: dict[str, object] = {"parameters": request.template.parameters} if request.template.id is not None: template["id"] = request.template.id if request.template.name is not None: template["name"] = request.template.name response = await self._client.messages.send( to=request.to, template=template, channel=request.channel, sandbox=request.sandbox, ) data = response.data recipients = data.recipients if data and data.recipients else [] return CanonicalSendResponse( status=getattr(data, "status", None), templateId=getattr(data, "template_id", None), templateName=getattr(data, "template_name", None), recipients=[ CanonicalRecipient( id=r.message_id, # ← message_id → id to=r.to, channel=r.channel, body=r.body, ) for r in recipients ], ) ``` ```go // internal/models/contract.go — map the SDK response to the contract shape. func NewSendMessageContractResponse(data sentdm.MessageSendResponseData) SendMessageContractResponse { recipients := make([]MessageRecipient, 0, len(data.Recipients)) for _, r := range data.Recipients { recipients = append(recipients, MessageRecipient{ ID: r.MessageID, // ← message_id → id To: r.To, Channel: r.Channel, Body: r.Body, }) } return SendMessageContractResponse{ Status: data.Status, TemplateID: data.TemplateID, TemplateName: data.TemplateName, Recipients: recipients, } } // internal/services/sentclient.go — the thin wrapper (note: Sandbox, not TestMode). func (c *SentClient) SendMessageRaw(ctx context.Context, params sentdm.MessageSendParams) (*sentdm.MessageSendResponse, error) { ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() return c.client.Messages.Send(ctx, params) } ``` ```java // service/impl/CanonicalMessageServiceImpl.java public CanonicalSendResponse send(CanonicalSendRequest request) { SentClient sentClient = clientProvider.client(); MessageSendResponse response = sentClient.messages().send(buildParams(request)); var data = response.data().orElseThrow(() -> new RuntimeException("Empty response data")); String status = data.status().orElse("QUEUED"); var recipients = data.recipients().orElse(List.of()).stream() .map(r -> new CanonicalSendResponse.Recipient( r.messageId().orElse(""), // ← message_id → id r.to().orElse(""), r.channel().orElse(null), r.body().orElse(null))) .toList(); return new CanonicalSendResponse(status, data.templateId().orElse(null), data.templateName().orElse(null), recipients); } ``` ```csharp // Services/SentDmService.cs public async Task SendCanonicalAsync( CanonicalSendRequest request, CancellationToken ct = default) { var parameters = new MessageSendParams { Template = new Sentdm.Models.Messages.Template { ID = request.Template.Id, Name = request.Template.Name, Parameters = request.Template.Parameters ?? new Dictionary() }, To = request.To.ToArray(), Channel = request.Channel is { Count: > 0 } ? request.Channel.ToArray() : null, Sandbox = request.Sandbox }; var result = await Client.Messages.Send(parameters, ct).ConfigureAwait(false); var data = result.Data; var recipients = (data?.Recipients ?? Array.Empty()) .Select(r => new CanonicalRecipient( r.MessageID ?? string.Empty, // ← message_id → id r.To ?? string.Empty, r.Channel ?? string.Empty, r.Body ?? string.Empty)) .ToList(); return new CanonicalSendResponse( data?.Status ?? string.Empty, data?.TemplateID, data?.TemplateName, recipients); } ``` ```php // app/Services/SentDM/SentDMService.php public function send(array $to, ?array $channel, array $template, bool $sandbox = false): array { $response = $this->client->messages->send( to: $to, template: [ 'id' => $template['id'] ?? null, 'name' => $template['name'] ?? null, 'parameters' => $template['parameters'] ?? [], ], channel: $channel, sandbox: $sandbox, ); $data = $response->data; $recipients = array_map(fn ($r) => [ 'id' => $r->messageID, // ← message_id → id 'to' => $r->to, 'channel' => $r->channel, 'body' => $r->body, ], $data->recipients ?? []); return [ 'status' => $data->status, 'templateId' => $data->templateID, 'templateName' => $data->templateName, 'recipients' => $recipients, ]; } ``` ```ruby # app/services/sent_dm/send_message_service.rb def call validate! response = client.messages.send_( to: recipients, # an array — one call can fan out to many recipients template: { id: template_id, name: template_name, parameters: variables }, channel: channels # the Ruby SDK parameter is `channel:` (an array) ) success( status: response.data.status, recipients: response.data.recipients.map do |r| { id: r.message_id, to: r.to, channel: r.channel, body: r.body } # ← message_id → id end ) rescue ApplicationService::ValidationError => e failure(:validation_error, e.message) rescue StandardError => e handle_api_error(e) end ``` Map at the edge, every time. The SDK speaks snake_case (`message_id`, `template_id`); your contract speaks camelCase (`id`, `templateId`). Never leak raw SDK types into controllers or clients. The mapping is what keeps your surface stable when the SDK changes. See the full table in the [reference architecture](/build/architecture). ## The controller [#the-controller] The controller is deliberately thin: build the per-request client, validate the body, call the service, persist each recipient into the message store, and return the mapped response. That's it. No business logic. `validateBody` and `asyncHandler` are the [shared helpers](/build/project-setup#shared-helpers) from project setup. ```ts // controllers/messages.controller.ts router.post( '/', validateBody(SendCanonicalSchema), asyncHandler(async (req, res) => { const dto = req.body as SendCanonicalDto; const { sentService } = servicesForRequest(req); // client built from Bearer key const result = await sentService.send({ to: dto.to, channel: dto.channel, template: dto.template, sandbox: dto.sandbox, }); // Persist each recipient so the webhook receiver can advance its status later. for (const r of result.recipients) { if (r.id) { messageStore.record({ id: r.id, to: r.to, channel: r.channel, templateId: result.templateId, templateName: result.templateName, status: result.status, }); } } res.status(200).json(result); }), ); ``` Notice `servicesForRequest(req)`. The SDK client is built **per request** from the caller's `Authorization: Bearer` key, never a boot-time singleton or an env var. This is the single most important pattern in the whole guide; see [Authentication](/build/authentication). ## Channels [#channels] Pick channels per send with the `channel` array, or omit it and let the template's channel decide. - **`sms`**: plain SMS. Universally reachable; strict on template content. - **`whatsapp`**: rich templates, buttons, media. Requires approved WhatsApp templates. - **`rcs`**: richer than SMS where carriers and handsets support it. Passing more than one channel lets Sent route across them. Read [Channels](/start/concepts/channels) for how routing and fallback work. ## Sandbox sends [#sandbox-sends] Set `sandbox: true` (the request field is named `Sandbox` in the Go/C# SDKs too) to exercise the entire path (validation, mapping, store, and your response shape) without delivering a real message or spending credit. Flip it off for production traffic. ```json { "to": ["+14155550123"], "template": { "name": "order_update" }, "sandbox": true } ``` ## What you get back, and what you don't [#what-you-get-back-and-what-you-dont] A successful send returns immediately with a **non-terminal** status, typically `QUEUED`: ```json { "status": "QUEUED", "templateId": "…", "templateName": "order_update", "recipients": [{ "id": "…", "to": "+14155550123", "channel": "sms", "body": "…" }] } ``` A `200` from `messages.send` means Sent **accepted** the message, not that it was delivered. The final outcome (`SENT`, `DELIVERED`, `READ`, or `FAILED`) arrives **asynchronously over a webhook**, minutes later. That's why the controller records each recipient into the message store on the way out: so the inbound webhook can advance its status. Close that loop in [Status tracking](/build/status-tracking). The send-then-track flow, end to end: >R: POST /api/messages (Bearer key) R->>S: send({ to, channel, template, sandbox }) S->>API: messages.send(...) API-->>S: { data: { status: QUEUED, recipients[] } } S-->>R: mapped { status, recipients:[{ id, ... }] } R-->>C: 200 (message accepted, non-terminal) Note over API,W: minutes later, asynchronously API->>W: POST /webhooks/sent (message.delivered) W->>W: updateStatus(message_id → DELIVERED) `} /> ## Next steps [#next-steps] # Verifying Webhook Signatures (/build/signature-verification.md) # Verifying Webhook Signatures [#verifying-webhook-signatures] This is the most important page in this section. A webhook endpoint is a public URL that mutates your state. If you don't verify signatures correctly, anyone who discovers the URL can forge `delivered` and `failed` events. Verification is the security boundary, and it is not optional boilerplate. Sent signs webhooks **Svix-style**: the same HMAC scheme used by [Svix](https://www.svix.com), a widely used webhook-infrastructure provider, so libraries and knowledge built around Svix's convention transfer directly. The scheme is small and exact; get every detail right and nothing else matters. Get one wrong and either everything is rejected or everything is forged. **The SDKs do not verify inbound webhooks.** There is no `client.webhooks.verifySignature()`. It does not exist. The SDKs expose webhook *management* (create, list, rotate, toggle, test), but verification is hand-rolled per language against the scheme below. If a future SDK adds a verifier with this exact scheme, prefer it. Until then, this code is yours to own. For the product-level overview, see [Signature verification](/start/webhooks/signature-verification) in the concepts docs. This page is the implementation. **Quick path.** Copy your language's function from [The verifier, in seven languages](#the-verifier-in-seven-languages) verbatim, call it with the raw request body plus the `webhook-id` / `webhook-timestamp` / `webhook-signature` headers (`X-Webhook-ID` / `X-Webhook-Timestamp` / `X-Webhook-Signature` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and your stored secret, and reject the request unless it returns valid, before any other processing. The scheme details below explain *why* the code is shaped this way, and the [rotation](#handling-rotation) and [mistakes](#five-mistakes-to-avoid) sections are worth a read once, but the verifier function itself is the part you need first. ## The scheme [#the-scheme] Three lines. Memorize them: ```text key = base64_decode( secret without the "whsec_" prefix ) signed_content = "{webhook-id}.{webhook-timestamp}.{raw_body}" # X-Webhook-ID / X-Webhook-Timestamp on version 1 expected = "v1," + base64( HMAC_SHA256(key, signed_content) ) ``` Then **constant-time compare** `expected` against each space-separated token of the `webhook-signature` header (`X-Webhook-Signature` on version 1), never `==`/`===`: a normal comparison's early exit leaks timing an attacker can use to forge a signature (see [Signature verification](/start/webhooks/signature-verification) in the concepts docs for the full rationale). Every piece matters: - **The secret is base64, not UTF-8.** Strip the `whsec_` prefix, then base64-decode the rest. The HMAC key is the *decoded bytes*. - **The MAC covers `id.timestamp.body`**, joined by literal dots, rather than the body alone. The id and timestamp are *inside* the signature. - **Sign the raw body**, the exact bytes Sent sent, before any JSON parse or re-serialization. - **The output is versioned**: `v1,` followed by the base64 of the digest. ## The verifier, in seven languages [#the-verifier-in-seven-languages] Same scheme, idiomatic per language. ```ts import { createHmac, timingSafeEqual } from "node:crypto"; const SIGNATURE_VERSION = "v1"; const TOLERANCE_SECONDS = 300; export function computeSignature( id: string, timestamp: string, rawBody: Buffer | string, secret: string, ): string { const keyMaterial = secret.startsWith("whsec_") ? secret.slice(6) : secret; const key = Buffer.from(keyMaterial, "base64"); // base64-decode the secret const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8"); const signedContent = `${id}.${timestamp}.${body}`; // id.timestamp.body const digest = createHmac("sha256", key).update(signedContent, "utf8").digest("base64"); return `${SIGNATURE_VERSION},${digest}`; // v1, } function constantTimeEquals(a: string, b: string): boolean { const ab = Buffer.from(a), bb = Buffer.from(b); if (ab.length !== bb.length) return false; return timingSafeEqual(ab, bb); } export function verifyWebhook(input: { id?: string; timestamp?: string; signature?: string; rawBody: Buffer | string; secret: string; }): { valid: true } | { valid: false; reason: string } { const { id, timestamp, signature, rawBody, secret } = input; if (!id || !timestamp || !signature) return { valid: false, reason: "missing signature headers" }; if (!secret) return { valid: false, reason: "webhook secret not configured" }; const ts = Number(timestamp); if (!Number.isFinite(ts)) return { valid: false, reason: "invalid timestamp" }; const now = Math.floor(Date.now() / 1000); if (Math.abs(now - ts) > TOLERANCE_SECONDS) return { valid: false, reason: "timestamp outside tolerance window" }; const expected = computeSignature(id, timestamp, rawBody, secret); // Version 2 sends two signatures for 24 hours after a rotation; accept any match. const matched = signature.split(" ").some((c) => constantTimeEquals(c.trim(), expected)); return matched ? { valid: true } : { valid: false, reason: "signature mismatch" }; } ``` ```python import base64, hashlib, hmac, time SIGNATURE_VERSION = "v1" DEFAULT_TOLERANCE_SECONDS = 300 def compute_signature(webhook_id: str, timestamp: str, raw_body: bytes, secret: str) -> str: key_material = secret[len("whsec_"):] if secret.startswith("whsec_") else secret key = base64.b64decode(key_material) # base64-decode the secret signed_content = b"%s.%s.%s" % ( # id.timestamp.body (bytes) webhook_id.encode(), timestamp.encode(), raw_body, ) digest = hmac.new(key, signed_content, hashlib.sha256).digest() return f"{SIGNATURE_VERSION},{base64.b64encode(digest).decode('ascii')}" def verify_webhook(*, webhook_id, timestamp, signature, raw_body, secret, tolerance_seconds=DEFAULT_TOLERANCE_SECONDS): if not webhook_id or not timestamp or not signature: return False, "missing signature headers" if not secret: return False, "webhook secret not configured" try: ts = int(timestamp) except (TypeError, ValueError): return False, "invalid timestamp" if abs(int(time.time()) - ts) > tolerance_seconds: return False, "timestamp outside tolerance window" expected = compute_signature(webhook_id, timestamp, raw_body, secret) # Version 2 sends two signatures for 24 hours after a rotation; accept any match. matched = any( hmac.compare_digest(candidate.strip(), expected) for candidate in signature.split(" ") if candidate.strip() ) return (True, None) if matched else (False, "signature mismatch") ``` ```go import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "strconv" "strings" "time" ) const ToleranceSeconds = 300 func Verify(id, timestamp, signature string, rawBody []byte, secret string) (bool, string) { if secret == "" { return false, "webhook secret not configured" } if id == "" || timestamp == "" || signature == "" { return false, "missing signature headers" } ts, err := strconv.ParseInt(timestamp, 10, 64) if err != nil { return false, "invalid timestamp" } if diff := time.Now().Unix() - ts; diff > ToleranceSeconds || diff < -ToleranceSeconds { return false, "timestamp outside tolerance window" } expected, err := computeSignature(id, timestamp, rawBody, secret) if err != nil { return false, "invalid secret encoding" } // Version 2 sends two signatures for 24 hours after a rotation; accept any match. for _, candidate := range strings.Fields(signature) { if hmac.Equal([]byte(candidate), []byte(expected)) { // constant-time return true, "" } } return false, "signature mismatch" } func computeSignature(id, timestamp string, body []byte, secret string) (string, error) { key := strings.TrimPrefix(secret, "whsec_") // Secrets are standard, padded base64 (32 random bytes), so StdEncoding is // correct here -- not the URL-safe or raw (unpadded) alphabet. keyBytes, err := base64.StdEncoding.DecodeString(key) // base64-decode the secret if err != nil { return "", err } mac := hmac.New(sha256.New, keyBytes) mac.Write([]byte(id + "." + timestamp + ".")) // id.timestamp. mac.Write(body) // + raw body return "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil)), nil } ``` ```java import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.Base64; public class WebhookSignatureVerifier { private static final String SIGNATURE_VERSION = "v1"; private static final String HMAC_ALGORITHM = "HmacSHA256"; private static final long TOLERANCE_SECONDS = 300; public enum Result { VALID, MISSING_HEADERS, INVALID } public Result verify(String id, String timestamp, String signature, String rawBody, String secret) { return verify(id, timestamp, signature, rawBody, secret, System.currentTimeMillis() / 1000); } Result verify(String id, String timestamp, String signature, String rawBody, String secret, long nowSeconds) { if (isBlank(id) || isBlank(timestamp) || isBlank(signature)) return Result.MISSING_HEADERS; if (isBlank(secret)) return Result.INVALID; // fail closed final long ts; try { ts = Long.parseLong(timestamp.trim()); } catch (NumberFormatException e) { return Result.INVALID; } if (Math.abs(nowSeconds - ts) > TOLERANCE_SECONDS) return Result.INVALID; final String expected; try { expected = computeSignature(secret, id, timestamp.trim(), rawBody); } catch (Exception e) { return Result.INVALID; } // Version 2 sends two signatures for 24 hours after a rotation; accept any match. byte[] expectedBytes = expected.getBytes(StandardCharsets.UTF_8); for (String candidate : signature.trim().split(" ")) { if (candidate.isEmpty()) continue; if (MessageDigest.isEqual(candidate.trim().getBytes(StandardCharsets.UTF_8), expectedBytes)) return Result.VALID; } return Result.INVALID; } private String computeSignature(String secret, String id, String timestamp, String rawBody) throws Exception { String keyMaterial = secret.startsWith("whsec_") ? secret.substring(6) : secret; byte[] key = Base64.getDecoder().decode(keyMaterial); // base64-decode the secret String signedContent = id + "." + timestamp + "." + rawBody; // id.timestamp.body Mac mac = Mac.getInstance(HMAC_ALGORITHM); mac.init(new SecretKeySpec(key, HMAC_ALGORITHM)); byte[] digest = mac.doFinal(signedContent.getBytes(StandardCharsets.UTF_8)); return SIGNATURE_VERSION + "," + Base64.getEncoder().encodeToString(digest); } private static boolean isBlank(String s) { return s == null || s.isBlank(); } } ``` ```csharp using System.Security.Cryptography; using System.Text; public class WebhookSignatureVerifier { public const int ToleranceSeconds = 300; public readonly record struct Result(bool Valid, string Reason) { public static Result Ok() => new(true, string.Empty); public static Result Fail(string reason) => new(false, reason); } public Result Verify(string? id, string? timestamp, string? signature, byte[] rawBody, string? secret) { if (string.IsNullOrEmpty(secret)) return Result.Fail("webhook secret not configured"); if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(timestamp) || string.IsNullOrEmpty(signature)) return Result.Fail("missing signature headers"); if (!long.TryParse(timestamp, out var ts)) return Result.Fail("invalid timestamp"); var diff = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts; if (diff > ToleranceSeconds || diff < -ToleranceSeconds) return Result.Fail("timestamp outside tolerance window"); if (!TryComputeSignature(id, timestamp, rawBody, secret, out var expected)) return Result.Fail("invalid secret encoding"); var expectedBytes = Encoding.UTF8.GetBytes(expected); // Version 2 sends two signatures for 24 hours after a rotation; accept any match. foreach (var candidate in signature.Split(' ', StringSplitOptions.RemoveEmptyEntries)) { if (CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(candidate), expectedBytes)) return Result.Ok(); } return Result.Fail("signature mismatch"); } private static bool TryComputeSignature(string id, string timestamp, byte[] body, string secret, out string signature) { signature = string.Empty; var key = secret.StartsWith("whsec_", StringComparison.Ordinal) ? secret["whsec_".Length..] : secret; byte[] keyBytes; try { keyBytes = Convert.FromBase64String(key); } // base64-decode the secret catch (FormatException) { return false; } var prefix = Encoding.UTF8.GetBytes($"{id}.{timestamp}."); // id.timestamp. var signedContent = new byte[prefix.Length + body.Length]; Buffer.BlockCopy(prefix, 0, signedContent, 0, prefix.Length); Buffer.BlockCopy(body, 0, signedContent, prefix.Length, body.Length); // + raw body bytes using var hmac = new HMACSHA256(keyBytes); signature = "v1," + Convert.ToBase64String(hmac.ComputeHash(signedContent)); return true; } } ``` ```php secret)) return false; if ($webhookId === '' || $timestamp === '' || $signature === '') return false; if (!is_numeric($timestamp) || abs(time() - (int) $timestamp) > self::TOLERANCE_SECONDS) return false; $expected = $this->expectedSignature($webhookId, $timestamp, $rawBody); if ($expected === null) return false; // Version 2 sends two signatures for 24 hours after a rotation; accept any match. foreach (preg_split('/\s+/', trim($signature)) as $candidate) { if ($candidate !== '' && hash_equals($expected, $candidate)) return true; } return false; } private function expectedSignature(string $webhookId, string $timestamp, string $rawBody): ?string { $key = $this->secret; if (str_starts_with($key, 'whsec_')) $key = substr($key, strlen('whsec_')); $keyBytes = base64_decode($key, true); // base64-decode the secret if ($keyBytes === false) return null; $signed = "{$webhookId}.{$timestamp}.{$rawBody}"; // id.timestamp.body return 'v1,' . base64_encode(hash_hmac('sha256', $signed, $keyBytes, true)); } } ``` ```ruby require "base64" require "openssl" module SentDm class SignatureVerifier SIGNATURE_VERSION = "v1".freeze TOLERANCE_SECONDS = 300 def initialize(id:, timestamp:, signature:, raw_body:, secret:, now: Time.now.to_i) @id, @timestamp, @signature = id, timestamp, signature @raw_body, @secret, @now = raw_body, secret, now end def self.verify(...) = new(...).verify def verify return [false, "missing signature headers"] if @id.to_s.empty? || @timestamp.to_s.empty? || @signature.to_s.empty? return [false, "webhook secret not configured"] if @secret.to_s.empty? ts = Integer(@timestamp, exception: false) return [false, "invalid timestamp"] if ts.nil? return [false, "timestamp outside tolerance window"] if (@now - ts).abs > TOLERANCE_SECONDS # Sign the raw header string, not the parsed integer: Integer() strips # surrounding whitespace, so a padded header would sign different bytes # than Sent did. `ts` is only used for the tolerance check above. expected = expected_signature(@timestamp) # Version 2 sends two signatures for 24 hours after a rotation; accept any match. matched = @signature.split(" ").any? { |c| secure_compare(c.strip, expected) } matched ? [true, nil] : [false, "signature mismatch"] end private def expected_signature(timestamp) # `timestamp` is the raw header value (a String), matching what Sent signed. key = Base64.decode64(@secret.to_s.delete_prefix("whsec_")) # base64-decode the secret signed = "#{@id}.#{timestamp}.#{@raw_body}" # id.timestamp.body digest = OpenSSL::HMAC.digest("sha256", key, signed) "#{SIGNATURE_VERSION},#{Base64.strict_encode64(digest)}" end def secure_compare(a, b) # Plain Ruby + openssl (already required above) — works outside Rails too, # unlike ActiveSupport::SecurityUtils.secure_compare. OpenSSL.fixed_length_secure_compare(a, b) rescue ArgumentError false # differing lengths — not a match, and not constant-time either way end end end ``` ## The replay window [#the-replay-window] A valid signature on a captured request is still an attack if it's replayed hours later. So reject any event whose timestamp is more than **300 seconds (5 minutes)** away from now, in either direction: ```text reject if abs(now - webhook-timestamp) > 300 ``` Because the timestamp is part of the signed content, an attacker can't rewrite it to a fresh value without invalidating the signature. The window and the signature reinforce each other. The window is safe to enforce on retries too: each attempt is signed when it is sent, so a redelivery carries its own timestamp rather than the original's and clears the check however long the backoff ran before it. That also makes the timestamp the wrong thing to build a dedupe key from, since it differs between attempts at one event. `webhook-id` (`X-Webhook-Event-ID` on version 1) doesn't: see [The webhook receiver](/build/webhook-receiver). ## Handling rotation [#handling-rotation] On a [version 2](/start/webhooks/event-types#webhook-versions) webhook, rotation overlaps: for 24 hours after the rotate call, `webhook-signature` carries a signature from the new secret and one from the old, so a receiver still holding the old secret keeps verifying while you roll the new one out. After that, only the new secret signs. The verifiers in the preceding section already accept any matching token. On a version 1 webhook, rotating a secret replaces it in one step: the old secret is invalid the moment the rotate call returns, and every delivery from then on is signed **only** with the new secret. That includes events queued before the rotation: Sent signs each delivery when it sends it, with the webhook's current secret, URL and timeout, so nothing already in the queue arrives under the old key. `X-Webhook-Signature` always carries exactly one `v1,…` token. What makes rotation safe lives on your side: hold a *set* of candidate secrets per endpoint and accept a delivery if **any** of them verifies. Add the new secret to the set the moment rotate returns. On version 2 the old secret keeps matching for 24 hours, so nothing fails while the new one rolls out; retire the old entry after that. On version 1 the old entry is harmless (it never matches again), and deliveries that arrive before the new secret reaches your store fail verification and are retried, so keep that gap short. The verifiers in the preceding section also split the header on spaces and test each token. A version 1 webhook sends exactly one signature, so there the split is defensive. Pair this page with [Endpoint management](/build/endpoint-management), where the store persists the new secret as soon as it's issued. ## Five mistakes to avoid [#five-mistakes-to-avoid] **1. Not decoding the secret.** The most common bug. `HMAC(secret_string, body)` (using the literal `whsec_...` string as the key) will never match. Strip the prefix and *base64-decode* the rest; the key is the decoded bytes. **2. Signing only the body.** The MAC covers `{id}.{timestamp}.{body}`, joined by literal dots. Signing just the body drops the id and timestamp from the signature and breaks cross-endpoint and replay protection. **3. Ignoring the replay window.** A signature verifies forever unless you bound it in time. Without the ±300s check, a captured-and-replayed request sails through. Enforce it. **4. Comparing with `==`.** A plain equality check leaks timing information. Always use a constant-time compare: `timingSafeEqual` / `hmac.compare_digest` / `hmac.Equal` / `MessageDigest.isEqual` / `FixedTimeEquals` / `hash_equals` / `secure_compare`. **5. Verifying parsed-then-reserialized JSON.** Sign the exact raw bytes Sent sent; a re-serialized body rarely matches them (covered in [The webhook receiver](/build/webhook-receiver)). ## Next steps [#next-steps] # Tracking Delivery Status (/build/status-tracking.md) # Tracking Delivery Status [#tracking-delivery-status] You send a message and get back a `QUEUED` acknowledgement. Its *real* outcome (delivered, read, or failed) arrives later, asynchronously, over the webhooks you built with the [receiver](/build/webhook-receiver), [signature verification](/build/signature-verification), and [endpoint management](/build/endpoint-management). This page closes the loop: how to fold that event stream into a single, queryable status per message. The pattern is small and the same in every language: **record on send, advance forward-only on each webhook, expose a read endpoint.** Samples on this page are shown in TypeScript, Python, and Go; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). For the product-level view of what each status means, see [Message status tracking](/start/guides/message-status-tracking) and the [event types](/start/webhooks/event-types) reference. ## The status model [#the-status-model] Statuses form a strict progression. A message ranks up as it advances and never goes backwards. This is what makes out-of-order and duplicate deliveries safe. | Status | Rank | Meaning | |---|---|---| | `QUEUED` | 0 | Accepted by Sent, not yet routed. | | `ROUTED` | 1 | Handed to a carrier / channel. | | `SENT` | 2 | Left Sent toward the recipient. | | `DELIVERED` | 3 | Confirmed delivered. | | `FAILED` | 3 | Terminal failure (shares the rank of `DELIVERED`). | | `READ` | 4 | Recipient read it, the only state ranked higher than `DELIVERED`. | Two rules fall out of the ranks: - **Forward-only.** Apply a new status only if its rank is *higher* than the current one. A late `SENT` webhook arriving after `DELIVERED` is ignored. - **Terminal is terminal.** `READ` and `FAILED` are locked; nothing supersedes them. A `DELIVERED` and a `FAILED` can't overwrite each other. They share a rank, so neither wins a race. Events can arrive out of order. Sent delivers *at least once* and over an unordered network, so you may see `DELIVERED` before `SENT`. Ranking, not arrival order, decides the stored status. ## Idempotency and dedupe [#idempotency-and-dedupe] Because delivery is at-least-once, the same event can arrive twice. Two layers protect you: 1. **Dedupe on a per-event key** at the receiver: the `webhook-id` header (`X-Webhook-Event-ID` on version 1), which is the event's own id and is identical on every attempt at it, a no-op before processing even starts (built in [The webhook receiver](/build/webhook-receiver)). Don't key off version 1's `X-Webhook-ID`: that's the *endpoint* id, identical on every delivery from it. 2. **Forward-only updates** in the store: even if a duplicate slips through, re-applying the same or a lower-ranked status changes nothing. This is your real safety net. Together they make the whole pipeline safe to replay. ## The message store [#the-message-store] The store records a message when you send it, then `updateStatus` advances it as webhooks arrive. `updateStatus` is the heart of it: it's a no-op if the id is unknown, if the message is terminal, or if the incoming rank isn't higher. ```ts const RANK: Record = { QUEUED: 0, ROUTED: 1, SENT: 2, DELIVERED: 3, FAILED: 3, READ: 4, }; const TERMINAL = new Set(["READ", "FAILED"]); updateStatus(id: string, next: string): StoredMessage | null { const record = this.map.get(id); if (!record) return null; // unknown id const status = normalize(next); if (!status) return record; if (TERMINAL.has(record.status)) return record; // locked if (rank(status) <= rank(record.status)) return record; // no regress / dupe record.status = status; record.updatedAt = new Date().toISOString(); record.history.push({ status, at: record.updatedAt }); return record; } ``` ```python RANK = {"QUEUED": 0, "ROUTED": 1, "SENT": 2, "DELIVERED": 3, "FAILED": 3, "READ": 4} TERMINAL = {"READ", "FAILED"} def update_status(self, id: str, next_status: str | None) -> dict | None: with self._lock: record = self._map.get(id) if record is None: return None # unknown id status = _normalize(next_status) if not status: return dict(record) if record["status"] in TERMINAL: return dict(record) # locked if _rank(status) <= _rank(record["status"]): return dict(record) # no regress / dupe now = _now() record["status"] = status record["updatedAt"] = now record["history"].append({"status": status, "at": now}) return dict(record) ``` ```go var rank = map[string]int{ "QUEUED": 0, "ROUTED": 1, "SENT": 2, "DELIVERED": 3, "FAILED": 3, "READ": 4, } var terminal = map[string]bool{"READ": true, "FAILED": true} func (s *MessageStore) UpdateStatus(id, next string) (*StoredMessage, bool) { s.mu.Lock() defer s.mu.Unlock() rec, exists := s.messages[id] if !exists { return nil, false // unknown id } status, ok := normalize(next) if !ok { return rec, true } if terminal[rec.Status] { return rec, true // locked } if rank[status] <= rank[rec.Status] { return rec, true // no regress / dupe } now := time.Now().UTC().Format(time.RFC3339) rec.Status = status rec.UpdatedAt = now rec.History = append(rec.History, StatusEvent{Status: status, At: now}) return rec, true } ``` ## Mapping events to statuses [#mapping-events-to-statuses] The webhook payload usually carries `message_status` directly. When it doesn't, derive the status from the event type. The two agree, so either source works: ```ts const STATUS_BY_EVENT: Record = { "message.queued": "QUEUED", "message.routed": "ROUTED", "message.sent": "SENT", "message.delivered": "DELIVERED", "message.read": "READ", "message.failed": "FAILED", }; // In the processor, after verification: const nextStatus = payload.message_status ?? STATUS_BY_EVENT[eventType]; if (payload.message_id && nextStatus) { messageStore.updateStatus(payload.message_id, nextStatus); } ``` ```python STATUS_BY_EVENT = { "message.queued": "QUEUED", "message.routed": "ROUTED", "message.sent": "SENT", "message.delivered": "DELIVERED", "message.read": "READ", "message.failed": "FAILED", } # In the processor, after verification: next_status = payload.get("message_status") or STATUS_BY_EVENT.get(event_type) if message_id and next_status: message_store.update_status(message_id, next_status) ``` ```go var statusByEvent = map[string]string{ "message.queued": "QUEUED", "message.routed": "ROUTED", "message.sent": "SENT", "message.delivered": "DELIVERED", "message.read": "READ", "message.failed": "FAILED", } // In the processor, after verification: next := payload.MessageStatus if next == "" { next = statusByEvent[eventType] } if payload.MessageID != "" && next != "" { store.Default.UpdateStatus(payload.MessageID, next) } ``` `message.received` (an inbound reply) has no `message_id` of yours to advance. It's a new inbound message, not a status update. Route it to your reply-handling logic instead. See [event types](/start/webhooks/event-types). ## Exposing the status [#exposing-the-status] Record the message on the send path so there's something to advance, then serve its current state at `GET /api/messages/:id`: If you're multi-tenant, requiring *a* valid key isn't enough. A message id alone must never be enough to read someone else's status. Record a **tenant identifier** (a hash of the API key, or your own customer id resolved from it, never the raw key itself) alongside the message, and check it on every read, not just on write. The examples below do this with a SHA-256 hash of the key; single-tenant apps can skip the tenant check entirely, since there's only one tenant. ```ts import { createHash } from "node:crypto"; const tenantIdFor = (apiKey: string) => createHash("sha256").update(apiKey).digest("hex"); // On send: record so webhooks have a row to advance. const tenantId = tenantIdFor(apiKey); // the key resolved by servicesForRequest, see Authentication for (const r of result.recipients) { messageStore.record({ id: r.id, tenantId, to: r.to, channel: r.channel, templateId: result.templateId, templateName: result.templateName, status: result.status, }); } // Read endpoint: a valid key is necessary but not sufficient — the message's // tenantId must match the caller's, or this returns 404 (never 403, so a // wrong-tenant read looks identical to "doesn't exist"). router.get("/:id", (req, res) => { const apiKey = apiKeyFromRequest(req); if (!apiKey) { throw new ApiError(401, "Unauthorized", "Missing API key — send it as Authorization: Bearer ."); } const message = messageStore.get(req.params.id); if (!message || message.tenantId !== tenantIdFor(apiKey)) { return res.status(404).json({ error: "not found" }); } res.json(message); }); ``` ```python import hashlib def tenant_id_for(api_key: str) -> str: return hashlib.sha256(api_key.encode()).hexdigest() # On send: record so webhooks have a row to advance. tenant_id = tenant_id_for(api_key) # the key resolved by get_sent_client, see Authentication for r in result.recipients: message_store.record( id=r.id, tenant_id=tenant_id, to=r.to, channel=r.channel, template_id=result.template_id, template_name=result.template_name, status=result.status, ) # Read endpoint: a valid key is necessary but not sufficient — the message's # tenant_id must match the caller's, or this returns 404 (never 403, so a # wrong-tenant read looks identical to "doesn't exist"). @router.get("/api/messages/{message_id}") async def get_message( message_id: str, token: str | None = Depends(get_optional_token), ): api_key = _resolve_api_key(token) # 401s if missing; see Authentication message = message_store.get(message_id) if message is None or message.tenant_id != tenant_id_for(api_key): raise HTTPException(status_code=404, detail="not found") return message ``` ```go func tenantIDFor(apiKey string) string { sum := sha256.Sum256([]byte(apiKey)) return hex.EncodeToString(sum[:]) } // On send: record so webhooks have a row to advance. tenantID := tenantIDFor(apiKey) // the key resolved by ClientResolver, see Authentication for _, r := range result.Recipients { store.Default.Record(store.RecordInput{ ID: r.ID, TenantID: tenantID, To: r.To, Channel: r.Channel, TemplateID: result.TemplateID, TemplateName: result.TemplateName, Status: result.Status, }) } // Read endpoint: a valid key is necessary but not sufficient — the message's // TenantID must match the caller's, or this returns 404 (never 403, so a // wrong-tenant read looks identical to "doesn't exist"). e.GET("/api/messages/:id", func(c echo.Context) error { apiKey := resolver.APIKeyFromRequest(c) if apiKey == "" { return ErrMissingAPIKey // 401; see Authentication } msg, ok := store.Default.Get(c.Param("id")) if !ok || msg.TenantID != tenantIDFor(apiKey) { return c.JSON(http.StatusNotFound, echo.Map{"error": "not found"}) } return c.JSON(http.StatusOK, msg) }) ``` Each record keeps a `history` array too (a timestamped trail of every status it passed through), which is invaluable when debugging a delivery. ## Productionize the store [#productionize-the-store] Keeping this store in **process memory** is perfect for a single instance and for learning the pattern, but it's the wrong choice in production: it's lost on restart, and a second instance won't see the first's data. The send path and the webhook receiver may even land on different instances. The logic (record on send, forward-only advance on webhook, dedupe on the per-event key) is identical against a real datastore. Swap the in-memory map for Redis (with a TTL) or your primary database. The `updateStatus` rank check maps cleanly onto a conditional `UPDATE ... WHERE rank < :newRank`. [Scaling & deployment](/build/scaling-and-deployment) covers the swap. ## Next steps [#next-steps] # Testing Your Sent Integration: Unit, Route, and Sandbox (/build/testing.md) # Testing Your Sent Integration: Unit, Route, and Sandbox [#testing-your-sent-integration-unit-route-and-sandbox] The [layered architecture](/build/architecture) exists partly so this page is short. Because the SDK is reached only through the service layer, and credentials arrive per request rather than from global config, every layer is testable in isolation without real network calls or secrets. Four kinds of test cover the whole integration. Samples on this page are shown in TypeScript and Python; the patterns are framework-agnostic and transfer directly to the other [supported SDK languages](/sdks). ## 1 · Unit-test the service layer with a mocked SDK [#1--unit-test-the-service-layer-with-a-mocked-sdk] The service layer is the one place SDK types appear. Test it by injecting a **mock SDK client** and asserting two things: the SDK was called with the right shape, and the response was mapped into your contract (snake → camel) correctly. No network, no key. ```ts // services/sent.service.spec.ts const mockClient = { messages: { send: vi.fn() } }; const service = new SentService(mockClient as any, mockLogger as any); it('send maps the SDK response into the canonical shape', async () => { mockClient.messages.send.mockResolvedValue({ data: { status: 'QUEUED', template_id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', template_name: 'welcome', recipients: [{ message_id: 'msg_123', to: '+14155550123', channel: 'sms' }], }, }); const result = await service.send({ to: ['+14155550123'], channel: ['sms'], template: { name: 'welcome' }, }); // SDK snake_case → contract camelCase; message_id → id. expect(result).toEqual({ status: 'QUEUED', templateId: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', templateName: 'welcome', recipients: [{ id: 'msg_123', to: '+14155550123', channel: 'sms', body: undefined }], }); }); ``` ```python # tests/test_sent_service.py — pytest-asyncio import pytest from unittest.mock import AsyncMock, MagicMock from app.models.schemas import CanonicalSendRequest from app.services.sent_service import SentService @pytest.mark.asyncio async def test_send_canonical_maps_response(): data = MagicMock( status="QUEUED", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8", template_name="welcome", recipients=[MagicMock(message_id="msg_123", to="+14155550123", channel="sms", body=None)], ) client = MagicMock() client.messages.send = AsyncMock(return_value=MagicMock(data=data)) service = SentService(client) result = await service.send_canonical(CanonicalSendRequest( to=["+14155550123"], channel=["sms"], template={"name": "welcome"}, )) # SDK snake_case → contract camelCase; message_id → id. assert result.status == "QUEUED" assert result.templateId == "7ba7b820-9dad-11d1-80b4-00c04fd430c8" assert result.recipients[0].id == "msg_123" ``` A **test container** (e.g. `tests/setup.ts`) that swaps the whole dependency container for mocks (a `sentService`/`messagesService` full of `vi.fn()` and a no-op logger) keeps this clean in TypeScript. Injecting dependencies rather than importing singletons is what makes this work; the same pattern applies with pytest fixtures or Spring's `@MockBean`. ## 2 · Integration-test your routes over HTTP [#2--integration-test-your-routes-over-http] Mount the real app with a mocked service container and drive it over HTTP. This exercises routing, edge validation, body parsing, and error mapping together: everything except the actual Sent call. ```ts // tests/messages.integration.spec.ts import request from 'supertest'; import { createApp } from '../app'; import { setupTestContainer } from './setup'; beforeEach(() => { setupTestContainer({ sentService: { send: vi.fn().mockResolvedValue({ status: 'QUEUED', templateId: '550e8400-e29b-41d4-a716-446655440000', templateName: 'welcome', recipients: [{ id: 'msg_123', to: '+14155550123', channel: 'sms' }], }), } as any, }); app = createApp(); }); it('POST /api/messages succeeds with a valid payload', async () => { const res = await request(app) .post('/api/messages') .set('Authorization', 'Bearer test-key') .send({ to: ['+14155550123'], channel: ['sms'], template: { name: 'welcome', parameters: { name: 'Ada' } }, }); expect(res.status).toBe(200); expect(res.body.recipients[0].id).toBe('msg_123'); }); it('POST /api/messages returns 400 for an invalid body', async () => { const res = await request(app) .post('/api/messages') .set('Authorization', 'Bearer test-key') .send({ template: { name: 'welcome' } }); // missing `to` expect(res.status).toBe(400); expect(res.body.error.code).toBe('ValidationError'); }); ``` ```python # tests/test_messages.py — FastAPI TestClient (see conftest.py fixtures) from app.models.schemas import CanonicalSendResponse, CanonicalRecipient async def fake_send_canonical(self, request): # Return the real response model — the route iterates result.recipients as objects. return CanonicalSendResponse( status="QUEUED", templateId="550e8400-e29b-41d4-a716-446655440000", templateName="welcome", recipients=[CanonicalRecipient(id="msg_123", to="+14155550123", channel="sms")], ) def test_send_succeeds(client, monkeypatch): # send_canonical is async — replace it with an async stub. monkeypatch.setattr( "app.services.sent_service.SentService.send_canonical", fake_send_canonical ) res = client.post( "/api/messages", headers={"Authorization": "Bearer test-key"}, json={ "to": ["+14155550123"], "channel": ["sms"], "template": {"name": "welcome", "parameters": {"name": "Ada"}}, }, ) assert res.status_code == 200 assert res.json()["recipients"][0]["id"] == "msg_123" def test_health(client): res = client.get("/health") assert res.json() == {"status": "ok", "backend": "python", "framework": "fastapi"} ``` Also assert the unhappy paths: a request with no `Authorization` header should `401`, a malformed body should `400`, and an unknown route should `404`. These are cheap to write and catch the mistakes that hurt most in production. ## 3 · Safe end-to-end sends with `sandbox: true` [#3--safe-end-to-end-sends-with-sandbox-true] When you want a real round-trip against Sent without delivering to a real handset, pass `sandbox: true` on the send. The request goes through the full stack and returns a real response shape, but no message is actually delivered, ideal for CI smoke tests and staging. ```ts await sentService.send({ to: ['+1234567890'], channel: ['sms'], template: { name: 'welcome', parameters: { name: 'Test' } }, sandbox: true, // full round-trip, nothing delivered }); ``` `sandbox` is a per-send flag, not an environment mode. The same running service handles sandbox and live sends side by side. Make sure production traffic does **not** carry `sandbox: true`, and that any test harness that sets it can't leak into prod. Confirm it's off before go-live. See [Going to production](/build/going-to-production). ## 4 · Test the webhook verifier against a known vector [#4--test-the-webhook-verifier-against-a-known-vector] The verifier is the most security-critical code you own, and it's pure (inputs in, boolean out), so pin it with a fixed **test vector**: a known secret, id, timestamp, and body with a pre-computed expected signature, hardcoded once and never regenerated by your own code. A fixed vector catches the case a same-code "compute it twice" check can't: if your implementation has a systemic misunderstanding of the scheme (wrong join order, wrong encoding), computing it twice in your own codebase reproduces the same mistake both times and still "passes." A hardcoded expected value only passes if your output matches the scheme itself. ```ts // Fixed inputs and a hardcoded expected output — computed once, out of band, // and never regenerated by computeSignature itself. const SECRET = 'whsec_abcdef1234567890'; const ID = '1f2e3d4c-5b6a-7980-1234-567890abcdef'; const TS = '1750000000'; const BODY = '{"field":"message","event":"message.delivered"}'; const EXPECTED = 'v1,toBvqGNFsjQ5xSZO93Z3qiyVckIbArJtTaEPaUYZJGw='; it('matches the known test vector byte-for-byte', async () => { expect(await computeSignature(ID, TS, BODY, SECRET)).toBe(EXPECTED); }); ``` Apply the same idea to your **receiver's** verify function, and cover the failure modes explicitly: - Strips the `whsec_` prefix and decodes the key as **base64** (not utf-8). - A tampered body produces a **different** signature (assert rejection). - A stale timestamp (> 300 s) is rejected: replay protection. - Rotation: a signature computed with a retired secret is **rejected**, and a header carrying two space-separated signatures is accepted if either matches. A version 2 webhook is signed with the old and new secret for 24 hours after rotating; a version 1 webhook is signed with the current secret only, so update the verifier's stored secret immediately. See [Going to production](/build/going-to-production) for the rotation runbook. - Verification runs on the **raw body**, before JSON parsing. Because the vector is fixed, this test is also your cross-language conformance check: hard-code the same `SECRET`/`ID`/`TS`/`BODY` in your Python, Go, or Java verifier tests and they must all produce `v1,`. See [Signature verification](/build/signature-verification). ## Next steps [#next-steps] # Building the Webhook Receiver (/build/webhook-receiver.md) # Building the Webhook Receiver [#building-the-webhook-receiver] This is the inbound half of the integration. As a message moves through Sent (`queued → routed → sent → delivered → read`, or `failed`) and when a recipient replies, Sent `POST`s a signed event to an endpoint you registered. The receiver is a single route, `POST /webhooks/sent`, and getting it right is mostly about *order of operations*. If you're new to the event model, read [Webhooks: getting started](/start/webhooks/getting-started) and the [message lifecycle](/start/webhooks/lifecycle) first. This page assumes you know *what* the events mean and focuses on *how to receive them safely*. A webhook endpoint is a public URL that mutates your state. Treat it as a security boundary: verify every request against the raw body before you act on it. The verification itself is the next page ([Signature verification](/build/signature-verification)); this page builds the receiver *around* it. **Quick path.** Grab your framework's raw-body setup from [Why the raw body matters](#why-the-raw-body-matters), verify with the function from [Signature verification](/build/signature-verification), then follow [Acknowledge fast, process async](#acknowledge-fast-process-async): reject on a bad signature or an unparseable body, otherwise return `200` immediately and do the actual state update after. That's the whole receiver. [The pipeline](#the-pipeline) below just walks through why those five steps are in that exact order. ## The pipeline [#the-pipeline] Every receiver runs the same five steps against the raw request body and the signature headers, in this exact order. A [version 2](/start/webhooks/event-types#webhook-versions) webhook, the default, sends `webhook-id`, `webhook-timestamp`, and `webhook-signature`; a version 1 webhook sends the `X-Webhook-*` equivalents. The samples read the version 2 header and fall back to version 1: raw body + headers] --> B{Required
headers?} B -- no --> E400[400] B -- yes --> C{Signature
valid?} C -- no --> E401[401] C -- yes --> P{JSON
parses?} P -- no --> E400B[400] P -- yes --> F{Seen
event id?} F -- yes --> G[Ack 200
skip processing] F -- no --> D[Ack 200
received: true] D --> H[Process async:
update state, branch on event] `} /> *In plain English: each `{diamond}` is a yes/no check, read left to right: missing headers, a bad signature, or an unparseable body rejects early; every surviving event gets a `200`, and only a fresh one gets processed.* The ordering is deliberate: 1. **Verify**: reject with `400` if signature headers are missing, `401` if the signature doesn't match or the timestamp is stale. 2. **Parse** the JSON only after verification succeeds: reject with `400` if the body is unparseable. 3. **Dedupe** on a **per-event** key: Sent delivers *at least once*, so retries must be no-ops. Use `webhook-id` on version 2 or `X-Webhook-Event-ID` on version 1, which carry the same value on every attempt at an event, **not** `X-Webhook-ID` (see the warning below). A duplicate still gets a `200`; it just skips the next two steps. 4. **Acknowledge** immediately with `200 { "received": true }`. 5. **Process** the event after acknowledging: update your message store, branch on the event type. This post-ack async step is what this guide calls **the processor**. **On version 1, `X-Webhook-ID` is the *endpoint's* id, not a per-event id.** It's identical on every delivery to a given endpoint (it's part of the signed content, binding the signature to that endpoint). So it's the wrong key to dedupe on. Keying off it would drop every event after the first. The per-event id is `X-Webhook-Event-ID`, and it's the one to store. Version 2's `webhook-id` is already per-event, so on version 2 it's both the signed id and the dedupe key. Don't reach for the timestamp header either: it's the send time of the attempt in hand, so it differs between the original and its retries and would record one event once per attempt. A payload-derived key (`message_id` + `message_status`) is a narrower alternative that also collapses the same status transition arriving as two separate events, at the cost of covering only events that carry a `message_id`. Your status store is forward-only and idempotent either way (see [Tracking delivery status](/build/status-tracking)), which is the real safety net; the dedupe guard just spares you redundant downstream work. ## Why the raw body matters [#why-the-raw-body-matters] The signature covers the **exact bytes** Sent sends: the webhook id, the timestamp, and the raw JSON body concatenated as `{id}.{timestamp}.{rawBody}`. If your framework parses the JSON and hands you a re-serialized string, key order, whitespace, and Unicode escaping can all differ from the original bytes, and the HMAC will never match. So the rule is: **capture the raw body before any JSON middleware touches it, and verify against those bytes.** Parse the JSON only *after* verification succeeds. Each framework has its own way to opt out of automatic parsing for this one route. ```ts // Mount express.raw ONLY on the receiver path, before the global json() parser. // This hands the handler a Buffer of the exact bytes Sent signed. app.use("/webhooks", express.raw({ type: "application/json" })); // In the handler: const rawBody: Buffer = Buffer.isBuffer(req.body) ? req.body : Buffer.from(typeof req.body === "string" ? req.body : JSON.stringify(req.body ?? {})); ``` ```python # FastAPI: read the body as bytes BEFORE any Pydantic model binding. @router.post("/sent") async def receive(request: Request): raw_body: bytes = await request.body() h = request.headers # version 2 headers first, version 1 as the fallback id_ = h.get("webhook-id") or h.get("x-webhook-id") timestamp = h.get("webhook-timestamp") or h.get("x-webhook-timestamp") signature = h.get("webhook-signature") or h.get("x-webhook-signature") # ... verify(raw_body, ...) then json.loads(raw_body) only after ``` ```go // Echo: read the whole body into bytes; do not bind a struct first. rawBody, err := io.ReadAll(c.Request().Body) if err != nil { return c.JSON(http.StatusBadRequest, echo.Map{"error": "cannot read body"}) } // Version 2 headers first, version 1 as the fallback. header := func(v2, v1 string) string { if v := c.Request().Header.Get(v2); v != "" { return v } return c.Request().Header.Get(v1) } id := header("webhook-id", "X-Webhook-ID") timestamp := header("webhook-timestamp", "X-Webhook-Timestamp") signature := header("webhook-signature", "X-Webhook-Signature") // verify(rawBody, ...) then json.Unmarshal(rawBody, &event) after ``` ```java // Spring: bind the body as a raw String (or byte[]), NOT a parsed DTO. @PostMapping("/webhooks/sent") public ResponseEntity receive( @RequestBody String rawBody, @RequestHeader HttpHeaders headers) { // Version 2 headers first, version 1 as the fallback. String id = Optional.ofNullable(headers.getFirst("webhook-id")).orElse(headers.getFirst("X-Webhook-ID")); String timestamp = Optional.ofNullable(headers.getFirst("webhook-timestamp")).orElse(headers.getFirst("X-Webhook-Timestamp")); String signature = Optional.ofNullable(headers.getFirst("webhook-signature")).orElse(headers.getFirst("X-Webhook-Signature")); // verify(rawBody, ...) then objectMapper.readValue(rawBody, ...) after } ``` ```csharp // ASP.NET Core: read the request body stream yourself. [HttpPost("/webhooks/sent")] public async Task Receive() { using var reader = new StreamReader(Request.Body); var rawBody = await reader.ReadToEndAsync(); // Version 2 headers first, version 1 as the fallback. string Header(string v2, string v1) => Request.Headers.TryGetValue(v2, out var v) ? v.ToString() : Request.Headers[v1].ToString(); var id = Header("webhook-id", "X-Webhook-ID"); var timestamp = Header("webhook-timestamp", "X-Webhook-Timestamp"); var signature = Header("webhook-signature", "X-Webhook-Signature"); // Verify(rawBody, ...) then JsonSerializer.Deserialize(rawBody) after } ``` ```php // Laravel: getContent() returns the raw request body verbatim. public function receive(Request $request) { $rawBody = $request->getContent(); // Version 2 headers first, version 1 as the fallback. $id = $request->header('webhook-id') ?? $request->header('X-Webhook-ID'); $timestamp = $request->header('webhook-timestamp') ?? $request->header('X-Webhook-Timestamp'); $signature = $request->header('webhook-signature') ?? $request->header('X-Webhook-Signature'); // verify($rawBody, ...) then json_decode($rawBody) after } ``` ```ruby # Rails: request.raw_post is the unparsed body. Skip CSRF for this action. def receive raw_body = request.raw_post # Version 2 headers first, version 1 as the fallback. id = request.headers["webhook-id"] || request.headers["X-Webhook-ID"] timestamp = request.headers["webhook-timestamp"] || request.headers["X-Webhook-Timestamp"] signature = request.headers["webhook-signature"] || request.headers["X-Webhook-Signature"] # verify(raw_body, ...) then JSON.parse(raw_body) after end ``` Scope the raw-body handling to the **receiver route only**. The rest of your API still wants normal JSON parsing. In Express that means mounting `express.raw` on `/webhooks` and `json()` everywhere else; in Rails it means `skip_before_action :verify_authenticity_token` on that action; in Spring it's just binding `String` instead of a DTO for that endpoint. ## Acknowledge fast, process async [#acknowledge-fast-process-async] Sent waits for your `2xx`. If you do slow work (database writes, downstream API calls, sending email) *before* responding, you risk timing out, and Sent will retry an event you actually handled. **After 10 consecutive delivery failures, Sent auto-disables the endpoint**: not a soft warning, a hard cutoff. A slow, timing-out receiver doesn't just risk duplicate processing; ten bad responses in a row and your integration silently stops receiving webhooks at all until someone re-enables it from the Sent dashboard. So acknowledge first, then process. In a single-process app that's just responding before the `await`; in production, hand the verified event to a queue and return `200` immediately. ```ts // Verified above. Parse, dedupe, ack, THEN process. let event: WebhookEvent; try { event = WebhookEventSchema.parse(JSON.parse(rawBody.toString("utf8"))); } catch { return res.status(400).json({ error: "invalid payload" }); } // Dedupe on the event's own id: webhook-id on version 2, X-Webhook-Event-ID on // version 1 (NOT X-Webhook-ID, which is the version 1 endpoint id). const eventId = (req.headers["webhook-id"] ?? req.headers["x-webhook-event-id"]) as string | undefined; if (eventId && !idempotency.firstSeen(eventId)) { return res.status(200).json({ received: true }); // duplicate — no-op } // Acknowledge immediately so Sent doesn't retry while we work. res.status(200).json({ received: true }); void processEvent(eventType ?? event.event, event, logger); ``` ```python # Verified above. Parse, dedupe, ack; BackgroundTasks runs after the response. try: event = json.loads(raw_body) except ValueError: return JSONResponse({"error": "invalid payload"}, status_code=400) # Dedupe on the event's own id: webhook-id on version 2, X-Webhook-Event-ID on # version 1 (NOT X-Webhook-ID, which is the version 1 endpoint id). event_id = request.headers.get("webhook-id") or request.headers.get("x-webhook-event-id") if event_id and not idempotency.first_seen(event_id): return JSONResponse({"received": True}) # duplicate — no-op background_tasks.add_task(process_event, event_type, event) return JSONResponse({"received": True}) ``` ```go // Verified above. Parse, dedupe, ack; process in a goroutine. var event WebhookEvent if err := json.Unmarshal(rawBody, &event); err != nil { return c.JSON(http.StatusBadRequest, echo.Map{"error": "invalid payload"}) } // Dedupe on the event's own id: webhook-id on version 2, X-Webhook-Event-ID on // version 1 (NOT X-Webhook-ID, which is the version 1 endpoint id). eventID := c.Request().Header.Get("webhook-id") if eventID == "" { eventID = c.Request().Header.Get("X-Webhook-Event-ID") } if eventID != "" && !idempotency.FirstSeen(eventID) { return c.JSON(http.StatusOK, echo.Map{"received": true}) // duplicate — no-op } go processEvent(eventType, event) // process off the response path return c.JSON(http.StatusOK, echo.Map{"received": true}) ``` `idempotency` here is a placeholder for whatever's backing `firstSeen`: a plain in-memory `Set` is fine on a single instance, but the moment you run more than one, it needs to be a **shared** store: two instances can each receive the same retried delivery and both see "unseen" if they're not checking the same place. See [Idempotency across instances](/build/scaling-and-deployment#idempotency-across-instances) for the shared, atomic version (Redis `SET NX`). ## When processing fails after the ack [#when-processing-fails-after-the-ack] Acknowledging first means you've told Sent the event is handled. If `processEvent` then throws (a bad payload variant, your database is down, a downstream call fails), **Sent will not retry** it for you. That failure is now entirely yours to catch: - **Don't fire-and-forget in production.** A bare `go processEvent(...)` or `void processEvent(...)` with no error handling silently drops the event on failure. At minimum, catch the error and log it with the event's `message_id` so it's findable. - **Put a real queue behind the ack**, not an in-process goroutine/task, once this matters for more than a demo: one with its own retry policy and a dead-letter queue for events that fail repeatedly. That queue can retry your *processing* even though Sent's own delivery retry is already spent. - **Alert on the DLQ as well as on errors.** A message stuck `SENT` forever because its `DELIVERED` event silently failed to process looks identical to "still in flight" unless something pages you when events land in the dead-letter queue. This is the actual failure mode that matters most for this endpoint: the inbound flow is what keeps your delivery status correct, so a swallowed processing error doesn't just lose one event. It leaves that message's status permanently stale. ## The response contract [#the-response-contract] Your status code is a *signal* to Sent. Return the right one: | Situation | Status | Body | |---|---|---| | Verified & accepted | `200` | `{ "received": true }` | | Missing required signature headers | `400` | `{ "error": "missing signature headers" }` | | Signature mismatch or stale timestamp | `401` | `{ "error": "invalid signature" }` | | Unparseable JSON (*after* a valid signature) | `400` | `{ "error": "invalid payload" }` | | No signing secret known yet (none registered) | `503` | `{ "error": "no signing secret configured" }` | The `503` case is worth calling out: because the signing secret is **born when you register an endpoint** (see [Endpoint management](/build/endpoint-management)), a receiver that has never held a secret has nothing to verify against and should say so rather than silently accept or 500. Once an endpoint is registered, verification proceeds normally. **Return `2xx` even for event types you don't handle.** A non-`2xx` tells Sent the delivery failed and it will retry with backoff. If you only care about `message.delivered` and `message.failed`, still `200` the `message.queued` and `message.routed` events, just log and move on. Silence is acknowledgement. Never echo header values, the raw signature, or the signing secret in a response or log line. A rejection body should name the *reason* (`"invalid signature"`), never the offending value. ## Where the secret comes from [#where-the-secret-comes-from] One thing that surprises people: there is no `SENT_DM_WEBHOOK_SECRET` env var driving this in production. The signing secret is **born when a customer registers a webhook** (the create call returns it once), and the receiver verifies against that in-memory secret. That whole lifecycle is [Endpoint management](/build/endpoint-management); the verification math is [Signature verification](/build/signature-verification). ## Next steps [#next-steps] # Authentication (/reference-legacy/api/authentication.md) **Legacy API Notice:** This documentation covers the Legacy Sent API (v2). For new integrations, please refer to the [latest Sent API v3 Authentication](/reference/api/authentication). # Authentication [#authentication] This guide shows you how to get Legacy Sent API (v2) credentials and send authenticated requests. Every v2 request requires two headers: ```http x-sender-id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` For why credentials travel in request headers rather than the URL or body, see [API Authentication](/start/concepts/api-authentication). ## Get your credentials [#get-your-credentials] 1. Log into your [Sent Dashboard](https://app.sent.dm). 2. Navigate to **Settings** → **API Keys**. 3. Click **Generate New API Key**. 4. Copy your `x-sender-id` and `x-api-key` values using the copy icon to the right of each key. Store both values as environment variables rather than hardcoding them: ```bash # .env file SENT_SENDER_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx SENT_API_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` ## Send an authenticated request [#send-an-authenticated-request] Include both headers in every request (most HTTP clients let you set them once as default headers) and always call `https://api.sent.dm` over HTTPS. To verify your credentials: ```bash curl -v -X GET https://api.sent.dm/v2/contacts \ -H "x-sender-id: $SENT_SENDER_ID" \ -H "x-api-key: $SENT_API_KEY" ``` A `200` response confirms your credentials work. A `401` response means authentication failed. Match the response body against the [authentication errors](#authentication-errors) below. ## Authentication headers [#authentication-headers] | Header | Type | Purpose | Example | | ------------- | ------------- | ----------------------------------------- | -------------------------------------- | | `x-sender-id` | String (UUID) | Your unique identifier for data isolation | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` | | `x-api-key` | String (UUID) | Your secret API key for authentication | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` | Both credentials are UUIDs: exactly 36 characters, including hyphens. ## Authentication errors [#authentication-errors] v2 authentication failures return `401` with a problem-details body. Two response bodies exist: ### Missing or invalid sender ID (401) [#missing-or-invalid-sender-id-401] Returned when the `x-sender-id` header is missing or is not a valid UUID: ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "Missing or invalid sender identifier", "status": 401, "errors": { "generalErrors": ["Missing or invalid sender identifier"] } } ``` **Solution**: Include the `x-sender-id` header and verify it matches your sender ID, formatted as a UUID. ### Invalid or missing API key (401) [#invalid-or-missing-api-key-401] Returned when the `x-api-key` header is missing, or the key is not an active key belonging to the sender ID: ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "Invalid or missing API credentials", "status": 401, "errors": { "generalErrors": ["Invalid or missing API credentials"] } } ``` **Solution**: Include the `x-api-key` header and check that the key is active, belongs to the sender ID, and hasn't been rotated or deleted. ### Debugging authentication issues [#debugging-authentication-issues] 1. **Verify credential format**: both values are UUIDs, exactly 36 characters including hyphens (see [Authentication headers](#authentication-headers)). 2. **Check environment variables**: ```bash echo $SENT_SENDER_ID echo $SENT_API_KEY ``` 3. **Verify dashboard settings**: confirm the API key is active in your dashboard and hasn't been rotated, disabled, or deleted. ## API key management [#api-key-management] ### Do's [#dos] - **Store in environment variables**: Never hardcode credentials - **Use different keys**: Separate keys for development, staging, and production - **Rotate regularly**: Update API keys every 90 days or after security incidents - **Monitor usage**: Track API key usage patterns and set up alerts - **Restrict access**: Limit who has access to production API keys ### Don'ts [#donts] - **Never commit to version control**: Add `.env` to `.gitignore` - **Avoid client-side exposure**: Never send API keys to browsers or mobile apps - **Don't share keys**: Each environment and team member should have unique keys - **Avoid logging**: Don't log API keys in application logs ## Rate limiting [#rate-limiting] Rate limits apply per customer account: requests authenticated with the same `x-sender-id` share one pool. For the limit values, the quick-message daily cap, and the `429` response format, see the [v2 Rate Limits reference](/reference-legacy/api/rate-limits). ## Next steps [#next-steps] method: GET route: /v2/contacts/id # GET /v2/contacts/id Get contact by ID for authenticated customer Retrieves a specific contact by their unique identifier for the authenticated customer. The customer ID is extracted from the authentication token. Returns detailed contact information including phone number and creation timestamp. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetContactByIdEndpoint` **Tags:** V2 ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The unique identifier (GUID) of the resource to retrieve | ## Responses ### 200 Contact found and returned successfully #### application/json ```typescript { id?: string, phoneNumber?: string, formatE164?: string, formatInternational?: string, formatNational?: string, formatRfc?: string, countryCode?: string, regionCode?: string, availableChannels?: string, defaultChannel?: string } ``` ##### Example ```json { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "phoneNumber": "+1234567890", "formatE164": "+1234567890", "formatInternational": "+1 234-567-890", "formatNational": "(234) 567-890", "formatRfc": "tel:+1-234-567-890", "countryCode": "1", "regionCode": "US", "availableChannels": "sms,whatsapp", "defaultChannel": "sms" } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: GET route: /v2/contacts/phone # GET /v2/contacts/phone Get contact by phone number for authenticated customer Retrieves a contact by their phone number for the authenticated customer. Phone number should be in international format (e.g., +1234567890). The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetContactByPhoneEndpoint` **Tags:** V2 ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `phoneNumber` | `string` | true | The phone number in international format (e.g., +1234567890) | ## Responses ### 200 Contact found and returned successfully #### application/json ```typescript { id?: string, phoneNumber?: string, formatE164?: string, formatInternational?: string, formatNational?: string, formatRfc?: string, countryCode?: string, regionCode?: string, availableChannels?: string, defaultChannel?: string } ``` ##### Example ```json { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "phoneNumber": "+1234567890", "formatE164": "+1234567890", "formatInternational": "+1 234-567-890", "formatNational": "(234) 567-890", "formatRfc": "tel:+1-234-567-890", "countryCode": "1", "regionCode": "US", "availableChannels": "sms,whatsapp", "defaultChannel": "sms" } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: GET route: /v2/contacts # GET /v2/contacts Get paginated contacts for authenticated customer Retrieves a paginated list of contacts for the authenticated customer. Supports server-side pagination with configurable page size. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetContactsByCustomerEndpoint` **Tags:** V2 ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | The page number (zero-indexed). Default is 0. | | `pageSize` | `integer` | true | The number of items per page. Default is 20. | ## Responses ### 200 Contacts retrieved successfully with pagination metadata #### application/json ```typescript { items?: Array<{ id?: string, phoneNumber?: string, formatE164?: string, formatInternational?: string, formatNational?: string, formatRfc?: string, countryCode?: string, regionCode?: string, availableChannels?: string, defaultChannel?: string }>, totalCount?: integer, page?: integer, pageSize?: integer, totalPages?: integer } ``` ##### Example ```json { "items": [ { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "phoneNumber": "+1234567890", "formatE164": "+1234567890", "formatInternational": "+1 234-567-890", "formatNational": "(234) 567-890", "formatRfc": "tel:+1-234-567-890", "countryCode": "1", "regionCode": "US", "availableChannels": "sms,whatsapp", "defaultChannel": "sms" }, { "id": "6ba7b811-9dad-11d1-80b4-00c04fd430c8", "phoneNumber": "+1234567891", "formatE164": "+1234567891", "formatInternational": "+1 234-567-891", "formatNational": "(234) 567-891", "formatRfc": "tel:+1-234-567-891", "countryCode": "1", "regionCode": "US", "availableChannels": "sms", "defaultChannel": "sms" } ], "totalCount": 150, "page": 0, "pageSize": 20, "totalPages": 8 } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden # Data Models (/reference-legacy/api/data-models.md) **Legacy API Notice:** This documentation covers the Legacy Sent API (v2). For new integrations, please refer to the [latest Sent API v3 Data Models](/reference/api/data-models). # Data Models [#data-models] Complete reference for the data structures used in the legacy Sent API v2. ## Contact Models [#contact-models] ### Contact Object [#contact-object] The contact object represents a phone number with its various formats and available messaging channels. | Field | Type | Description | |-------|------|-------------| | `id` | UUID | Unique contact identifier | | `phoneNumber` | String | Phone number as originally provided | | `formatE164` | String | E.164 international format | | `formatInternational` | String | Human-readable international format | | `formatNational` | String | National format for the country | | `formatRfc` | String | RFC 3966 tel: URI format | | `countryCode` | String | Country calling code | | `regionCode` | String | ISO 3166-1 alpha-2 country code | | `availableChannels` | String | Comma-separated available channels | | `defaultChannel` | String | Recommended messaging channel | ### Contact List Response [#contact-list-response] `GET /v2/contacts` returns the [pagination wrapper](#pagination-model) with each entry in `items` being a [Contact object](#contact-object): ```json { "items": [ { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "phoneNumber": "+1234567890", "formatE164": "+1234567890", "formatInternational": "+1 234-567-890", "formatNational": "(234) 567-890", "formatRfc": "tel:+1-234-567-890", "countryCode": "1", "regionCode": "US", "availableChannels": "sms,whatsapp", "defaultChannel": "sms" } ], "totalCount": 150, "page": 0, "pageSize": 20, "totalPages": 8 } ``` ## Template Models [#template-models] ### Template Object [#template-object] Message templates for multi-channel messaging (SMS, WhatsApp). | Field | Type | Description | |-------|------|-------------| | `id` | UUID | Unique template identifier | | `displayName` | String | Human-readable template name | | `category` | Enum | Template category (see below) | | `language` | ISO Code | Language/locale (for example, `en_US`) | | `definition` | Object | Template Definition object (see below) | | `status` | Enum | Template status (see below) | | `isPublished` | Boolean | Whether template is published for use | | `whatsappTemplateId` | String | WhatsApp internal template ID (when applicable) | | `whatsappTemplateName` | String | WhatsApp internal template name (when applicable) | | `createdAt` | DateTime | ISO 8601 creation timestamp | | `updatedAt` | DateTime | ISO 8601 last update timestamp | ### Template Definition Object [#template-definition-object] Defines the content and components of a template, including channel-specific bodies and interactive elements. | Field | Type | Description | |-------|------|-------------| | `header` | Object? | Optional header; supports `type` and `template`, with variables | | `body` | Object | Message body definitions: supports `multiChannel`, `sms`, and `whatsapp` | | `footer` | Object? | Optional footer with `type` and `template` | | `buttons` | Array<Button> | Optional interactive buttons (max 10, WhatsApp limit; per type: 1 COPY_CODE, 1 PHONE_NUMBER, 2 URL, 10 QUICK_REPLY) | | `definitionVersion` | String | Definition schema version (for example, `1.0`) | Body fields (`multiChannel`, `sms`, `whatsapp`) share the same shape: | Field | Type | Description | |-------|------|-------------| | `template` | String | Message text with variable placeholders (for example, `Hello {{1:name}}`) | | `variables` | Array<Variable> | Variables referenced in the template | ### Variable Object [#variable-object] Represents a dynamic placeholder used in headers and bodies. | Field | Type | Description | |-------|------|-------------| | `id` | Integer | Sequential variable ID starting from 1 | | `name` | String | Readable variable name | | `type` | Enum | One of `variable`, `link`, `media` | | `props.variableType` | Enum | One of `text`, `link`, `image`, `file` | | `props.sample` | String | Sample value for approval and previews | | `props.url` | String? | Full URL (for link/media) | | `props.shortUrl` | String? | Shortened URL (optional) | | `props.alt` | String? | Alternative text (media) | | `props.mediaType` | Enum? | One of `image`, `video`, `document` (media only) | ### Button Object [#button-object] Interactive button used primarily for WhatsApp templates. | Field | Type | Description | |-------|------|-------------| | `id` | Integer | Button identifier | | `type` | Enum | One of `URL`, `PHONE_NUMBER`, `QUICK_REPLY`, `VOICE_CALL`, `COPY_CODE` | | `props.text` | String | Button label | | `props.urlType` | Enum? | One of `static`, `dynamic` (URL buttons) | | `props.url` | String? | Destination URL (URL buttons) | | `props.countryCode` | String? | For example, `+1` (phone buttons) | | `props.phoneNumber` | String? | Local number (phone buttons) | | `props.quickReplyType` | String? | One of `custom`, `pre-configured` (quick reply) | | `props.activeFor` | Integer? | Active window in seconds (voice call) | | `props.offerCode` | String? | Code to copy (copy code) | ### Template Categories [#template-categories] | Category | Description | Use Cases | |----------|-------------|-----------| | `AUTHENTICATION` | OTP and verification | 2FA, login codes | | `MARKETING` | Promotional content | Campaigns, offers | | `UTILITY` | Transactional messages | Confirmations, updates | ### Template Status Values [#template-status-values] | Status | Description | |--------|-------------| | `DRAFT` | Not submitted for review | | `PENDING` | Under review | | `APPROVED` | Approved for use | | `REJECTED` | Rejected and cannot be used | | `PAUSED` | Temporarily disabled | | `ARCHIVED` | Archived and not in active use | ### Template List Response [#template-list-response] `GET /v2/templates` returns the [pagination wrapper](#pagination-model) with each entry in `items` being a [Template object](#template-object). ## Message Models [#message-models] ### Send Message Request [#send-message-request] Request payload for sending messages via contact ID or phone number. | Field | Type | Required | Description | |-------|------|----------|-------------| | `contactId` | UUID | Yes* | Contact ID (for contact endpoint) | | `phoneNumber` | String | Yes* | Phone number (for phone endpoint) | | `templateId` | UUID | Yes | Template to use | | `templateVariables` | Object | No | Template variable values | *One of contactId or phoneNumber is required depending on endpoint ### Message Response [#message-response] `POST /v2/messages/phone` and `POST /v2/messages/contact` return `202 Accepted` with the ID of the queued message: ```json { "messageId": "8ba7b830-9dad-11d1-80b4-00c04fd430c8" } ``` `POST /v2/messages/quick-message` returns `200 OK` with one message ID per channel; `whatsappMessageId` is `null` when the number is not WhatsApp-capable: ```json { "smsMessageId": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "whatsappMessageId": "8ba7b830-9dad-11d1-80b4-00c04fd430c9" } ``` ## Pagination Model [#pagination-model] Standard pagination structure used by list endpoints. | Field | Type | Description | |-------|------|-------------| | `items` | Array | List of objects | | `totalCount` | Integer | Total items available | | `page` | Integer | Current page (0-based) | | `pageSize` | Integer | Items per page | | `totalPages` | Integer | Total pages available | ## Channel Types [#channel-types] | Channel | Description | |---------|-------------| | `sms` | Traditional SMS messaging | | `whatsapp` | WhatsApp Business messaging | ## Phone Number Formats [#phone-number-formats] The API accepts various phone number formats and normalizes them: | Format | Example | Description | |--------|---------|-------------| | E.164 | `+1234567890` | International format (recommended) | | International | `+1 234-567-890` | With formatting | | National | `(234) 567-890` | Country-specific format | | IDD Prefix | `0011234567890` | International dialing | | Raw | `1234567890` | Digits only (requires context) | ## Webhook Payload [#webhook-payload] Delivery status updates are not returned by v2 endpoints. They are delivered as events to the webhook endpoints registered for your account, using the platform-wide envelope: | Field | Type | Description | |-------|------|-------------| | `field` | String | Parent event type; `message` for status updates | | `event` | String | Granular sub-type, for example `message.delivered` | | `timestamp` | String | ISO 8601 timestamp of event creation | | `payload` | Object | Event-specific data (see below) | For message status events, `payload` contains: | Field | Type | Description | |-------|------|-------------| | `updated_at` | String | ISO 8601 timestamp of the status change | | `account_id` | UUID | Your account identifier | | `message_id` | UUID | The message ID returned by the send endpoint | | `template_id` | UUID | Template used for the message | | `template_name` | String | Template display name | | `outbound_number` | String | Sending phone number | | `message_status` | String | Message status (see below) | | `channel` | String | `sms` or `whatsapp` | Example event: ```json { "field": "message", "event": "message.delivered", "timestamp": "2025-10-31T10:10:42Z", "payload": { "updated_at": "2025-10-31T10:10:41Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "DELIVERED", "channel": "sms" } } ``` ### Webhook Status Values [#webhook-status-values] | Status | Event | Description | |--------|-------|-------------| | `QUEUED` | `message.queued` | Message accepted and waiting to be dispatched | | `ROUTED` | `message.routed` | Message assigned to a carrier or provider | | `SENT` | `message.sent` | Message sent to carrier or WhatsApp | | `DELIVERED` | `message.delivered` | Message delivered to recipient's device | | `READ` | `message.read` | Message read by recipient (WhatsApp and RCS) | | `FAILED` | `message.failed` | Message delivery failed permanently | | `SCHEDULED` | `message.scheduled` | Message held until a `scheduled_at` instant you set, or until the recipient's quiet hours end | | `CANCELLED` | `message.cancelled` | A held message was cancelled before release; it is never sent | | `FILTERED` | `message.filtered` | Message suppressed by a policy gate; not dispatched | | `BLOCKED` | `message.blocked` | Message gated by an account-level precondition; not dispatched | The full event catalog, including inbound message and template events, signature verification, and retry behavior, is documented in the [webhook events reference](/start/webhooks/event-types). # Error Catalog (/reference-legacy/api/error-catalog.md) **Legacy API Notice:** This documentation covers the Legacy Sent API (v2). For new integrations, please refer to the [latest Sent API v3 Error Catalog](/reference/api/error-catalog). # Error Catalog [#error-catalog] This catalog lists every error message the legacy Sent API v2 returns, with its cause and remediation. The entry codes (`AUTH-001`, `VAL-002`, and so on) are catalog identifiers for lookup on this page; they do not appear in API responses. For the response structure and status-code overview, see the [Error Reference](/reference-legacy/api/errors); for retry and error-handling implementation patterns, see [How to handle Sent API errors](/start/guides/handling-api-errors). ## Authentication Errors (401) [#authentication-errors-401] ### AUTH-001: Invalid or Missing API Credentials [#auth-001-invalid-or-missing-api-credentials] **Error**: `"Invalid or missing API credentials"` **Cause**: The `x-api-key` header is missing, or the key does not belong to the customer in `x-sender-id`. **Remediation**: - Include the `x-api-key` header on every request - Verify the key is active on the API Keys page of your dashboard and matches your sender ID - Generate a new API key if the key was rotated or deleted ```bash curl -H "x-api-key: your-api-key-here" \ -H "x-sender-id: your-sender-id" \ https://api.sent.dm/v2/contacts ``` ### AUTH-002: Missing or Invalid Sender Identifier [#auth-002-missing-or-invalid-sender-identifier] **Error**: `"Missing or invalid sender identifier"` **Cause**: The `x-sender-id` header is missing or its value is not a valid UUID. **Remediation**: Include the `x-sender-id` header with your sender ID exactly as shown on the API Keys page of your dashboard. ## Validation Errors (400) [#validation-errors-400] ### VAL-001: Required Field Missing [#val-001-required-field-missing] **Errors**: - `"Phone number is required"`: `phoneNumber` on message sends, number lookup, and contact lookup by phone - `"Custom message is required"`: `customMessage` on quick message - `"Contact ID is required"`: `id` on contact lookup by ID - `"Message ID is required"`: `id` on message lookup - `"Template ID is required"`: `id` on template lookup and delete - `"Template body is required"`: template definition body on template creation **Remediation**: Include the named field with a non-empty value. ### VAL-002: Invalid ID Format [#val-002-invalid-id-format] **Errors**: - `"Invalid contact ID format. Expected a valid GUID."` - `"Invalid message ID format. Expected a valid GUID."` - `"Invalid template ID format. Expected a valid GUID."` **Cause**: The provided ID is not a valid UUID. **Remediation**: Use the UUID exactly as returned by the API (for example, `550e8400-e29b-41d4-a716-446655440000`). ### VAL-003: Invalid Pagination Parameters [#val-003-invalid-pagination-parameters] **Errors**: - `GET /v2/contacts`: `"Page must be zero or greater"` and `"PageSize must be greater than zero"` - `GET /v2/templates`: `"Page must be greater than or equal to 0"` and `"PageSize must be between 1 and 1000"` **Remediation**: Use `page` >= 0 and a positive `pageSize` (at most 1000 for templates). ### VAL-004: Template Variable Validation Failed [#val-004-template-variable-validation-failed] **Errors**: - `"Missing required template variables: {names}"` - `"Variable '{name}' is invalid: param text cannot have new-line/tab characters or more than 4 consecutive spaces."` - `"Variable '{name}' does not match the required pattern."` **Cause**: The `templateVariables` map on a send request omits a variable the template requires, or a value violates the format rules. **Remediation**: - Provide every variable defined in the template, with names matching exactly - Remove new-line and tab characters and runs of more than 4 spaces from values - For variables with a validation pattern, supply a value matching that pattern ## Business Logic Errors [#business-logic-errors] ### BUS-001: Insufficient Balance [#bus-001-insufficient-balance] **Error**: `"Insufficient balance to send message."` **HTTP Status**: 402 Payment Required **Cause**: The account balance is below the minimum required to send a message. **Remediation**: Add funds to your account in the dashboard, then retry the request. ### BUS-002: Template Not Found [#bus-002-template-not-found] **Error**: `"Template not found"` **HTTP Status**: 404 Not Found **Cause**: The `templateId` on a send request does not exist or does not belong to your customer account. **Remediation**: - Verify the template ID against `GET /v2/templates` - Confirm the template belongs to the authenticated customer account ## Not Found Errors (404) [#not-found-errors-404] ### NOT-001: Resource Not Found [#not-001-resource-not-found] **Error**: `404` with an empty response body **Cause**: The contact, message, template, or phone number requested from a `GET` lookup endpoint (or a template targeted by `DELETE`) does not exist for the authenticated customer. **Remediation**: - Verify the ID or phone number is correct - Confirm the resource belongs to your customer account ## Rate Limit Errors (429) [#rate-limit-errors-429] ### RATE-001: Rate Limit Exceeded [#rate-001-rate-limit-exceeded] **Error**: `"Rate limit exceeded. Please retry after {seconds} seconds."` **Cause**: The per-minute limit on the send-message endpoints was exceeded. **Remediation**: Wait the number of seconds in the `Retry-After` header, then retry. Limit values and the full `429` response are documented on [Rate Limits](/reference-legacy/api/rate-limits). ### RATE-002: Quick-Message Daily Limit Exceeded [#rate-002-quick-message-daily-limit-exceeded] **Error**: `"Daily message limit exceeded. You have sent 5 of 5 allowed messages today. Limit resets at midnight UTC."` **Cause**: `POST /v2/messages/quick-message` allows 5 messages per customer per day. **Remediation**: Wait for the reset at midnight UTC, or use `POST /v2/messages/phone` with your own template for higher volume. ## Server Errors (500) [#server-errors-500] ### SRV-001: Failed to Queue Message [#srv-001-failed-to-queue-message] **Error**: `"Failed to queue message for processing."` **Cause**: The send endpoint could not hand the message to the delivery pipeline. **Remediation**: Retry the request; contact support if the error persists. ### SRV-002: Template Creation Failed [#srv-002-template-creation-failed] **Errors**: - `"Failed to create template"` - `"Template was created but could not be retrieved"` **Cause**: `POST /v2/templates` failed while persisting or reading back the template. **Remediation**: List your templates to check whether the template was created, then retry if it is absent; contact support if the error persists. ## Delivery Failures Are Not API Errors [#delivery-failures-are-not-api-errors] Message sends are asynchronous: `POST /v2/messages/phone` and `POST /v2/messages/contact` return `202` once the message is queued, before any carrier or WhatsApp interaction. Failures that happen later (unreachable numbers, carrier rejections, WhatsApp errors) do not produce an API error response. They surface as a `FAILED` message status, which you can observe via `GET /v2/messages/{id}` or a `message.failed` [webhook event](/start/webhooks/event-types). Webhook delivery problems (timeouts, non-2xx responses from your endpoint) are also handled outside the v2 API surface; see [webhook retries](/start/webhooks/handling-retries). # Error Reference (/reference-legacy/api/errors.md) **Legacy API Notice:** This documentation covers the Legacy Sent API (v2). For new integrations, please refer to the [latest Sent API v3 Error Handling](/reference/api/errors). # Error Reference [#error-reference] The legacy Sent API v2 uses standard HTTP status codes and returns error details in a problem-details JSON format. This page describes the response format and status codes. For a message-by-message lookup with causes and remediation, see the [Error Catalog](/reference-legacy/api/error-catalog); for retry and error-handling implementation patterns, see [How to handle Sent API errors](/start/guides/handling-api-errors). ## Error response format [#error-response-format] Error bodies share one structure. Validation errors key the `errors` object by request field name: ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "One or more validation errors occurred.", "status": 400, "errors": { "phoneNumber": ["Phone number is required"] } } ``` | Field | Type | Description | |-------|------|-------------| | `type` | String | Link to the RFC 9110 definition of the status code | | `title` | String | Human-readable summary of the error | | `status` | Integer | HTTP status code, repeated in the body | | `errors` | Object | Map of request field name to an array of error messages | Errors that are not tied to a request field appear under the `generalErrors` key: ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "One or more validation errors occurred.", "status": 404, "errors": { "generalErrors": ["Template not found"] } } ``` The `GET` lookup endpoints (contacts, messages, templates, number lookup) return `404` with an empty body instead of a problem-details payload when the resource does not exist. ## HTTP status codes [#http-status-codes] | Status Code | Meaning | Returned When | |-------------|---------|---------------| | `400` | Bad Request | A required field is missing, an ID is malformed, or a template variable fails validation | | `401` | Unauthorized | Authentication headers are missing or invalid | | `402` | Payment Required | Account balance is insufficient to send a message | | `404` | Not Found | The contact, message, or template does not exist for the authenticated customer | | `429` | Too Many Requests | A rate limit was exceeded | | `500` | Internal Server Error | An unexpected server-side failure occurred | ### 401 Unauthorized [#401-unauthorized] Authentication failures return one of two titles: - `Missing or invalid sender identifier`: the `x-sender-id` header is missing or is not a valid UUID - `Invalid or missing API credentials`: the `x-api-key` header is missing, or the key does not match the sender ID ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "Invalid or missing API credentials", "status": 401, "errors": { "generalErrors": ["Invalid or missing API credentials"] } } ``` ### 402 Payment Required [#402-payment-required] `POST /v2/messages/phone` and `POST /v2/messages/contact` return `402` when the account balance is below the minimum required to send: ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "One or more validation errors occurred.", "status": 402, "errors": { "generalErrors": ["Insufficient balance to send message."] } } ``` ### 429 Too Many Requests [#429-too-many-requests] The v2 send-message endpoints are rate limited per customer account. Limit values, `X-RateLimit-*` response headers, and the `429` body are documented on [Rate Limits](/reference-legacy/api/rate-limits). ### 500 Internal Server Error [#500-internal-server-error] `500` responses indicate an unexpected server-side failure, for example `Failed to queue message for processing.` on the send endpoints. The [Error Catalog](/reference-legacy/api/error-catalog) lists the server error messages. # Sent Legacy v2 API (/reference-legacy/api.md) **Legacy API Notice:** This documentation covers the Legacy Sent API (v2). While this API remains fully supported, we recommend new integrations use the [latest Sent API v3](/reference/api) for enhanced features, improved performance, and long-term support. # Sent Legacy v2 API [#sent-legacy-v2-api] The Legacy Sent API (v2) is a REST API for sending messages, managing contacts and templates, and looking up phone numbers. For a walkthrough of sending your first message, follow the [Quickstart Guide](/start/quickstart). ## Quick Start [#quick-start] ### Base URL [#base-url] ``` https://api.sent.dm ``` ### Authentication [#authentication] Every v2 request requires two authentication headers: ```http x-sender-id: YOUR_SENDER_ID x-api-key: YOUR_API_KEY ``` - `x-sender-id`: Your unique sender/customer identifier - `x-api-key`: Your secret API key Generate credentials on the [API Keys page](https://app.sent.dm/dashboard/api-keys) of your Sent Dashboard. For setup steps, header formats, and 401 error responses, see the [v2 Authentication guide](/reference-legacy/api/authentication). ## Endpoint Documentation [#endpoint-documentation] ### Try with Postman [#try-with-postman] Import the v2 collection into Postman to explore the legacy endpoints. For new integrations, use the [v3 collection](/reference/api) instead: --- ## Authentication & Security [#authentication--security] --- ## API Reference Documentation [#api-reference-documentation] --- ## Integration Guides [#integration-guides] --- ## Support & Resources [#support--resources] ### Documentation [#documentation] - **[Quickstart Guide](/start/quickstart)** - Complete onboarding walkthrough - **[Support Center](/start/reference-guides/support)** - FAQs, troubleshooting, and community resources - **[API Status](https://status.sent.dm)** - Real-time service status and incident reports ### Get Help [#get-help] - **Email Support**: [support@sent.dm](mailto:support@sent.dm) method: GET route: /v2/messages/{id} # GET /v2/messages/{id} Get message details by ID Retrieves comprehensive details about a specific message using the message ID. Returns complete message data including delivery status, channel information, template details, contact information, and pricing. The customer ID is extracted from the authentication token to ensure the message belongs to the authenticated customer. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetMessageByIdEndpoint` **Tags:** V2 ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ## Responses ### 200 Message details retrieved successfully #### application/json ```typescript { id?: string, customerId?: string, contactId?: string, phoneNumber?: string, phoneNumberInternational?: string, regionCode?: string, templateId?: string, templateName?: string, templateCategory?: string, channel?: string, messageBody?: unknown, status?: string, createdAt?: string, price?: number, activeContactPrice?: number, events?: Array<{ status: string, timestamp: string, description?: string }> } ``` ##### Example ```json { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "customerId": "550e8400-e29b-41d4-a716-446655440000", "contactId": "550e8400-e29b-41d4-a716-446655440002", "phoneNumber": "+1234567890", "phoneNumberInternational": "+1 234-567-8900", "regionCode": "US", "templateId": "550e8400-e29b-41d4-a716-446655440003", "templateName": "Welcome Message", "templateCategory": "UTILITY", "channel": "WhatsApp", "messageBody": { "header": null, "content": "Welcome to our service, John! We're excited to have you.", "footer": null, "buttons": null, "subject": null, "media": null, "headerMedia": null }, "status": "DELIVERED", "createdAt": "2026-11-12T13:33:36.370363+00:00", "price": 0.0055, "activeContactPrice": 0.015, "events": [ { "status": "QUEUED", "timestamp": "2026-11-12T13:33:36.3704156+00:00", "description": "Message queued for sending" }, { "status": "SENT", "timestamp": "2026-11-12T13:33:41.3704326+00:00", "description": "Message sent to WhatsApp" }, { "status": "DELIVERED", "timestamp": "2026-11-12T13:33:46.3704331+00:00", "description": "Message delivered to recipient" }, { "status": "READ", "timestamp": "2026-11-12T13:38:36.3704332+00:00", "description": "Message read by recipient" } ] } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: POST route: /v2/messages/quick-message # POST /v2/messages/quick-message Send quick message with default template (rate limited to 5 per day) Sends a message to a phone number using the default template. This endpoint is rate limited to 5 messages per customer per day. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2PostQuickMessageEndpoint` **Tags:** V2 ## Request Body ### application/json ```typescript { phoneNumber?: string, customMessage?: string } ``` ## Responses ### 204 No Content ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: POST route: /v2/messages/contact # POST /v2/messages/contact Send message to contact Sends a message to a specific contact using a template. The message can be sent via SMS or WhatsApp depending on the contact's capabilities. Optionally specify a webhook URL to receive delivery status updates. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2PostMessageByContactEndpoint` **Tags:** V2 ## Request Body ### application/json ```typescript { contactId?: string, templateId?: string, templateVariables?: object } ``` ## Responses ### 204 No Content ### 400 Invalid request - ContactId or TemplateId is empty, or validation errors #### application/problem+json ```typescript { statusCode?: integer, message?: string, errors?: object } ``` ### 401 Unauthorized - Customer authentication required ### 403 BUSINESS_032 - the account has no payment method on file method: POST route: /v2/messages/phone # POST /v2/messages/phone Send message to phone number Sends a message to a phone number using a template. The phone number doesn't need to be a pre-existing contact. The message can be sent via SMS or WhatsApp. Optionally specify a webhook URL to receive delivery status updates. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2PostMessageByNumberEndpoint` **Tags:** V2 ## Request Body ### application/json ```typescript { phoneNumber?: string, templateId?: string, templateVariables?: object } ``` ## Responses ### 204 No Content ### 400 Invalid request - Phone number is empty or TemplateId is invalid #### application/problem+json ```typescript { statusCode?: integer, message?: string, errors?: object } ``` ### 401 Unauthorized - Customer authentication required ### 403 BUSINESS_032 - the account has no payment method on file method: GET route: /v2/number-lookup # GET /v2/number-lookup Lookup phone number information Retrieves detailed information about a phone number including validation, formatting, country information, and available messaging channels. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetNumberLookupEndpoint` **Tags:** V2 ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `phoneNumber` | `string` | true | - | ## Responses ### 200 Phone number information retrieved successfully #### application/json ```typescript { phoneNumber?: string, formatE164?: string, formatInternational?: string, formatNational?: string, formatRfc?: string, countryCode?: string, regionCode?: string, numberType?: string, phoneTimezones?: string } ``` ##### Example ```json { "phoneNumber": "1234567890", "formatE164": "+1234567890", "formatInternational": "+1 234-567-890", "formatNational": "(234) 567-890", "formatRfc": "tel:+1-234-567-890", "countryCode": "1", "regionCode": "US", "numberType": "mobile", "phoneTimezones": "America/New_York" } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden # Rate Limits (/reference-legacy/api/rate-limits.md) **Legacy API Notice:** This documentation covers the Legacy Sent API (v2). For new integrations, please refer to the [latest Sent API v3 Rate Limits](/reference/api/rate-limits). # Rate Limits [#rate-limits] This page is the authoritative reference for rate limits on the legacy Sent API v2; other v2 pages link here rather than restating limit values. Rate limits apply per customer account: all requests authenticated with the same `x-sender-id` count against one pool. Unauthenticated requests are limited per IP address. ## Per-minute request limit [#per-minute-request-limit] The v2 send-message endpoints use the standard per-minute limit: | Endpoint | Limit | Window | |----------|-------|--------| | `POST /v2/messages/phone` | 10,000 requests per minute | Sliding 60-second window | | `POST /v2/messages/contact` | 10,000 requests per minute | Sliding 60-second window | The 10,000-per-minute pool is shared with the [standard-tier Sent API v3 endpoints](/reference/api/rate-limits): v2 and v3 requests from the same account count against the same limit. ## Quick-message daily limit [#quick-message-daily-limit] `POST /v2/messages/quick-message` enforces a separate limit of 5 messages per customer per day. The counter resets at midnight UTC. Requests that fail validation do not count against the limit. Above the limit, the endpoint returns `429` with this message in the [error response body](/reference-legacy/api/errors): ``` Daily message limit exceeded. You have sent 5 of 5 allowed messages today. Limit resets at midnight UTC. ``` This limit is enforced by the endpoint itself; its `429` response does not include the `X-RateLimit-*` headers described below. ## 429 response [#429-response] When the per-minute limit is exceeded, the API returns `429 Too Many Requests` with these headers: | Header | Description | |--------|-------------| | `Retry-After` | Seconds to wait before retrying | | `X-RateLimit-Limit` | Maximum requests allowed in the window | | `X-RateLimit-Remaining` | Requests remaining (always `0` on 429) | | `X-RateLimit-Reset` | Unix timestamp when the window resets | The response body follows the standard v2 [error response format](/reference-legacy/api/errors): ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "Rate limit exceeded. Please retry after 60 seconds.", "status": 429, "errors": { "generalErrors": ["Rate limit exceeded. Please retry after 60 seconds."] } } ``` ## Endpoints without explicit limits [#endpoints-without-explicit-limits] The remaining v2 endpoints (contact lookup and listing, template management, message lookup, and number lookup) have no explicit per-request rate limit. For backoff, monitoring, and throttling implementations, see [How to handle Sent API rate limits](/start/guides/handling-rate-limits). method: POST route: /v2/templates # POST /v2/templates Create a new template with enhanced metadata and optional submission for review Creates a new message template for the authenticated customer with comprehensive template definitions including headers, body, footer, and interactive buttons. Supports automatic metadata generation using AI (display name, language, category). Optionally submits the template for WhatsApp review. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2PostTemplatesTwoEndpoint` **Tags:** V2 ## Request Body ### application/json ```typescript { category?: string, language?: string, definition?: unknown, submitForReview?: boolean } ``` ## Responses ### 200 Success #### application/json ```typescript { id?: string, displayName?: string, category?: string, language?: string, definition?: unknown, status?: string, isPublished?: boolean, whatsappTemplateId?: string, whatsappTemplateName?: string, createdAt?: string, updatedAt?: string } ``` ### 400 Bad request - Invalid template definition or validation errors #### application/problem+json ```typescript { statusCode?: integer, message?: string, errors?: object } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: DELETE route: /v2/templates/{id} # DELETE /v2/templates/{id} Delete template by ID Deletes a message template by ID for the authenticated customer. Templates with no messages are hard deleted; templates with message history are soft deleted. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2DeleteTemplatesTwoEndpoint` **Tags:** V2 ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The unique identifier (GUID) of the resource to retrieve | ## Responses ### 204 Template deleted successfully - no content returned ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: GET route: /v2/templates/{id} # GET /v2/templates/{id} Get template by ID with enhanced metadata Retrieves a specific message template by its unique identifier for the authenticated customer with comprehensive template definitions including headers, body, footer, and interactive buttons. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetTemplatesTwoByIdEndpoint` **Tags:** V2 ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ## Responses ### 200 Template found and returned successfully with enhanced metadata #### application/json ```typescript { id?: string, displayName?: string, category?: string, language?: string, definition?: unknown, status?: string, isPublished?: boolean, whatsappTemplateId?: string, whatsappTemplateName?: string, createdAt?: string, updatedAt?: string } ``` ##### Example ```json { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "displayName": "Welcome Message Template", "category": "UTILITY", "language": "en_US", "definition": { "header": { "type": "text", "template": "Welcome to {{1:variable}}!", "variables": [ { "id": 1, "name": "companyName", "type": "variable", "props": { "variableType": "text", "sample": "SentDM", "regex": null, "url": null, "shortUrl": null, "alt": null, "mediaType": null } } ], "example_url": null, "static_resource": false, "location": null }, "body": { "multiChannel": { "type": "text", "template": "Hello {{1:variable}}, thank you for joining our service. We're excited to help you with your messaging needs!", "variables": [ { "id": 1, "name": "customerName", "type": "variable", "props": { "variableType": "text", "sample": "John Doe", "regex": null, "url": null, "shortUrl": null, "alt": null, "mediaType": null } } ] }, "sms": null, "whatsapp": null, "rcs": null, "mms": null }, "footer": { "type": "text", "template": "Best regards, The SentDM Team", "variables": null }, "buttons": null, "definitionVersion": "1.0", "authenticationConfig": null }, "status": "APPROVED", "isPublished": true, "whatsappTemplateId": "123456789", "whatsappTemplateName": "welcome_message_v1", "createdAt": "2024-01-15T10:30:00+00:00", "updatedAt": "2024-01-16T14:22:00+00:00" } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden method: GET route: /v2/templates # GET /v2/templates Get all templates for authenticated customer with enhanced metadata and filtering Retrieves all message templates available for the authenticated customer with comprehensive template definitions including headers, body, footer, and interactive buttons. Supports advanced filtering by search term, status, and category, plus pagination. The customer ID is extracted from the authentication token. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv2GetTemplatesEndpoint` **Tags:** V2 ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | The page number (zero-indexed). Default is 0. | | `pageSize` | `integer` | true | The number of items per page (1-1000). Default is 100. | | `search` | `string` | false | Optional search term to filter templates by name or content | | `status` | `string` | false | Optional filter by template status (e.g., APPROVED, PENDING, REJECTED, DRAFT) | | `category` | `string` | false | Optional filter by template category (e.g., MARKETING, UTILITY, AUTHENTICATION) | ## Responses ### 200 Templates retrieved successfully with enhanced metadata and pagination #### application/json ```typescript { items?: Array<{ id?: string, displayName?: string, category?: string, language?: string, definition?: unknown, status?: string, isPublished?: boolean, whatsappTemplateId?: string, whatsappTemplateName?: string, createdAt?: string, updatedAt?: string }>, totalCount?: integer, page?: integer, pageSize?: integer, totalPages?: integer } ``` ##### Example ```json { "items": [ { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "displayName": "Welcome Message Template", "category": "MARKETING", "language": "en_US", "definition": { "header": { "type": "text", "template": "Welcome to {{0:variable}}!", "variables": [ { "id": 1, "name": "companyName", "type": "variable", "props": { "variableType": "text", "sample": "SentDM", "regex": null, "url": null, "shortUrl": null, "alt": null, "mediaType": null } } ], "example_url": null, "static_resource": false, "location": null }, "body": { "multiChannel": { "type": "text", "template": "Hello {{1:variable}}, thank you for joining our service. We're excited to help you with your messaging needs!", "variables": [ { "id": 1, "name": "customerName", "type": "variable", "props": { "variableType": "text", "sample": "John Doe", "regex": null, "url": null, "shortUrl": null, "alt": null, "mediaType": null } } ] }, "sms": null, "whatsapp": null, "rcs": null, "mms": null }, "footer": { "type": "text", "template": "Best regards, The SentDM Team", "variables": null }, "buttons": null, "definitionVersion": "1.0", "authenticationConfig": null }, "status": "APPROVED", "isPublished": true, "whatsappTemplateId": "123456789", "whatsappTemplateName": "welcome_message_v1", "createdAt": "2024-01-15T10:30:00+00:00", "updatedAt": "2024-01-16T14:22:00+00:00" } ], "totalCount": 1, "page": 0, "pageSize": 50, "totalPages": 1 } ``` ### 401 Unauthorized - Customer authentication required ### 403 Forbidden # Glossary (/reference-legacy/glossary.md) **Legacy API Notice:** This glossary covers terms for the Legacy Sent API (v2). For new integrations, please refer to the [current Sent API v3 Glossary](/reference/glossary). # Glossary [#glossary] ## A [#a] ### API Key [#api-key] Secret authentication token sent in the `x-api-key` header, together with the `x-sender-id` header, on every v2 API request. See [Authentication](/reference-legacy/api/authentication). ### Authentication Message [#authentication-message] WhatsApp message category for OTP codes, verification messages, and login confirmations. Usually has the lowest cost per message. ### Available Channels [#available-channels] Comma-separated list of messaging channels (for example, `sms,whatsapp`) that can reach a specific contact based on their phone number validation. ## B [#b] ### Balance [#balance] Customer account credit amount used for message payments, with detailed transaction history. ### Business Account [#business-account] WhatsApp Business Account (WABA) identifier required for WhatsApp messaging integration. ## C [#c] ### Channel [#channel] Communication method used to deliver messages: - **SMS**: Traditional text messaging - **WhatsApp**: Business messaging via Meta's WhatsApp Business API ### Contact [#contact] A phone number recipient in your messaging system, including validation data, available channels, and formatting information. ### Contact ID [#contact-id] Unique UUID identifier for a contact within a customer's account. ### Customer [#customer] Primary entity representing a business account in the Sent platform. Contains messaging configuration, API keys, and channel settings. ### Customer ID [#customer-id] Unique UUID identifier for a customer account. ## D [#d] ### Default Channel [#default-channel] Preferred messaging channel for a contact, determined by phone number validation and regional settings. ### Delivery Status [#delivery-status] Message state indicating current status, such as `QUEUED`, `SENT`, `DELIVERED`, `READ`, or `FAILED`. The full set of statuses is listed in [Data Models](/reference-legacy/api/data-models#webhook-status-values). ## E [#e] ### E.164 Format [#e164-format] International phone number standard (for example, `+1234567890`) used as the canonical format throughout the platform. ### Endpoint [#endpoint] API route handling specific operations (for example, `/v2/contacts/id` or `/v2/messages/phone`). ## F [#f] ### Formatting [#formatting] Phone number representations in various formats: - **E.164**: `+1234567890` (canonical) - **International**: `+1 234-567-890` (human-readable) - **National**: `(234) 567-890` (country-specific) - **RFC 3966**: `tel:+1-234-567-890` (URI format) ## K [#k] ### KYC (Know Your Customer) [#kyc-know-your-customer] Compliance data including business information, contact details, and use case descriptions required for messaging services. ## M [#m] ### Marketing Message [#marketing-message] WhatsApp message category for promotional content and campaigns. Typically has higher cost per message and requires opt-in. ### Message Activity [#message-activity] Event tracking for message processing including channel selection, sending status, and delivery confirmation. ### Message Body [#message-body] Final rendered content of a message after template variable substitution. ### Message Template [#message-template] Pre-approved message format for WhatsApp or reusable content for SMS, supporting variable substitution. ### Messaging Profile [#messaging-profile] SMS provider configuration for messaging, containing webhook URLs and delivery settings. ## P [#p] ### Pagination [#pagination] Result set structure with `items`, `totalCount`, `page`, `pageSize`, and `totalPages` for handling large data sets. ### Phone Number Validation [#phone-number-validation] Process determining if a phone number is valid, possible, and identifying its type (mobile, fixed-line, etc.). ### Pricing [#pricing] Cost structure for messages varying by channel, region, and message category (especially for WhatsApp). ## R [#r] ### Region Code [#region-code] ISO 3166-1 alpha-2 country code (for example, `US` or `CA`) used for pricing and channel availability. ## S [#s] ### Sender ID [#sender-id] Customer identifier used in conjunction with API keys for request authentication and data scoping. ### SMS [#sms] Short Message Service - traditional text messaging. ### System User Access Token [#system-user-access-token] Long-lived WhatsApp API authentication token for business messaging operations. ## T [#t] ### Template [#template] Pre-defined message format supporting variable substitution: - **WhatsApp Template**: Must be approved by Meta before use - **SMS Template**: Can be used immediately without approval ### Template Category [#template-category] Classification for WhatsApp templates: - **AUTHENTICATION**: OTP and verification messages - **MARKETING**: Promotional content requiring opt-in - **UTILITY**: Transactional messages and confirmations ### Template Status [#template-status] Template approval state, such as `DRAFT`, `PENDING`, `APPROVED`, or `REJECTED`. The full set of statuses is listed in [Data Models](/reference-legacy/api/data-models#template-status-values). ### Transaction [#transaction] Financial record tracking balance changes from message costs, payments, or refunds. ## U [#u] ### Unified Messaging Intelligence [#unified-messaging-intelligence] Sent's system for automatically selecting the optimal messaging channel based on contact validation, availability, and cost. ### UUID (Universally Unique Identifier) [#uuid-universally-unique-identifier] 128-bit identifier format used for all entity IDs throughout the platform. ### Utility Message [#utility-message] WhatsApp message category for transactional content like order confirmations and delivery notifications. ## V [#v] ### Validation [#validation] Process of verifying phone number format, reachability, and available messaging channels. ### Variable Substitution [#variable-substitution] Process of replacing placeholder values (for example, `{{1}}` or `{{name}}`) in message templates with actual content. ## W [#w] ### Webhook [#webhook] HTTP callback URL for receiving real-time message status updates and delivery confirmations. ### WhatsApp Business API [#whatsapp-business-api] Meta's business messaging platform integrated for professional messaging capabilities. ### WhatsApp Template [#whatsapp-template] Pre-approved message format required by Meta for business messaging, supporting rich media and interactive elements. method: GET route: /v3/me # GET /v3/me Get authenticated account Returns the account associated with the provided API key. The response includes account identity, contact information, messaging channel configuration, and — depending on the account type — either a list of child profiles or the profile's own settings. **Account types:** - `organization` — Has child profiles. The `profiles` array is populated. - `user` — Standalone account with no profiles. - `profile` — Child of an organization. Includes `organization_id`, `short_name`, `status`, and `settings`. **Channels:** The `channels` object always includes `sms`, `whatsapp`, and `rcs`. Each channel has a `configured` boolean. Configured channels expose additional details such as `phone_number`. **Sending number:** `sending_phone_number` is the account's US SMS sender. It is intentionally the same value as `channels.sms.phone_number` — the two are kept in step, and it is published under both names because `sending_phone_number` is what this value is called on `GET /v3/profiles`. Read either. One difference: `sending_phone_number` is always present, including as `null`, while `channels.sms.phone_number` is omitted when there is no sender. `sending_phone_number_profile_id` names the account that holds that number in inventory — normally this account, and a different one where a number is shared. Both are `null` when the account has no US SMS sender. **Template auto-creation:** `enable_template_auto_creation_for_sp` reports whether this account may mark a template for automatic creation on its sender profiles. It is granted by Sent and off by default. A `profile` reports `false`, having no sender profiles of its own to create anything on. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint` **Tags:** Accounts ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Account retrieved successfully. Response shape varies by account type (organization, user, or profile). #### application/json ```typescript { success?: boolean, data?: { type?: string, id?: string, organization_id?: string, name?: string, short_name?: string, email?: string, icon?: string, description?: string, created_at?: string, channels?: unknown, sending_phone_number?: string, sending_phone_number_profile_id?: string, status?: string, enable_template_auto_creation_for_sp?: boolean, settings?: { allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string }, profiles?: Array<{ id?: string, name?: string, icon?: string, description?: string, short_name?: string, role?: string, status?: string, created_at?: string, settings?: unknown }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "type": "profile", "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "organization_id": "d290f1ee-6c54-4b01-90e6-d701748f0851", "name": "Marketing", "short_name": "MKT", "email": "marketing@acme.com", "icon": "https://cdn.sent.dm/icons/marketing.png", "description": "Marketing department sender profile", "created_at": "2025-01-20T14:00:00+00:00", "channels": { "sms": { "configured": true, "phone_number": "+14155550100" }, "whatsapp": { "configured": true, "phone_number": "+14155550100", "business_name": "Acme Corporation" }, "rcs": { "configured": false, "phone_number": "+14155550100" } }, "sending_phone_number": "+14155550100", "sending_phone_number_profile_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": "approved", "enable_template_auto_creation_for_sp": false, "settings": { "allow_contact_sharing": false, "allow_template_sharing": false, "inherit_contacts": false, "inherit_templates": false, "inherit_tcr_brand": true, "inherit_tcr_campaign": false, "billing_model": "organization" }, "profiles": [] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8987632+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid or missing API key #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "AUTH_001", "message": "Invalid or missing API key. Ensure the x-api-key header is set with a valid key.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.898765+00:00", "version": "v3" } } ``` ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving account information. Please try again later.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8987655+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # Authentication (/reference/api/authentication.md) # Authentication [#authentication] The Sent API v3 authenticates every request with an API key. Send it in the `x-api-key` header, or as a Bearer token in the `Authorization` header. The key identifies your account, and no other identifier is required. --- ## Request headers [#request-headers] | Header | Type | Required | Description | |--------|------|----------|-------------| | `x-api-key` | String (UUID) | Either | Your secret API key. Identifies and authorizes your account on every request. | | `Authorization` | `Bearer ` | Either | The same API key as a Bearer token, for clients that can only send OAuth2 or Bearer credentials. | Send one header or the other. If a request carries both, the API uses `x-api-key` and ignores `Authorization`. The `Bearer` scheme name is case-insensitive. Any other scheme, such as `Basic`, counts as a missing key. API keys are UUIDs (for example, `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`). There is one key format for all environments. Sandbox behavior is controlled per request with the `"sandbox"` body field on mutation endpoints, not by a separate key type. See [Sandbox mode](/reference/api/test-mode). To create, rotate, or revoke keys, see [Creating and managing API keys](/start/guides/api-keys). ### Example requests [#example-requests] ```bash curl https://api.sent.dm/v3/me \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -H "Content-Type: application/json" ``` The same request with the key as a Bearer token: ```bash curl https://api.sent.dm/v3/me \ -H "Authorization: Bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -H "Content-Type: application/json" ``` --- ## Response headers [#response-headers] All v3 responses include: | Header | Description | |--------|-------------| | `X-Request-Id` | Unique request identifier for tracing and support, in the form `req_` followed by 16 hex characters. If the request supplies an `X-Request-Id` header, that value is echoed back. | | `X-Response-Time` | Server processing time in milliseconds, for example `12ms`. | | `X-API-Version` | Always `v3`. | --- ## Authentication errors [#authentication-errors] Authentication failures return the standard v3 error envelope: ```json { "success": false, "status": 401, "error": { "code": "AUTH_002", "message": "Invalid or missing API key", "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_a1b2c3d4e5f60718", "timestamp": "2026-07-25T12:00:00+00:00", "version": "v3" } } ``` ### AUTH error codes [#auth-error-codes] | Code | Status | Message | Returned when | |------|--------|---------|---------------| | `AUTH_001` | 401 | Authentication required | The request has no authenticated identity for a reason other than the API key, for example an invalid or expired voice token. A missing or unrecognized API key is `AUTH_002`. | | `AUTH_002` | 401 | Invalid or missing API key | Neither header carries a key, the key is empty, or it does not match an active key. | | `AUTH_003` | 401 | Missing or invalid sender identifier | Legacy v1/v2 endpoints only: the `x-sender-id` header is missing or is not a valid UUID. v3 endpoints do not return this code. | | `AUTH_004` | 403 | Access denied | The authenticated account does not have permission for the operation. See [Roles and permissions](/reference/api/roles-and-permissions). | | `AUTH_005` | 403 | Account onboarding is not complete | Defined for onboarding gating; not returned by v3 authentication. | | `AUTH_006` | 403 | KYC verification is not complete | Defined for onboarding gating; not returned by v3 authentication. | | `AUTH_007` | 403 | Channel setup is not complete | Defined for onboarding gating; not returned by v3 authentication. | Onboarding state does not block authentication. Message volume during partial onboarding is limited in the send pipeline instead: over-limit messages are accepted by the API and finalized with a `BLOCKED` status. See [Trust & Safety](/start/concepts/trust-and-safety). The complete list of API error codes is in the [Error catalog](/reference/api/error-catalog). ### Failed-attempt lockout [#failed-attempt-lockout] After 10 consecutive failed authentication attempts with the same credential, the API locks that credential and returns `429` with error code `BUSINESS_002`, the message `Too many failed authentication attempts. Please try again later.`, and a `Retry-After: 60` header. The lockout duration escalates with continued failures: 1, 5, 15, 30, then 60 minutes. A successful authentication resets the counter. --- ## Rate limits [#rate-limits] Authenticated requests are rate limited per customer account. For limits, tiers, and `429` response headers, see [Rate limits](/reference/api/rate-limits). --- ## Related pages [#related-pages] - [Creating and managing API keys](/start/guides/api-keys): create, store, verify, rotate, and revoke keys. - [API authentication](/start/concepts/api-authentication): why v3 authenticates with a single header-based key. - [Error catalog](/reference/api/error-catalog): every error code across the API. method: POST route: /v3/profiles/{profileId}/campaigns # POST /v3/profiles/{profileId}/campaigns Create a campaign for a profile's brand **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Creates a new campaign scoped under the brand of the specified profile. Each campaign must include at least one use case with sample messages. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsCreateBrandCampaignEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, campaign?: unknown } ``` ## Responses ### 201 Campaign created successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customerId?: string, isInherited?: boolean, type?: string, name?: string, description?: string, brandId?: string, status?: { }, tcrCampaignId?: string, submittedToTCR?: boolean, submittedAt?: string, cost?: number, billedDate?: string, messageFlow?: string, volume?: string, privacyPolicyLink?: string, termsAndConditionsLink?: string, optinMessage?: string, optoutMessage?: string, helpMessage?: string, optinKeywords?: string, optoutKeywords?: string, helpKeywords?: string, dcaElectionsComplete?: boolean, dcaElectionsCompletedAt?: string, tcrSyncError?: string, hasSubmissionTransaction?: boolean, useCases?: Array<{ id?: string, campaignId?: string, customerId?: string, messagingUseCaseUs?: unknown, sampleMessages?: Array, createdAt?: string, updatedAt?: string }>, createdAt?: string, updatedAt?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "customerId": "00000000-0000-0000-0000-000000000000", "isInherited": false, "type": "App", "name": "Customer Notifications", "description": "Appointment reminders and account notifications", "brandId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": null, "tcrCampaignId": null, "submittedToTCR": false, "submittedAt": null, "cost": null, "billedDate": null, "messageFlow": "User signs up on website and opts in to receive SMS notifications", "volume": null, "privacyPolicyLink": null, "termsAndConditionsLink": null, "optinMessage": null, "optoutMessage": null, "helpMessage": null, "optinKeywords": null, "optoutKeywords": null, "helpKeywords": null, "dcaElectionsComplete": null, "dcaElectionsCompletedAt": null, "tcrSyncError": null, "hasSubmissionTransaction": false, "useCases": [ { "id": "c3d4e5f6-a7b8-9012-cdef-123456789012", "campaignId": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "customerId": "00000000-0000-0000-0000-000000000000", "messagingUseCaseUs": "ACCOUNT_NOTIFICATION", "sampleMessages": [ "Hi {name}, your appointment is confirmed for {date} at {time}.", "Your order #{order_id} has been shipped. Track at {url}" ], "createdAt": "0001-01-01T00:00:00+00:00", "updatedAt": null } ], "createdAt": "2026-11-12T15:32:26.8880003+00:00", "updatedAt": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8881373+00:00", "version": "v3" } } ``` ### 400 Invalid request - validation errors or inherit_tcr_campaign=true #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Cannot create campaigns when inherit_tcr_campaign=true. Set inherit_tcr_campaign=false to create your own campaigns.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8881397+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Valid API key required ### 403 Forbidden ### 404 Profile or brand not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_009", "message": "Brand not found for this profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8881402+00:00", "version": "v3" } } ``` ### 500 Internal server error occurred #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to create campaign. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8881406+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/profiles/{profileId}/campaigns/{campaignId} # DELETE /v3/profiles/{profileId}/campaigns/{campaignId} Delete a campaign **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Deletes a campaign by ID from the brand of the specified profile. The profile must belong to the authenticated organization. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsDeleteBrandCampaignEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route parameter | | `campaignId` | `string` | true | Campaign ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 Campaign deleted successfully ### 400 Invalid profile or campaign ID format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid profile or campaign ID format", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8896651+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Valid API key required ### 403 Forbidden ### 404 Profile, brand, or campaign not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_010", "message": "Campaign not found for this profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8896663+00:00", "version": "v3" } } ``` ### 500 Internal server error occurred #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to delete campaign. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8896668+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/profiles/{profileId}/campaigns # GET /v3/profiles/{profileId}/campaigns Get campaigns for a profile's brand **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Retrieves all campaigns linked to the profile's brand, including use cases and sample messages. A profile with inherit_tcr_campaign=true gets its organization's campaigns and, beside them, any campaign of its own (added with POST /v3/channels/sms/compliances/US/TEN_DLC/campaigns); `isInherited` says which is which. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsGetBrandCampaignsEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Campaigns retrieved successfully #### application/json ```typescript { success?: boolean, data?: Array<{ id?: string, customerId?: string, isInherited?: boolean, type?: string, name?: string, description?: string, brandId?: string, status?: { }, tcrCampaignId?: string, submittedToTCR?: boolean, submittedAt?: string, cost?: number, billedDate?: string, messageFlow?: string, volume?: string, privacyPolicyLink?: string, termsAndConditionsLink?: string, optinMessage?: string, optoutMessage?: string, helpMessage?: string, optinKeywords?: string, optoutKeywords?: string, helpKeywords?: string, dcaElectionsComplete?: boolean, dcaElectionsCompletedAt?: string, tcrSyncError?: string, hasSubmissionTransaction?: boolean, useCases?: Array<{ id?: string, campaignId?: string, customerId?: string, messagingUseCaseUs?: unknown, sampleMessages?: Array, createdAt?: string, updatedAt?: string }>, createdAt?: string, updatedAt?: string }>, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": [ { "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "customerId": "00000000-0000-0000-0000-000000000000", "isInherited": false, "type": "App", "name": "Customer Notifications", "description": "Appointment reminders and account notifications", "brandId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": null, "tcrCampaignId": null, "submittedToTCR": false, "submittedAt": null, "cost": null, "billedDate": null, "messageFlow": "User signs up on website and opts in to receive SMS notifications", "volume": null, "privacyPolicyLink": null, "termsAndConditionsLink": null, "optinMessage": null, "optoutMessage": null, "helpMessage": null, "optinKeywords": null, "optoutKeywords": null, "helpKeywords": null, "dcaElectionsComplete": null, "dcaElectionsCompletedAt": null, "tcrSyncError": null, "hasSubmissionTransaction": false, "useCases": [ { "id": "c3d4e5f6-a7b8-9012-cdef-123456789012", "campaignId": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "customerId": "00000000-0000-0000-0000-000000000000", "messagingUseCaseUs": "ACCOUNT_NOTIFICATION", "sampleMessages": [ "Hi {name}, your appointment is confirmed for {date} at {time}.", "Your order #{order_id} has been shipped. Track at {url}" ], "createdAt": "0001-01-01T00:00:00+00:00", "updatedAt": null } ], "createdAt": "2026-11-12T15:32:26.8911987+00:00", "updatedAt": null } ], "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8911996+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Valid API key required ### 403 Forbidden ### 404 Profile or brand not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_009", "message": "Brand not found for this profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8912012+00:00", "version": "v3" } } ``` ### 500 Internal server error occurred #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to retrieve campaigns. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8912021+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PUT route: /v3/profiles/{profileId}/campaigns/{campaignId} # PUT /v3/profiles/{profileId}/campaigns/{campaignId} Update a campaign **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Updates an existing campaign under the brand of the specified profile. Once the campaign has been submitted to TCR its volume can no longer move between low volume (under 2,000 messages a day) and high volume. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsUpdateBrandCampaignEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route | | `campaignId` | `string` | true | Campaign ID from route | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, campaign?: unknown } ``` ## Responses ### 200 Campaign updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customerId?: string, isInherited?: boolean, type?: string, name?: string, description?: string, brandId?: string, status?: { }, tcrCampaignId?: string, submittedToTCR?: boolean, submittedAt?: string, cost?: number, billedDate?: string, messageFlow?: string, volume?: string, privacyPolicyLink?: string, termsAndConditionsLink?: string, optinMessage?: string, optoutMessage?: string, helpMessage?: string, optinKeywords?: string, optoutKeywords?: string, helpKeywords?: string, dcaElectionsComplete?: boolean, dcaElectionsCompletedAt?: string, tcrSyncError?: string, hasSubmissionTransaction?: boolean, useCases?: Array<{ id?: string, campaignId?: string, customerId?: string, messagingUseCaseUs?: unknown, sampleMessages?: Array, createdAt?: string, updatedAt?: string }>, createdAt?: string, updatedAt?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "customerId": "00000000-0000-0000-0000-000000000000", "isInherited": false, "type": "App", "name": "Customer Notifications Updated", "description": "Updated appointment reminders and account notifications", "brandId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": null, "tcrCampaignId": null, "submittedToTCR": false, "submittedAt": null, "cost": null, "billedDate": null, "messageFlow": null, "volume": null, "privacyPolicyLink": null, "termsAndConditionsLink": null, "optinMessage": null, "optoutMessage": null, "helpMessage": null, "optinKeywords": null, "optoutKeywords": null, "helpKeywords": null, "dcaElectionsComplete": null, "dcaElectionsCompletedAt": null, "tcrSyncError": null, "hasSubmissionTransaction": false, "useCases": [ { "id": "c3d4e5f6-a7b8-9012-cdef-123456789012", "campaignId": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "customerId": "00000000-0000-0000-0000-000000000000", "messagingUseCaseUs": "ACCOUNT_NOTIFICATION", "sampleMessages": [ "Hi {name}, your appointment is confirmed for {date} at {time}.", "Your order #{order_id} has been shipped. Track at {url}" ], "createdAt": "0001-01-01T00:00:00+00:00", "updatedAt": null } ], "createdAt": "2026-11-05T15:32:26.8962633+00:00", "updatedAt": "2026-11-12T15:32:26.896264+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8962768+00:00", "version": "v3" } } ``` ### 400 Invalid request - validation errors or inherit_tcr_campaign=true #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "These campaigns are read-only. Set inherit_tcr_campaign to false to manage your own campaigns.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8962786+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Valid API key required ### 403 Forbidden ### 404 Profile, brand, or campaign not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_010", "message": "Campaign not found for this profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.896279+00:00", "version": "v3" } } ``` ### 409 The campaign is registered with TCR and the volume would change its tier #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error occurred #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to update campaign. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8962794+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/channels/rcs # POST /v3/channels/rcs Add an RCS agent Asks for an RCS agent and records the order form the carriers vet it against. Always `202`: an agent is approved by the carriers, not by this call, and nothing here can make that happen sooner. ## What it asks for The RCS Agent Order Form — the same one our team fills in on your behalf today, so nothing has to be collected from you twice. **All fields are required** and must be submitted together so the carrier review has everything it needs. The only exception is `opt_in_screenshot_url`. **Agent identity:** `display_name`, `description`, `agent_use_case` (must be one of the accepted use cases; the error names the set), `brand_color` (six-digit hex, `#RRGGBB`). **Brand identity:** `brand_name` — the brand this agent presents. Not taken from `compliance.brand`: a business may present a different brand on RCS than the one its 10DLC registration is filed against, and the carriers vet this one. `privacy_policy_url`, `terms_and_conditions_url`, `website_url`, `logo_url`, and `banner_url` must be absolute `http(s)` URLs that the carriers can fetch without authentication. The form specifies 224×224 px and 50 KB for the logo and 1440×448 px and 200 KB for the banner; these cannot be checked without the image bytes. **Contact details:** `brand_phone_number`, `customer_support_phone_number`, `brand_email`, `customer_support_email`, `contact_name_and_title`. **Company:** `company_ein`, `entity_type`, `official_address` (street, city, state, postal_code, country), `brief_company_description`. **Consent and messages:** `opt_in_process_description`, `start_message`, `help_message`, `stop_message`, `sample_messages` (at least one example message). **Optional:** `opt_in_screenshot_url` (validated as an http(s) URL if supplied). Anything supplied is checked against accepted values rather than passed through: a value the provider rejects would otherwise surface days later, to somebody who cannot fix it without asking you. **A customer has one agent.** Asking again while you have one is `409`. ## What comes back, and what does not Returns **the agent** — the form as stored, plus `id` and `status`. Not your other channels, which this call cannot have changed. `status` is `PROVISIONING` until the agent is handed to the carriers and approved. **`GET /v3/channels` reports `rcs: null` until then** — a channel row is what routing reads to decide you are sendable, and writing one for an unapproved agent would claim a channel that cannot carry traffic. Send `x-profile-id` with an organization key to ask for one of your profiles' agents. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsAddRcsChannelEndpoint` **Tags:** Channels ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, display_name?: string, description?: string, agent_use_case?: "VERIFICATION" | "NOTIFICATIONS" | "MARKETING" | "MULTI_USE", brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, logo_url?: string, banner_url?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: unknown, brief_company_description?: string, opt_in_process_description?: string, opt_in_screenshot_url?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array } ``` ## Responses ### 202 The agent is recorded with status PROVISIONING, awaiting carrier approval #### application/json ```typescript { success?: boolean, data?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "c87b77eb-d936-497f-b662-a865a35d802c", "status": "PROVISIONING", "reason_code": "CHANNEL_011", "reason": "This channel is being set up", "display_name": "Example Retail", "description": "Order and delivery notifications for Example Retail customers.", "agent_use_case": "NOTIFICATIONS", "brand_name": "Example Retail", "privacy_policy_url": "https://example.com/privacy", "terms_and_conditions_url": "https://example.com/terms", "website_url": "https://example.com", "brand_color": "#1a73e8", "brand_phone_number": "+12125550100", "customer_support_phone_number": "+18005550100", "brand_email": "hello@example.com", "customer_support_email": "support@example.com", "contact_name_and_title": "Jane Smith, Head of Marketing", "company_ein": "12-3456789", "entity_type": "PRIVATE_PROFIT", "official_address": { "street": "123 Main St", "city": "New York", "state": "NY", "postal_code": "10001", "country": "US" }, "brief_company_description": "Example Retail sells home goods across the US and ships to 48 states.", "opt_in_process_description": "Customers opt in at checkout by checking the SMS/RCS notifications box.", "start_message": "Welcome to Example Retail! Reply HELP for help or STOP to opt out.", "help_message": "For help, visit https://example.com/support or call 1-800-555-0100.", "stop_message": "You have been unsubscribed from Example Retail notifications.", "sample_messages": [ "Your order #12345 has shipped and will arrive tomorrow." ], "created_at": "2025-06-01T12:00:00+00:00" }, "meta": { "request_id": "req_7D5fRp1sSw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 A required field is missing or not an accepted value #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "brand_name is required", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7D5fRp1sSw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 Not Found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 409 This customer already has an RCS agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_007", "message": "This customer already has an RCS agent. An agent cannot be withdrawn through the API once asked for, so contact support to change or replace it.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7D5fRp1sSw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 500 The agent could not be written #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/channels/sms # POST /v3/channels/sms Add an SMS market — a country and sender type Gives the customer a sender in one country — the first market it sends in, and the fifth. ## What to have in place first **Call `GET /v3/compliance/requirements?country=US&type=TEN_DLC` first.** It returns this request's body ready to fill in, plus the brand and campaign calls to make before it, in order. You never have to track forty countries' rules yourself. **A market that registers with a compliance regime needs an identity, and this call takes one.** US `TEN_DLC` registers with The Campaign Registry and files that registration against a business identity. Send it in `compliance.brand` and it is recorded here, before the registration that attaches to it — so a customer with no identity reaches a first 10DLC market in one call. `{ "inherit": true }` runs on your organization's instead. A market with neither — none stored, none sent — is `400`, because accepting it would write a channel that could never register and leave it provisioning for ever with nothing saying why. **Everything the regime wants arrives in this request's `compliance`**, as two declared objects: `brand` — the identity the registration is filed against — and `campaign`, with the use case, the consent narrative, the volume, the sample messages and the keywords. There is nothing to set up first. Nothing is submitted here either: the rows are what a submission is later assembled from, and filing is externally rejectable so it happens on its own path. **A half you run yourself has to be complete here.** Whichever of `brand` and `campaign` is your own rather than your organization's must carry every field the regime asks of it, counting what you already hold — send the rest in this request. A missing one is `400` naming each field, rather than a `202` for a market that could never be filed. A half you inherit is asked for nothing. A market that registers with nobody — an alphanumeric sender in most countries — needs neither, and may need documents instead. ## Sending it Takes the same fields `channels.sms` takes on `POST /v3/sender-profiles`, because it is the same work, and both run one provisioning path. `compliance` is top-level and answers for the market in this request, carrying `brand` and `campaign` where the market registers. **Accepts multipart as well as JSON**, with each file named after the compliance key it satisfies — a market that pre-registers its sender needs its documents at the same moment it needs the sender. Every required document must be attached to this request; a missing or invalid file is rejected before the market is added. **`area_codes` puts the sender somewhere specific**, in your order of preference, for a `LOCAL` sender in any country or a US `TEN_DLC` sender — a 10DLC number is an ordinary local long code bound to a registered campaign, so both take the same codes out of the same inventory. It is honoured exactly: you get a number in one of the codes you named or you get none, never one in a code you left out. ## Several numbers **`numbers` lists the numbers you want, one entry per area code**, e.g. `[{"area_code": "212", "quantity": 2}, {"quantity": 1}]` for two numbers in 212 and one in any area code. `quantity` defaults to 1, and an entry without `area_code` means any area code. Omit `numbers` for one number. It is for `LOCAL` and `TEN_DLC` only and cannot be combined with `area_codes`. A market holds at most 49 numbers, counting the ones it already has. **On a `LOCAL` market you already hold, `numbers` adds those numbers to it** instead of `409`. US `TEN_DLC` numbers belong to the market's campaign and are assigned when the campaign is approved, not at request time. Until then they read as `PROVISIONING` in the response's `numbers`, each with the area code it was asked for. A profile inheriting your organization's campaign cannot request `numbers` (`400`). `numbers` on a `TEN_DLC` market you already hold is `409`: change its campaign's numbers with `PATCH /v3/channels/sms/{country}/{type}`, add numbers to one of its campaigns with `POST /v3/channels/sms/numbers/US/TEN_DLC`, or add a new campaign with `POST /v3/channels/sms/compliances/US/TEN_DLC/campaigns`. **A market you already send in is `409`**: adding what is already there is a mistake worth reporting rather than a silent no-op. A market is a `(country, sender_type)` pair, so a **second sender type in a country you already send in is fine** — `US TOLL_FREE` alongside `US TEN_DLC` is the ordinary case. Two of the same type is not. **A market you hold that has no sender yet is not a duplicate**, and re-sending it re-asks for a sender rather than being refused. That is the way out of an area-code request nothing could fill: send the call again to name different codes, or no codes at all to take a number anywhere in the country. It answers `201` with the sender when the pool has one, otherwise `202` with the codes recorded — and changes nothing else; compliance on a market you hold is `PATCH /v3/channels/sms/{country}/{type}`. One exception: while a market's sender type is still unassigned, adding any type to that country is `409` once it has a sender, because the market you have may be about to become the one you asked for. Returns **the market**, in the shape `GET` and `PATCH` on `/v3/channels/sms/{country}/{type}` use — so what this answers can be read back and written back without reshaping. Not every channel you have: adding a market cannot change an RCS agent or a WhatsApp account, and `GET /v3/channels` is the whole picture. `201` when the market is ready; `202` while a sender or a registration is still outstanding. Send `x-profile-id` with an organization key to add a market to one of your profiles. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsAddSmsChannelEndpoint` **Tags:** Channels ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, country?: string, number_type?: "LOCAL" | "TOLL_FREE" | "SHORT_CODE" | "ALPHANUMERIC" | "TEN_DLC" | "MOBILE" | "10DLC", sender_value?: string, area_codes?: Array, numbers?: Array<{ area_code?: string, quantity?: integer }>, compliance?: { brand?: { inherit?: boolean, legal_name?: string, business_name?: string, tax_id?: string, tax_id_type?: string, ein_issuing_country?: string, entity_type?: "PRIVATE_PROFIT" | "PUBLIC_PROFIT" | "NON_PROFIT" | "SOLE_PROPRIETOR" | "GOVERNMENT", street?: string, city?: string, state?: string, postal_code?: string, country?: string, website?: string, contact_name?: string, contact_email?: string, contact_phone?: string }, campaign?: { inherit?: boolean, description?: string, message_flow?: string, use_cases?: Array<{ use_case: "MARKETING" | "ACCOUNT_NOTIFICATION" | "CUSTOMER_CARE" | "FRAUD_ALERT" | "2FA" | "DELIVERY_NOTIFICATION" | "SECURITY_ALERT" | "M2M" | "HIGHER_EDUCATION" | "POLLING_VOTING" | "PUBLIC_SERVICE_ANNOUNCEMENT", sample_messages: Array }>, opt_in_message?: string, opt_out_message?: string, help_message?: string, opt_in_keywords?: string, opt_out_keywords?: string, help_keywords?: string, privacy_policy_link?: string, terms_and_conditions_link?: string, volume?: string } } } ``` ### multipart/form-data ```typescript { sandbox?: boolean, country?: string, number_type?: "LOCAL" | "TOLL_FREE" | "SHORT_CODE" | "ALPHANUMERIC" | "TEN_DLC" | "MOBILE" | "10DLC", sender_value?: string, area_codes?: Array, numbers?: Array<{ area_code?: string, quantity?: integer }>, compliance?: { brand?: { inherit?: boolean, legal_name?: string, business_name?: string, tax_id?: string, tax_id_type?: string, ein_issuing_country?: string, entity_type?: "PRIVATE_PROFIT" | "PUBLIC_PROFIT" | "NON_PROFIT" | "SOLE_PROPRIETOR" | "GOVERNMENT", street?: string, city?: string, state?: string, postal_code?: string, country?: string, website?: string, contact_name?: string, contact_email?: string, contact_phone?: string }, campaign?: { inherit?: boolean, description?: string, message_flow?: string, use_cases?: Array<{ use_case: "MARKETING" | "ACCOUNT_NOTIFICATION" | "CUSTOMER_CARE" | "FRAUD_ALERT" | "2FA" | "DELIVERY_NOTIFICATION" | "SECURITY_ALERT" | "M2M" | "HIGHER_EDUCATION" | "POLLING_VOTING" | "PUBLIC_SERVICE_ANNOUNCEMENT", sample_messages: Array }>, opt_in_message?: string, opt_out_message?: string, help_message?: string, opt_in_keywords?: string, opt_out_keywords?: string, help_keywords?: string, privacy_policy_link?: string, terms_and_conditions_link?: string, volume?: string } } } ``` ## Responses ### 201 The market is ready #### application/json ```typescript { success?: boolean, data?: { country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "country": "GB", "number_type": "ALPHANUMERIC", "numbers": [ { "sender_value": "ExmplRetail", "area_code": null, "status": "ACTIVE" } ], "status": "ACTIVE", "compliance": { "documents": [ { "key": "senderid_registration_requirements", "file_name": "sender-id-registration.pdf", "document_id": "b792e8ae-2cb4-4209-85b9-32be4c2fcdd6" } ] } }, "meta": { "request_id": "req_5B3dPn9qSu", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 202 Added, or re-asked, with a sender or a registration still outstanding #### application/json ```typescript { success?: boolean, data?: { country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "country": "US", "number_type": "TEN_DLC", "numbers": [ { "sender_value": null, "area_code": null, "status": "PROVISIONING" } ], "status": "PROVISIONING", "reason_code": "CHANNEL_011", "reason": "Sent is setting this market up.", "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US", "website": "https://example.com" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ], "documents": [] } }, "meta": { "request_id": "req_5B3dPn9qSu", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 Bad Request #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "TEN_DLC is a US registration and cannot be added for GB.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_5B3dPn9qSu", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 The customer could not be read #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 409 The customer already sends in that market, or in that country under a sender type that is not assigned yet, or the campaign is registered with TCR and the volume would change its tier #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_007", "message": "This customer already sends in US as TEN_DLC", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_5B3dPn9qSu", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 422 A required pre-registration document is missing or an uploaded file is invalid #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/channels/voice # POST /v3/channels/voice Turn phone calls on for a number Adds voice to one of the numbers you hold, or gives you a new one. Send `number` for a number that is already yours (see `GET /v3/channels`); leave it out to be given a new US number, optionally in a particular `area_code`. Sending both is refused. Nothing registers, so the number can carry calls as soon as this returns. What happens on a call is decided by your `callback_url`: when a call arrives on the number, or a caller presses a key on a menu, Sent POSTs a signed question there and follows the answer. The response carries the `callback_secret` the questions are signed with, the one time it is shown without rotating; verify a question the way you verify a webhook. `POST /v3/channels/voice/{number}/test` sends a test question and reports the verdict. Send `agent_id` instead of `callback_url`, or with it, to have one of your voice agents (`GET /v3/voice/agents`) answer calls to the number. The agent wins over the callback URL for calls to the number; calls your app places from it still follow your app. `routes_to` in the response says which answers, and reads `agent_pending` while the number is still being moved to the agent. Calls follow the move within about an hour, as the provider applies it on its own clock. While numbers cannot be bound to agents, a request with `agent_id` is refused with `502` before any number is obtained or anything is written; send `callback_url` instead. Your first voice number becomes the line app-originated calls are placed from when a voice token names no number; send `default_for_app_calls: true` to give that role to another number. A number you turned off earlier is turned back on, and the same number with a different `callback_url` has its URL replaced and keeps its secret. Read the number's settings with `GET /v3/channels/voice` and change them with `PATCH /v3/channels/voice/{number}`. With `sandbox: true` the request is validated and a simulated number reported with `202`; nothing is written and no number is bought. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsAddVoiceChannelEndpoint` **Tags:** Channels, Voice ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, number?: string, area_code?: string, callback_url?: string, agent_id?: string, default_for_app_calls?: boolean } ``` ## Responses ### 201 Voice is on for the number; store callback_secret now #### application/json ```typescript { success?: boolean, data?: { number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string, callback_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "callback_secret": "whsec_MWYyZDFlMmU2N2RmNmI3YThmNTZhODFiYzJlNGQzYjI=", "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "callback", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-07-22T12:00:00+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8029207+00:00", "version": "v3" } } ``` ### 202 Sandbox: the request is valid and this is what would have been written #### application/json ```typescript { success?: boolean, data?: { number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string, callback_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 The number is not a phone number or not one of your numbers, number and area_code were both sent, callback_url is not a public HTTP or HTTPS URL, neither callback_url nor agent_id was sent, or agent_id is not an agent id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_022", "message": "Phone number is not owned by this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8029225+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 agent_id is not one of your voice agents #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 409 Another account already carries calls on this number, or no number is available in the area code asked for #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 502 The number could not be set up to receive calls or moved to your agent, or agent_id was sent while numbers cannot be bound to agents (refused before any number is obtained); nothing was written #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/channels/whatsapp # POST /v3/channels/whatsapp Add a WhatsApp account Connects a WhatsApp Business Account shared with us through a Multi-Partner Solution to the calling sender profile. Send `x-profile-id` for the profile the account belongs to. **Two fields, because everything else is derived.** `waba_id` says which of your organization's shared accounts this is — you hold one per client, and nothing else can say which. `phone_number_id` names the account's number, which is what assigns it to the profile as the number it sends from. The solution the account arrived through, the client business portfolio that owns it, the access token and its expiry are all resolved from your organization. They are not accepted here: the first two are Meta's answer about provenance, and the token is minted per client business and rotates roughly every sixty days, so a value you sent would be stale before it was useful. `phone_number_id` is optional. Omit it to connect the account now and settle the number later — the channel reads as `ACTION_NEEDED` with `reason_code` `CHANNEL_007`, and the profile's WhatsApp messages fail until a number is named. They do not fall back to your organization's account. Call this endpoint again with `phone_number_id` to name one. The same resolution runs behind `channels.whatsapp` on `POST /v3/sender-profiles`, so connecting at create and connecting afterwards fill the same fields. Returns **the account**, not every channel you have — adding one cannot change a market or an RCS agent, and `GET /v3/channels` is the whole picture. Giving an account up is not self-service: ask support, because deregistering a number lands in your own Meta business. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsAddWhatsappChannelEndpoint` **Tags:** Channels ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, waba_id?: string, phone_number_id?: string } ``` ## Responses ### 200 The account is connected to the profile #### application/json ```typescript { success?: boolean, data?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "waba_id": "102290129340398", "phone_number_id": "106540352242922", "solution_id": "473829105612345", "owner_business_id": "918273645098765", "status": "ACTIVE" }, "meta": { "request_id": "req_8E6gSq2tUx", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 waba_id is missing, the call was not scoped to a sender profile with x-profile-id, the account is not one this organization can reach, Meta would not issue a token for it, or the number is already in use by another profile #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "WhatsApp Business Account not found", "details": { "waba_id": [ "WhatsApp Business Account not found" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_8E6gSq2tUx", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 500 The account was connected but could not be read back #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/channels # GET /v3/channels Get your channels Every market you send SMS in, your WhatsApp account, your RCS agent and the numbers you carry phone calls on — with each one's status, and what each market has supplied. **Status lives on the channel, never on you or your brand.** An identity has no lifecycle; what has one is the registration of a sender in a market and the approval of a channel. So a customer live in one country and mid-registration in another reports exactly that, rather than one flattened answer. `sms[n].compliance` carries what each market holds: `brand` and `campaign` for markets that register with a compliance regime such as US TEN_DLC, and `documents` for markets that pre-register an alphanumeric or similar sender. Absent means the market registers with nobody and nothing has been supplied. `GET /v3/compliance/requirements` says what a market demands of any new customer; this says what you gave it. Send `x-profile-id` with an organization key to read one of your profiles' channels. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsGetChannelsEndpoint` **Tags:** Channels ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The channels you send on #### application/json ```typescript { success?: boolean, data?: { customer_id?: string, sms?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, whatsapp?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, rcs?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, mms?: Array<{ country?: string, number_type?: string, sender_value?: string, status?: string }>, voice?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "customer_id": "550e8400-e29b-41d4-a716-446655440000", "sms": [ { "country": "US", "number_type": "TEN_DLC", "sender_value": "+12125550100", "numbers": [], "status": "ACTIVE", "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ], "documents": [] } }, { "country": "GB", "number_type": "ALPHANUMERIC", "sender_value": "ExmplRetail", "numbers": [], "status": "ACTIVE", "compliance": { "documents": [ { "key": "senderid_registration_requirements", "file_name": "sender-id-registration.pdf", "document_id": "b792e8ae-2cb4-4209-85b9-32be4c2fcdd6" } ] } } ], "whatsapp": null, "rcs": { "id": "c87b77eb-d936-497f-b662-a865a35d802c", "status": "PROVISIONING", "reason_code": "CHANNEL_011", "reason": "This channel is being set up", "display_name": "Example Retail", "description": "Order and delivery notifications for Example Retail customers.", "agent_use_case": "NOTIFICATIONS", "brand_name": "Example Retail", "privacy_policy_url": "https://example.com/privacy", "terms_and_conditions_url": "https://example.com/terms", "website_url": "https://example.com", "brand_color": "#1a73e8", "brand_phone_number": "+12125550100", "customer_support_phone_number": "+18005550100", "brand_email": "hello@example.com", "customer_support_email": "support@example.com", "contact_name_and_title": "Jane Smith, Head of Marketing", "company_ein": "12-3456789", "entity_type": "PRIVATE_PROFIT", "official_address": { "street": "123 Main St", "city": "New York", "state": "NY", "postal_code": "10001", "country": "US" }, "brief_company_description": "Example Retail sells home goods across the US and ships to 48 states.", "opt_in_process_description": "Customers opt in at checkout by checking the SMS/RCS notifications box.", "start_message": "Welcome to Example Retail! Reply HELP for help or STOP to opt out.", "help_message": "For help, visit https://example.com/support or call 1-800-555-0100.", "stop_message": "You have been unsubscribed from Example Retail notifications.", "sample_messages": [ "Your order #12345 has shipped and will arrive tomorrow." ], "created_at": "2025-06-01T12:00:00+00:00" }, "mms": [], "voice": [ { "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "none", "created_at": "2025-06-01T12:00:00+00:00", "updated_at": "2025-06-01T12:00:00+00:00" } ] }, "meta": { "request_id": "req_4A2cNm8pRt", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 The customer could not be read #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_004", "message": "The customer could not be read", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_4A2cNm8pRt", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/channels/voice/{number} # GET /v3/channels/voice/{number} Get one voice number Reads one of your voice numbers, active or inactive: its status, whether it is the default line for calls placed from your app, and its callback URL. The signing secret is not on this read. The same shape `GET /v3/channels/voice` lists, and the same shape `PATCH` on this path accepts and returns, so what comes back can be sent back. The number is the E.164 value in the path with the plus sign URL-encoded (`%2B`). **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsGetVoiceChannelEndpoint` **Tags:** Channels, Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `number` | `string` | true | The number in E.164 format with the plus sign URL-encoded, e.g. %2B12125550100 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The voice number #### application/json ```typescript { success?: boolean, data?: { number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "none", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-07-22T12:00:00+00:00" }, "meta": { "request_id": "req_8H3jNq5sWx", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` ### 400 The number is not a phone number #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "'number' must be a valid phone number in E.164 format (e.g. +14155551234)", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_8H3jNq5sWx", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 This account has no voice number for that number #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_013", "message": "This account has no voice number +12125550100", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_8H3jNq5sWx", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/channels/voice # GET /v3/channels/voice List your voice numbers Every number you turned phone calls on for, active or inactive, oldest first. Each entry carries the number's status, whether it is the default line for calls placed from your app, and its callback URL. The signing secret is never on a read; it is shown when voice is turned on and by `POST /v3/channels/voice/{number}/rotate-secret`. The same entries `GET /v3/channels` reports under `voice`, and the same shape `GET /v3/channels/voice/{number}` returns for one of them. Change a number with `PATCH /v3/channels/voice/{number}`. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsGetVoiceChannelsEndpoint` **Tags:** Channels, Voice ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Your voice numbers #### application/json ```typescript { success?: boolean, data?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }>, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": [ { "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "none", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-07-22T12:00:00+00:00" }, { "number": "+12125550101", "status": "INACTIVE", "default_for_app_calls": false, "callback_url": "https://example.com/voice-support", "agent_id": null, "routes_to": "none", "created_at": "2026-07-23T09:30:00+00:00", "updated_at": "2026-08-01T16:45:00+00:00" } ], "meta": { "request_id": "req_5V2kLm8nQr", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/channels/sms/{country}/{type} # GET /v3/channels/sms/{country}/{type} Get one SMS market (country and sender type) Reads one market you send in — its sender, where that sender stands, and everything its compliance holds. ## What `compliance` carries A market that registers with a compliance regime reports `brand` — the identity the registration is filed against — and `campaign`, the programme filed against it. Each carries `inherit`, saying whether it is yours or your organization's. A market that registers with nobody has neither, so **both keys are absent** rather than null: absent says this market does not ask, where null would say it asks and you supplied nothing. It reports `documents` instead. `GET /v3/compliance/requirements` says what a market demands of any new customer; this says what you gave it. ## Writing it back **`PATCH` this same path**, with the `compliance` object from this response: ```json { "compliance": { "brand": { "tax_id": "12-3456789" } } } ``` Nothing else to learn — what comes back can be sent back, an omitted key is left alone. There is no sub-resource for either half: both are singletons of the market, so both are written here. `GET /v3/compliance/requirements` says what a market demands of anybody; this says what you gave it. Send `x-profile-id` with an organization key to read one of your profiles' markets. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsMarketGetSmsMarketEndpoint` **Tags:** Channels ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `country` | `string` | true | ISO 3166-1 alpha-2 country code, e.g. us | | `type` | `string` | true | Sender type: local, mobile, 10dlc (or ten_dlc), toll_free, short_code, alphanumeric. Matched ignoring case. | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The market #### application/json ```typescript { success?: boolean, data?: { country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "country": "US", "number_type": "TEN_DLC", "numbers": [ { "sender_value": "+12125550100", "area_code": "212", "status": "ACTIVE" } ], "status": "ACTIVE", "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US", "website": "https://example.com" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ], "documents": [] } }, "meta": { "request_id": "req_6C4eQo0rTv", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 Unrecognised country or sender type #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "type must be one of: LOCAL, MOBILE, TEN_DLC, TOLL_FREE, SHORT_CODE, ALPHANUMERIC", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_6C4eQo0rTv", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 The customer does not send in that market #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_013", "message": "This customer does not send in US as TEN_DLC", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_6C4eQo0rTv", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/channels/sms # GET /v3/channels/sms List your SMS markets Every market you send SMS in, each with its sender, where that sender stands, and what its compliance holds. The same entries `GET /v3/channels` reports under `sms`, and the same shape `GET /v3/channels/sms/{country}/{type}` returns for one of them — so a list, a member read and the all-channels read cannot describe a market differently. Send `x-profile-id` with an organization key to list one of your profiles' markets. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsMarketGetSmsMarketsEndpoint` **Tags:** Channels ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Your SMS markets #### application/json ```typescript { success?: boolean, data?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": [ { "country": "US", "number_type": "TEN_DLC", "numbers": [ { "sender_value": "+12125550100", "area_code": "212", "status": "ACTIVE" } ], "status": "ACTIVE", "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ], "documents": [] } }, { "country": "GB", "number_type": "ALPHANUMERIC", "numbers": [ { "sender_value": "ExmplRetail", "area_code": null, "status": "ACTIVE" } ], "status": "ACTIVE", "compliance": { "documents": [ { "key": "senderid_registration_requirements", "file_name": "sender-id-registration.pdf", "document_id": "b792e8ae-2cb4-4209-85b9-32be4c2fcdd6" } ] } } ], "meta": { "request_id": "req_3Z0aNl7oQs", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 The customer could not be read #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_004", "message": "The customer could not be read", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_3Z0aNl7oQs", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/channels/sms/{country}/{type} # PATCH /v3/channels/sms/{country}/{type} Amend one SMS market — compliance, documents and numbers Supplies whatever this market is waiting on, and answers with the market as stored — the same shape `GET` on this path returns, so **what comes back can be sent back**. **A market reporting `ACTION_NEEDED` is fixed here**, whatever it is waiting on: | Outstanding | Send | | --- | --- | | a `brand` or `campaign` value (US `TEN_DLC`) | `compliance`, as below | | a document, in any market | a multipart file named after the document's key | | a registration sent back for correction | `compliance.brand` and/or `compliance.campaign` — the identity is accepted even once filed, and the registration goes back for review | | different numbers | `numbers`, the list the market asks for from now on | ## Partial, at every level **An omitted key is left alone. An explicit `null` clears it.** Those are different requests, so `{}` changes nothing and is refused rather than silently accepted, and correcting one field does not blank the others. ```json { "compliance": { "brand": { "contact_phone": "+12125550123" } } } ``` That leaves the campaign untouched, along with every other field of the identity. ## What a US `TEN_DLC` market holds Two halves, both singular: `brand`, the identity the registration is filed against, and `campaign`, the programme filed against it. Each carries `inherit`. | Body | Effect | | --- | --- | | `"brand": { … }` | supplies or corrects the identity, and takes one of your own | | `"brand": { "inherit": true }` | runs on your organization's, giving up your own | | `"brand": null` | the same thing, said the short way | | `"campaign": { … }` | supplies or corrects the programme, and takes one of your own | | `"campaign": { "inherit": true }` | runs on your organization's | | key omitted | left exactly as it is | **Nothing here creates a second anything.** One identity and one campaign per market, so a write is an upsert and a replayed request lands on the row it already wrote. Sending the campaign twice does not file two registrations. ## Every other market Markets that register with no regime have neither half, so `compliance` is `400` there. Their compliance is documents, sent here as multipart. ## Documents Send `multipart/form-data` with **each file named after the compliance key it satisfies** — the key the market's `requirements` names. A file that matches no document the market asks for is `400` naming the keys that would, and a file the upload rules refuse (empty, too large, an unsupported type) is `422`. `compliance` and `numbers` may ride in the same form as text parts holding their JSON. ## Numbers `numbers` takes the list `POST /v3/channels/sms` takes, for a `LOCAL` or `TEN_DLC` market, and **replaces** what the market asks for — send the list you want, not a difference. Numbers already assigned stay; a list that leaves one of them out is `400`, because nothing here releases a number. ```json { "numbers": [ { "area_code": "415", "quantity": 2 }, { "quantity": 1 } ] } ``` A `LOCAL` market is claimed from inventory at once, and whatever inventory cannot cover stays pending. A `TEN_DLC` market's numbers are recorded on its campaign and assigned once the carriers elect it — on the next acquisition cycle when it already has been. They need a campaign of the profile's own: one inherited from the organization is `400`. ## What it will refuse **A filed identity is `409`.** Once the registration has gone to The Campaign Registry they hold a copy, and a local change would diverge from it silently. The campaign is not frozen — omit `brand` and the same body is accepted. The exception is a registration sent back for correction: the identity is accepted, and a correction to either half sends the registration back for review. Refiling it with The Campaign Registry stays with Sent. **More than one campaign is `409`.** The schema permits several and an account built on the admin side may hold them; this surface writes one, and editing whichever sorted first would leave the others unmentioned and unedited. Nothing is submitted to a regime here. These are the rows a submission is later assembled from, which is what lets them be corrected without waiting on something externally rejectable. Send `x-profile-id` with an organization key to write one of your profiles' markets. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsMarketPatchSmsMarketEndpoint` **Tags:** Channels ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `country` | `string` | true | ISO 3166-1 alpha-2 country code, e.g. us | | `type` | `string` | true | Sender type, e.g. 10dlc (or ten_dlc), local or alphanumeric. Only 10dlc in us declares compliance values. | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, compliance?: { brand?: { inherit?: boolean, legal_name?: string, business_name?: string, tax_id?: string, tax_id_type?: string, ein_issuing_country?: string, entity_type?: "PRIVATE_PROFIT" | "PUBLIC_PROFIT" | "NON_PROFIT" | "SOLE_PROPRIETOR" | "GOVERNMENT", street?: string, city?: string, state?: string, postal_code?: string, country?: string, website?: string, contact_name?: string, contact_email?: string, contact_phone?: string }, campaign?: { inherit?: boolean, description?: string, message_flow?: string, use_cases?: Array<{ use_case: "MARKETING" | "ACCOUNT_NOTIFICATION" | "CUSTOMER_CARE" | "FRAUD_ALERT" | "2FA" | "DELIVERY_NOTIFICATION" | "SECURITY_ALERT" | "M2M" | "HIGHER_EDUCATION" | "POLLING_VOTING" | "PUBLIC_SERVICE_ANNOUNCEMENT", sample_messages: Array }>, opt_in_message?: string, opt_out_message?: string, help_message?: string, opt_in_keywords?: string, opt_out_keywords?: string, help_keywords?: string, privacy_policy_link?: string, terms_and_conditions_link?: string, volume?: string } } } ``` ### multipart/form-data ```typescript { sandbox?: boolean, compliance?: { brand?: { inherit?: boolean, legal_name?: string, business_name?: string, tax_id?: string, tax_id_type?: string, ein_issuing_country?: string, entity_type?: "PRIVATE_PROFIT" | "PUBLIC_PROFIT" | "NON_PROFIT" | "SOLE_PROPRIETOR" | "GOVERNMENT", street?: string, city?: string, state?: string, postal_code?: string, country?: string, website?: string, contact_name?: string, contact_email?: string, contact_phone?: string }, campaign?: { inherit?: boolean, description?: string, message_flow?: string, use_cases?: Array<{ use_case: "MARKETING" | "ACCOUNT_NOTIFICATION" | "CUSTOMER_CARE" | "FRAUD_ALERT" | "2FA" | "DELIVERY_NOTIFICATION" | "SECURITY_ALERT" | "M2M" | "HIGHER_EDUCATION" | "POLLING_VOTING" | "PUBLIC_SERVICE_ANNOUNCEMENT", sample_messages: Array }>, opt_in_message?: string, opt_out_message?: string, help_message?: string, opt_in_keywords?: string, opt_out_keywords?: string, help_keywords?: string, privacy_policy_link?: string, terms_and_conditions_link?: string, volume?: string } } } ``` ## Responses ### 200 The market as stored #### application/json ```typescript { success?: boolean, data?: { country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "country": "US", "number_type": "TEN_DLC", "numbers": [ { "sender_value": "+12125550100", "area_code": "212", "status": "ACTIVE" } ], "status": "ACTIVE", "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US", "website": "https://example.com", "tax_id": "12-3456789" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout.", "message_flow": "Customers opt in at checkout by checking a consent box." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout.", "message_flow": "Customers opt in at checkout by checking a consent box." } ], "documents": [] } }, "meta": { "request_id": "req_9F7hTr3uVy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 A rejected value, an unknown key or file, numbers that leave out a held number, or a body that changes nothing #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Supply at least one value to change", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_9F7hTr3uVy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 No such market, or the customer does not send in it #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_013", "message": "This customer does not send in US as TEN_DLC", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_9F7hTr3uVy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 409 The identity has been filed, the account holds several campaigns, or the campaign is registered with TCR and the volume would change its tier #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_007", "message": "The identity for this profile has already been filed with The Campaign Registry and cannot be changed here. Contact support.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_9F7hTr3uVy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 422 An uploaded file the upload rules refuse #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/channels/voice/{number} # PATCH /v3/channels/voice/{number} Change one voice number Changes one of your voice numbers and answers with the number as stored, the same shape `GET` on this path returns, so what comes back can be sent back. ## What it changes | Body | Effect | | --- | --- | | `"status": "ACTIVE"` | turns calls on again for a number you turned off; the callback URL and the secret it had are kept | | `"status": "INACTIVE"` | turns calls off; the callback URL and the secret stay on the number | | `"default_for_app_calls": true` | makes this the line app-originated calls are placed from when a voice token names no number | | `"callback_url": "https://example.com/voice"` | replaces where Sent asks what to do with each call on the number; the signing secret and the status are kept | | `"agent_id": "agent_…"` | one of your voice agents answers calls to the number, within about an hour of the change (the provider applies the move on its own clock, and `routes_to` reads `agent` as soon as it has recorded it); it wins over `callback_url` for calls to the number, and calls your app places from it still follow your app. `routes_to` reads `agent_pending` while the number is still being moved to the agent | | `"agent_id": null` | unbinds the agent, so `callback_url` answers calls to the number again | | key omitted | left exactly as it is | `status` is matched ignoring case. Any combination is accepted: `status: "ACTIVE"` with `default_for_app_calls: true` turns a number on as the new default, and a `callback_url` sent with either status is written too. `agent_id` is applied first, so a refusal to move the number to or from the agent leaves everything as it was, and the `409` and `400` refusals below are decided before anything is written, so they leave everything as it was too. A body that names none of them is refused. A number can be on without a callback URL: calls placed from your app then connect straight to the number or user they dial, and calls to the number are declined. ## What it will refuse **`default_for_app_calls: false` is `400`.** An account with active voice numbers always has exactly one default, so the default moves by giving it to another number. **Turning the default line off is `409`** while other active voice numbers remain. Move the default to another number first. Turning off your last voice number is allowed; that turns phone calls off. **Making an inactive number the default is `400`.** Send `status: "ACTIVE"` in the same call. **A number you never turned voice on for is `404`**, and so is an `agent_id` that is not one of your agents. Add the number with `POST /v3/channels/voice`. **`502` means the number could not be moved to or from the agent**, or an `agent_id` was sent while numbers cannot be bound to agents; nothing was written. The number is the E.164 value in the path with the plus sign URL-encoded (`%2B`). With `sandbox: true` nothing is written: the request is validated against the stored number and the number is reported with `200` as it would read after the change. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsPatchVoiceChannelEndpoint` **Tags:** Channels, Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `number` | `string` | true | The number in E.164 format with the plus sign URL-encoded, e.g. %2B12125550100 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, status?: "ACTIVE" | "INACTIVE", default_for_app_calls?: boolean, callback_url?: string, agent_id?: string } ``` ## Responses ### 200 The voice number as stored #### application/json ```typescript { success?: boolean, data?: { number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "callback", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-08-01T16:45:00+00:00" }, "meta": { "request_id": "req_2D6gPt4vYz", "timestamp": "2026-08-01T16:45:00+00:00", "version": "v3" } } ``` ### 400 The number is not a phone number, status is not ACTIVE or INACTIVE, callback_url is not a public HTTP or HTTPS URL, agent_id is not an agent id or null, default_for_app_calls is false, the body changes nothing, or an inactive number was made the default #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Supply at least one of status, default_for_app_calls, callback_url or agent_id", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_2D6gPt4vYz", "timestamp": "2026-08-01T16:45:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 This account has no voice number for that number, or agent_id is not one of your voice agents #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_013", "message": "This account has no voice number +12125550100", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_2D6gPt4vYz", "timestamp": "2026-08-01T16:45:00+00:00", "version": "v3" } } ``` ### 409 The number is the default line for app calls and other active voice numbers remain #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_007", "message": "This number is the default line for app calls and other voice numbers are active; move the default to another number first", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_2D6gPt4vYz", "timestamp": "2026-08-01T16:45:00+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 502 The number could not be moved to or from the voice agent, or agent_id was sent while numbers cannot be bound to agents; nothing was written #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/channels/voice/{number}/rotate-secret # POST /v3/channels/voice/{number}/rotate-secret Rotate a voice number's callback secret Generates a new signing secret for the questions Sent sends to this number's callback URL and returns it. The previous secret stops signing immediately, so update your backend before the next call reaches it. The number is the E.164 value in the path with the plus sign URL-encoded (`%2B`). With `sandbox: true` a secret is generated and returned with `202`, and nothing is written. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsRotateVoiceSecretEndpoint` **Tags:** Channels, Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `number` | `string` | true | The voice number from the route, in E.164 format with the plus sign URL-encoded (%2B), for example /v3/channels/voice/%2B12025550123/rotate-secret. | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 200 The new secret. The old one no longer signs anything #### application/json ```typescript { success?: boolean, data?: { callback_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "callback_secret": "whsec_MWYyZDFlMmU2N2RmNmI3YThmNTZhODFiYzJlNGQzYjI=" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8665131+00:00", "version": "v3" } } ``` ### 202 Sandbox: a secret that was not stored #### application/json ```typescript { success?: boolean, data?: { callback_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 Invalid number, or the number has never had voice turned on #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_024", "message": "Phone number is not voice-enabled for this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8665147+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/channels/voice/{number}/test # POST /v3/channels/voice/{number}/test Test a voice number's callback URL Sends a synthetic call.request question, flagged "test": true, to the number's callback URL, signed with that number's real secret, and reports what came back. Use it to build and debug your callback endpoint without placing calls: no call is placed, nothing is billed, and nothing is stored. One attempt with the same deadline as a live call, no retry. The outcome is ok when your endpoint answered 2xx with a valid answer; otherwise it is timeout, connection_failed, http_error or invalid_answer, with the reason and, for an invalid answer, the field at fault. The number is the E.164 value in the path with the plus sign URL-encoded (`%2B`). With `sandbox: true` nothing is sent: the verdict comes back ok with `202` and no request or response in it. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ChannelsTestVoiceCallbackEndpoint` **Tags:** Channels, Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `number` | `string` | true | The voice number from the route, in E.164 format with the plus sign URL-encoded (%2B), for example /v3/channels/voice/%2B12025550123/test. The test question goes to this number's callback URL and is signed with this number's secret. | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 200 The test ran. Read outcome to see whether your endpoint passed #### application/json ```typescript { success?: boolean, data?: { outcome?: string, call_id?: string, request?: { url?: string, headers?: object, body?: string }, response?: { status_code?: integer, body?: string }, answer?: { }, error?: { reason?: string, path?: string, message?: string } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "outcome": "ok", "call_id": "call_9f2ab000-0000-4000-8000-000000000001", "request": { "url": "https://example.com/voice", "headers": { "User-Agent": "SentDM-Voice/1.0", "X-Webhook-ID": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "X-Webhook-Timestamp": "1784721600", "X-Webhook-Signature": "v1,xJ/WfHm26o0BBWZ/SIDmZio7C3BbqlcbxvO/QIZpjUA=", "X-Request-Id": "req_7X9zKp2jDw" }, "body": "{\"type\":\"call.request\",\"version\":\"1\",\"callId\":\"call_9f2ab000-0000-4000-8000-000000000001\",\"number\":\"+12025550123\",\"timestamp\":\"2026-07-22T12:00:00+00:00\",\"test\":true,\"direction\":\"outbound\",\"from\":{\"kind\":\"user\",\"identity\":\"test-user\"},\"to\":{\"kind\":\"number\",\"number\":\"+12025550142\"}}" }, "response": { "status_code": 200, "body": "{ \"action\": { \"action\": \"connectToUser\", \"identity\": \"agent-42\" } }" }, "answer": { "valueKind": "Object" }, "error": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8719327+00:00", "version": "v3" } } ``` ### 202 Sandbox: nothing was sent #### application/json ```typescript { success?: boolean, data?: { outcome?: string, call_id?: string, request?: { url?: string, headers?: object, body?: string }, response?: { status_code?: integer, body?: string }, answer?: { }, error?: { reason?: string, path?: string, message?: string } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 Invalid number, or number not voice-enabled for this account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_024", "message": "Phone number is not voice-enabled for this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8719353+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 The account has no voice-enabled number #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_023", "message": "Phone calls are not enabled for this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8719362+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while testing the callback URL", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.8719407+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/compliance/requirements # GET /v3/compliance/requirements Get compliance requirements for a market **Call this first.** It returns what a channel, country and sender type demand before you can send there — and `setup[]`, the calls that satisfy those demands, in order, each with a body you can copy and send as it stands. You never have to track forty countries' rules yourself. ## Channel `channel` is `sms`, `whatsapp` or `rcs`, and **defaults to `sms`** — so a caller that omits it gets exactly what this endpoint has always returned. `sms` is the only one answered today; the other two are `501` until their requirements are declared. They are refused rather than answered with an empty requirement set, because empty would say the channel demands nothing, and both demand plenty — WhatsApp a business verification and a display name review, RCS a carrier approval. Saying "not yet" is the true answer and the same one `POST /v3/sender-profiles` gives for `channels.whatsapp`. `type` is an SMS sender type, and SMS is the only channel whose senders have one. Requirements vary enormously. US `TEN_DLC` registers a brand and a campaign with The Campaign Registry and asks for a substantial set of values. An alphanumeric sender in one country pre-registers with supporting documents; in another it needs nothing at all. This is the authoritative answer for whichever market you are asking about, and it is the same declaration used to validate the calls themselves — so it can never drift from what is actually enforced. ## `setup[]` — what to do **One step.** `POST /v3/channels/sms` adds the market and records everything it registers with — the identity in `compliance.brand`, the programme in `compliance.campaign`. There were three, in a load-bearing order, while the identity and the campaign were resources of their own; they are members of this call's body now, so there is nothing to sequence. Correct any of it afterwards with `PATCH /v3/channels/sms/{country}/{type}`, which takes the same `compliance` object one key at a time. Each step's `body` has every key that market wants already present, with the values left **blank**. Blank rather than filled with placeholders, because the body is meant to be sent: a null value counts as not supplied, so posting a step verbatim comes back naming every blank you left. `attachments[]` lists files to send as multipart on the channel call, each under the field name given — a file cannot be a JSON value, so documents are never listed in `compliance[]`. Every step is a call for whoever holds the key. To set a **sender profile** up instead, send the same requests with the `x-profile-id` header naming it; there is no separate path. ## `requirements[]` — what each value means Each entry names a key for the `compliance` array, its value type, and whether it is required. `required_when` marks values needed only in certain cases — evaluate it against your own payload, e.g. `brand.entity_type == PUBLIC_PROFIT`. `options` lists accepted values where the market constrains them, and `label` is suitable for rendering a form field. Values Sent supplies on your behalf are never listed: correlation ids, environment flags, carrier elections, and booleans derivable from what you already send. ## When nothing is required `required` is `false` and `requirements` is empty, and the single `setup` step carries no `compliance` array at all. A `sender_id_pattern` may still be present — many markets constrain the sender string without registering anything. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ComplianceGetComplianceRequirementsEndpoint` **Tags:** Compliance ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `channel` | `string` | false | Channel the sender is for: sms, whatsapp or rcs. Defaults to sms, which is the only one answered today — the other two are 501 until their requirements are declared. | | `country` | `string` | false | ISO 3166-1 alpha-2 country code, e.g. US, XK, IN | | `type` | `string` | false | Sender type: LOCAL, MOBILE, TEN_DLC, TOLL_FREE, SHORT_CODE, ALPHANUMERIC. 10DLC is accepted as a synonym of TEN_DLC, the same as on POST /v3/sender-profiles. Applies to channel=sms, the only channel whose senders have a type. | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Requirements for the requested market #### application/json ```typescript { success?: boolean, data?: { channel?: string, country?: string, type?: string, required?: boolean, sender_id_pattern?: string, requirements?: Array<{ key?: string, type?: string, format?: string, required?: boolean, required_when?: string, options?: Array, min_length?: integer, max_items?: integer, item_fields?: Array, label?: string, notes?: string }>, setup?: Array<{ step?: integer, resource?: string, method?: string, path?: string, why?: string, body?: unknown, attachments?: Array<{ field_name?: string, label?: string, required?: boolean }> }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "channel": "sms", "country": "US", "type": "TEN_DLC", "required": true, "sender_id_pattern": null, "requirements": [ { "key": "brand", "type": "object", "format": null, "required": false, "required_when": null, "options": null, "min_length": null, "max_items": null, "item_fields": [ { "key": "inherit", "type": "boolean", "format": null, "required": false, "required_when": null, "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Run on the organization's brand", "notes": "True to register under the parent organization's identity rather than one of this profile's own; every field below is then neither asked for nor accepted. Omitted, the brand is the organization's unless this block supplies identity fields, which says plainly enough that it wants one of its own." }, { "key": "legal_name", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Registered legal name", "notes": "TCR companyName — the name on the incorporation documents, which is often not the name recipients would recognise." }, { "key": "business_name", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Public-facing name", "notes": "TCR displayName — the name recipients would recognise. Named for what it holds rather than for TCR's field, which is why it is not `display_name`." }, { "key": "tax_id", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Tax identifier", "notes": "TCR ein. TcrBrandSubmissionValidator refuses a submission without one, so it is wanted here rather than discovered at filing time." }, { "key": "tax_id_type", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Kind of tax identifier", "notes": "Which kind of identifier `tax_id` is, e.g. us_ein. Derived onto the brand form, and not itself sent to TCR." }, { "key": "ein_issuing_country", "type": "string", "format": "iso3166_alpha2", "required": false, "required_when": null, "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Country that issued the tax id", "notes": "TCR einIssuingCountry — where the tax id was issued, which is not always where the business trades. Defaults to `country` when omitted, which is right for most. Takes the code or the country spelled out, as `country` does." }, { "key": "entity_type", "type": "enum", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": [ "PRIVATE_PROFIT", "PUBLIC_PROFIT", "NON_PROFIT", "SOLE_PROPRIETOR", "GOVERNMENT" ], "min_length": null, "max_items": null, "item_fields": null, "label": "Entity type", "notes": "TCR entityType. Decides which vetting TCR applies and, for SOLE_PROPRIETOR, fixes the campaign fee regardless of volume. Also refused at submission if absent." }, { "key": "street", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Street address", "notes": null }, { "key": "city", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "City", "notes": null }, { "key": "state", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "State or region", "notes": "TCR state. Two letters for a US registration." }, { "key": "postal_code", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Postal code", "notes": null }, { "key": "country", "type": "string", "format": "iso3166_alpha2", "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Country of registration", "notes": "Two letters — US. The country spelled out in full is accepted too and stored as its code, which is what a read answers with and what is filed." }, { "key": "website", "type": "string", "format": "url", "required": false, "required_when": null, "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Website", "notes": "TCR website. Optional, and worth sending: carriers weigh it when vetting, so a brand that has one and omits it is vetted on less than it could be." }, { "key": "contact_name", "type": "string", "format": null, "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Responsible contact", "notes": "Split into TCR's firstName/lastName on submission. BrandService refuses a blank one, so a missing name is reported here rather than thrown after the profile was written." }, { "key": "contact_email", "type": "string", "format": "email", "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Contact email", "notes": "TCR email." }, { "key": "contact_phone", "type": "string", "format": "e164", "required": false, "required_when": "compliance.brand.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Contact phone", "notes": "TCR sends it as both phone and mobilePhone, so it is asked for once. Named for the contact it belongs to rather than as a bare `phone` on a block that also carries an address." } ], "label": "Business identity", "notes": "The identity the registration is filed against. Omit to have none; { \"inherit\": true } to register under your organization's." }, { "key": "campaign", "type": "object", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": [ { "key": "inherit", "type": "boolean", "format": null, "required": false, "required_when": null, "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Run on the organization's campaign", "notes": "True to register under the parent organization's programme rather than one of this profile's own; every field below is then neither asked for nor accepted. Owning the identity and inheriting the campaign is refused — a campaign is filed against an identity registration, and chk_tcr_inheritance forbids that pairing outright." }, { "key": "description", "type": "string", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "What this programme sends", "notes": "TCR description: what recipients will get and why, in a sentence. The only one of these TCR takes verbatim as a description of the programme, which is why it is asked for rather than derived from the customer's name." }, { "key": "message_flow", "type": "string", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": 40, "max_items": null, "item_fields": null, "label": "Consent narrative", "notes": "TCR messageFlow: how recipients opt in, in prose. Under 40 characters is refused, and carriers reject vague descriptions — say where opt-in happens, that the box is unchecked by default, and that consent is not a condition of purchase." }, { "key": "use_cases", "type": "array", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": 5, "item_fields": [ { "key": "use_case", "type": "enum", "format": null, "required": true, "required_when": null, "options": [ "MARKETING", "ACCOUNT_NOTIFICATION", "CUSTOMER_CARE", "FRAUD_ALERT", "2FA", "DELIVERY_NOTIFICATION", "SECURITY_ALERT", "M2M", "HIGHER_EDUCATION", "POLLING_VOTING", "PUBLIC_SERVICE_ANNOUNCEMENT" ], "min_length": null, "max_items": null, "item_fields": null, "label": "Use case", "notes": "What this entry sends. MIXED and LOW_VOLUME are refused — volume decides those." }, { "key": "sample_messages", "type": "array", "format": null, "required": true, "required_when": null, "options": null, "min_length": null, "max_items": 5, "item_fields": null, "label": "Sample messages", "notes": "TCR sample1..sample5 for this use case. One to five, each carrying the brand name and an opt-out instruction." } ], "label": "Use cases", "notes": "What the campaign sends, and an example of each. One to five entries; how they register is decided by volume, never declared." }, { "key": "opt_in_message", "type": "string", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Opt-in confirmation", "notes": "TCR optinMessage. Should state message frequency and that rates may apply. Its presence is what sets subscriberOptin." }, { "key": "opt_out_message", "type": "string", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Opt-out confirmation", "notes": "TCR optoutMessage. Its presence is what sets subscriberOptout." }, { "key": "help_message", "type": "string", "format": null, "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Help reply", "notes": "TCR helpMessage. Its presence is what sets subscriberHelp." }, { "key": "opt_in_keywords", "type": "string", "format": "csv_keywords", "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Opt-in keywords", "notes": "TCR optinKeywords, comma separated, e.g. START,YES." }, { "key": "opt_out_keywords", "type": "string", "format": "csv_keywords", "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Opt-out keywords", "notes": "TCR optoutKeywords, comma separated. STOP, END, CANCEL, UNSUBSCRIBE and QUIT are honoured regardless of what is declared." }, { "key": "help_keywords", "type": "string", "format": "csv_keywords", "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Help keywords", "notes": "TCR helpKeywords, comma separated, e.g. HELP,INFO." }, { "key": "privacy_policy_link", "type": "string", "format": "url", "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Privacy policy URL", "notes": "TCR privacyPolicyLink." }, { "key": "terms_and_conditions_link", "type": "string", "format": "url", "required": false, "required_when": "compliance.campaign.inherit != true", "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Terms and conditions URL", "notes": "TCR termsAndConditionsLink." }, { "key": "volume", "type": "string", "format": null, "required": false, "required_when": null, "options": null, "min_length": null, "max_items": null, "item_fields": null, "label": "Expected monthly volume", "notes": "Decides how the campaign registers and which fee tier applies: below the low-volume threshold it registers as LOW_VOLUME with sub-use-cases, above it as a single use case or MIXED. Omitting it registers the campaign at the higher-fee standard tier." } ], "label": "Messaging campaign", "notes": "What the programme sends and how recipients consented. Omit to run on your organization's; supplying it takes one of your own. { \"inherit\": true } says so outright." } ], "setup": [ { "step": 1, "resource": "channel", "method": "POST", "path": "/v3/channels/sms", "why": "Adds the market, claims a number for it, and records everything The Campaign Registry asks — the identity in `compliance.brand`, the programme in `compliance.campaign`. The registration stays outstanding until it is filed and answered, which happens off this call.", "body": { "country": "US", "number_type": "TEN_DLC", "sender_value": null, "compliance": { "brand": { "inherit": null, "legal_name": null, "business_name": null, "tax_id": null, "tax_id_type": null, "ein_issuing_country": null, "entity_type": null, "street": null, "city": null, "state": null, "postal_code": null, "country": null, "website": null, "contact_name": null, "contact_email": null, "contact_phone": null }, "campaign": { "inherit": null, "description": null, "message_flow": null, "use_cases": null, "opt_in_message": null, "opt_out_message": null, "help_message": null, "opt_in_keywords": null, "opt_out_keywords": null, "help_keywords": null, "privacy_policy_link": null, "terms_and_conditions_link": null, "volume": null } } }, "attachments": null } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7910467+00:00", "version": "v3" } } ``` ### 400 Missing or unrecognised channel, country or sender type #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "type must be one of: LOCAL, MOBILE, TEN_DLC, TOLL_FREE, SHORT_CODE, ALPHANUMERIC", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7910492+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 501 That channel's requirements are not published here yet #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 503 The market exists but its configuration is incomplete, so nothing can be sent there yet #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/contacts # POST /v3/contacts Create a contact Creates a new contact by phone number and associates it with the authenticated customer. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ContactsCreateContactEndpoint` **Tags:** Contacts ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, phone_number?: string } ``` ## Responses ### 201 Contact created successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, phone_number?: string, format_e164?: string, format_international?: string, format_national?: string, format_rfc?: string, country_code?: string, region_code?: string, available_channels?: string, default_channel?: string, opt_out?: boolean, is_inherited?: boolean, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "00000000-0000-0000-0000-000000000000", "phone_number": "+1234567890", "format_e164": "+1234567890", "format_international": "+1 234-567-890", "format_national": "(234) 567-890", "format_rfc": "tel:+1-234-567-890", "country_code": "1", "region_code": "US", "available_channels": "sms", "default_channel": "sms", "opt_out": false, "is_inherited": false, "created_at": "2026-11-12T15:32:26.7789179+00:00", "updated_at": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.778937+00:00", "version": "v3" } } ``` ### 400 Invalid request - phone number missing or invalid #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Phone number is required", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7789388+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 409 Contact already exists for this customer #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_007", "message": "Contact with this phone number already exists for this customer", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7789392+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7789397+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/contacts/{id} # DELETE /v3/contacts/{id} Delete a contact **Deprecated.** Use `PATCH /v3/contacts/{id}` with `{"opt_out": true}` instead, and expect this to be removed in a future release. It still behaves exactly as before, so nothing needs to change today. Opting a contact out stops every send to them, which is what deleting one was mostly used for — and it keeps the record of who they were and that they asked. A delete discards the consent history along with the contact, which is the part you need if anyone ever asks why you stopped, or why you started again. Dissociates a contact from the authenticated customer. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ContactsDeleteContactEndpoint` **Tags:** Contacts ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Contact ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 Contact deleted successfully ### 400 Invalid contact ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid contact ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7802412+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Contact not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_001", "message": "Contact not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7802424+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7802428+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/contacts/{id} # GET /v3/contacts/{id} Get contact by ID Retrieves a specific contact by their unique identifier. Returns detailed contact information including phone formats, available channels, and opt-out status. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ContactsGetContactByIdEndpoint` **Tags:** Contacts ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Contact ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Contact found and returned successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, phone_number?: string, format_e164?: string, format_international?: string, format_national?: string, format_rfc?: string, country_code?: string, region_code?: string, available_channels?: string, default_channel?: string, opt_out?: boolean, is_inherited?: boolean, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "00000000-0000-0000-0000-000000000000", "phone_number": "+1234567890", "format_e164": "+1234567890", "format_international": "+1 234-567-890", "format_national": "(234) 567-890", "format_rfc": "tel:+1-234-567-890", "country_code": "1", "region_code": "US", "available_channels": "sms,whatsapp", "default_channel": "sms", "opt_out": false, "is_inherited": false, "created_at": "2026-11-12T15:32:26.7821547+00:00", "updated_at": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.782155+00:00", "version": "v3" } } ``` ### 400 Invalid request - ContactId is empty or invalid format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_003", "message": "Invalid ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7821572+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid or missing API credentials ### 403 Forbidden ### 404 Contact not found for the authenticated customer #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_001", "message": "Contact not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7821576+00:00", "version": "v3" } } ``` ### 500 Internal server error - Contact support with request ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.782158+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/contacts/{contactId}/message-summary # GET /v3/contacts/{contactId}/message-summary Get message summary for a contact Returns aggregate message counts, time bounds, channels used, and per-channel success/fail scores (each as a percentage 0-100 of messages on that channel) for one of your contacts. Successful terminal states: SENT/DELIVERED/READ for outbound, RECEIVED for inbound. Fail: FAILED. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ContactsGetContactMessageSummaryEndpoint` **Tags:** Contacts ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `contactId` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Summary returned successfully #### application/json ```typescript { success?: boolean, data?: { contact_id?: string, message_count?: integer, first_message_at?: string, last_message_at?: string, channels_used?: Array, channel_scores?: Array<{ channel?: string, success_score?: integer, fail_score?: integer }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "contact_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "message_count": 42, "first_message_at": "2026-10-13T15:32:26.7836872+00:00", "last_message_at": "2026-11-12T12:32:26.7836996+00:00", "channels_used": [ "sms", "whatsapp" ], "channel_scores": [ { "channel": "sms", "success_score": 91, "fail_score": 9 }, { "channel": "whatsapp", "success_score": 90, "fail_score": 10 } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7837588+00:00", "version": "v3" } } ``` ### 400 Invalid request - ContactId is empty or invalid format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid or missing API credentials ### 403 Forbidden ### 404 Contact not found for the authenticated customer #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_001", "message": "Contact not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7837606+00:00", "version": "v3" } } ``` ### 500 Internal server error - Contact support with request ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/contacts # GET /v3/contacts Get contacts list Retrieves a paginated list of contacts for the authenticated customer. Supports filtering by search term, channel, or phone number. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ContactsGetContactsEndpoint` **Tags:** Contacts ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | Page number (1-indexed) | | `page_size` | `integer` | true | Number of items per page | | `search` | `string` | false | Optional search term for filtering contacts | | `channel` | `string` | false | Optional channel filter (sms, whatsapp) | | `phone` | `string` | false | Optional phone number filter (alternative to list view) | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Contacts retrieved successfully #### application/json ```typescript { success?: boolean, data?: { contacts?: Array<{ id?: string, customer_id?: string, phone_number?: string, format_e164?: string, format_international?: string, format_national?: string, format_rfc?: string, country_code?: string, region_code?: string, available_channels?: string, default_channel?: string, opt_out?: boolean, is_inherited?: boolean, created_at?: string, updated_at?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "contacts": [ { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "00000000-0000-0000-0000-000000000000", "phone_number": "+1234567890", "format_e164": "+1234567890", "format_international": "+1 234-567-890", "format_national": "(234) 567-890", "format_rfc": "tel:+1-234-567-890", "country_code": "1", "region_code": "US", "available_channels": "sms,whatsapp", "default_channel": "sms", "opt_out": false, "is_inherited": false, "created_at": "2026-11-12T15:32:26.7850889+00:00", "updated_at": null } ], "pagination": { "page": 1, "page_size": 20, "total_count": 150, "total_pages": 8, "has_more": true, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7851186+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_005", "message": "Page must be greater than 0", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7851206+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Contact not found (when filtering by phone) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_001", "message": "Contact not found with the specified phone number", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7851211+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7851215+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/contacts/{id} # PATCH /v3/contacts/{id} Update a contact Updates a contact's default channel and/or opt-out status. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ContactsUpdateContactEndpoint` **Tags:** Contacts ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Contact ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, default_channel?: string, opt_out?: boolean } ``` ## Responses ### 200 Contact updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, phone_number?: string, format_e164?: string, format_international?: string, format_national?: string, format_rfc?: string, country_code?: string, region_code?: string, available_channels?: string, default_channel?: string, opt_out?: boolean, is_inherited?: boolean, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "00000000-0000-0000-0000-000000000000", "phone_number": "+1234567890", "format_e164": "+1234567890", "format_international": "+1 234-567-890", "format_national": "(234) 567-890", "format_rfc": "tel:+1-234-567-890", "country_code": "1", "region_code": "US", "available_channels": "sms,whatsapp", "default_channel": "whatsapp", "opt_out": false, "is_inherited": false, "created_at": "2026-10-13T15:32:26.7866387+00:00", "updated_at": "2026-11-12T15:32:26.7866392+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7866396+00:00", "version": "v3" } } ``` ### 400 Invalid channel value #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_006", "message": "Invalid channel. Must be 'sms' or 'whatsapp'.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7866414+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Contact not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_001", "message": "Contact not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7866419+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7866423+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/conversations/{id} # GET /v3/conversations/{id} List messages for a conversation Retrieves a paginated list of the messages in a single conversation (scoped to the authenticated customer), ordered by created date (most recent first). **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ConversationsGetConversationByIdEndpoint` **Tags:** Conversations ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Conversation id from the route. | ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | - | | `page_size` | `integer` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Messages retrieved successfully #### application/json ```typescript { success?: boolean, data?: { messages?: Array<{ id?: string, customer_id?: string, contact_id?: string, phone?: string, phone_international?: string, region_code?: string, template_id?: string, template_name?: string, template_category?: string, channel?: string, message_body?: { header?: string, content?: string, footer?: string, buttons?: Array<{ type?: string, text?: string, value?: string, postbackData?: string }>, subject?: string, media?: Array<{ url?: string, mediaType?: string, mimeType?: string, sizeBytes?: integer, sourceHashSha256?: string }>, headerMedia?: { type?: string, url?: string } }, status?: string, direction?: string, created_at?: string, price?: number, active_contact_price?: number, events?: Array<{ status: string, timestamp: string, description?: string, reason_code?: string, reason?: string }>, reason_code?: string, reason?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "messages": [ { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "41681f0a-15b4-45ab-afca-d9af35b4d3a1", "contact_id": "14b278db-6db8-448f-a5db-8d6ce46a3451", "phone": "+1234567890", "phone_international": "+1 234-567-890", "region_code": "US", "template_id": null, "template_name": null, "template_category": null, "channel": "sms", "message_body": null, "status": "DELIVERED", "direction": "OUTBOUND", "created_at": "2026-11-12T15:27:26.7763258+00:00", "price": 0.0075, "active_contact_price": 0, "events": null, "reason_code": null, "reason": null } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7763605+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_005", "message": "Page must be greater than 0", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7763628+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7763631+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/conversations # GET /v3/conversations List conversation messages Retrieves a paginated list of the authenticated customer's messages across all conversations, ordered by created date (most recent first). **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ConversationsGetConversationsEndpoint` **Tags:** Conversations ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | - | | `page_size` | `integer` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Messages retrieved successfully #### application/json ```typescript { success?: boolean, data?: { messages?: Array<{ id?: string, customer_id?: string, contact_id?: string, phone?: string, phone_international?: string, region_code?: string, template_id?: string, template_name?: string, template_category?: string, channel?: string, message_body?: { header?: string, content?: string, footer?: string, buttons?: Array<{ type?: string, text?: string, value?: string, postbackData?: string }>, subject?: string, media?: Array<{ url?: string, mediaType?: string, mimeType?: string, sizeBytes?: integer, sourceHashSha256?: string }>, headerMedia?: { type?: string, url?: string } }, status?: string, direction?: string, created_at?: string, price?: number, active_contact_price?: number, events?: Array<{ status: string, timestamp: string, description?: string, reason_code?: string, reason?: string }>, reason_code?: string, reason?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "messages": [ { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "41681f0a-15b4-45ab-afca-d9af35b4d3a1", "contact_id": "14b278db-6db8-448f-a5db-8d6ce46a3451", "phone": "+1234567890", "phone_international": "+1 234-567-890", "region_code": "US", "template_id": null, "template_name": null, "template_category": null, "channel": "sms", "message_body": null, "status": "DELIVERED", "direction": "OUTBOUND", "created_at": "2026-11-12T15:27:26.7774385+00:00", "price": 0.0075, "active_contact_price": 0, "events": null, "reason_code": null, "reason": null } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7774401+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_005", "message": "Page must be greater than 0", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7774417+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.777442+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # Data Models (/reference/api/data-models.md) # Data Models [#data-models] Every Sent API v3 response uses the same JSON envelope. This page documents the shared structures: the response envelope, its error and metadata objects, and the pagination metadata returned by list endpoints. Request and response schemas for individual resources are generated from the OpenAPI specification and rendered on each endpoint page. See [Resource schemas](#resource-schemas). **Naming Convention:** The API v3 uses `snake_case` for all JSON property names (for example, `phone_number`, `created_at`). --- ## Response Envelope [#response-envelope] All v3 endpoints return the standard `ApiResponse` envelope: | Field | Type | Description | |-------|------|-------------| | `success` | boolean | `true` when the request succeeded, `false` when it failed | | `data` | object | The response data. Omitted from error responses | | `error` | [ApiError](#apierror) | Error details. Omitted from successful responses | | `meta` | [ApiMeta](#apimeta) | Metadata about the request and response | ### Example Success Response [#example-success-response] ```json { "success": true, "data": { "id": "0b9df168-9917-4b1e-bc5d-9cee5d2ce2d2", "phone_number": "+15551234567", "created_at": "2026-01-15T10:30:00Z" }, "meta": { "request_id": "req_abc123", "timestamp": "2026-01-15T10:30:00Z", "version": "v3" } } ``` ### Example Error Response [#example-error-response] ```json { "success": false, "status": 404, "error": { "code": "RESOURCE_001", "message": "Contact not found", "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_def456", "timestamp": "2026-01-15T10:30:00Z", "version": "v3" } } ``` [Error Handling](/reference/api/errors) documents HTTP status codes and error response semantics; the [Error Catalog](/reference/api/error-catalog) enumerates every error code with causes and remediation. ### ApiError [#apierror] | Field | Type | Description | |-------|------|-------------| | `code` | string | Machine-readable error code (for example, `RESOURCE_001`) | | `message` | string | Human-readable error message | | `details` | object | Field-level validation errors: a map of field name to an array of error messages. Omitted when unset | | `doc_url` | string | URL to documentation about this error. Omitted when unset | ### ApiMeta [#apimeta] | Field | Type | Description | |-------|------|-------------| | `request_id` | string | Unique identifier for this request, for tracing and support | | `timestamp` | string (date-time) | Server timestamp when the response was generated | | `version` | string | API version used for this request (`v3`) | --- ## Paginated List Responses [#paginated-list-responses] Paginated list endpoints return the items array and a `pagination` object inside `data`. The array property is named after the resource: | Endpoint | Array property | |----------|----------------| | [`GET /v3/contacts`](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsGetContactsEndpoint) | `contacts` | | [`GET /v3/templates`](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesGetTemplatesEndpoint) | `templates` | | [`GET /v3/webhooks`](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhooksEndpoint) | `webhooks` | | [`GET /v3/webhooks/{id}/events`](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhookEventsEndpoint) | `events` | | `GET /v3/conversations` | `messages` | | `GET /v3/conversations/{id}` | `messages` | | [`GET /v3/voice/calls`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallsEndpoint) | `calls` | | [`GET /v3/voice/agents`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsGetVoiceAgentsEndpoint) | `agents` | Paginated endpoints accept the `page` query parameter (1-indexed, default `1`) and the `page_size` query parameter (default `20`, range 1–100). ### Example Paginated Response [#example-paginated-response] ```json { "success": true, "data": { "contacts": [ { "id": "0b9df168-9917-4b1e-bc5d-9cee5d2ce2d2", "phone_number": "+15551234567" } ], "pagination": { "page": 1, "page_size": 20, "total_count": 42, "total_pages": 3, "has_more": true, "cursors": null } }, "meta": { "request_id": "req_abc123", "timestamp": "2026-01-15T10:30:00Z", "version": "v3" } } ``` ### PaginationMeta [#paginationmeta] | Field | Type | Description | |-------|------|-------------| | `page` | integer | Current page number (1-indexed) | | `page_size` | integer | Number of items per page | | `total_count` | integer | Total number of items across all pages | | `total_pages` | integer | Total number of pages | | `has_more` | boolean | Whether there are more pages after this one | | `cursors` | [PaginationCursors](#paginationcursors) \| null | Optional cursor pagination pointers. `null` when the response is paginated by page number only | ### PaginationCursors [#paginationcursors] | Field | Type | Description | |-------|------|-------------| | `after` | string \| null | Cursor to fetch the next page | | `before` | string \| null | Cursor to fetch the previous page | --- ## Resource Schemas [#resource-schemas] Request and response schemas for each resource are generated from the OpenAPI specification and rendered on the endpoint pages. Each mutation endpoint page documents its own request body; the pages below document the full response model for each resource: | Resource | Response model | Documented on | |----------|----------------|---------------| | Contacts | `ContactResponse` | [Get contact by ID](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsGetContactByIdEndpoint) | | Messages | `MessageResponse` | [Get message status](/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesGetMessageEndpoint) | | Templates | `TemplateResponse` | [Get template by ID](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesGetTemplateEndpoint) | | Profiles | `ProfileDetailResponse` | [Get profile by ID](/reference/api/profiles/SentDmServicesEndpointsCustomerAPIv3ProfilesGetProfileEndpoint) | | Webhooks | `WebhookV3Response` | [Get a webhook](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhookEndpoint) | | Brand campaigns | `BrandCampaignV3Response` | [Get campaigns for a profile's brand](/reference/api/brands/SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsGetBrandCampaignsEndpoint) | | Users | `UserResponse` | [Get user by ID](/reference/api/users/SentDmServicesEndpointsCustomerAPIv3UsersGetUserEndpoint) | | Account | `AccountResponse` | [Get authenticated account](/reference/api/accounts/SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint) | | Number lookup | `NumberLookupResultResponse` | [Get phone number details](/reference/api/number-lookup/SentDmServicesEndpointsCustomerAPIv3NumbersGetNumberEndpoint) | ### Message Status Values [#message-status-values] The generated schema types the `status` field on `MessageResponse` as a plain string, so the endpoint page does not enumerate its values. `QUEUED`, `ROUTED`, `SENT`, `DELIVERED`, `READ`, and `FAILED` cover the outbound lifecycle, and `RECEIVED` marks an inbound message from a contact. Four more statuses describe a send that was held, called off, or suppressed: - `SCHEDULED`: the send is held for a future instant, either a `scheduled_at` you set or the end of the recipient's quiet hours. Sent releases the message automatically once that instant arrives and it continues through the normal send path, so `SCHEDULED` is not terminal. - `CANCELLED`: you called a held send off with `POST /v3/messages/{id}/cancel` before it was released. Reachable only from `SCHEDULED`, terminal, and never sent. See [Cancelling scheduled messages](/start/guides/cancelling-messages). - `FILTERED`: a policy gate suppressed the send before any provider call, either because the recipient opted out or is on your phone-channel suppression list, or because your routing rules denied it. - `BLOCKED`: an account-level precondition stopped the send before policy evaluation, for example an insufficient balance, an unmet onboarding entitlement, or a template that is not approved for sending. `FILTERED`, `BLOCKED`, and `CANCELLED` are policy or customer outcomes rather than delivery failures, so all three are excluded from your deliverability rate. Only `FAILED` counts against it. A message that is or was held reports its instant in `scheduled_at`, which `GET /v3/messages/{id}` returns alongside the base `MessageResponse` fields, and which `message.scheduled` and `message.cancelled` also carry. On a `CANCELLED` message it is the instant that was called off. Each of the preceding statuses has a matching webhook sub-type. `PROCESSED`, which a message reports for the short interval between acceptance and routing, is the one status without a sub-type, so status webhooks never carry it. See [Event Types](/start/webhooks/event-types) for the full status catalog and the payload shape of each event. # Error Catalog (/reference/api/error-catalog.md) # Error Catalog [#error-catalog] This catalog is the canonical reference for Sent API v3 error codes. Every documented code appears below with its cause and step-by-step remediation; other documentation pages link to this catalog rather than restating code details. The same codes also explain outcomes that happen after a request succeeds. A message that ends `FAILED`, `FILTERED` or `BLOCKED` reports why as `reason_code` and `reason`, and so does a channel that is not `ACTIVE`. A cause the API rejects synchronously keeps its code there: an opted-out recipient is `BUSINESS_004` on a refused request and on a filtered message alike. Codes only an outcome can have are listed under [Message Outcome Codes](#message-outcome-codes) and [Channel Status Reasons](#channel-status-reasons). A phone call that ends without completing reports why as `failure_reason`; those values are under [Call Failure Reasons](#call-failure-reasons). Branch on `reason_code`; the wording of `reason` may improve, but a code never changes meaning. --- ## Authentication Errors [#authentication-errors] ### AUTH_001: User is not authenticated [#auth_001-user-is-not-authenticated] **Error Message:** "User is not authenticated" **HTTP Status:** 401 Unauthorized **Cause:** The request reached an endpoint without an authenticated identity, for a reason other than the API key. A request with no API key, or an unrecognized one, returns [AUTH_002](#auth_002-invalid-or-missing-api-key) instead, whichever header it used. On v3 you see AUTH_001 when the voice token on an in-app calling request is invalid or expired, and as the fallback code for any other `401`. **Remediation:** 1. If the message is `Invalid or expired voice token`, mint a new voice token on your backend and retry. See [In-app calls](/start/guides/in-app-calls#mint-a-voice-token) 2. If you expected your API key to authenticate the request, check `error.code`: a key problem is reported as `AUTH_002`, so follow its remediation below --- ### AUTH_002: Invalid or missing API key [#auth_002-invalid-or-missing-api-key] **Error Message:** "Invalid or missing API key" **HTTP Status:** 401 Unauthorized **Cause:** The request carries no API key in either header, or the key it carries is invalid, revoked, or not recognized. **Remediation:** 1. Send the API key on every request, in the `x-api-key` header or as `Authorization: Bearer `. Any other `Authorization` scheme counts as no key 2. Verify your API key is correct and complete 3. Check that you're using the API key for the correct environment (each environment should have its own key) 4. Log into your [Sent Dashboard](https://app.sent.dm) and verify the key is active 5. Generate a new API key if the current one was revoked **Example Fix:** ```bash # ❌ Missing key curl -X GET https://api.sent.dm/v3/me # ✅ Correct curl -X GET https://api.sent.dm/v3/me \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # ✅ Also correct curl -X GET https://api.sent.dm/v3/me \ -H "Authorization: Bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ``` --- ### AUTH_004: Insufficient permissions [#auth_004-insufficient-permissions] **Error Message:** "Insufficient permissions for this operation" **HTTP Status:** 403 Forbidden **Cause:** Your user role doesn't have permission to perform this operation. **Remediation:** 1. Check your organization role (`owner`, `admin`, `developer`, `billing`) 2. Contact your organization owner to request additional permissions 3. Some operations require the `owner` or `admin` role **See:** [Roles and Permissions](/reference/api/roles-and-permissions) for the operations each role can perform and how to look up your own role --- ### AUTH_005: Account not yet activated [#auth_005-account-not-yet-activated] **Error Message:** "Your account is not yet activated. Please wait for account activation before using the API." **HTTP Status:** 403 Forbidden **Cause:** The API key is valid and channel setup is complete, but the account is still pending final activation by Sent. **Remediation:** 1. You have completed all required setup steps, so no action is needed from your side 2. Wait for the activation confirmation email from Sent 3. Contact [support@sent.dm](mailto:support@sent.dm) if activation takes longer than expected --- ### AUTH_006: KYC verification not complete [#auth_006-kyc-verification-not-complete] **Error Message:** "Your KYC verification is not complete. Please submit your KYC documents before using the API." **HTTP Status:** 403 Forbidden **Cause:** The API key is valid but the account has not completed KYC verification. Applies to accounts in status: `SIGNED_UP`, `KYC_STARTED`, `WHITELISTED`, `ONBOARDING_STARTED`, or `KYC_RESUBMISSION_REQUESTED`. **Remediation:** 1. Log into your [Sent Dashboard](https://app.sent.dm) and complete the KYC verification flow 2. If resubmission was requested, address the flagged items and resubmit your documents 3. Contact [support@sent.dm](mailto:support@sent.dm) if you need assistance with KYC --- ### AUTH_007: Channel setup not complete [#auth_007-channel-setup-not-complete] **Error Message:** "Your channel setup is not complete. Please configure at least one messaging channel before using the API." **HTTP Status:** 403 Forbidden **Cause:** The API key is valid and KYC is approved, but no messaging channel (SMS or WhatsApp) has been configured. Applies to accounts in status: `KYC_COMPLETED` or `MESSAGE_COMPLIANCE_COMPLETED`. **Remediation:** 1. Log into your [Sent Dashboard](https://app.sent.dm) and complete channel setup 2. Configure at least one SMS or WhatsApp sender 3. See [Channel Setup](/start/quickstart/channel-setup) for step-by-step instructions --- ## Validation Errors [#validation-errors] ### VALIDATION_001: Request validation failed [#validation_001-request-validation-failed] **Error Message:** "Request validation failed" **HTTP Status:** 400 Bad Request. Also returned with: - `413 Payload Too Large` and the message "Request body is too large" when the request body exceeds the endpoint's size limit. - `422 Unprocessable Entity` from `POST /v3/sender-profiles` and `POST /v3/channels/sms` when a compliance document the market requires was not uploaded, or an uploaded file was rejected. `details` names each affected document or file. **Cause:** The request body or parameters failed validation. Check the `details` field for specific field-level errors. **Remediation:** 1. Review the `error.details` object for field-specific error messages 2. Ensure all required fields are provided 3. Verify data types match the schema (for example, strings vs numbers) **Example:** ```json { "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "to": ["'to' must contain at least one recipient"], "template": ["'template' must have either 'id' (non-empty GUID) or 'name' (non-empty string)"] } } } ``` --- ### VALIDATION_002: Invalid phone number format [#validation_002-invalid-phone-number-format] **Error Message:** "Invalid phone number format" **HTTP Status:** 400 Bad Request **Cause:** The phone number is not in a valid format. **Remediation:** 1. Use E.164 format: `+1234567890` 2. Include the country code (for example, `+1` for US) 3. Remove any non-numeric characters except the leading `+` **Valid Examples:** - `+1234567890` (US) - `+447911123456` (UK) - `+919876543210` (India) --- ### VALIDATION_003: Invalid GUID format [#validation_003-invalid-guid-format] **Error Message:** "Invalid GUID format" **HTTP Status:** 400 Bad Request **Cause:** A UUID field contains an invalid format. **Remediation:** 1. Ensure UUIDs follow the format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` 2. Verify the UUID is complete (36 characters including hyphens) 3. Check that you're not passing an empty string or null **Valid Example:** `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` --- ### VALIDATION_004: Required field is missing [#validation_004-required-field-is-missing] **Error Message:** "Required field is missing" **HTTP Status:** 400 Bad Request **Cause:** A required field is not present in the request body. **Remediation:** 1. Check the API documentation for required fields 2. Ensure the field name is spelled correctly (snake_case) 3. Verify the field is not null or undefined --- ### VALIDATION_005: Field value out of valid range [#validation_005-field-value-out-of-valid-range] **Error Message:** "Field value out of valid range" **HTTP Status:** 400 Bad Request **Cause:** A numeric field value is outside the allowed minimum/maximum range. **Remediation:** 1. Check the API documentation for valid ranges 2. For `retry_count`: must be between 1 and 5 3. For `timeout_seconds`: must be between 5 and 120 4. Ensure integer values are not negative where prohibited **Example:** ```json { "error": { "code": "VALIDATION_005", "message": "Field value out of valid range", "details": { "retry_count": ["Value must be between 1 and 5"] } } } ``` --- ### VALIDATION_006: Invalid enum value [#validation_006-invalid-enum-value] **Error Message:** "Invalid enum value" **HTTP Status:** 400 Bad Request **Cause:** A field value is not one of the allowed enum values. **Remediation:** 1. Check the API documentation for allowed values 2. Verify the value matches exactly (case-sensitive) 3. Common enums: channel (`sent`, `sms`, `whatsapp`, `rcs`), template category (`MARKETING`, `UTILITY`, `AUTHENTICATION`) An unrecognized channel is rejected rather than ignored, and the error message lists the accepted values. `sent` is the auto-detect value; see [Channel routing](/reference/channel-routing). --- ### VALIDATION_008: Invalid template variable value [#validation_008-invalid-template-variable-value] **Error Message:** varies by cause (see below) **HTTP Status:** 400 Bad Request. Also reported as the `reason_code` of a `FAILED` message, when variables are found missing or invalid after the send was accepted with `202`. **Cause:** A supplied template variable value is rejected before the message is accepted. Three distinct causes share this code, and the message tells you which one applies: | Message | Cause | | --- | --- | | `Variable '{name}' does not match the required pattern.` | The value fails the variable's configured validation pattern. | | `Variable '{name}' is invalid: param text cannot have new-line/tab characters or more than 4 consecutive spaces.` | The value contains a newline, carriage return, or tab, or more than four consecutive spaces. | | `Template variables cannot be empty for WhatsApp: {names}` | One or more variables were supplied with a blank value on a WhatsApp-only send. | **Remediation:** 1. Read the variable name from the error message. It names every offending variable, so you can fix them in one pass rather than one send at a time. 2. For a pattern mismatch, check the variable's pattern on the template and confirm the value matches it. 3. For invalid text, strip newlines, carriage returns, and tabs from the value, and collapse any run of more than four spaces. These are rejected because WhatsApp does not accept them in a parameter. The rule applies to template variables only: free-form `text` keeps its line breaks, tabs, and spacing on every channel. 4. For an empty value on WhatsApp, supply a non-empty value or omit the variable if the template does not require it. WhatsApp rejects a text parameter with no text, so the send can never succeed. The empty-value rule applies only when the send is pinned to WhatsApp. On an auto-detect send (`channel` omitted) the same value is accepted, because the message can still route over another channel. --- ### VALIDATION_011: Voice identity is invalid [#validation_011-voice-identity-is-invalid] **Error Message:** "Voice identity is invalid" **HTTP Status:** 400 Bad Request **Cause:** An app user's identity is empty, longer than 200 characters, or contains something other than letters, digits, `-` and `_`. It is checked on `identity` of `POST /v3/voice/tokens` and on `to.value` of `POST /v3/voice/calls/{id}/participants` when `to.kind` is `user`. The identity names the user in every call, so only characters that survive a URL and a token unchanged are accepted. **Remediation:** 1. Read `error.details` for the field at fault. 2. Use your own stable user id, such as `agent-42`, with letters, digits, hyphens, and underscores only. 3. Keep it to 200 characters or fewer. --- ## Resource Errors [#resource-errors] ### RESOURCE_001: Contact not found [#resource_001-contact-not-found] **Error Message:** "Contact not found" **HTTP Status:** 404 Not Found **Cause:** The specified contact ID doesn't exist or doesn't belong to your account. **Remediation:** 1. Verify the contact ID is correct 2. List all contacts to find the correct ID: `GET /v3/contacts` 3. Check that you're using the correct API key for the account that owns the contact **Debug Steps:** ```bash # List contacts to find valid IDs curl -X GET https://api.sent.dm/v3/contacts \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ``` --- ### RESOURCE_002: Template not found [#resource_002-template-not-found] **Error Message:** "Template not found" **HTTP Status:** 404 Not Found **Cause:** The specified template ID doesn't exist. **Remediation:** 1. Verify the template ID is correct 2. List all templates: `GET /v3/templates` 3. Ensure the template hasn't been deleted --- ### RESOURCE_003: Message not found [#resource_003-message-not-found] **Error Message:** "Message not found" **HTTP Status:** 404 Not Found **Cause:** The specified message ID doesn't exist. **Remediation:** 1. Verify the message ID is correct 2. Note that message IDs are only available after sending 3. Messages may be purged after retention period 4. A message ID that belongs to another account also returns this error rather than `403`, so the response does not reveal whether the ID exists --- ### RESOURCE_004: Customer not found [#resource_004-customer-not-found] **Error Message:** "Customer not found" **HTTP Status:** 404 Not Found **Cause:** The specified customer ID doesn't exist or is not accessible. **Remediation:** 1. Verify the customer ID is correct 2. Check that your API key has access to this customer 3. Contact support if the customer should exist --- ### RESOURCE_005: Organization not found [#resource_005-organization-not-found] **Error Message:** "Organization not found" **HTTP Status:** 404 Not Found **Cause:** The specified organization ID doesn't exist or you don't have access. **Remediation:** 1. Verify the organization ID is correct 2. Ensure you're using an organization-level API key 3. Check that your account is a member of the organization --- ### RESOURCE_006: User not found [#resource_006-user-not-found] **Error Message:** "User not found" **HTTP Status:** 404 Not Found **Cause:** The specified user ID doesn't exist in your organization. **Remediation:** 1. Verify the user ID is correct 2. List organization users to find valid IDs 3. The user may have been removed from the organization --- ### RESOURCE_007: Resource already exists [#resource_007-resource-already-exists] **Error Message:** "Resource already exists" **HTTP Status:** 409 Conflict **Cause:** Attempting to create a resource that already exists (for example, a duplicate contact). **Remediation:** 1. Check if the resource already exists using a list or get endpoint 2. Update the existing resource instead of creating 3. Use a unique identifier for your idempotency key --- ### RESOURCE_008: Webhook not found [#resource_008-webhook-not-found] **Error Message:** "Webhook not found" **HTTP Status:** 404 Not Found **Cause:** The specified webhook ID doesn't exist. **Remediation:** 1. Verify the webhook ID is correct 2. List all webhooks: `GET /v3/webhooks` 3. Check if the webhook was deleted --- ### RESOURCE_009: Brand not found [#resource_009-brand-not-found] **Error Message:** "Brand not found for this profile" **HTTP Status:** 404 Not Found **Cause:** No 10DLC brand is registered for the profile, and none is inherited from its organization. **Remediation:** 1. Register the brand first; see the [10DLC Registration Guide](/start/advanced/10dlc-registration) 2. Confirm you are targeting the right profile with `GET /v3/profiles` --- ### RESOURCE_010: Campaign not found [#resource_010-campaign-not-found] **Error Message:** "Campaign not found for this profile" **HTTP Status:** 404 Not Found **Cause:** The specified campaign ID doesn't belong to this profile's brand. **Remediation:** 1. List the profile's campaigns and reuse the returned `id` 2. Verify the campaign belongs to the brand registered for this profile --- ### RESOURCE_011: Batch not found [#resource_011-batch-not-found] **Error Message:** "Batch not found" **HTTP Status:** 404 Not Found **Cause:** The specified batch SMS operation doesn't exist. **Remediation:** 1. Verify the batch ID is correct 2. Check whether the batch has expired or was already processed --- ### RESOURCE_012: Phone number not found [#resource_012-phone-number-not-found] **Error Message:** "Phone number not found" **HTTP Status:** 404 Not Found **Cause:** The specified phone number isn't provisioned on your account. **Remediation:** 1. List your numbers to confirm the exact value 2. Use E.164 format (for example, `+14155550123`) --- ### RESOURCE_013: Resource not found [#resource_013-resource-not-found] **Error Message:** "Resource not found" **HTTP Status:** 404 Not Found **Cause:** Generic not-found fallback, returned when no more specific code applies. **Remediation:** 1. Verify the resource ID in the request path 2. Check the endpoint path is correct for the resource type --- ### RESOURCE_014: Profile not found [#resource_014-profile-not-found] **Error Message:** "Profile not found" **HTTP Status:** 404 Not Found **Cause:** The specified `profileId` isn't a child profile of your organization. Passing your organization's own ID also fails. **Remediation:** 1. Use a profile ID returned by `GET /v3/profiles` 2. Confirm the profile belongs to your organization --- ### RESOURCE_015: Call not found [#resource_015-call-not-found] **Error Message:** "Call not found" **HTTP Status:** 404 Not Found **Cause:** No call with this id belongs to your account. A call that belongs to another account is reported as not found rather than forbidden, so an id never reveals whether it exists. **Remediation:** 1. Use the id from the `call.request` question, a `call.*` webhook, or `GET /v3/voice/calls`. It has the form `call_` followed by a GUID. 2. Send the request with the API key of the account the call belongs to. --- ### RESOURCE_017: Participant not found [#resource_017-participant-not-found] **Error Message:** "Participant not found" **HTTP Status:** 404 Not Found **Cause:** The `participantId` on `PATCH` or `DELETE /v3/voice/calls/{id}/participants/{participantId}` is not a live participant of this call's conference room. A participant in another room or another account answers the same way, and so does one who has already left. **Remediation:** 1. List the room with `GET /v3/voice/calls/{id}/participants` and use an `id` from that list. 2. Treat a `404` on remove as done: the participant is no longer in the room. --- ## Business Logic Errors [#business-logic-errors] ### BUSINESS_002: Rate limit exceeded [#business_002-rate-limit-exceeded] **Error Message:** "Rate limit exceeded" **HTTP Status:** 429 Too Many Requests **Cause:** You've exceeded the allowed number of requests per minute. **Remediation:** 1. Check the `Retry-After` header for wait time 2. Implement exponential backoff in your code 3. Consider using webhooks instead of polling 4. Contact support if you need higher limits **See:** [Rate Limits Documentation](/reference/api/rate-limits) --- ### BUSINESS_003: Insufficient account balance [#business_003-insufficient-account-balance] **Error Message:** "Insufficient balance" **HTTP Status:** 402 Payment Required **Cause:** Your account doesn't have enough credit to complete the operation. **Note:** `POST /v3/messages` does not return this error. Sends are accepted with `202`; when the balance is insufficient, each message is finalized asynchronously as `BLOCKED` with `reason_code: "BUSINESS_003"` and clears after a top-up. Legacy v2 send endpoints reject an out-of-balance request synchronously with this error. **Remediation:** 1. Check your current balance and add funds in [Billing → Overview](https://app.sent.dm/dashboard/billing) (the balance is not exposed through the API) 2. Review pricing for the operation you're attempting --- ### BUSINESS_004: Contact has opted out [#business_004-contact-has-opted-out] **Error Message:** "Contact has opted out of messaging" **HTTP Status:** 400 Bad Request **Cause:** An operation targeted a contact that has opted out of messaging. **Note:** `POST /v3/messages` does not return this error. Sends are accepted with `202` regardless of recipient opt-out state, and each consent-blocked message is finalized asynchronously as `FILTERED` with `reason_code: "BUSINESS_004"` (see `ERR_CONSENT_BLOCKED` below). **Remediation:** 1. Inspect the affected contacts via `GET /v3/contacts/{id}` and confirm their `opt_out` status. 2. Remove opted-out contacts from your messaging lists. 3. Re-engagement requires the contact to opt back in through a STOP/START style flow or via an `opt_out: false` update to the contact (where you have a verifiable record of new consent). --- ### ERR_CONSENT_BLOCKED: Per-message consent block [#err_consent_blocked-per-message-consent-block] **Where it surfaces:** - `GET /v3/messages/{id}`: `status = FILTERED`, with `reason_code: "BUSINESS_004"` - `GET /v3/messages/{id}/activities`: a `FILTERED` activity carrying the same `reason_code` and `reason` - The `message.filtered` webhook event, with `payload.reason_code: "BUSINESS_004"` `ERR_CONSENT_BLOCKED` itself is the internal classification and never appears in a response or payload. What you see is `BUSINESS_004`, the same code an opted-out contact returns elsewhere in the API. A `FILTERED` message whose `reason_code` is `DELIVERY_004` was stopped by a routing rule rather than by consent. **Cause:** The send-time consent policy refused this individual message because the recipient's contact has `opt_out = true` or their phone is on the customer's phone-channel suppression list. The check runs pre-routing, so no provider call is made and the customer is not charged. **Remediation:** 1. Stop targeting this contact until they re-confirm consent. 2. If the opt-out is incorrect (for example, test data), update the contact's `opt_out` field through `PATCH /v3/contacts/{id}`. Only do this when you have a verifiable record of renewed consent. 3. For phone-level suppression entries that should be removed, contact support. --- ### BUSINESS_005: Template not approved [#business_005-template-not-approved] **Error Message:** "Template not approved for sending" **HTTP Status:** 400 Bad Request **Cause:** The WhatsApp template hasn't been approved yet. **Remediation:** 1. Check template status: `GET /v3/templates/{id}` 2. Wait for WhatsApp/Meta approval (typically 24-48 hours) 3. For urgent needs, use SMS channel instead 4. Review template guidelines to ensure approval --- ### BUSINESS_006: Message cannot be cancelled in its current state [#business_006-message-cannot-be-cancelled-in-its-current-state] **Error Messages:** | Message | Cause | |---|---| | `Only a scheduled message can be cancelled. This message has already been released for sending, is in flight, or has finished.` | `POST /v3/messages/{id}/cancel` targeted a message that is not `SCHEDULED`. | **HTTP Status:** 409 Conflict **Cause:** A resend or cancel targeted a message whose current state doesn't allow it. **Remediation:** 1. For a `FILTERED` message, don't retry the resend; a `FILTERED` message is always refused. Check its `reason_code` with `GET /v3/messages/{id}` to see why it was filtered. 2. For a message still in flight, held for quiet hours, or sent less than 15 minutes ago, wait and retry the resend later. 3. On cancel, only a message that is currently `SCHEDULED` can be cancelled. Read the current status with `GET /v3/messages/{id}`: a message that has left `SCHEDULED` never returns to it, so retrying returns the same error. See [Cancelling scheduled messages](/start/guides/cancelling-messages). 4. Send a new message with `POST /v3/messages` if you need to make changes. --- ### BUSINESS_007: Channel not available [#business_007-channel-not-available] **Error Message:** "Sending from \{COUNTRY\} as \{type\} is not available yet. Contact support if you expected it to be." **HTTP Status:** 503 Service Unavailable, from `GET /v3/compliance/requirements`. Also reported as the `reason_code` of a `FAILED` message. **Cause:** - On `GET /v3/compliance/requirements`: the requested country and number type market is not available yet. - On a message: the send needed MMS, and MMS is not enabled for the account. **Remediation:** 1. For the compliance requirements request, contact support if you expected the market to be available. 2. For a message, contact [support@sent.dm](mailto:support@sent.dm) to enable MMS on the account. See [Sending MMS](/start/guides/mms). --- ### BUSINESS_008: Operation would exceed quota [#business_008-operation-would-exceed-quota] **Error Message:** "Operation would exceed quota" **HTTP Status:** 400 Bad Request **Cause:** The operation would exceed your account's quota limits, such as those for messages, contacts, or templates. **Remediation:** 1. Check your current usage in the [Dashboard](https://app.sent.dm) 2. Upgrade your plan to increase quotas 3. Delete unused resources to free up quota 4. Contact support for temporary quota increases --- ### BUSINESS_009: Feature not supported [#business_009-feature-not-supported] **Error Message:** "Compliance requirements for the \{channel\} channel are not published yet. Only `"sms"` is available here." **HTTP Status:** 501 Not Implemented, from `GET /v3/compliance/requirements`. Also reported as the `reason_code` of a `FAILED` message. **Cause:** - On `GET /v3/compliance/requirements`: `channel` was set to a channel other than `sms`. Only SMS has published compliance requirements. - On a message: the channel does not support this kind of message; the message type or operation is not available for this sender or destination. **Remediation:** 1. For the compliance requirements request, omit `channel` or set it to `sms`. 2. For a message, read its `reason` for the likely cause, and send the content on a channel or sender that supports it. --- ### BUSINESS_010: Webhook is inactive [#business_010-webhook-is-inactive] **Error Message:** "Webhook is inactive" **HTTP Status:** 400 Bad Request **Cause:** The operation targets a webhook that is not active. Sending a test event to an inactive webhook returns this code. A webhook can be inactive because you turned it off, or because Sent turned it off automatically after repeated delivery failures. **Remediation:** 1. Check the webhook's status on the **Webhooks** page in the [Dashboard](https://app.sent.dm). 2. If Sent turned it off automatically, fix the endpoint first: confirm it is reachable and returns a 2xx within the timeout. Then turn the webhook back on. Turning it back on without fixing the endpoint will lead to Sent turning it off again. 3. Re-send the test event once the webhook is active. --- ### BUSINESS_011: Destination country is not allowed [#business_011-destination-country-is-not-allowed] **Error Message:** "Calls and messages to the destination country are not allowed" **HTTP Status:** 400 Bad Request, from `POST /v3/voice/calls/{id}/participants`. Also reported as the `reason_code` of a `FAILED` message. **Cause:** - On a call, the phone participant's number is in a country Sent does not allow calls to. A `connectToNumber` answer to such a destination is an invalid answer, reported as `destination_blocked` by the test endpoint, and the call fails with `invalid_answer`. A call placed from your app straight to such a number is refused before your callback is asked and fails with `destination_blocked`. - On a message, WhatsApp refused it because the WhatsApp business account is restricted from messaging recipients in the destination country. **Remediation:** 1. Check the destination number and its country code. 2. For a message, check the business account's restrictions in WhatsApp Business Manager. 3. Contact [support@sent.dm](mailto:support@sent.dm) if you expected the destination country to be allowed. --- ### BUSINESS_012: Template is not active on the requested channel [#business_012-template-is-not-active-on-the-requested-channel] **Error Message:** "This template is not active on the requested channel" **HTTP Status:** 400 Bad Request **Cause:** The template exists and is approved, but not on the channel this send is pinned to. Template approval is per channel, so a template approved for SMS is not automatically usable on WhatsApp. **Remediation:** 1. Check the template's per-channel status with `GET /v3/templates/{id}`. 2. Send on a channel where the template is active, or omit `channel` to let Sent choose one that is. 3. If you need the template on that channel, submit it for approval there and wait for it to be approved. This is distinct from [BUSINESS_005](#business_005-template-not-approved), which means the template is not approved anywhere. BUSINESS_012 means it is approved, but not on the channel you asked for. --- ### WHATSAPP_TEMPLATE_REQUIRED: Free-form WhatsApp outside Meta's window [#whatsapp_template_required-free-form-whatsapp-outside-metas-window] **Error Message:** "Free-form WhatsApp messages are only allowed within 24 hours of the user's latest inbound WhatsApp message. Send an approved template instead." **HTTP Status:** Not returned on an HTTP response. `POST /v3/messages` accepts the batch with `202`, and this code arrives as the terminal `FAILED` status on the individual message. **Cause:** A free-form message (`text` rather than `template`) was sent with `channel: "whatsapp"` while Meta's 24-hour customer-service window was shut. Only an inbound WhatsApp message from the contact opens that window; an outbound template does not. Meta can also reject a send that Sent considered inside the window, returning error `131047` (re-engagement required). Sent surfaces that as this same code, so treat it as one condition with one fix. **Where it surfaces:** the message's terminal status. `GET /v3/messages/{id}` reports `status: "FAILED"` with `reason_code: "WHATSAPP_TEMPLATE_REQUIRED"`, and the `message.failed` webhook carries the same `payload.reason_code` and `payload.reason`. **Remediation:** 1. Send an approved WhatsApp template instead. A template is always accepted, window or no window. 2. Omit `channel` to let Sent choose. An auto-detect send falls back to RCS or SMS when Meta's window is shut, so the message still goes out if the contact is reachable there. 3. Wait for the contact to message you on WhatsApp, which re-opens the window for 24 hours. This is Meta's rule and applies to sends pinned to `channel: "whatsapp"` only. The counterpart for SMS, RCS, and auto-detect is [CONVERSATION_TEMPLATE_REQUIRED](#conversation_template_required-no-open-conversation), which is Sent's own rule and records `BLOCKED` rather than `FAILED`. --- ### CONVERSATION_TEMPLATE_REQUIRED: No open conversation [#conversation_template_required-no-open-conversation] **Error Messages:** | Message | Cause | |---|---| | `No open conversation with this contact. Send an approved template to start one before sending free-form content.` | The contact has never replied and no template was ever sent. | | `This contact has never replied, and the template that opened the conversation is more than 7 days old, so it has lapsed. Send an approved template to start a new one before sending free-form content.` | A template opened the conversation, the contact never replied, and the template is more than 7 days old. | | `Free-form messages are enabled for this account, but they need an active sender and none is active yet. Until one is, send an approved template to start the conversation.` | Sent switched free-form messages on for your account, but the channel has no `ACTIVE` sender yet. | **HTTP Status:** Not returned on an HTTP response. `POST /v3/messages` accepts the batch with `202`, and this code arrives as the terminal `BLOCKED` status on the individual message. The gate runs before routing, so nothing reaches a carrier and the message is excluded from your deliverability rate; it fires `message.blocked`, not `message.failed`. **Cause:** A free-form message (`text` rather than `template`) was sent on SMS, RCS, or with `channel` omitted to a contact who has **never replied**, and either no approved template was ever sent to them or the last one is more than 7 days old. A contact who has replied at any point in the past is never blocked by this gate. Your own free-form messages do not count as templates, and neither leg of a STOP exchange counts as a reply. **Where it surfaces:** the message's terminal status. `GET /v3/messages/{id}` reports `status: "BLOCKED"` with `reason_code: "CONVERSATION_TEMPLATE_REQUIRED"`, and the `message.blocked` webhook carries the same `payload.reason_code` and `payload.reason`. **Remediation:** 1. Send an approved template to open or re-open the conversation. Free-form text is then accepted for 7 days, and indefinitely once the contact replies. 2. Do not retry the same free-form send. It will keep being blocked until a template or a reply from the contact opens the conversation. 3. This only affects contacts who have never replied, so it is most common on cold outreach; see [Conversation Windows](/start/guides/two-way-conversations#conversation-windows). --- ### BUSINESS_014: Account is suspended [#business_014-account-is-suspended] **Error Message:** "This account is suspended" **HTTP Status:** 403 Forbidden **Cause:** The account is suspended and cannot send messages or create templates. A request that changes or deletes a suspended Sender Profile is refused too, even with your organization's key while the organization itself is active. The message then reads "This action is not allowed. Account `{id}` has been suspended." and names the suspended account. **Remediation:** 1. Contact support. A suspension is not something you can clear through the API. 2. Do not retry the request. Every send will return this code until the suspension is lifted, so a retry loop will not recover. --- ### BUSINESS_015: Market not supported [#business_015-market-not-supported] **Error Message:** "This country and number type combination is not available" **HTTP Status:** 422 Unprocessable Entity, from `POST /v3/sender-profiles`. Also reported as the `reason_code` of a `FAILED` message. **Cause:** - On `POST /v3/sender-profiles`: the `channels.sms` block asks for a number type that is not available in the requested country. `details` names the market. Nothing is created. - On a message: messaging to the destination country or region is not supported for this sender. **Remediation:** 1. Choose a different country or number type, or contact support to request the market. --- ### BUSINESS_016: Sender type not supported [#business_016-sender-type-not-supported] **Error Message:** "This number type cannot be provisioned yet" **HTTP Status:** 422 Unprocessable Entity **Cause:** `POST /v3/sender-profiles` asked for a `channels.sms.number_type` that can't be provisioned in any country. `details` lists the number types that can. Nothing is created. **Remediation:** 1. Ask for one of the number types listed in `details`. 2. Omit the `channels.sms` block to create a profile with no sender of its own. It reaches only the countries Sent runs a shared route for, which excludes the US. --- ### BUSINESS_017: WhatsApp business account unavailable [#business_017-whatsapp-business-account-unavailable] **HTTP Status:** Not returned on an HTTP response. Reported as the `reason_code` of a `FAILED` message. **Cause:** The WhatsApp business account cannot send at the moment: WhatsApp has restricted or locked it (for example, over a policy violation), its payment method has a problem, or it is in maintenance. **Remediation:** 1. Check the account's status and payment method in WhatsApp Business Manager. 2. Omit `channel` so auto-detect can send over another channel while WhatsApp is unavailable. --- ### BUSINESS_018: WhatsApp marketing messages disabled [#business_018-whatsapp-marketing-messages-disabled] **HTTP Status:** Not returned on an HTTP response. Reported as the `reason_code` of a `FAILED` message. **Cause:** Marketing sends are switched off for this WhatsApp business account. **Remediation:** 1. Enable marketing messages for the account in WhatsApp Business Manager. 2. Until then, send `UTILITY` or `AUTHENTICATION` templates, or send marketing over another channel. --- ### BUSINESS_019: Sender not configured for the channel [#business_019-sender-not-configured-for-the-channel] **HTTP Status:** Not returned on an HTTP response. Reported as the `reason_code` of a `FAILED` message. **Cause:** The sender is not set up to send on the channel the message was routed to: the number or sender ID is invalid, not enabled for messaging or temporarily unusable; its 10DLC, toll-free or sender ID registration is missing or incomplete; or, on WhatsApp, the business number is not registered or has no approved display name. **Remediation:** 1. Check the channel with `GET /v3/channels`. A market that is not `ACTIVE` carries a `reason_code` saying what it's waiting on (see [Channel Status Reasons](#channel-status-reasons)). 2. Contact [support@sent.dm](mailto:support@sent.dm) with the message ID if the channel reports `ACTIVE`. --- ### BUSINESS_020: Onboarding message limit reached [#business_020-onboarding-message-limit-reached] **HTTP Status:** Not returned on an HTTP response. Reported as the `reason_code` of a `BLOCKED` message. **Cause:** The account has sent as many messages as its current onboarding stage allows. It has finished KYC or channel setup, but not the step after, which lifts the limit. **Remediation:** 1. Complete the next onboarding step in the [Sent Dashboard](https://app.sent.dm). 2. Check the blocked messages with `GET /v3/messages/{id}` once the limit is lifted, and resend any that are still `BLOCKED`. --- ### BUSINESS_022: Phone number is not owned by this account [#business_022-phone-number-is-not-owned-by-this-account] **Error Message:** "Phone number is not owned by this account" **HTTP Status:** 400 Bad Request **Cause:** `POST /v3/channels/voice` named a `number` you do not hold, or `POST /v3/voice/calls/{id}/participants` named a `caller_id` that is not one of your numbers. A `connectToNumber` answer whose `callerId` you do not own is an invalid answer instead, reported as `caller_id_not_owned` by the test endpoint, and the call fails with `invalid_answer`. **Remediation:** 1. List the numbers you hold with `GET /v3/channels`. 2. To take calls on a new number instead, leave `number` out of `POST /v3/channels/voice`, optionally with an `area_code`. 3. For a participant or a `callerId`, use one of your own numbers, or omit the field and the call's owning number is used. --- ### BUSINESS_023: Phone calls are not enabled for this account [#business_023-phone-calls-are-not-enabled-for-this-account] **Error Message:** "Phone calls are not enabled for this account" **HTTP Status:** 403 Forbidden **Cause:** `POST /v3/voice/tokens` or `POST /v3/channels/voice/{number}/test` was called while the account has no active voice number. **Remediation:** 1. Turn calls on for a number with `POST /v3/channels/voice`. See [Voice](/start/guides/managing-channels#voice). --- ### BUSINESS_024: Phone number is not voice-enabled for this account [#business_024-phone-number-is-not-voice-enabled-for-this-account] **Error Message:** "Phone number is not voice-enabled for this account" **HTTP Status:** 400 Bad Request **Cause:** The number is not one of your active voice numbers. `POST /v3/voice/tokens` (for `number`) and `POST /v3/channels/voice/{number}/test` return it for a number that never had calls turned on and for one that was turned off. `POST /v3/channels/voice/{number}/rotate-secret` returns it for a number that never had calls turned on. **Remediation:** 1. List your voice numbers with `GET /v3/channels/voice`. 2. Turn calls on for the number with `POST /v3/channels/voice`, or use a number from the list. --- ### BUSINESS_025: The participant could not be added to the call [#business_025-the-participant-could-not-be-added-to-the-call] **Error Message:** "The participant could not be added to the call" **HTTP Status:** 400 Bad Request **Cause:** `POST /v3/voice/calls/{id}/participants` passed every check on Sent's side, but the request to dial the participant into the room was refused when it was placed. A participant who is busy or does not answer is not this error: by then the request was accepted with `202`, and that outcome arrives later as the participant leg's `call.failed`. **Remediation:** 1. Check the destination number or identity, and that an app user is registered. 2. Retry. Contact [support@sent.dm](mailto:support@sent.dm) with the request ID if it repeats. --- ### BUSINESS_026: Call recording is not available [#business_026-call-recording-is-not-available] **Error Message:** "Call recording is not available" **HTTP Status:** 403 Forbidden **Cause:** `POST /v3/voice/calls/{id}/recordings` was called, to start or to stop, while call recording is not available. An answer that asks for a recording still connects the call, without the recording. **Remediation:** 1. Contact [support@sent.dm](mailto:support@sent.dm) if you need call recording. 2. Until it is available, do not rely on `record: true` or `startRecording` in your answers. --- ### BUSINESS_027: The number could not be set up to receive calls [#business_027-the-number-could-not-be-set-up-to-receive-calls] **Error Message:** "The number could not be set up to receive calls; try again shortly" **HTTP Status:** 502 Bad Gateway **Cause:** `POST /v3/channels/voice` could not attach the number to Sent's voice service, which is what routes a call on it to your callback, or `POST /v3/channels/voice` or `PATCH /v3/channels/voice/{number}` could not move the number to or from the voice agent named in `agent_id`. Nothing was written, so the number is not half on and not half bound. **Remediation:** 1. Repeat the request. Your request was right, and a retry usually succeeds. 2. Contact [support@sent.dm](mailto:support@sent.dm) with the request ID if it keeps failing. --- ### BUSINESS_028: No phone number is available for the requested area [#business_028-no-phone-number-is-available-for-the-requested-area] **Error Message:** "No phone number is available for the requested area; try another area code" **HTTP Status:** 409 Conflict **Cause:** `POST /v3/channels/voice` without `number` asked for a new number, and none could be had for the country and `area_code`. Nothing was bought and nothing was charged. **Remediation:** 1. Try another `area_code`. 2. Omit `area_code` to take a number from anywhere in the country. --- ### BUSINESS_029: Requested sender is not available on this account [#business_029-requested-sender-is-not-available-on-this-account] **Error Message:** "One of the numbers in the channels 'from' list is not a valid sender for that channel" **HTTP Status:** Not returned on an HTTP response. Reported as the `reason_code` of a `BLOCKED` message. **Cause:** A `POST /v3/messages` request listed a number in a `channels.sms` entry's `from` that is not an active SMS number on your account. The number may have been released, may belong to another account, or may never have existed; the reason does not say which. The message's `reason` names the number by its position, for example `channels.sms[0].from[1] is not a valid sms sender.` The whole message is blocked, nothing is sent from the other listed numbers, and nothing is charged. **Remediation:** 1. Check the number at that position against your active SMS numbers in `GET /v3/channels/sms`. 2. Remove or replace it, and send the message again. --- ### BUSINESS_030: Template is protected and cannot be deleted [#business_030-template-is-protected-and-cannot-be-deleted] **Error Message:** "Auto-reply (OPT_OUT) templates are required for TCPA compliance and cannot be deleted" or "This template is read-only. It becomes editable after WhatsApp approval" **HTTP Status:** 400 Bad Request **Cause:** The template is one of the account's OPT_IN, OPT_OUT, or HELP auto-reply templates, which answer the consent keywords TCPA requires and which every account must keep, or it is a LOB template that stays read-only until WhatsApp approves it. The request was well-formed and the template exists. The MCP `templates.delete` tool returns the same code, and `templates.list` reports `canDelete: false` on every template this applies to. **Remediation:** 1. Leave the primary OPT_IN, OPT_OUT, and HELP templates in place. Edit their text instead of deleting them. 2. For a LOB template, wait for WhatsApp approval, then edit or delete it. --- ### LIMIT_001: Scheduled message limit exceeded [#limit_001-scheduled-message-limit-exceeded] **Error Message:** "Scheduled message limit exceeded" **HTTP Status:** 429 Too Many Requests **Cause:** Accepting the request would push the account's outstanding scheduled messages past the 1,000,000-message cap. This limit applies to messages currently in `SCHEDULED` status across all senders and recipients on the account. **Remediation:** 1. Wait for existing scheduled messages to be released and sent, which reduces the outstanding count. 2. [Cancel](/start/guides/cancelling-messages) scheduled messages you no longer need. A cancelled message stops counting toward the limit. 3. Schedule fewer messages at once, or stagger scheduling over time. 4. Contact support if you need a higher limit for your use case. ### BUSINESS_031: Voice agent limit reached [#business_031-voice-agent-limit-reached] **Error Message:** "This account may hold at most 20 voice agents." **HTTP Status:** 409 Conflict **Cause:** `POST /v3/voice/agents` would take the account past the number of voice agents it may hold. The message names the cap. The check runs before a sandbox request too, so a sandbox create says what a real one would. **Remediation:** 1. Delete an agent you no longer use with `DELETE /v3/voice/agents/{id}`. A deleted agent no longer counts. 2. Contact [support@sent.dm](mailto:support@sent.dm) if you need more agents than the cap allows. **See:** [Voice agents](/start/guides/voice-agents) --- ## Conflict Errors [#conflict-errors] ### CONFLICT_001: Concurrent idempotent request [#conflict_001-concurrent-idempotent-request] **Error Message:** "A request with this Idempotency-Key is currently being processed. Please retry shortly." **HTTP Status:** 409 Conflict **Cause:** Another request with the same idempotency key is currently being processed. **Remediation:** 1. Wait for the original request to complete 2. Use a unique idempotency key for each distinct operation 3. Don't reuse idempotency keys across different operations --- ### CONFLICT_005: Idempotency key reused for a different request [#conflict_005-idempotency-key-reused-for-a-different-request] **Error Message:** "This Idempotency-Key was already used for a different request. Send a new key for a new operation, or repeat the original request unchanged to receive its response." **HTTP Status:** 422 Unprocessable Entity **Cause:** The `Idempotency-Key` was already used within the last 24 hours by a request with a different method, path, query string, or body. The stored response belongs to that first request, so the API neither replays it nor executes this one. **Remediation:** 1. Send a new idempotency key for a new operation. 2. To get the original response, repeat the original request unchanged, byte for byte. **See:** [Idempotency](/reference/api/idempotency#response-caching) --- ### CONFLICT_006: Template is in review [#conflict_006-template-is-in-review] **Error Message:** "This template is in review; its definition, category and language are frozen until the review completes" **HTTP Status:** 409 Conflict **Cause:** A `PUT /v3/templates/{id}` tried to change the template's `definition`, `category`, or `language`, or to resubmit it with `submit_for_review`, while it was still with a reviewer. A template counts as in review when its own status is `PENDING`, and also when its status is something else but any one of its channels is still awaiting a verdict, which is why an `APPROVED` template can return this. The freeze is checked before anything is written, so a refused request leaves the template exactly as the reviewer sees it. **Remediation:** 1. Wait for the review to finish. Subscribe to `templates` [webhook events](/start/webhooks/event-types#templates) to learn the outcome per channel rather than polling. 2. Send only `name` if you need a change now. The display name is editable throughout, including during review. 3. Resubmit after the verdict lands. A `REJECTED` template is editable again, and an `APPROVED` one accepts a [live edit](/reference/api/template-definition#editing-an-approved-template). --- ### CONFLICT_007: Default line for app calls is in use [#conflict_007-default-line-for-app-calls-is-in-use] **Error Message:** "This number is the default line for app calls and other voice numbers are active; move the default to another number first" **HTTP Status:** 409 Conflict **Cause:** `PATCH /v3/channels/voice/{number}` sent `status: "INACTIVE"` for the number calls placed from your app go out from, while other voice numbers are active. An account with active voice numbers always has exactly one default, so the default moves by being given to another number, never by being removed. **Remediation:** 1. `PATCH` another active voice number with `default_for_app_calls: true`. 2. Turn this number off. Turning off your last voice number is allowed; that turns phone calls off. --- ### CONFLICT_008: Call is no longer active [#conflict_008-call-is-no-longer-active] **Error Message:** "Call is no longer active" **HTTP Status:** 409 Conflict **Cause:** A hangup, recording or participant command reached a call that has ended, or that ended between your read and the command. **Remediation:** 1. Read `GET /v3/voice/calls/{id}` for the final status. Nothing can change a call once it has ended. 2. Rely on `call.completed` and `call.failed` to learn when a call ends, rather than polling. --- ### CONFLICT_009: Call is not in a conference [#conflict_009-call-is-not-in-a-conference] **Error Message:** "Call is not in a conference" **HTTP Status:** 409 Conflict **Cause:** A participant command reached a call your answer connected to a user or a number rather than to a conference room, or a call one of your voice agents answers, which is never in a conference. It can also arrive for a moment right after a `connectToConference` answer, because the room is recorded on the call as Sent reads the answer. **Remediation:** 1. Answer the `call.request` with `connectToConference` for calls you want to add participants to. 2. Retry a `409` that arrives within a second or two of answering; the example app retries for a few seconds. --- ### CONFLICT_011: Call has no phone leg [#conflict_011-call-has-no-phone-leg] **Error Message:** "Call has no phone leg" **HTTP Status:** 409 Conflict **Cause:** `POST /v3/voice/calls/{id}/hangup` or `POST /v3/voice/calls/{id}/recordings` reached a call with no leg on the phone network, such as a call between two of your app users. Such a call can be changed only by the apps in it, so the command is refused up front rather than reported as an ended call. **Remediation:** 1. End the call from the app with `hangup()` in [`@sentdm/voice-client`](/sdks/voice). 2. Do not ask for a recording of a call between two app users; it cannot be recorded. 3. A call with a phone caller, or one connected to a phone number, accepts both commands. --- ### CONFLICT_014: Voice agent is in use [#conflict_014-voice-agent-is-in-use] **Error Message:** "This voice agent is in use: voice number +12125550100 routes calls to it; agent_4c1d2e3f-0000-4000-8000-000000000002 lists it in transfer_targets. To delete it, first unbind the number with `PATCH /v3/channels/voice/{number}` and `"agent_id": null`, and remove it from that agent's transfer_targets or delete that agent." **HTTP Status:** 409 Conflict **Cause:** `DELETE /v3/voice/agents/{id}` reached an agent that something still points at: one of your voice numbers routes calls to it, or another of your agents lists it in `transfer_targets`. Deleting it would leave the number routing calls to nobody, or the other agent naming a target that is gone. The message names every number and agent that holds it, and what to do about each. **Remediation:** 1. Unbind each number named with `PATCH /v3/channels/voice/{number}` and `"agent_id": null`, or bind it to another agent. 2. Remove the agent from the `transfer_targets` of each agent named with `PATCH /v3/voice/agents/{id}`, or delete those agents. 3. Delete the agent again. **See:** [Delete an agent](/start/guides/voice-agents#delete-an-agent) --- ### CONFLICT_015: Call is answered by a voice agent [#conflict_015-call-is-answered-by-a-voice-agent] **Error Message:** "Calls a voice agent answers can't be hung up or recorded through the API" **HTTP Status:** 409 Conflict **Cause:** `POST /v3/voice/calls/{id}/hangup` or `POST /v3/voice/calls/{id}/recordings` reached a live call one of your voice agents answers. Such a call is run by the agent's session, and the two commands cannot reach it, so the request is refused up front rather than reported as an ended call. An agent call that has ended answers `CONFLICT_008`, and the participant commands answer `CONFLICT_009`, because an agent call is never in a conference. **Remediation:** 1. End the call from the agent with the `hangup` tool. See the [voice agent protocol](/reference/api/voice-agent-protocol#tools). 2. Do not ask for a recording of an agent call through this endpoint. 3. Read `GET /v3/voice/calls/{id}`: `mode` is `agent` on every call this applies to. **See:** [Calls an agent answers](/start/guides/voice-agents#calls-an-agent-answers) --- ### CONFLICT_016: Webhook is managed by your organization [#conflict_016-webhook-is-managed-by-your-organization] **Error Message:** "This webhook is your organization's; only the organization can change, test or delete it" **HTTP Status:** 409 Conflict **Cause:** A Sender Profile tried to update, toggle, test, or delete its organization's inheritable version 2 webhook. The profile sees that webhook in its list and reads the events about itself, but the webhook belongs to the organization. Nothing was changed. **Remediation:** 1. Make the change with your organization's API key, without `x-profile-id`. 2. To give the profile a webhook it controls, create one with the profile's own key. It receives that profile's events only. **See:** [Inheritable webhooks](/start/webhooks/event-types#inheritable-webhooks-version-2) --- ### CONFLICT_017: Campaign volume tier is locked [#conflict_017-campaign-volume-tier-is-locked] **Error Message:** "This campaign is registered with TCR, so its volume can no longer move between low and high volume" **HTTP Status:** 409 Conflict **Cause:** A campaign update asked to move `volume` across the `2000` boundary, from the low-volume tier to the standard tier or back, after the campaign was submitted to The Campaign Registry (`submittedToTCR` is `true` or `tcrCampaignId` is set). TCR fixes the tier when the campaign registers, and a campaign update can't change it. Refused on `PUT /v3/profiles/{profileId}/campaigns/{campaignId}`, and on `POST /v3/channels/sms` and `PATCH /v3/channels/sms/{country}/{type}` when they carry `compliance.campaign`. Nothing was changed. **Remediation:** 1. Keep `volume` on the same side of `2000`. A change within the tier is accepted, for example from `"5000"` to `"8000"`. 2. To register at the other tier, register a new campaign with the `volume` you need. **See:** [Update or delete a campaign](/start/advanced/10dlc-campaigns-api#update-or-delete-a-campaign) --- ## Service Errors [#service-errors] ### SERVICE_001: Cache service temporarily unavailable [#service_001-cache-service-temporarily-unavailable] **Error Message:** "Cache service temporarily unavailable. Please retry your request." **HTTP Status:** 503 Service Unavailable **Cause:** The cache backing idempotency processing is unavailable, so the API cannot guarantee your request is not a duplicate. Returned on requests that carry an `Idempotency-Key` header while the cache is down. **Remediation:** 1. Retry the request after a short delay, reusing the same `Idempotency-Key` 2. Check [API Status](https://status.sent.dm) for known issues --- ## Internal Errors [#internal-errors] ### INTERNAL_001: Unexpected internal server error [#internal_001-unexpected-internal-server-error] **Error Message:** "Unexpected internal server error" **HTTP Status:** 500 Internal Server Error **Cause:** An unexpected error occurred on the server. **Remediation:** 1. Retry the request after a short delay 2. If the error persists, contact support with: - The `request_id` from the response - Timestamp of the error - The operation you were attempting --- ### INTERNAL_002: Database operation failed [#internal_002-database-operation-failed] **Error Message:** "Database operation failed" **HTTP Status:** 500 Internal Server Error **Cause:** An unexpected database error occurred while processing your request. **Remediation:** 1. Retry the request after a short delay 2. If the error persists, contact support with the request ID 3. This is typically a transient issue --- ### INTERNAL_003: External service error [#internal_003-external-service-error] **Error Message:** "An upstream service error occurred" **HTTP Status:** 500 Internal Server Error. `POST /v3/sender-profiles` returns it with `502 Bad Gateway` and the message "Could not verify this WhatsApp account with Meta" when the WhatsApp account in `channels.whatsapp` can't be verified because Meta couldn't be reached. Nothing is created. **Cause:** An upstream service Sent depends on returned an error or couldn't be reached. **Remediation:** 1. Wait a few moments and retry 2. Check [API Status](https://status.sent.dm) for known issues --- ### INTERNAL_004: Timeout waiting for operation [#internal_004-timeout-waiting-for-operation] **Error Message:** "Timeout waiting for operation" **HTTP Status:** 504 Gateway Timeout **Cause:** The operation timed out while waiting for an external service or internal processing. **Remediation:** 1. The operation may still be in progress - check the resource status 2. Retry the request with the same idempotency key 3. Contact support if timeouts persist --- ### INTERNAL_005: Service temporarily unavailable [#internal_005-service-temporarily-unavailable] **Error Message:** "Service temporarily unavailable" **HTTP Status:** 503 Service Unavailable **Cause:** The API is temporarily unavailable due to maintenance or high load. **Remediation:** 1. Retry with exponential backoff 2. Check [API Status](https://status.sent.dm) 3. Wait for service restoration --- ## Message Outcome Codes [#message-outcome-codes] These codes are never returned on an HTTP response. `POST /v3/messages` accepts the send with `202`, and when the message ends `FAILED`, `FILTERED` or `BLOCKED` the code arrives as `reason_code` on `GET /v3/messages/{id}` (top level and on the event), on `GET /v3/messages/{id}/activities`, and on the `message.failed`, `message.filtered` and `message.blocked` webhooks. A cause with a code elsewhere in this catalog reuses it, so these cover only what a message outcome alone can have. Several carrier conditions fold into one code, so read `reason` for the likely causes. | Code | Meaning | What to do | |------|---------|------------| | `DELIVERY_001` | The send never reached the carrier: a routing or processing error, content the network couldn't accept, or no reported cause | Check the content and media, then resend. Contact support with the message ID if it repeats | | `DELIVERY_002` | The carrier accepted the message and later reported it undelivered, with no specific reason | Resend later; treat repeated failures to one number as a bad number | | `DELIVERY_003` | The account has no sender set up for this destination on this channel | Add the market with `POST /v3/channels/sms`, or send on another channel | | `DELIVERY_004` | Sending to this destination isn't allowed right now: it's blocked for the account, its sender is still being set up, or the recipient recently couldn't be reached on this channel | Check the market's status with `GET /v3/channels`; wait for it to reach `ACTIVE` | | `DELIVERY_005` | No route is available: the destination network or region isn't provisioned for this sender | Send on another channel, or contact support to add coverage | | `DELIVERY_006` | The channel's content policy blocked the text, links or media | Revise the content and resend | | `DELIVERY_007` | The recipient isn't on this channel: no WhatsApp account, or no RCS-capable handset | Omit `channel` so auto-detect can pick one the recipient has | | `DELIVERY_008` | WhatsApp held back a marketing message: the recipient has received too many recently, or is in a marketing experiment | Send later or over another channel; don't retry immediately | | `DELIVERY_009` | The channel rejected the credentials the message was sent with | Reconnect the WhatsApp or RCS account, or contact support | | `DELIVERY_010` | The message couldn't be delivered: the line or handset can't receive it, the carrier discarded it, or every available channel failed | Treat as permanent for this recipient and channel | | `DELIVERY_011` | The carrier rejected the message: the line is barred, the recipient hasn't opted in to this sender, or the network refused it | Confirm consent; don't retry on the same sender | | `DELIVERY_012` | Carrier screening blocked it as spam, a blocked keyword or content, or a block-listed number | Revise the content; check the sender's registration covers this use | | `DELIVERY_013` | The recipient couldn't be reached: phone off, out of coverage, busy, or storage full | Resend later | | `DELIVERY_014` | The message expired before it could be delivered | Resend if still relevant | | `DELIVERY_015` | The carrier reported a temporary error, such as congestion | Resend later; a later send may succeed | | `DELIVERY_016` | The channel couldn't use the media: unsupported type, file too large, or a link it couldn't fetch | Check the [MMS media rules](/start/guides/mms#supported-media-types) and that the URL is public | --- ## Channel Status Reasons [#channel-status-reasons] These codes are never returned on an HTTP response. Every SMS market, WhatsApp account and RCS agent that isn't `ACTIVE` reports one as `reason_code`, with a sentence as `reason`. They appear on `GET /v3/channels`, the single-market reads, and Sender Profiles, and for SMS markets on the `channel.*` webhooks too. WhatsApp and RCS don't publish `channel.*` webhooks yet. The code is decided by the same logic as the status, so the two never disagree. On reads, an `ACTIVE` channel carries neither field. A `channel.*` webhook for an `ACTIVE` market omits `reason_code` but can still carry `reason` when the event brought its own explanation, such as a correction requested against a sender that still works. | Status | Code | Meaning | What to do | |--------|------|---------|------------| | `ACTION_NEEDED` | `CHANNEL_001` | Information or documents the channel requires are missing, or were rejected. On an SMS market, `reason` names what | Send them with `PATCH /v3/channels/sms/{country}/{type}`; see [Managing channels](/start/guides/managing-channels) | | `ACTION_NEEDED` | `CHANNEL_002` | The registration came back from review and must be corrected | Correct what Sent emailed about and resubmit | | `ACTION_NEEDED` | `CHANNEL_003` | The registration was rejected (RCS verification or launch) | Correct the submission and resubmit, or contact support | | `ACTION_NEEDED` | `CHANNEL_004` | The channel was suspended and can't send | Contact support | | `ACTION_NEEDED` | `CHANNEL_005` | Setting the channel up failed | Contact support to retry | | `ACTION_NEEDED` | `CHANNEL_006` | No WhatsApp Business Account is connected | Connect one in the Sent Dashboard | | `ACTION_NEEDED` | `CHANNEL_007` | The WhatsApp Business Account has no phone number registered | Register a number on the account | | `INACTIVE` | `CHANNEL_008` | The channel had a working sender and lost it: the number was released or its campaign lapsed | Contact support to restore it; sends fail until then | | `PENDING_REVIEW` | `CHANNEL_009` | The registration is with the registry or the carriers | Wait; nothing on your side speeds it up | | `PROVISIONING` | `CHANNEL_010` | The registration was approved and a number is being acquired | Wait for `channel.activated` | | `PROVISIONING` | `CHANNEL_011` | The channel is being set up | Wait for `channel.activated` | --- ## Call Failure Reasons [#call-failure-reasons] These values are never returned on an HTTP response. A phone call that ends without completing reports why as `failure_reason` on `GET /v3/voice/calls/{id}` and `GET /v3/voice/calls`, and as `reason` on the `call.failed` webhook. The field is null on the read and omitted on the webhook when no reason was recorded, and always on a call that completed. The values are Sent's classification, never a carrier's own code. | Reason | Meaning | What to do | |--------|---------|------------| | `callback_timeout` | The last attempt to reach your callback with the `call.request` question failed in a way other than a `4xx`: it timed out, could not connect, was answered with a `3xx` or a `5xx`, returned a body over 64 KiB, or the callback URL is one Sent will not call. Sent asks once and retries once unless the first answer was a `4xx`, and the reason reflects the last attempt | Answer within 2.5 seconds and do no network calls in the handler. Check the response size and that the URL answers directly, without a redirect. See [Deadlines and Retries](/start/guides/answering-calls#deadlines-and-retries) | | `invalid_answer` | The last attempt returned a `2xx` with a body Sent could not use. This includes a `connectToNumber` to a blocked country or with a `callerId` you do not own | Run `POST /v3/channels/voice/{number}/test`, which names the field at fault. See the [Voice Callback Contract](/reference/api/voice-callback) | | `rejected` | Your callback refused the `call.request` with a `4xx` or a `reject` action, or the phone that was dialed was busy. On a `call.input` the same answers hang the call up and it ends `COMPLETED` instead | Nothing, when that was the intent. A busy callee is reported the same way | | `no_answer` | The phone that was dialed did not pick up | Nothing on your side. Consider a fallback destination in your routing | | `insufficient_balance` | The account balance was at or below zero when a call was placed from your app, to a phone, an app user or a room alike, or when an answer added a phone leg to a call that had none. Inbound calls are not checked before the question | Add funds. Legs to app users and rooms cost nothing, but a call from your app still needs a balance greater than zero to start | | `destination_blocked` | A call placed from your app to a phone number in a country Sent does not allow calls to. Refused before your callback is asked; an answer that dials such a number fails as `invalid_answer` instead | Check the destination. Contact [support@sent.dm](mailto:support@sent.dm) to have the country allowed | | `callback_not_configured` | A call arrived on a number that has no callback URL and no voice agent, so there was nobody to ask. Calls placed from your app on such a number connect straight to what they dial instead | Set `callback_url` or `agent_id` with `PATCH /v3/channels/voice/{number}` | | `agent_busy` | The call arrived on a number bound to a voice agent that already had `limits.max_concurrent_calls` calls going. The call is not offered to the agent and does not go to its fallback | Raise `limits.max_concurrent_calls` on the agent, or spread calls across more agents | | `agent_unreachable` | The call arrived on a number bound to a voice agent that could not take it and has no `fallback`: the agent connects in and was not connected, the connection Sent opened to its `websocket_url` failed or was not accepted in time, the agent's connection was lost during the call and the session was not resumed within the window, or the agent no longer exists | Keep the agent connected and answering pings, or set a `fallback` number on it. See [Fallback](/start/guides/voice-agents#fallback) | --- ## Troubleshooting Guide [#troubleshooting-guide] ### General Troubleshooting Steps [#general-troubleshooting-steps] 1. **Check the Error Code**: Use the error code to find its entry in this catalog 2. **Review Request ID**: Include `meta.request_id` when contacting support 3. **Verify API Version**: Ensure you're using v3 endpoints (`/v3/`) 4. **Test in Sandbox Mode**: Use `sandbox: true` to validate without side effects ### Getting Help [#getting-help] If you can't resolve an error: 1. **Documentation**: Check this catalog and the [Error Handling](/reference/api/errors) guide 2. **Support email**: [support@sent.dm](mailto:support@sent.dm) 3. **Include in Support Request:** - Request ID (`meta.request_id`) - Error code and message - Timestamp of occurrence - Endpoint and method - Request payload (sanitized) --- ## Error Code Quick Reference [#error-code-quick-reference] Every code documented on this page, in page order: | Code | Category | HTTP Status | Quick Fix | |------|----------|-------------|-----------| | AUTH_001 | Authentication | 401 | Renew the voice token. A missing or wrong API key is `AUTH_002` | | AUTH_002 | Authentication | 401 | Send the key in `x-api-key` or `Authorization: Bearer`, then verify or regenerate it | | AUTH_004 | Authentication | 403 | [Check user permissions](/reference/api/roles-and-permissions) | | AUTH_005 | Authentication | 403 | Wait for account activation | | AUTH_006 | Authentication | 403 | Complete KYC verification | | AUTH_007 | Authentication | 403 | Configure a messaging channel | | VALIDATION_001 | Validation | 400, 413, 422 | Check `error.details` | | VALIDATION_002 | Validation | 400 | Use E.164 phone format | | VALIDATION_003 | Validation | 400 | Check UUID format | | VALIDATION_004 | Validation | 400 | Provide all required fields | | VALIDATION_005 | Validation | 400 | Check value is within range | | VALIDATION_006 | Validation | 400 | Check enum values | | VALIDATION_008 | Validation | 400 (or message `FAILED`) | Fix the template variable value named in the message | | VALIDATION_011 | Validation | 400 | Use letters, digits, `-` and `_`, up to 200 characters | | RESOURCE_001 | Resource | 404 | Verify contact ID exists | | RESOURCE_002 | Resource | 404 | Verify template ID exists | | RESOURCE_003 | Resource | 404 | Verify message ID exists | | RESOURCE_004 | Resource | 404 | Verify customer ID exists | | RESOURCE_005 | Resource | 404 | Verify organization ID | | RESOURCE_006 | Resource | 404 | Verify user ID exists | | RESOURCE_007 | Resource | 409 | Update the existing resource | | RESOURCE_008 | Resource | 404 | Verify webhook ID exists | | RESOURCE_009 | Resource | 404 | Register a brand for the profile | | RESOURCE_010 | Resource | 404 | Verify campaign belongs to the profile's brand | | RESOURCE_011 | Resource | 404 | Verify batch ID exists | | RESOURCE_012 | Resource | 404 | Verify the number is provisioned (E.164) | | RESOURCE_013 | Resource | 404 | Verify the resource ID and endpoint path | | RESOURCE_014 | Resource | 404 | Use a profile ID from `GET /v3/profiles` | | RESOURCE_015 | Resource | 404 | Use a call id from a question, a webhook or `GET /v3/voice/calls` | | RESOURCE_017 | Resource | 404 | List the room and use an `id` from it | | BUSINESS_002 | Business Logic | 429 | Implement backoff | | BUSINESS_003 | Business Logic | 402 | Add account funds | | BUSINESS_004 | Business Logic | 400 | Remove opted-out contacts | | ERR_CONSENT_BLOCKED | Business Logic | n/a (message `FILTERED`) | Stop targeting the contact | | BUSINESS_005 | Business Logic | 400 | Wait for template approval | | BUSINESS_006 | Business Logic | 409 | Check the message is `SCHEDULED` before cancelling | | BUSINESS_007 | Business Logic | 503 (or message `FAILED`) | Contact support about the market or MMS | | BUSINESS_008 | Business Logic | 400 | Check quota limits | | BUSINESS_009 | Business Logic | 501 (or message `FAILED`) | Request `sms` requirements; send on a supported channel | | BUSINESS_010 | Business Logic | 400 | Re-enable the webhook after fixing the endpoint | | BUSINESS_011 | Business Logic | 400 (or message `FAILED`) | Check the destination country; contact support if it should be allowed | | BUSINESS_012 | Business Logic | 400 | Use a channel the template is active on | | WHATSAPP_TEMPLATE_REQUIRED | Business Logic | - (message `FAILED`) | Send an approved template, or omit `channel` to fall back | | CONVERSATION_TEMPLATE_REQUIRED | Business Logic | - (message `BLOCKED`) | Send an approved template to open or re-open the conversation | | BUSINESS_014 | Business Logic | 403 | Contact support; do not retry | | BUSINESS_015 | Business Logic | 422 (or message `FAILED`) | Choose another country or number type | | BUSINESS_016 | Business Logic | 422 | Ask for a number type listed in `details` | | BUSINESS_017 | Business Logic | - (message `FAILED`) | Check the WhatsApp business account | | BUSINESS_018 | Business Logic | - (message `FAILED`) | Enable marketing on the WhatsApp business account | | BUSINESS_019 | Business Logic | - (message `FAILED`) | Check the channel's `reason_code` | | BUSINESS_020 | Business Logic | - (message `BLOCKED`) | Complete the next onboarding step | | BUSINESS_022 | Business Logic | 400 | Use a number you hold, or leave `number` out to get one | | BUSINESS_023 | Business Logic | 403 | Turn calls on for a number first | | BUSINESS_024 | Business Logic | 400 | Use a number from `GET /v3/channels/voice` | | BUSINESS_025 | Business Logic | 400 | Retry; contact support with the request ID if it repeats | | BUSINESS_026 | Business Logic | 403 | Contact support to turn call recording on | | BUSINESS_027 | Business Logic | 502 | Repeat the request | | BUSINESS_028 | Business Logic | 409 | Try another `area_code`, or omit it | | BUSINESS_029 | Business Logic | - (message `BLOCKED`) | Remove or replace the number at the position `reason` names in `channels` | | BUSINESS_030 | Business Logic | 400 | Keep the primary OPT_IN, OPT_OUT, and HELP templates; edit them instead of deleting | | BUSINESS_031 | Business Logic | 409 | Delete a voice agent you no longer use | | LIMIT_001 | Business Logic | 429 | Wait for scheduled messages to send, cancel ones you no longer need, or schedule fewer at once | | CONFLICT_001 | Conflict | 409 | Wait for the original request | | CONFLICT_005 | Conflict | 422 | Use a new key, or resend the original request unchanged | | CONFLICT_006 | Conflict | 409 | Wait for the template review to finish; only `name` is editable meanwhile | | CONFLICT_007 | Conflict | 409 | Move the default to another number first | | CONFLICT_008 | Conflict | 409 | The call has ended; nothing to do | | CONFLICT_009 | Conflict | 409 | Answer with `connectToConference`; retry a `409` right after answering | | CONFLICT_011 | Conflict | 409 | Hang up from the app; app-to-app calls cannot be recorded | | CONFLICT_014 | Conflict | 409 | Unbind the numbers and remove the agent from other agents' `transfer_targets` first | | CONFLICT_015 | Conflict | 409 | Hang up from the agent with the `hangup` tool; agent calls cannot be recorded this way | | CONFLICT_016 | Conflict | 409 | Change the webhook with your organization's key | | CONFLICT_017 | Conflict | 409 | Keep `volume` within its tier, or register a new campaign | | SERVICE_001 | Service | 503 | Retry after a short delay | | INTERNAL_001 | Internal | 500 | Retry or contact support | | INTERNAL_002 | Internal | 500 | Retry or contact support | | INTERNAL_003 | Internal | 500, 502 | Retry after a delay | | INTERNAL_004 | Internal | 504 | Retry or contact support | | INTERNAL_005 | Internal | 503 | Retry with backoff | | DELIVERY_001 to DELIVERY_016 | Message outcome | - (message `FAILED`/`FILTERED`/`BLOCKED`) | See [Message Outcome Codes](#message-outcome-codes) | | CHANNEL_001 to CHANNEL_011 | Channel status | - (channel not `ACTIVE`) | See [Channel Status Reasons](#channel-status-reasons) | | `callback_timeout` to `callback_not_configured` | Call failure reason | - (call `FAILED`, `NO_ANSWER` or `REJECTED`) | See [Call Failure Reasons](#call-failure-reasons) | **Need More Help?** Contact [support@sent.dm](mailto:support@sent.dm) with your request ID for personalized assistance. --- # Error Handling (/reference/api/errors.md) # Error Handling [#error-handling] All errors in the Sent API v3 follow a consistent JSON envelope format with structured error codes, making it easy to programmatically handle errors and troubleshoot issues. --- ## Error Response Format [#error-response-format] All errors follow a consistent JSON envelope: ```json { "success": false, "status": 404, "error": { "code": "RESOURCE_001", "message": "Contact not found", "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_a1b2c3d4e5f60718", "timestamp": "2026-01-15T10:30:00Z", "version": "v3" } } ``` ### Top-level Fields [#top-level-fields] | Field | Type | Description | |-------|------|-------------| | `success` | boolean | Always `false` on an error response | | `status` | integer | HTTP status code, repeated in the body | | `error` | object | The error itself, described below | | `meta` | object | Request metadata, described below | An error response carries no `data` field. ### Error Object Fields [#error-object-fields] | Field | Type | Description | |-------|------|-------------| | `code` | string | Machine-readable error code (for example, `RESOURCE_001`) | | `message` | string | Human-readable error message | | `details` | object | Field-level validation errors, as a map of field name to an array of messages. Omitted when there are none | | `doc_url` | string | Link to the documentation page for this class of error. Omitted when unset | `details` and `doc_url` are omitted rather than sent as `null`, so read them defensively. ### Meta Object Fields [#meta-object-fields] | Field | Type | Description | |-------|------|-------------| | `request_id` | string | Unique request identifier for support and debugging | | `timestamp` | string | ISO 8601 timestamp of the error | | `version` | string | API version (always `v3`) | --- ## HTTP Status Codes [#http-status-codes] | Status | Description | Common Causes | |--------|-------------|---------------| | `200 OK` | Request successful | - | | `201 Created` | Resource created successfully | - | | `204 No Content` | Request successful, no response body | DELETE operations | | `400 Bad Request` | Invalid request format or parameters | Missing required fields, invalid JSON | | `401 Unauthorized` | Authentication failed | Missing or invalid API key | | `403 Forbidden` | Permission denied | Insufficient role permissions | | `404 Not Found` | Resource not found | Invalid resource ID | | `409 Conflict` | Resource conflict | Duplicate entry, concurrent modification | | `413 Payload Too Large` | Request body too large | Body exceeds the endpoint's size limit | | `422 Unprocessable Entity` | Validation failed | Invalid field values, business rule violations, `Idempotency-Key` reused for a different request | | `429 Too Many Requests` | Rate limit exceeded | Too many requests in time window | | `500 Internal Server Error` | Unexpected server error | Server-side issue | | `501 Not Implemented` | Not supported yet | Compliance requirements requested for a channel other than SMS | | `502 Bad Gateway` | Upstream service error | Provider service unavailable | | `503 Service Unavailable` | Service temporarily unavailable | Maintenance or overload | --- ## Error Code Reference [#error-code-reference] The [Error Catalog](/reference/api/error-catalog) is the canonical enumeration of every error code, with causes and step-by-step remediation. The codes below are the ones client code most commonly branches on: | Code | HTTP Status | Meaning | Handling | |------|-------------|---------|------------| | `AUTH_001` | 401 | User is not authenticated | Renew the voice token. A missing or wrong API key returns `AUTH_002` instead | | `AUTH_002` | 401 | Invalid or missing API key | Send the key in `x-api-key` or `Authorization: Bearer`. Verify it, and regenerate it if revoked | | `VALIDATION_001` | 400 | Request validation failed | Check the `details` field for field-level errors | | `RESOURCE_001` | 404 | Contact not found | Verify the contact ID exists and belongs to your account | | `BUSINESS_002` | 429 | Rate limit exceeded | Back off and respect the `Retry-After` header | | `CONFLICT_001` | 409 | Concurrent idempotent request in progress | Wait for the original request to complete before retrying | | `SERVICE_001` | 503 | Cache service temporarily unavailable | Retry the request after a short delay | | `INTERNAL_001` | 500 | Unexpected internal server error | Retry, then contact support with the request ID | For the full `AUTH_*`, `VALIDATION_*`, `RESOURCE_*`, `BUSINESS_*`, `CONFLICT_*`, `SERVICE_*`, and `INTERNAL_*` listings, refer to the [Error Code Quick Reference](/reference/api/error-catalog#error-code-quick-reference) in the Error Catalog. **Example Validation Error with Details** (`POST /v3/messages` with an empty `to` array and a `template` missing both `id` and `name`): ```json { "success": false, "status": 400, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "to": ["'to' must contain at least one recipient"], "template": ["'template' must have either 'id' (non-empty GUID) or 'name' (non-empty string)"] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { ... } } ``` ### Send-time Error Codes (ERR_*) [#send-time-error-codes-err_] These codes are produced by the per-message send pipeline. They are not returned in the HTTP response. `POST /v3/messages` responds `202` for the batch, and each message is finalized asynchronously with a terminal status. The `ERR_*` code is Sent's internal classification: what you receive is the public `reason_code` it maps to, with a `reason` sentence beside it. | Code | Terminal status | `reason_code` | What it means | |------|-----------------|---------------|---------------| | `ERR_CONSENT_BLOCKED` | `FILTERED` | `BUSINESS_004` | The recipient's contact has `opt_out = true`, or their phone is on your phone-channel suppression list. The send is suppressed pre-routing: no provider call is made and no charge applies. | | `ERR_ROUTE_DENIED` | `FILTERED` | `DELIVERY_004` | Routing rules denied every candidate route for this send, and no fallback was allowed. | | `ERR_TEMPLATE_PARAMS_INVALID` | `FAILED` | `VALIDATION_008` | Required template variables were missing or failed validation. | Read each message's outcome, and its `reason_code` and `reason`, through: - `GET /v3/messages/{id}`: the `status` field carries the terminal status, and `reason_code` and `reason` sit beside it and on the matching event - `GET /v3/messages/{id}/activities`: the `FILTERED` or `FAILED` activity carries the same pair - The `message.filtered` and `message.failed` webhook events, as `payload.reason_code` and `payload.reason` Every other way a message can end `FAILED`, `FILTERED` or `BLOCKED` is reported the same way. See [Message Outcome Codes](/reference/api/error-catalog#message-outcome-codes) for the codes only an outcome can have. ### Conversation-window codes [#conversation-window-codes] Two send-time codes are not `ERR_*` prefixed, because they are part of the two-way messaging contract and carry an actionable reason. Like the `ERR_*` codes, they are not returned on the HTTP response: `POST /v3/messages` responds `202` and the outcome lands on the message as its terminal status. Both call for an approved template as the first step, but they answer to different rules and a template does not clear both: on SMS, RCS, and auto-detect it opens a 7-day window for a contact who has never replied, while only a recent inbound WhatsApp message opens Meta's 24-hour one. | Code | Terminal status | Trigger | Whose rule | |------|-----------------|---------|------------| | `CONVERSATION_TEMPLATE_REQUIRED` | `BLOCKED` | Free-form send on SMS, RCS, or auto-detect to a contact who has never replied, and either no template was ever sent or the last one is more than 7 days old. | Sent's | | `WHATSAPP_TEMPLATE_REQUIRED` | `FAILED` | Free-form send pinned to `channel: "whatsapp"` outside Meta's 24-hour customer-service window, or a Meta `131047` re-engagement rejection. | Meta's | Each is its own `reason_code`, on the message and on its webhook. The terminal status differs between them: the conversation gate records `BLOCKED` (excluded from your deliverability rate, fires `message.blocked`), while the WhatsApp gate records `FAILED`. Full causes and remediation: [CONVERSATION_TEMPLATE_REQUIRED](/reference/api/error-catalog#conversation_template_required-no-open-conversation) and [WHATSAPP_TEMPLATE_REQUIRED](/reference/api/error-catalog#whatsapp_template_required-free-form-whatsapp-outside-metas-window). Window mechanics: [Conversation Windows](/start/guides/two-way-conversations#conversation-windows). --- ## Common Error Scenarios [#common-error-scenarios] ### Authentication Issues [#authentication-issues] **Missing API Key** ```bash curl -X GET https://api.sent.dm/v3/me # Response: 401 AUTH_002 ``` **Solution:** Send the API key, in the `x-api-key` header or as `Authorization: Bearer`: ```bash curl -X GET https://api.sent.dm/v3/me \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ``` ### Validation Issues [#validation-issues] **Invalid Phone Number** A `POST /v3/messages` request with a recipient that is not in E.164 format returns: ```json { "success": false, "status": 400, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "to": ["Each entry in 'to' must be a valid phone number in E.164 format (e.g. +14155551234)"] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" } } ``` **Solution:** Use E.164 format for every entry in `to`: ```json { "to": ["+14155551234"] } ``` ### Resource Not Found [#resource-not-found] **Contact Not Found** ```json { "success": false, "status": 404, "error": { "code": "RESOURCE_001", "message": "Contact not found", "doc_url": "https://docs.sent.dm/reference/api/error-catalog" } } ``` **Solution:** Verify the contact ID exists: ```bash curl -X GET https://api.sent.dm/v3/contacts \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ``` ### Rate Limiting [#rate-limiting] **Too Many Requests** ```json { "success": false, "status": 429, "error": { "code": "BUSINESS_002", "message": "Rate limit exceeded", "doc_url": "https://docs.sent.dm/reference/api/rate-limits" } } ``` **Response Headers:** ```http Retry-After: 60 X-RateLimit-Limit: 10000 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 1705312800 ``` **Solution:** Implement exponential backoff and respect the `Retry-After` header. See [Rate Limits](/reference/api/rate-limits) for per-endpoint limit values and the full set of rate limit headers. --- ## Related guides [#related-guides] - [How to handle Sent API errors](/start/guides/handling-api-errors): success-flag checks, error-code branching, request-ID logging, client-side validation, and testing error paths with sandbox mode. - [How to retry Sent API requests safely](/start/guides/retrying-requests-safely): retry loops that use idempotency keys to prevent duplicate operations. - [How to handle Sent API rate limits](/start/guides/handling-rate-limits): backoff, monitoring, and throttling for `429` responses. # Idempotency (/reference/api/idempotency.md) # Idempotency [#idempotency] The Sent API v3 supports idempotency for safely retrying requests without accidentally performing the same operation twice. With an idempotency key, the API guarantees **at-most-once execution** for a mutation: duplicate requests with the same key return the original response instead of executing again. For retry loops and client implementations that use this contract, see [How to retry Sent API requests safely](/start/guides/retrying-requests-safely). --- ## How It Works [#how-it-works] 1. The client generates a unique key for each distinct operation 2. The client sends it in the `Idempotency-Key` header 3. The API caches the successful response for 24 hours 4. Duplicate requests with the same key return the cached response ```http POST /v3/messages Idempotency-Key: msg_send_abc123 Content-Type: application/json { "to": ["+1234567890"], "template": { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "parameters": { "customer_name": "John" } } } ``` --- ## Supported Requests [#supported-requests] Idempotency applies to every `POST`, `PUT`, and `PATCH` request to a `/v3` endpoint that carries the `Idempotency-Key` header. | Condition | Behavior | |-----------|----------| | `POST`, `PUT`, or `PATCH` to `/v3/*` with `Idempotency-Key` | Idempotency processing applies | | `POST`, `PUT`, or `PATCH` without `Idempotency-Key`, or with an empty one | Request executes normally; the header is optional | | `POST`, `PUT`, or `PATCH` with a key that doesn't meet the [format requirements](#idempotency-key-format) | The key is ignored and the request executes normally, without idempotency | | `GET` or `DELETE` request | The `Idempotency-Key` header is ignored | --- ## Idempotency Key Format [#idempotency-key-format] ### Requirements [#requirements] - **Length**: 1-255 characters - **Characters**: Letters, digits, hyphens (`-`), and underscores (`_`) - **Scope**: Per customer account - **Expiration**: 24 hours A key that is longer than 255 characters or contains any other character is not rejected. The API ignores it and executes the request without idempotency protection, so a retry with the same key executes again. Validate keys on the client side if you depend on deduplication. ### Valid Examples [#valid-examples] ``` req-abc123 send_msg_001 webhook-retry-1 invoice-payment-2024-001 create-contact-john-doe ``` ### Invalid Examples [#invalid-examples] The API ignores these keys and executes the request without idempotency: ``` req abc 123 # Contains spaces create@contact # Contains special character @ send.msg.001 # Contains periods ``` --- ## Response Caching [#response-caching] | Rule | Behavior | |------|----------| | Cached responses | Only successful (2xx) responses are cached | | Error responses | Not cached, so a retry with the same key executes the request again | | Cache lifetime | 24 hours from the original response | | Response size limit | Responses larger than 5 MB are not cached; duplicates execute again | | Replayed content | The original status code and body, byte for byte | A cached response is replayed only to the same request. The API stores a fingerprint of the original request's method, path (including the query string), and body alongside the response. A request that reuses the key within 24 hours with a different method, path, query string, or body is neither replayed nor executed: it's rejected with `422 Unprocessable Entity` and error code `CONFLICT_005`. The body is compared byte for byte, so a semantically identical payload serialized differently (for example, with keys in a different order) counts as a different request. After the 24-hour lifetime the key expires, and a request that reuses it executes as a new operation. ```json { "success": false, "status": 422, "error": { "code": "CONFLICT_005", "message": "This Idempotency-Key was already used for a different request. Send a new key for a new operation, or repeat the original request unchanged to receive its response.", "doc_url": "https://docs.sent.dm/reference/api/idempotency" }, "meta": { ... } } ``` Never reuse a key for a different operation. Generate a new key for each new operation, and resend the original request unchanged when retrying. If the cache backing idempotency is unavailable, the API rejects idempotent requests with `503 Service Unavailable` and error code `SERVICE_001` rather than risking a duplicate execution. --- ## Concurrent Requests [#concurrent-requests] When a duplicate request arrives while the original request with the same key is still executing: - The duplicate waits up to 5 seconds for the original to complete, then returns the cached response. If the duplicate's method, path, or body differs from the original's, it's rejected with `422` and `CONFLICT_005` instead. - If the original has not completed within that window, the duplicate is rejected with `409 Conflict` and error code `CONFLICT_001`. Retrying with the same key after the original completes returns the cached response. ```json { "success": false, "status": 409, "error": { "code": "CONFLICT_001", "message": "A request with this Idempotency-Key is currently being processed. Please retry shortly.", "doc_url": "https://docs.sent.dm/reference/api/idempotency" }, "meta": { ... } } ``` --- ## Response Headers [#response-headers] ### Idempotent-Replayed [#idempotent-replayed] When a cached response is returned, the `Idempotent-Replayed: true` header is included: ```http HTTP/1.1 201 Created Idempotent-Replayed: true X-Original-Request-Id: req_original_abc123 X-Request-Id: req_replay_def456 Content-Type: application/json { "success": true, "data": { ... }, "error": null, "meta": { ... } } ``` ### Header Reference [#header-reference] | Header | Description | |--------|-------------| | `Idempotent-Replayed` | `true` if this is a cached response | | `X-Original-Request-Id` | Request ID of the original request | | `X-Request-Id` | Request ID of the current request | --- ## Idempotency vs Sandbox Mode [#idempotency-vs-sandbox-mode] Both features help with safe API usage, but serve different purposes: | Feature | Purpose | Side Effects | Response | |---------|---------|--------------|----------| | **Sandbox Mode** | Validate requests | None (validation only) | Fake/sample data | | **Idempotency** | Prevent duplicates | Only on first request | Real/cached data | The two features can be combined in one request: a `sandbox: true` payload sent with an `Idempotency-Key` is validated without side effects, and its response is cached and replayed like any other. Refer to the [Sandbox Mode reference](/reference/api/test-mode) for the sandbox contract. --- ## Related guides [#related-guides] - [How to retry Sent API requests safely](/start/guides/retrying-requests-safely): key derivation, retry loops that reuse keys, `CONFLICT_001` handling, and a reusable client implementation. - [How to handle Sent API errors](/start/guides/handling-api-errors): error envelope handling in client code. # Sent v3 API (/reference/api.md) # Sent v3 API [#sent-v3-api] The Sent v3 API sends SMS, WhatsApp, and RCS messages through a single REST interface. This section documents the API's authentication, rate limits, sandbox mode, data models, and error semantics. ## Quick Start [#quick-start] ### Sent API Base URL [#sent-api-base-url] ``` https://api.sent.dm ``` Every request requires an API key. See the [Authentication reference](/reference/api/authentication) for the header, key management, and error codes. If you are new to Sent, the [Quickstart Guide](/start/quickstart) walks through sending your first message. --- ## Authentication & Security [#authentication--security] --- ## API Reference [#api-reference] Schemas, error handling, and advanced integration patterns. --- ## Postman Collection [#postman-collection] Import the v3 collection into Postman and start testing immediately with pre-configured requests, example bodies, and documentation links: --- ## Support & Resources [#support--resources] - **[Quickstart Guide](/start/quickstart)** - Complete onboarding walkthrough - **[Support Center](/start/reference-guides/support)** - FAQs, troubleshooting, and community resources - **[API Status](https://status.sent.dm)** - Real-time service status and incident reports - **Support email**: [support@sent.dm](mailto:support@sent.dm) --- method: POST route: /v3/messages/{id}/cancel # POST /v3/messages/{id}/cancel Cancel a scheduled message Calls off a message you scheduled with `scheduled_at`, before it is released for sending. The message moves to `CANCELLED`, which is terminal, and it is never sent. **Only a SCHEDULED message can be cancelled.** A message that has already been released — queued, in flight, or finished — returns 409. The release sweeper runs continuously, so a cancellation sent within about a minute of the scheduled instant can lose that race and be refused; cancel with time to spare. **One message per call.** A send to many recipients, or on several channels, becomes one message per recipient × channel, each with its own id; cancel the ones you want stopped. There is no bulk cancellation. **Cancelling is free**, and nothing was charged for the hold in the first place — a scheduled message is only priced and billed at release. **A cancellation fires `message.cancelled`** on your webhook, exactly once, carrying the `scheduled_at` that was called off so a consumer can un-record the send it was expecting. Cancelling the same message again returns this same response and fires no second event. `Idempotency-Key` is honoured. A cancelled message cannot be resent — send a new one. The response is the message itself, in the same shape `GET /v3/messages/{id}` returns, so the `status` you read back is the one now stored on the row, and `scheduled_at` is the time it would have gone out. `GET /v3/messages/{id}` keeps reporting both afterwards. `events` is the message lifecycle as it stood immediately before the cancellation: the CANCELLED entry is written asynchronously and lands a moment later, so read `status` for the outcome. If you need the entry itself, re-fetch the message after a few seconds — `GET /v3/messages/{id}` is cached briefly, so an immediate re-fetch can still show the pre-cancellation state. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3MessagesCancelMessageV3Endpoint` **Tags:** Messages ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Message ID | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 200 The message is cancelled and will not be sent #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, contact_id?: string, phone?: string, phone_international?: string, region_code?: string, template_id?: string, template_name?: string, template_category?: string, channel?: string, message_body?: { header?: string, content?: string, footer?: string, buttons?: Array<{ type?: string, text?: string, value?: string, postbackData?: string }>, subject?: string, media?: Array<{ url?: string, mediaType?: string, mimeType?: string, sizeBytes?: integer, sourceHashSha256?: string }>, headerMedia?: { type?: string, url?: string } }, status?: string, direction?: string, created_at?: string, price?: number, active_contact_price?: number, events?: Array<{ status: string, timestamp: string, description?: string, reason_code?: string, reason?: string }>, reason_code?: string, reason?: string, scheduled_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "scheduled_at": "2026-10-01T07:00:00+00:00", "id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "customer_id": "00000000-0000-0000-0000-000000000000", "contact_id": "00000000-0000-0000-0000-000000000000", "phone": "+14155551234", "phone_international": "+1 415-555-1234", "region_code": "US", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "template_category": null, "channel": "sms", "message_body": null, "status": "CANCELLED", "direction": "OUTBOUND", "created_at": "2026-09-30T11:59:00+00:00", "price": null, "active_contact_price": null, "events": null, "reason_code": null, "reason": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7629803+00:00", "version": "v3" } } ``` ### 400 Invalid message ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "id": [ "Invalid message ID format." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7629845+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Message not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_003", "message": "Message not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7630231+00:00", "version": "v3" } } ``` ### 409 Message is not scheduled, so there is nothing to cancel (already released, in flight, or finished) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_006", "message": "Only a scheduled message can be cancelled. This message has already been released for sending, is in flight, or has finished.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7630233+00:00", "version": "v3" } } ``` ### 429 Rate limit exceeded #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while cancelling the message.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7630242+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/messages/{id}/activities # GET /v3/messages/{id}/activities Get message activities Retrieves the activity log for a specific message. Activities track the message lifecycle including acceptance, processing, sending, delivery, and any errors. A SCHEDULED entry carries scheduled_at, the release instant in UTC as it stood at that moment. Other entries have no scheduled_at key. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3MessagesGetMessageActivitiesEndpoint` **Tags:** Messages ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Message ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Message activities retrieved successfully #### application/json ```typescript { success?: boolean, data?: { message_id?: string, activities?: Array<{ status?: string, description?: string, from?: string, timestamp?: string, scheduled_at?: string, reason_code?: string, reason?: string, price?: string, active_contact_price?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "activities": [ { "status": "DELIVERED", "description": "Message delivered to recipient", "from": "+15551234567", "timestamp": "2026-11-12T15:07:26.7648987+00:00", "scheduled_at": null, "reason_code": null, "reason": null, "price": "0.0450", "active_contact_price": "0.0050" }, { "status": "SENT", "description": "Message sent via SMS", "from": "+15551234567", "timestamp": "2026-11-12T15:02:26.7649256+00:00", "scheduled_at": null, "reason_code": null, "reason": null, "price": "0.0450", "active_contact_price": "0.0050" }, { "status": "PROCESSED", "description": "Message processed and queued for sending", "from": null, "timestamp": "2026-11-12T15:01:26.7649258+00:00", "scheduled_at": null, "reason_code": null, "reason": null, "price": "0.0450", "active_contact_price": "0.0050" }, { "status": "QUEUED", "description": "Message accepted and queued for processing", "from": null, "timestamp": "2026-11-12T15:00:26.7649259+00:00", "scheduled_at": null, "reason_code": null, "reason": null, "price": null, "active_contact_price": null } ], "pagination": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7649343+00:00", "version": "v3" } } ``` ### 400 Invalid message ID format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Message not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_003", "message": "Message not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7649364+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving message activities.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7649367+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/messages/{id} # GET /v3/messages/{id} Get message status Retrieves the current status and details of a message by ID. Includes delivery status, timestamps, and error information if applicable. A message that is or was held for a later time (a send you scheduled with scheduled_at, a quiet-hours hold, or a message you cancelled while it was held) is returned as a ScheduledMessageResponse: the same fields plus scheduled_at, the instant it is held for in UTC — or, on a CANCELLED message, the instant that was called off. A message sent immediately has no scheduled_at key. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3MessagesGetMessageEndpoint` **Tags:** Messages ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Message ID | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Message retrieved successfully. data is a MessageResponse, or for a message that is or was held for a later time a ScheduledMessageResponse: the same fields plus scheduled_at #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, contact_id?: string, phone?: string, phone_international?: string, region_code?: string, template_id?: string, template_name?: string, template_category?: string, channel?: string, message_body?: { header?: string, content?: string, footer?: string, buttons?: Array<{ type?: string, text?: string, value?: string, postbackData?: string }>, subject?: string, media?: Array<{ url?: string, mediaType?: string, mimeType?: string, sizeBytes?: integer, sourceHashSha256?: string }>, headerMedia?: { type?: string, url?: string } }, status?: string, direction?: string, created_at?: string, price?: number, active_contact_price?: number, events?: Array<{ status: string, timestamp: string, description?: string, reason_code?: string, reason?: string }>, reason_code?: string, reason?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "customer_id": "550e8400-e29b-41d4-a716-446655440000", "contact_id": "550e8400-e29b-41d4-a716-446655440002", "phone": "+14155551234", "phone_international": "+1 415-555-1234", "region_code": "US", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "Welcome Message", "template_category": "UTILITY", "channel": "sms", "message_body": { "header": null, "content": "Welcome to our service, John! We're excited to have you.", "footer": null, "buttons": null, "subject": null, "media": null, "headerMedia": null }, "status": "DELIVERED", "direction": "OUTBOUND", "created_at": "2026-11-12T13:32:26.7679913+00:00", "price": 0.0055, "active_contact_price": 0.015, "events": [ { "status": "QUEUED", "timestamp": "2026-11-12T13:32:26.7680344+00:00", "description": "Message queued for sending", "reason_code": null, "reason": null }, { "status": "SENT", "timestamp": "2026-11-12T13:32:31.7680506+00:00", "description": "Message sent via SMS", "reason_code": null, "reason": null }, { "status": "DELIVERED", "timestamp": "2026-11-12T13:32:36.7680525+00:00", "description": "Message delivered to recipient", "reason_code": null, "reason": null } ], "reason_code": null, "reason": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7680611+00:00", "version": "v3" } } ``` ### 400 Invalid message ID format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid message ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7680635+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Message not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_003", "message": "Message not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7680639+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving the message.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7680643+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/messages # POST /v3/messages Send a message Sends a message to one or more recipients using a template. Supports multi-channel broadcast — when multiple channels are specified (e.g. ["sms", "whatsapp"]), a separate message is created for each (recipient, channel) pair. To choose which of your own numbers a send goes out from, use 'channels': {"sms": [{"from": ["+12125550000", "+14155550000"]}]}. Each channel holds a list of entries, each with 'from' and optionally 'country' and 'strategy'; 'country' and 'strategy' are stored but not acted on yet, so every entry's numbers apply to every recipient on that channel. Every number listed must be an active sender on your account. Like the other account-level preconditions below, that is checked per message rather than when the request is received: the request is still accepted with 202, and each affected message is reported as BLOCKED with error code BUSINESS_029 on GET /messages/{id} and the message.blocked webhook. Each channel's numbers restrict which numbers that channel may use; it does not choose channels — 'channel' does, and the two can be combined. With 'channel' left at auto-detect, a recipient best served by a channel you listed no numbers for still goes out on it. Where several of the listed numbers could serve a recipient, routing prefers the one whose area code matches theirs. Keys: sms, whatsapp, rcs, mms. Returns immediately with per-recipient message IDs for async tracking via webhooks or the GET /messages/{id} endpoint. Sends gated before any delivery attempt do not reject the request — an account-level precondition such as insufficient balance, a template not approved for sending, or free-form content with no open conversation with the contact. The send is accepted with 202 and the affected messages are reported as BLOCKED on GET /messages/{id} and the message.blocked webhook. To send later, set scheduled_at (ISO-8601 with an explicit UTC offset; a value without one is rejected) between 1 minute and 30 days ahead: the response is a ScheduledSendMessageResponse (the same fields plus scheduled_at; status is still QUEUED), each message then moves to SCHEDULED, is held and released at that time (within a few minutes), and a message.scheduled webhook fires once it is held. Balance and template approval are evaluated at release, not at acceptance. Quiet hours are not checked when the request is accepted: if the time falls inside a legally protected quiet-hours window for a recipient, that message is moved to the next allowed time at release and a second message.scheduled webhook reports the new scheduled_at. An account may hold at most 1,000,000 scheduled messages at once: a message scheduled past that is reported as BLOCKED (LIMIT_001) instead of being held. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3MessagesSendMessageV3Endpoint` **Tags:** Messages ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, to?: Array, channel?: Array, channels?: object, template?: { id?: string, name?: string, parameters?: object }, text?: string, media_urls?: Array, subject?: string, scheduled_at?: string } ``` ## Responses ### 202 Message accepted for processing (QUEUED). data is a SendMessageResponse, or for a request that carried scheduled_at a ScheduledSendMessageResponse: the same fields plus scheduled_at. Status is QUEUED in both, and each scheduled message moves to SCHEDULED once it is held #### application/json ```typescript { success?: boolean, data?: { status?: string, template_id?: string, template_name?: string, recipients?: Array<{ message_id?: string, to?: string, channel?: string, body?: string }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+14155551234", "channel": "sms", "body": "Hi John Doe, your order #12345 has been confirmed." }, { "message_id": "8ba7b831-9dad-11d1-80b4-00c04fd430c8", "to": "+14155551234", "channel": "whatsapp", "body": "Hi John Doe, your order #12345 has been confirmed." }, { "message_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "to": "+14155555678", "channel": "sms", "body": "Hi John Doe, your order #12345 has been confirmed." }, { "message_id": "9ba7b841-9dad-11d1-80b4-00c04fd430c8", "to": "+14155555678", "channel": "whatsapp", "body": "Hi John Doe, your order #12345 has been confirmed." } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7749203+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_004", "message": "Request validation failed", "details": { "to": [ "'to' must contain at least one recipient" ], "template": [ "'template' is required" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7749227+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Template not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_002", "message": "Template not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7749232+00:00", "version": "v3" } } ``` ### 429 Rate limit exceeded #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_002", "message": "Rate limit exceeded", "details": null, "doc_url": "https://docs.sent.dm/reference/api/rate-limits" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7749236+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to queue message for processing.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7749245+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/numbers/lookup/{phoneNumber} # GET /v3/numbers/lookup/{phoneNumber} Get phone number details Retrieves detailed information about a phone number including carrier, line type, porting status, and VoIP detection. Uses the customer's messaging provider for rich data, with fallback to the internal index. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3NumbersGetNumberEndpoint` **Tags:** Numbers ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `phoneNumber` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Phone number details returned successfully #### application/json ```typescript { success?: boolean, data?: { phone_number?: string, is_valid?: boolean, carrier_name?: string, line_type?: string, country_code?: string, mobile_country_code?: string, mobile_network_code?: string, is_ported?: boolean, is_voip?: boolean }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "phone_number": "+12025551234", "is_valid": true, "carrier_name": "T-Mobile", "line_type": "mobile", "country_code": "US", "mobile_country_code": "310", "mobile_network_code": "260", "is_ported": false, "is_voip": false }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7599898+00:00", "version": "v3" } } ``` ### 400 Invalid request - Phone number is missing or invalid #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Phone number is required", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7599927+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid or missing API credentials ### 403 Forbidden ### 404 Phone number not found in provider or internal index #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_013", "message": "Phone number not found or invalid", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7599934+00:00", "version": "v3" } } ``` ### 500 Internal server error - Contact support with request ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7599938+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # OpenAPI Specification (/reference/api/openapi-spec.md) # OpenAPI specification [#openapi-specification] Fetch the machine-readable OpenAPI document for v3 here: ``` https://docs.sent.dm/api/openapi/v3 ``` No API key needed. Use it to generate a client, validate a wrapper you maintain, or diff the API surface between releases. The document is generated from the deployed API rather than maintained by hand, so it describes the surface that's live. Every page in this reference section is rendered from the same document. --- ## Pin a revision [#pin-a-revision] The document carries no version number of its own. `info.version` is the string `v3` and doesn't increment, so use the SHA-256 digest of the body to identify a revision. Every response carries it two ways: | Header | Value | | --- | --- | | `ETag` | The digest, quoted | | `x-sent-spec-sha256` | The digest, bare | Record the digest alongside your generated client: ```bash curl -sS https://docs.sent.dm/api/openapi/v3 -o openapi.json shasum -a 256 openapi.json ``` To check for a change without downloading the document again, send the digest back: ```bash curl -sS -o /dev/null -w '%{http_code}\n' \ -H 'If-None-Match: ""' \ https://docs.sent.dm/api/openapi/v3 ``` `304` means the surface hasn't changed. `200` means it has, and the body is the new document. `HEAD` works the same way and returns the digest without a body, so use it when you only want to know whether to re-download: ```bash curl -sSI -H 'If-None-Match: ""' https://docs.sent.dm/api/openapi/v3 ``` Check the digest in CI to catch an API surface change before it reaches your users. A `200` where you expected a `304` is the signal to regenerate and review. ### Why the digest is stable [#why-the-digest-is-stable] Response examples in the document are built when the API generates it, and the timestamps inside them reflect that moment. Hashing the generator's output directly gives a different digest on every request even when nothing about the API has changed. The document served here pins every example timestamp to a single value, so the digest tracks the API surface instead of the clock. Nothing else is altered: no field is added, removed, renamed, or restructured. If you fetch from `api.sent.dm/swagger/v3/swagger.json` yourself, pin the timestamps before you hash or diff, or you'll see changes that aren't there. --- ## What the document covers [#what-the-document-covers] Every v3 endpoint: its path, method, request body, response bodies, error shapes, and the headers Sent returns. It also carries the schemas for the events Sent POSTs to your webhook endpoint, so you can generate types for the payload your handler receives rather than writing them by hand. Those schemas sit in `components/schemas` without being attached to an endpoint, because your endpoint receives them and ours doesn't serve them. Point your generator at the components directly. For the event catalogue with a worked example of each payload, see [Events Reference](/start/webhooks/event-types). --- ## What it doesn't cover [#what-it-doesnt-cover] - **Retry and signature behaviour.** How Sent retries a failed delivery, and how to verify a signature, are described in [Handling retries](/start/webhooks/handling-retries) and [Signature verification](/start/webhooks/signature-verification). - **Rate limits.** See [Rate limits](/reference/api/rate-limits) for the quotas that apply to your plan. - **The v2 API.** v2 has its own document at `https://api.sent.dm/swagger/v2/swagger.json`. It's maintained for backward compatibility, and new integrations should use v3. See [Migrating from v2 to v3](/reference/api/v2-to-v3). --- ## Working with strict validators [#working-with-strict-validators] The document is OpenAPI 3.0. Some validators reject `nullable` where it appears without an accompanying `type`, which this document does in a few places on composed schemas. If your generator stops there, drop `nullable: false` and rewrite `nullable: true` as a union with `null`. Both edits are safe because neither changes what the schema accepts. Sent publishes the document without those rewrites. If you're checking a client against the real API, an artifact that restructures schemas would send you looking for bugs that aren't there. method: POST route: /v3/profiles/{profileId}/complete # POST /v3/profiles/{profileId}/complete Complete profile setup **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Final step in the profile compliance workflow. Validates all prerequisites (KYC, brand, campaigns, required documents), connects the profile to the SMS and WhatsApp channels, and marks it onboarded. Prerequisites are always validated first: if any fail the call returns 400 naming every unmet one, and nothing is started. If they pass and the profile is already onboarded, the call returns 200 and does nothing. Otherwise it returns 202 and calls the provided webhook URL when background processing finishes. Callable with the organization's API key or the profile's own key. The key's user must be an admin or owner of the profile, or of the organization it belongs to. Prerequisites (all but the last are checked before the already-onboarded short-circuit, matching the previous contract; the last is checked after it, so a profile that is already onboarded is never rejected by it): - Profile must have a name, short name, and description (short name max 50 characters, description max 5000) - webHookUrl must be supplied on the request - A KYC form submission is required - A brand is required, either on the profile or inherited from the parent organization - TCR applications must have at least one campaign, own or inherited - Destination countries marked as main must have their required compliance documents uploaded - TCR applications must state whether they inherit the organization's TCR brand and campaign Outcome: - Once the prerequisites pass and background processing succeeds, the profile's conversionFlowStatus becomes ONBOARDED and its public status reads `approved` - A profile with no WhatsApp channel, or one still awaiting TCR registration or country documents, is onboarded like any other. Those are answered by the brand and campaign records, not by a status on the profile - If background processing fails, the profile keeps the status it already had and the webhook reports the reason **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ProfilesCompleteProfileEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, webHookUrl?: string } ``` ## Responses ### 200 Profile is already onboarded - returns current status #### application/json ```typescript { success?: boolean, data?: { status?: string, message?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "status": "approved", "message": "Profile is already completed" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.6974492+00:00", "version": "v3" } } ``` ### 202 Profile completion started successfully - webhook will be called when finished #### application/json ```typescript { success?: boolean, data?: { message?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "message": "Profile completion in progress" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.697466+00:00", "version": "v3" } } ``` ### 400 Invalid request - validation errors, or prerequisites not met (the response names every unmet one) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Valid API key required ### 403 Forbidden - the key's user is not an admin of the profile or of the organization it belongs to ### 404 Profile not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error occurred during validation #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/profiles # POST /v3/profiles Create a new profile **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Creates a new sender profile within an organization. Profiles represent different brands, departments, or use cases, each with their own messaging configuration and settings. Requires admin role in the organization. ## WhatsApp Business Account Every profile owns its own WhatsApp Business Account — accounts are never shared between profiles or inherited from the organization. Provide a `whatsapp_business_account` object with `waba_id`, `phone_number_id`, and `access_token`. Obtain these from Meta Business Manager by creating a System User with `whatsapp_business_messaging` and `whatsapp_business_management` permissions. Omit the field and the profile is created without WhatsApp, staying incomplete until it has an account of its own. ## Brand Include the optional `brand` field to create the brand for this profile at the same time. Cannot be used when `inherit_tcr_brand` is `true`. ## Payment Details When `billing_model` is `"profile"` or `"profile_and_organization"` you may include a `payment_details` object containing the card number, expiry (MM/YY), CVC, and billing ZIP code. Payment details are **never stored** on our servers and are forwarded directly to the payment processor. Providing `payment_details` when `billing_model` is `"organization"` is not allowed. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ProfilesCreateProfileEndpoint` **Tags:** Profiles ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, icon?: string, description?: string, short_name?: string, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string, billing_contact?: { name?: string, email?: string, phone?: string, address?: string }, whatsapp_business_account?: { waba_id?: string, phone_number_id?: string, access_token?: string }, brand?: { contact?: unknown, business?: { legalName?: string, taxId?: string, taxIdType?: string, entityType?: { }, street?: string, city?: string, state?: string, postalCode?: string, country?: string, url?: string, countryOfRegistration?: string }, compliance?: unknown }, payment_details?: { card_number?: string, expiry?: string, cvc?: string, zip_code?: string }, allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean } ``` ## Responses ### 201 Profile created successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, email?: string, icon?: string, description?: string, short_name?: string, status?: string, created_at?: string, updated_at?: string, allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string, sending_phone_number_profile_id?: string, sending_whatsapp_number_profile_id?: string, sending_phone_number?: string, whatsapp_phone_number?: string, allow_number_change_during_onboarding?: boolean, waba_id?: string, billing_contact?: { name?: string, email?: string, phone?: string, address?: string }, brand?: { id?: string, tcr_brand_id?: string, status?: { }, identity_status?: { }, universal_ein?: string, csp_id?: string, submitted_to_tcr?: boolean, submitted_at?: string, is_inherited?: boolean, created_at?: string, updated_at?: string, contact?: { name?: string, business_name?: string, role?: string, phone?: string, email?: string, phone_country_code?: string }, business?: { legal_name?: string, tax_id?: string, tax_id_type?: string, entity_type?: string, street?: string, city?: string, state?: string, postal_code?: string, country?: string, url?: string, country_of_registration?: string }, compliance?: { vertical?: { }, brand_relationship?: { }, is_tcr_application?: boolean, phone_number_prefix?: string, destination_countries?: Array<{ id?: string, isMain?: boolean }>, notes?: string, primary_use_case?: string } } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Sales Team", "email": "team@acme.com", "icon": "https://example.com/sales-icon.png", "description": "Sales department sender profile", "short_name": "SALES", "status": "incomplete", "created_at": "2026-11-12T15:32:26.7001996+00:00", "updated_at": "2026-11-12T15:32:26.700208+00:00", "allow_contact_sharing": false, "allow_template_sharing": false, "inherit_contacts": false, "inherit_templates": false, "inherit_tcr_brand": false, "inherit_tcr_campaign": false, "billing_model": "profile", "sending_phone_number_profile_id": null, "sending_whatsapp_number_profile_id": null, "sending_phone_number": null, "whatsapp_phone_number": null, "allow_number_change_during_onboarding": null, "waba_id": "123456789012345", "billing_contact": { "name": "Acme Corp", "email": "billing@acmecorp.com", "phone": "+12025551234", "address": "123 Main Street, New York, NY 10001, US" }, "brand": { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "tcr_brand_id": null, "status": null, "identity_status": null, "universal_ein": null, "csp_id": null, "submitted_to_tcr": false, "submitted_at": null, "is_inherited": false, "created_at": "2026-11-12T15:32:26.7003216+00:00", "updated_at": null, "contact": { "name": "John Smith", "business_name": "Acme Corp", "role": null, "phone": null, "email": "john@acmecorp.com", "phone_country_code": null }, "business": { "legal_name": "Acme Corporation LLC", "tax_id": null, "tax_id_type": null, "entity_type": null, "street": null, "city": null, "state": null, "postal_code": null, "country": "US", "url": null, "country_of_registration": null }, "compliance": { "vertical": "PROFESSIONAL", "brand_relationship": "SMALL_ACCOUNT", "is_tcr_application": true, "phone_number_prefix": null, "destination_countries": [ { "id": "US", "isMain": false } ], "notes": null, "primary_use_case": null } } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7005205+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters, or the organization has no WhatsApp Business Account configured and none was supplied in whatsapp_business_account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "name": [ "Profile name is required" ], "short_name": [ "short_name must be 3–11 characters, contain only letters, numbers, and spaces, and include at least one letter" ], "payment_details.expiry": [ "payment_details.expiry must be in MM/YY format (e.g. '09/27')" ], "whatsapp_business_account": [ "Organization does not have a WhatsApp Business Account configured. Complete WhatsApp Embedded Signup for your organization first, or provide direct credentials in the 'whatsapp_business_account' field." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7005321+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have admin access to this organization ### 404 Organization not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_005", "message": "Organization not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7005327+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to create profile. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7005331+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/profiles/{profileId} # DELETE /v3/profiles/{profileId} Delete a profile **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Soft deletes a sender profile. The profile will be marked as deleted but data is retained. Anything it still held is released first: phone numbers return to our inventory and can go to whoever asks next, its own WhatsApp account is deregistered, and its routing rules stop being used. Requires admin role in the organization. A number it holds that your WhatsApp Business Account still carries refuses the delete with a `409 CONFLICT_012`, and nothing is deleted: the number would return to our shared inventory while Meta still routes WhatsApp to it, and only you can take it off the account — deregister **and** delete it in WhatsApp Manager, then try again. A `409 CONFLICT_013` means the account could not be read, so we cannot tell. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ProfilesDeleteProfileEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 Profile deleted successfully ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have admin access to this profile ### 404 Profile not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_014", "message": "Profile not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7019077+00:00", "version": "v3" } } ``` ### 409 Refused, nothing deleted: a number the profile holds is still on your WhatsApp Business Account, or that account could not be read #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to delete profile. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7019092+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/profiles/{profileId} # GET /v3/profiles/{profileId} Get profile by ID **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Retrieves detailed information about a specific sender profile within an organization, including brand and KYC information if a brand has been configured. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ProfilesGetProfileEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Profile retrieved successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, email?: string, icon?: string, description?: string, short_name?: string, status?: string, created_at?: string, updated_at?: string, allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string, sending_phone_number_profile_id?: string, sending_whatsapp_number_profile_id?: string, sending_phone_number?: string, whatsapp_phone_number?: string, allow_number_change_during_onboarding?: boolean, waba_id?: string, billing_contact?: { name?: string, email?: string, phone?: string, address?: string }, brand?: { id?: string, tcr_brand_id?: string, status?: { }, identity_status?: { }, universal_ein?: string, csp_id?: string, submitted_to_tcr?: boolean, submitted_at?: string, is_inherited?: boolean, created_at?: string, updated_at?: string, contact?: { name?: string, business_name?: string, role?: string, phone?: string, email?: string, phone_country_code?: string }, business?: { legal_name?: string, tax_id?: string, tax_id_type?: string, entity_type?: string, street?: string, city?: string, state?: string, postal_code?: string, country?: string, url?: string, country_of_registration?: string }, compliance?: { vertical?: { }, brand_relationship?: { }, is_tcr_application?: boolean, phone_number_prefix?: string, destination_countries?: Array<{ id?: string, isMain?: boolean }>, notes?: string, primary_use_case?: string } } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Sales Team", "email": "team@acme.com", "icon": "https://example.com/sales-icon.png", "description": "Sales department sender profile", "short_name": "SALES", "status": "approved", "created_at": "2026-08-12T15:32:26.7045608+00:00", "updated_at": "2026-11-07T15:32:26.7045618+00:00", "allow_contact_sharing": false, "allow_template_sharing": false, "inherit_contacts": false, "inherit_templates": false, "inherit_tcr_brand": false, "inherit_tcr_campaign": false, "billing_model": "profile", "sending_phone_number_profile_id": null, "sending_whatsapp_number_profile_id": null, "sending_phone_number": null, "whatsapp_phone_number": null, "allow_number_change_during_onboarding": null, "waba_id": null, "billing_contact": null, "brand": { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "tcr_brand_id": null, "status": null, "identity_status": null, "universal_ein": null, "csp_id": null, "submitted_to_tcr": false, "submitted_at": null, "is_inherited": false, "created_at": "2026-08-12T15:32:26.7045625+00:00", "updated_at": null, "contact": { "name": "John Smith", "business_name": "Acme Corp", "role": null, "phone": null, "email": "john@acmecorp.com", "phone_country_code": null }, "business": { "legal_name": "Acme Corporation LLC", "tax_id": null, "tax_id_type": null, "entity_type": null, "street": null, "city": null, "state": null, "postal_code": null, "country": "US", "url": null, "country_of_registration": null }, "compliance": { "vertical": "PROFESSIONAL", "brand_relationship": "SMALL_ACCOUNT", "is_tcr_application": true, "phone_number_prefix": null, "destination_countries": [ { "id": "US", "isMain": false } ], "notes": null, "primary_use_case": null } } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7045641+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have access to this profile ### 404 Profile not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_014", "message": "Profile not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7045658+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to retrieve profile. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7045666+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/profiles # GET /v3/profiles List profiles in organization **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Retrieves all sender profiles within an organization, including brand information for each profile. Profiles represent different brands, departments, or use cases within an organization, each with their own messaging configuration. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ProfilesGetProfilesEndpoint` **Tags:** Profiles ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Profiles retrieved successfully #### application/json ```typescript { success?: boolean, data?: { profiles?: Array<{ id?: string, organization_id?: string, name?: string, email?: string, icon?: string, description?: string, short_name?: string, status?: string, created_at?: string, updated_at?: string, allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string, sending_phone_number_profile_id?: string, sending_whatsapp_number_profile_id?: string, sending_phone_number?: string, whatsapp_phone_number?: string, allow_number_change_during_onboarding?: boolean, waba_id?: string, billing_contact?: { name?: string, email?: string, phone?: string, address?: string }, brand?: { id?: string, tcr_brand_id?: string, status?: { }, identity_status?: { }, universal_ein?: string, csp_id?: string, submitted_to_tcr?: boolean, submitted_at?: string, is_inherited?: boolean, created_at?: string, updated_at?: string, contact?: { name?: string, business_name?: string, role?: string, phone?: string, email?: string, phone_country_code?: string }, business?: { legal_name?: string, tax_id?: string, tax_id_type?: string, entity_type?: string, street?: string, city?: string, state?: string, postal_code?: string, country?: string, url?: string, country_of_registration?: string }, compliance?: { vertical?: { }, brand_relationship?: { }, is_tcr_application?: boolean, phone_number_prefix?: string, destination_countries?: Array<{ id?: string, isMain?: boolean }>, notes?: string, primary_use_case?: string } } }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "profiles": [ { "id": "660e8400-e29b-41d4-a716-446655440001", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Marketing Team", "email": "team@acme.com", "icon": "https://example.com/marketing-icon.png", "description": "Marketing department sender profile", "short_name": "MKT", "status": "approved", "created_at": "2026-08-12T15:32:26.7061314+00:00", "updated_at": "2026-11-07T15:32:26.706132+00:00", "allow_contact_sharing": false, "allow_template_sharing": false, "inherit_contacts": false, "inherit_templates": false, "inherit_tcr_brand": false, "inherit_tcr_campaign": false, "billing_model": "profile", "sending_phone_number_profile_id": null, "sending_whatsapp_number_profile_id": null, "sending_phone_number": null, "whatsapp_phone_number": null, "allow_number_change_during_onboarding": null, "waba_id": null, "billing_contact": null, "brand": { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "tcr_brand_id": null, "status": null, "identity_status": null, "universal_ein": null, "csp_id": null, "submitted_to_tcr": false, "submitted_at": null, "is_inherited": false, "created_at": "2026-08-12T15:32:26.7061325+00:00", "updated_at": null, "contact": { "name": "John Smith", "business_name": "Acme Corp", "role": null, "phone": null, "email": "john@acmecorp.com", "phone_country_code": null }, "business": { "legal_name": "Acme Corporation LLC", "tax_id": null, "tax_id_type": null, "entity_type": null, "street": null, "city": null, "state": null, "postal_code": null, "country": "US", "url": null, "country_of_registration": null }, "compliance": { "vertical": "PROFESSIONAL", "brand_relationship": "SMALL_ACCOUNT", "is_tcr_application": true, "phone_number_prefix": null, "destination_countries": [], "notes": null, "primary_use_case": null } } } ], "pagination": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7061521+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have access to this organization ### 404 Organization not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_005", "message": "Organization not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7061538+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to retrieve profiles. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7061542+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/profiles/{profileId} # PATCH /v3/profiles/{profileId} Update profile settings **Deprecated.** This endpoint is replaced by `/v3/sender-profiles` and will be removed in a future release. It still behaves exactly as before, so nothing needs to change today — but new integrations should use `/v3/sender-profiles`, which models a profile's markets, compliance, brand, campaigns and billing explicitly. Updates a profile's configuration and settings. Requires admin role in the organization. Only provided fields will be updated (partial update). ## Brand Management Include the optional `brand` field to create or update the brand associated with this profile. The brand holds KYC and TCR compliance data (legal business info, contact details, messaging vertical). Once a brand has been submitted to TCR it cannot be modified. Setting `inherit_tcr_brand: true` and providing `brand` in the same request is not allowed. ## Payment Details When `billing_model` is `"profile"` or `"profile_and_organization"` you may include a `payment_details` object containing the card number, expiry (MM/YY), CVC, and billing ZIP code. Payment details are **never stored** on our servers and are forwarded directly to the payment processor. Providing `payment_details` when `billing_model` is `"organization"` is not allowed. ## Deprecated fields `sending_phone_number_profile_id` and `sending_whatsapp_number_profile_id` are **accepted and ignored**. Sender borrowing is gone: a profile cannot send from another profile's number, because two profiles behind one sender makes an inbound reply and a delivery receipt ambiguous about whose they are. Sending either **changes nothing and still returns `200`** — they are kept on the contract so an existing integration keeps working. Reads carry both keys too and always answer `null`, which is how you can confirm the value did not take. Give the profile a sender of its own instead — `POST /v3/channels/sms` or `POST /v3/channels/whatsapp`, sent with the `x-profile-id` header naming it. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3ProfilesUpdateProfileEndpoint` **Tags:** Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `profileId` | `string` | true | Profile ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, icon?: string, description?: string, short_name?: string, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string, billing_contact?: { name?: string, email?: string, phone?: string, address?: string }, sending_phone_number_profile_id?: string, sending_whatsapp_number_profile_id?: string, allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean, sending_phone_number?: string, whatsapp_phone_number?: string, allow_number_change_during_onboarding?: boolean, brand?: { contact?: unknown, business?: { legalName?: string, taxId?: string, taxIdType?: string, entityType?: { }, street?: string, city?: string, state?: string, postalCode?: string, country?: string, url?: string, countryOfRegistration?: string }, compliance?: unknown }, payment_details?: { card_number?: string, expiry?: string, cvc?: string, zip_code?: string } } ``` ## Responses ### 200 Profile updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, email?: string, icon?: string, description?: string, short_name?: string, status?: string, created_at?: string, updated_at?: string, allow_contact_sharing?: boolean, allow_template_sharing?: boolean, inherit_contacts?: boolean, inherit_templates?: boolean, inherit_tcr_brand?: boolean, inherit_tcr_campaign?: boolean, billing_model?: string, sending_phone_number_profile_id?: string, sending_whatsapp_number_profile_id?: string, sending_phone_number?: string, whatsapp_phone_number?: string, allow_number_change_during_onboarding?: boolean, waba_id?: string, billing_contact?: { name?: string, email?: string, phone?: string, address?: string }, brand?: { id?: string, tcr_brand_id?: string, status?: { }, identity_status?: { }, universal_ein?: string, csp_id?: string, submitted_to_tcr?: boolean, submitted_at?: string, is_inherited?: boolean, created_at?: string, updated_at?: string, contact?: { name?: string, business_name?: string, role?: string, phone?: string, email?: string, phone_country_code?: string }, business?: { legal_name?: string, tax_id?: string, tax_id_type?: string, entity_type?: string, street?: string, city?: string, state?: string, postal_code?: string, country?: string, url?: string, country_of_registration?: string }, compliance?: { vertical?: { }, brand_relationship?: { }, is_tcr_application?: boolean, phone_number_prefix?: string, destination_countries?: Array<{ id?: string, isMain?: boolean }>, notes?: string, primary_use_case?: string } } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Sales Team - Updated", "email": "team@acme.com", "icon": "https://example.com/sales-icon.png", "description": "Updated sales department sender profile", "short_name": "SALES", "status": "approved", "created_at": "2026-08-12T15:32:26.7082014+00:00", "updated_at": "2026-11-12T15:32:26.708202+00:00", "allow_contact_sharing": false, "allow_template_sharing": false, "inherit_contacts": false, "inherit_templates": false, "inherit_tcr_brand": false, "inherit_tcr_campaign": false, "billing_model": "organization", "sending_phone_number_profile_id": null, "sending_whatsapp_number_profile_id": null, "sending_phone_number": null, "whatsapp_phone_number": null, "allow_number_change_during_onboarding": null, "waba_id": null, "billing_contact": null, "brand": { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "tcr_brand_id": null, "status": null, "identity_status": null, "universal_ein": null, "csp_id": null, "submitted_to_tcr": false, "submitted_at": null, "is_inherited": false, "created_at": "2026-11-12T15:32:26.7082024+00:00", "updated_at": null, "contact": { "name": "John Smith", "business_name": "Acme Corp", "role": null, "phone": null, "email": "john@acmecorp.com", "phone_country_code": null }, "business": { "legal_name": "Acme Corporation LLC", "tax_id": null, "tax_id_type": null, "entity_type": null, "street": null, "city": null, "state": null, "postal_code": null, "country": "US", "url": null, "country_of_registration": null }, "compliance": { "vertical": "PROFESSIONAL", "brand_relationship": "SMALL_ACCOUNT", "is_tcr_application": true, "phone_number_prefix": null, "destination_countries": [ { "id": "US", "isMain": false } ], "notes": null, "primary_use_case": null } } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7082035+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "brand": [ "Cannot provide brand data when inherit_tcr_brand is true." ], "payment_details.expiry": [ "payment_details.expiry must be in MM/YY format (e.g. '09/27')" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7082076+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have admin access to this profile ### 404 Profile not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_014", "message": "Profile not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7082081+00:00", "version": "v3" } } ``` ### 409 Refused, nothing updated: changing a phone number would release the old one, and your WhatsApp Business Account still carries it (`CONFLICT_012`) or could not be read (`CONFLICT_013`) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to update profile. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.7082085+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # Rate Limits (/reference/api/rate-limits.md) # Rate Limits [#rate-limits] The Sent API v3 implements rate limiting to ensure platform stability and fair access for all users. Rate limits apply per customer account: all API keys for the same account share one rate limit pool, and requests scoped to a profile via the `x-profile-id` header count against the organization's pool. Unauthenticated requests are limited per IP address. For backoff, monitoring, and throttling implementations, see [How to handle Sent API rate limits](/start/guides/handling-rate-limits). --- ## Rate Limit Tiers [#rate-limit-tiers] ### Standard Endpoints [#standard-endpoints] Most API endpoints, including message sending (`POST /v3/messages`), use the standard limit: | Tier | Limit | Window | |------|-------|--------| | Standard | 10,000 requests per minute | Sliding 60-second window | ### Sensitive Endpoints [#sensitive-endpoints] Two endpoints that perform sensitive operations have stricter limits: | Tier | Limit | Window | |------|-------|--------| | Sensitive | 10 requests per minute | Fixed 60-second window | **Sensitive endpoints:** - Webhook secret rotation (`POST /v3/webhooks/{id}/rotate-secret`) - Webhook test delivery (`POST /v3/webhooks/{id}/test`) All other endpoints, including user invitation (`POST /v3/users`) and profile completion (`POST /v3/profiles/{profileId}/complete`), use the standard limit of 10,000 requests per minute. ### Which Requests Count [#which-requests-count] Requests rejected during authentication (`401`, `403`) do not count against rate limits. All other requests count toward your limit, including those that fail validation (`400`, `422`). --- ## Rate Limit Headers [#rate-limit-headers] Rate limit headers are sent **only on `429 Too Many Requests` responses**. Successful responses do not carry `X-RateLimit-*` headers, so there is no per-request quota readout. Treat `429` responses as the signal that you have reached the limit. ```http Retry-After: 60 X-RateLimit-Limit: 10000 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 1705312800 ``` ### Header Reference [#header-reference] | Header | Description | Example | |--------|-------------|---------| | `Retry-After` | Seconds until you can retry | `60` | | `X-RateLimit-Limit` | Maximum requests allowed in the window | `10000` | | `X-RateLimit-Remaining` | Requests remaining (always `0` on 429) | `0` | | `X-RateLimit-Reset` | Unix timestamp when the current window expires | `1705312800` | Standard limits use a sliding window, so capacity returns gradually as requests age out of the preceding 60 seconds rather than resetting at a fixed time. --- ## 429 Response Body [#429-response-body] When rate limited, the API returns error code `BUSINESS_002` in the standard error envelope: ```json { "success": false, "status": 429, "error": { "code": "BUSINESS_002", "message": "Rate limit exceeded. Please retry after 60 seconds.", "doc_url": "https://docs.sent.dm/reference/api/rate-limits" }, "meta": { "request_id": "req_abc123", "timestamp": "2024-01-15T10:30:00Z", "version": "v3" } } ``` --- ## Rate Limiting by Endpoint [#rate-limiting-by-endpoint] Rather than enumerate every operation, the rule is: | Scope | Limit | Window | |-------|-------|--------| | Webhook secret rotation (`POST /v3/webhooks/{id}/rotate-secret`) | 10/min | Fixed 60-second | | Webhook test delivery (`POST /v3/webhooks/{id}/test`) | 10/min | Fixed 60-second | | Voice token exchange (`POST /v3/voice/tokens/exchange`, called by [`@sentdm/voice-client`](/sdks/voice), not by your server) | 10/min per app identity, and 3,000/min per account | Sliding 60-second | | Voice SDK telemetry (`POST /v3/voice/telemetry`, called by [`@sentdm/voice-client`](/sdks/voice), not by your server) | 30/min per app identity, and 3,000/min per account | Sliding 60-second | | **Every other v3 endpoint** | 10,000/min | Sliding 60-second | The preceding exception list is exhaustive: the two sensitive endpoints and the voice SDK's token exchange and telemetry endpoints are the only exceptions in v3. Contacts, messages, templates, webhooks, users, profiles, conversations, brands, number lookup, calls, voice numbers, and `GET /v3/me` all use the standard 10,000/min limit, so a new endpoint is at 10,000/min unless this page says otherwise. The `/v2` API has its own limits, including a separate daily cap on quick-message. See [Rate limits (v2)](/reference-legacy/api/rate-limits). --- ## Increasing Rate Limits [#increasing-rate-limits] The standard limit is set high enough that most integrations never reach it – 10,000 requests per minute at 1,000 recipients per request accepts 10 million messages a minute from one account. If you do hit it, contact [support@sent.dm](mailto:support@sent.dm) with your use case, expected volume, and the `429` responses you are seeing. Before requesting an increase, confirm your integration isn't wasting its budget on avoidable requests. [How to handle Sent API rate limits](/start/guides/handling-rate-limits) covers caching, throttling, and using [webhooks](/start/webhooks/getting-started) instead of polling. --- ## Related guides [#related-guides] - [How to handle Sent API rate limits](/start/guides/handling-rate-limits): exponential backoff, 429 monitoring, client-side throttling, and paced batch processing. - [How to retry Sent API requests safely](/start/guides/retrying-requests-safely): idempotency keys for retried mutations. - [How to handle Sent API errors](/start/guides/handling-api-errors): the error envelope and code-based branching. # Roles and Permissions (/reference/api/roles-and-permissions.md) # Roles and Permissions [#roles-and-permissions] The Sent platform defines four user roles for organizations and Sender Profiles: `owner`, `admin`, `developer`, and `billing`. Roles gate a small set of API operations (profile management and user management) and sections of the [Sent Dashboard](https://app.sent.dm). A request that fails a role check returns HTTP 403 with error code [`AUTH_004`](/reference/api/error-catalog#auth_004-insufficient-permissions). --- ## Role catalog [#role-catalog] | Role | Assignable via API | Access | |------|--------------------|--------| | `owner` | No | The account that created the organization or profile. The owner is implicit: it has no entry in the user list and satisfies every role check, including the checks that require `admin`. | | `admin` | Yes | Passes all role checks: profile management, user management, and read operations. | | `developer` | Yes | Passes any-role checks: reading profiles and listing users. In the dashboard, has access to development and messaging sections but not user, profile, or billing management. | | `billing` | Yes | Passes any-role checks: reading profiles and listing users. In the dashboard, has access to the Billing section only. | Role values are lowercase in API requests and responses: `admin`, `billing`, `developer`. The `owner` role cannot be requested in an invitation or role update: only the original creator of the organization or profile carries it. --- ## How the API evaluates roles [#how-the-api-evaluates-roles] Every API key belongs to an account. Role checks are evaluated against the email address of the account that owns the API key: - The check passes immediately when that email matches the owner email of the organization or profile being accessed. - Otherwise, the check passes when an **active** user with that email exists on the organization or profile and holds an allowed role. - For Sender Profiles, checks cascade to the parent organization: owner or role access at the organization level also grants access to its profiles. - Users with `invited`, `suspended`, or `rejected` status fail role checks. Only `active` users count, including toward the rule that protects the last active `admin`. A failed check returns HTTP 403 with `error.code` `AUTH_004` and a `doc_url` pointing to the [authentication reference](/reference/api/authentication). --- ## API operations gated by role [#api-operations-gated-by-role] The following v3 operations perform a role check. All other v3 operations (messages, contacts, conversations, templates, campaigns, webhooks, number lookup, calls, voice numbers, and `/v3/me`) require only a valid API key and are not role-gated. {/* The 403 strings in this table are verbatim API responses: "admin" is the literal wording the API returns and cannot be rephrased. */} {/* vale Google.WordList = NO */} | Operation | Required role | 403 `AUTH_004` message | |-----------|--------------|------------------------| | `POST /v3/profiles` | `admin` (on the organization) | "You do not have admin access to this organization" | | `PATCH /v3/profiles/{profileId}` | `admin` | "You do not have admin access to this profile" | | `DELETE /v3/profiles/{profileId}` | `admin` | "You do not have admin access to this profile" | | `GET /v3/profiles/{profileId}` | Any role | "You do not have access to this profile" | | `POST /v3/users` | `admin` | "You do not have admin access to this organization or profile" | | `PATCH /v3/users/{userId}` | `admin` | "You do not have admin access to this organization or profile" | | `DELETE /v3/users/{userId}` | `admin` | "You do not have admin access to this organization or profile" | | `GET /v3/users` | Any role | "You do not have access to this organization or profile" | | `GET /v3/users/{userId}` | Any role | "You do not have access to this organization or profile" | {/* vale Google.WordList = YES */} "Any role" means any active user of the organization or profile, regardless of role. The owner passes every check in this table. User management enforces three hard constraints: you cannot change your own role, you cannot remove yourself, and you cannot demote or remove the last active `admin`. Invitations sent with `POST /v3/users` expire after 7 days. Assignable roles for invitations and role updates are `admin`, `billing`, and `developer`. --- ## Dashboard access by role [#dashboard-access-by-role] The dashboard gates its sections by the signed-in user's role: | Dashboard section | Roles with access | |-------------------|-------------------| | Overview | All roles | | Templates, Playground, Contacts | `owner`, `admin`, `developer` | | Profiles | `owner`, `admin` | | Number Lookup | `owner`, `admin`, `developer` | | Activities, API Keys, Webhooks | `owner`, `admin`, `developer` | | Compliance | `owner`, `admin` | | Channels, Settings | `owner`, `admin`, `developer` | | Users | `owner`, `admin` | | Billing | `owner`, `admin`, `billing` | --- ## Organization keys and the `x-profile-id` header [#organization-keys-and-the-x-profile-id-header] Every v3 operation accepts the optional `x-profile-id` request header (a profile UUID). It scopes the request to a child profile, so an organization API key can act on behalf of one of its profiles. | Condition | Result | |-----------|--------| | Organization key + UUID of one of its profiles | The request executes as that profile. The response echoes the `X-Profile-Id` header. | | Profile API key + `x-profile-id` | 403 `AUTH_004`: "Profile API keys cannot use x-profile-id. Only organization API keys can act on behalf of profiles." | | Header value is not a valid UUID | 400 `VALIDATION_003` | | Profile does not exist or belongs to another organization | 404 `RESOURCE_013`: "Profile not found." | | Header equals the caller's own account ID | Ignored (no-op) | Role checks on a profile-scoped request are evaluated against the profile, with the usual cascade to the parent organization. --- ## Resolving AUTH_004 [#resolving-auth_004] `AUTH_004` means the account behind the API key failed the role check for the operation. The messages in the preceding table identify which check failed. The relevant lookups: | Fact needed | Source | |-------------|--------| | Which account the API key belongs to | `GET /v3/me` returns the account, including its `type`: `organization`, `user`, or `profile`. | | Which users exist and their roles | `GET /v3/users` lists all users of the organization or profile with `role` and `status`. Callable by any active role. | | Who can grant access | The owner or an `admin` invites users with `POST /v3/users` and changes roles with `PATCH /v3/users/{userId}`. | An account whose email is neither the owner email nor an active entry in the `GET /v3/users` list has no role, and fails every check in the operations table. --- ## Example [#example] Listing users to look up a role: ```bash curl https://api.sent.dm/v3/users \ -H "x-api-key: YOUR_API_KEY" ``` ```json { "success": true, "data": { "users": [ { "id": "880e8400-e29b-41d4-a716-446655440003", "email": "admin@acme.com", "name": "John Admin", "role": "admin", "status": "active", "invited_at": "2026-01-24T15:25:20.114144+00:00", "last_login_at": "2026-07-24T13:25:20.1141456+00:00", "created_at": "2026-01-24T15:25:20.1141459+00:00", "updated_at": "2026-07-23T15:25:20.114146+00:00" }, { "id": "990e8400-e29b-41d4-a716-446655440004", "email": "developer@acme.com", "name": "Jane Developer", "role": "developer", "status": "invited", "invited_at": "2026-07-22T15:25:20.1141463+00:00", "last_login_at": null, "created_at": "2026-07-22T15:25:20.1141464+00:00", "updated_at": "2026-07-22T15:25:20.1141465+00:00" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-24T15:25:20.1141776+00:00", "version": "v3" } } ``` A role-check failure returns the standard [error envelope](/reference/api/errors): ```json { "success": false, "status": 403, "error": { "code": "AUTH_004", "message": "You do not have admin access to this organization or profile", "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-24T15:25:20.1199882+00:00", "version": "v3" } } ``` --- ## Related reference [#related-reference] - [Authentication](/reference/api/authentication): API keys, environments, and credential management - [Error Catalog](/reference/api/error-catalog): all error codes, including the other `AUTH_*` codes - [Sender Profiles](/start/concepts/sender-profiles): the organization and profile model method: POST route: /v3/sender-profiles # POST /v3/sender-profiles Create a sender profile Creates a sender profile under your organization. A profile is a customer of yours: it sends under its own or your identity, and your customers never see Sent. ## The minimum `{ "name": "Example Retail", "short_name": "Example" }`. `short_name` is the SMS sender id and is required. Inbox and opt-out list come from your organization. Its brand and campaign are your organization's only where `compliance` says `{ "inherit": true }` — omitted, the profile has neither. Billing defaults to the profile's own balance, with your organization covering what it cannot. **A sender is not one of them.** The brand and the campaign can be inherited; a number cannot. A profile either has a sender of its own — `channels.sms` — or it has none and reaches only the countries Sent runs a shared route for. The US has none: without a `TEN_DLC` number of its own, a profile's SMS to US numbers ends as `FAILED` with `DELIVERY_003`. ## Saying what a profile owns Every capability is one of three things, and there is no flag per state: - **Its own** — supply the capability's fields. Data is what owning looks like. - **The organization's** — `{ "inherit": true }`, with nothing else. - **None** — omit the block. There is no `"inherit": false` that also carries no data. A second way to say the same thing would let a request contradict itself. Inheriting needs no id. A customer has exactly one brand, so `brand` resolves without one. **The campaign has no block of its own.** It is only ever a registration, and every field of one is something a specific market demands — so it lives in `compliance`, alongside the rest of what that market asks for, and it says whose it is there too: `"compliance": { "campaign": { "inherit": true } }` runs the profile on your organization's campaign and brand, and stops this call asking for any campaign field. `"brand": { "inherit": true }` alone inherits the brand only: the campaign is then the profile's own. Inheriting takes *all* of your organization's, because inheritance resolves an owner rather than a single row. A profile with a `brand` of its own **cannot** inherit the campaign, and asking is refused with `400`: a campaign is filed against a brand registration, and your organization's campaign is filed against your organization's brand rather than this profile's. Inherit both, own both, or inherit the brand and own the campaign. `channels.sms` is the market the profile starts in — one `country` and `number_type`. It decides what else this call asks for: the compliance catalog is keyed on that pair, and it determines which fields `brand` accepts and what `compliance` answers for. **Several numbers in that market**: `channels.sms.numbers` lists them, one entry per area code, e.g. `[{"area_code": "212", "quantity": 2}, {"quantity": 1}]` for two in 212 and one in any area code. `quantity` defaults to 1, an entry without `area_code` means any area code, and the total is at most 49. The market is created with **one campaign**, the one in `compliance.campaign`, and a US `TEN_DLC` market's numbers are stored on it and assigned when it is approved. A profile inheriting your organization's campaign keeps one number. Every number is listed in `channels.sms[].numbers` with its area code and status. A profile is a tenant, not a market, so it can go on to send in several — but through `POST /v3/channels/sms` with the `x-profile-id` header, one market and its compliance at a time. Reads return every market as `channels.sms[]`, so the read shape is a list even where this one is not. `brand` is required when `number_type` is `TEN_DLC` — inherited or its own. A 10DLC registration has nothing to attach to without one, and no later call can supply it, so omitting it is refused with `400` rather than reported as outstanding. ## Use cases and volume A TCR campaign declares one to five `use_cases`, each with its own `sample_messages` — TCR attributes samples to the use case they illustrate, so they travel together. How that set registers is derived from `volume` and never declared. Below the low-volume threshold the campaign registers as `LOW_VOLUME` with every entry as a sub-use-case; above it, one entry registers as that use case outright and several register as `MIXED` with sub-use-cases. `MIXED` and `LOW_VOLUME` are therefore refused as `use_case` values: they describe the shape of a set, which is ours to work out. **Leaving `volume` out is accepted and costs more.** An absent value registers the campaign at the standard tier, which carries the higher fee — so say so when a campaign is low volume. Sole proprietor brands are the exception: their fee is fixed by entity type, and volume only decides the use case. ## Compliance `brand` is captured identically in every country. Everything a specific market demands on top of it — including every field of the campaign — goes in `compliance`, as key/value entries whose keys depend on the sender's country and type. US `TEN_DLC` registers with The Campaign Registry and asks for a substantial set; an alphanumeric sender may pre-register with documents, or need nothing at all. You do not have to know any of it. Omit `compliance` and the response lists exactly what is outstanding, with types and accepted values — or call `GET /v3/compliance/requirements` first. Anything Sent supplies on your behalf is never asked for, and is rejected if sent. Requirements can be conditional, and the condition is published as `required_when` so you can render a form from it rather than discover the rule by being rejected. Every US `TEN_DLC` campaign field carries `compliance.inherit != true` — send `"inherit": true` and none of them is asked for or accepted, because the profile is running on your organization's campaign. ## Uploading documents Send `application/json` for everything except a market that pre-registers a sender with supporting documents. For those, send `multipart/form-data` instead: put this entire document — unchanged — in a single field named `profile`, and attach each file under a field named after the compliance key it satisfies. Individual form fields per property are not read; the payload is always the one `profile` field. A pre-registration market has no `brand` and no `campaign` — those are asked for only where a regime registers one — so its `compliance` carries nothing at all, and the documents are the request: ```bash curl -X POST https://api.sent.dm/v3/sender-profiles \ -H 'x-api-key: YOUR_SECRET_TOKEN' \ -F 'profile={ "name": "Example Retail", "short_name": "EXAMPLE", "channels": { "sms": { "country": "XK", "number_type": "ALPHANUMERIC", "sender_value": "EXAMPLE" } } }' \ -F 'business_registration=@registration.pdf' \ -F 'letter_of_authorization=@loa.pdf' ``` `business_registration` and `letter_of_authorization` are illustrative. The real field names are whatever that market configures, so read them from `GET /v3/compliance/requirements`, which lists documents separately from the values — under `attachments`, each with the `field_name` to put the file under. A document has no JSON form, so naming one in `compliance` is refused with `400` rather than ignored: accepting it would report the requirement as satisfied while no file was ever stored. ## WhatsApp and RCS Neither can be inherited, so neither takes an `inherit`: the profile's WhatsApp account and RCS agent are its own or it has none. Sharing your organization's would share its inbox and its throughput, which makes the two indistinguishable to a recipient. `channels.whatsapp` names one of the accounts shared into your organization, and takes the two identifiers nothing else can supply: `waba_id`, because your organization holds one account per client, and `phone_number_id`, because naming the account's number is what assigns it to the profile as the number it sends from. Everything else is resolved from your organization — the Multi-Partner Solution the account arrived through, the client business portfolio that owns it, the access token and that token's expiry. None of them is accepted here: the first two are Meta's answer about provenance, so a value you sent could assert a partnership Meta disagrees with, and the token is minted per client business and rotates roughly every sixty days. `phone_number_id` is optional. Omit it to connect the account now and settle the number later — the channel reads as `ACTION_NEEDED` with `reason_code` `CHANNEL_007`, and the profile's WhatsApp messages fail until a number is named. They do not fall back to your organization's account. `POST /v3/channels/whatsapp` connects an account to an existing profile and resolves the same fields the same way. An account of its own needs a sender of its own, so `channels.whatsapp` requires `channels.sms`. A profile sending SMS on your organization's sender shares that inbox and opt-out list, and is not a separate tenant to give an account to — asking is refused with `400`, before your organization is asked to resolve anything. `channels.rcs` records the RCS agent. RCS (Rich Communication Services) is the next-generation SMS standard built into Android — it lets you send branded messages with images, buttons and read receipts over the carrier network, with no app install required. Learn more in the [Google RCS documentation](https://developers.google.com/business-communications/rcs-business-messaging). All fields on the agent form are required except `opt_in_screenshot_url`. The full form must be submitted in one go so the carrier review has everything it needs. A carrier approval no API call can trigger is arranged offline, so the status reports `PROVISIONING` until it is. ## Responses `201` when the profile is complete on return — the fully-inherited case, where nothing needs registering. `202` when something is still provisioning, with per-capability status and outstanding requirements. `409` when the WhatsApp account supplied is already recorded. `400` covers a wrong value as well as a missing one: a missing brand under `TEN_DLC`, a brand or campaign inherited under `TEN_DLC` that your organization does not have yet, an unknown compliance key, a bad type, a sender id the market does not allow, a `waba_id` that is not one of the accounts shared into your organization, or a WhatsApp account Meta rejects. `502` when Meta could not be reached to verify the WhatsApp account; nothing was created, so retry. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3SenderProfilesCreateSenderProfileEndpoint` **Tags:** Sender Profiles ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, short_name?: string, description?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { sms?: { country?: string, number_type?: string, sender_value?: string, area_codes?: Array, numbers?: Array<{ area_code?: string, quantity?: integer }> }, whatsapp?: { waba_id?: string, phone_number_id?: string }, rcs?: { display_name?: string, description?: string, agent_use_case?: string, hosting_region?: string, billing_category?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, logo_url?: string, banner_url?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, opt_in_screenshot_url?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array } }, compliance?: { brand?: { inherit?: boolean, legal_name?: string, business_name?: string, tax_id?: string, tax_id_type?: string, ein_issuing_country?: string, entity_type?: "PRIVATE_PROFIT" | "PUBLIC_PROFIT" | "NON_PROFIT" | "SOLE_PROPRIETOR" | "GOVERNMENT", street?: string, city?: string, state?: string, postal_code?: string, country?: string, website?: string, contact_name?: string, contact_email?: string, contact_phone?: string }, campaign?: { inherit?: boolean, description?: string, message_flow?: string, use_cases?: Array<{ use_case: "MARKETING" | "ACCOUNT_NOTIFICATION" | "CUSTOMER_CARE" | "FRAUD_ALERT" | "2FA" | "DELIVERY_NOTIFICATION" | "SECURITY_ALERT" | "M2M" | "HIGHER_EDUCATION" | "POLLING_VOTING" | "PUBLIC_SERVICE_ANNOUNCEMENT", sample_messages: Array }>, opt_in_message?: string, opt_out_message?: string, help_message?: string, opt_in_keywords?: string, opt_out_keywords?: string, help_keywords?: string, privacy_policy_link?: string, terms_and_conditions_link?: string, volume?: string } } } ``` ### multipart/form-data ```typescript { sandbox?: boolean, name?: string, short_name?: string, description?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { sms?: { country?: string, number_type?: string, sender_value?: string, area_codes?: Array, numbers?: Array<{ area_code?: string, quantity?: integer }> }, whatsapp?: { waba_id?: string, phone_number_id?: string }, rcs?: { display_name?: string, description?: string, agent_use_case?: string, hosting_region?: string, billing_category?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, logo_url?: string, banner_url?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, opt_in_screenshot_url?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array } }, compliance?: { brand?: { inherit?: boolean, legal_name?: string, business_name?: string, tax_id?: string, tax_id_type?: string, ein_issuing_country?: string, entity_type?: "PRIVATE_PROFIT" | "PUBLIC_PROFIT" | "NON_PROFIT" | "SOLE_PROPRIETOR" | "GOVERNMENT", street?: string, city?: string, state?: string, postal_code?: string, country?: string, website?: string, contact_name?: string, contact_email?: string, contact_phone?: string }, campaign?: { inherit?: boolean, description?: string, message_flow?: string, use_cases?: Array<{ use_case: "MARKETING" | "ACCOUNT_NOTIFICATION" | "CUSTOMER_CARE" | "FRAUD_ALERT" | "2FA" | "DELIVERY_NOTIFICATION" | "SECURITY_ALERT" | "M2M" | "HIGHER_EDUCATION" | "POLLING_VOTING" | "PUBLIC_SERVICE_ANNOUNCEMENT", sample_messages: Array }>, opt_in_message?: string, opt_out_message?: string, help_message?: string, opt_in_keywords?: string, opt_out_keywords?: string, help_keywords?: string, privacy_policy_link?: string, terms_and_conditions_link?: string, volume?: string } } } ``` ## Responses ### 201 Profile created and complete — nothing needed registering #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, short_name?: string, description?: string, api_key?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { customer_id?: string, sms?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, whatsapp?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, rcs?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, mms?: Array<{ country?: string, number_type?: string, sender_value?: string, status?: string }>, voice?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }> }, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> }, created_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "990e8400-e29b-41d4-a716-446655440004", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Demo Brand", "short_name": "DEMO", "description": null, "api_key": "sntdm_live_yyyyyyyyyyyy", "billing": { "inherit": true }, "notifications": "ORGANIZATION", "channels": { "sms": [], "whatsapp": null, "rcs": null, "mms": [], "voice": [] }, "created_at": "2025-06-01T12:00:00+00:00" }, "meta": { "request_id": "req_8Y0aLq3kEx", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 202 Profile accepted; capabilities are provisioning #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, short_name?: string, description?: string, api_key?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { customer_id?: string, sms?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, whatsapp?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, rcs?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, mms?: Array<{ country?: string, number_type?: string, sender_value?: string, status?: string }>, voice?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }> }, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> }, created_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Example Retail", "short_name": "Example", "description": null, "api_key": "sntdm_live_xxxxxxxxxxxx", "billing": { "inherit": false }, "notifications": "ORGANIZATION", "channels": { "sms": [ { "country": "US", "number_type": "TEN_DLC", "numbers": [], "status": "PENDING_REVIEW", "reason_code": "CHANNEL_009", "reason": "Registration is awaiting submission to or review by a regulator or carrier." } ], "whatsapp": null, "rcs": null, "mms": [], "voice": [] }, "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "business_name": "Example Retail", "tax_id": "12-3456789", "tax_id_type": "us_ein", "ein_issuing_country": "US", "entity_type": "PRIVATE_PROFIT", "street": "123 Main Street", "city": "New York", "state": "NY", "postal_code": "10001", "country": "US", "website": "https://example.com", "contact_name": "John Smith", "contact_email": "john@example.com", "contact_phone": "+12125550123" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who have bought from Example Retail, plus occasional offers.", "message_flow": "Customers opt in at checkout on https://example.com by ticking a box that is unchecked by default, and again in the account settings page. Consent is not a condition of purchase.", "use_cases": [ { "use_case": "DELIVERY_NOTIFICATION", "sample_messages": [ "Example Retail: order 10432 is out for delivery and arrives today. Track it at https://example.com/t/10432. Reply STOP to opt out.", "Example Retail: order 10432 was delivered. Reply STOP to opt out." ] }, { "use_case": "MARKETING", "sample_messages": [ "Example Retail: 20% off everything this weekend with code SAVE20 at https://example.com/sale. Reply STOP to opt out." ] } ], "opt_in_message": "Example Retail: you are subscribed to order updates and offers. Msg frequency varies. Msg & data rates may apply. Reply HELP for help, STOP to cancel.", "opt_out_message": "Example Retail: you are unsubscribed and will receive no further messages. Reply START to resubscribe.", "help_message": "Example Retail: email support@example.com or call +1 212 555 0123. Msg & data rates may apply. Reply STOP to unsubscribe.", "opt_in_keywords": "START,YES", "opt_out_keywords": "STOP,END,CANCEL,UNSUBSCRIBE,QUIT", "help_keywords": "HELP,INFO", "privacy_policy_link": "https://example.com/privacy", "terms_and_conditions_link": "https://example.com/terms", "volume": "1500" }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who have bought from Example Retail, plus occasional offers.", "message_flow": "Customers opt in at checkout on https://example.com by ticking a box that is unchecked by default, and again in the account settings page. Consent is not a condition of purchase.", "use_cases": [ { "use_case": "DELIVERY_NOTIFICATION", "sample_messages": [ "Example Retail: order 10432 is out for delivery and arrives today. Track it at https://example.com/t/10432. Reply STOP to opt out.", "Example Retail: order 10432 was delivered. Reply STOP to opt out." ] }, { "use_case": "MARKETING", "sample_messages": [ "Example Retail: 20% off everything this weekend with code SAVE20 at https://example.com/sale. Reply STOP to opt out." ] } ], "opt_in_message": "Example Retail: you are subscribed to order updates and offers. Msg frequency varies. Msg & data rates may apply. Reply HELP for help, STOP to cancel.", "opt_out_message": "Example Retail: you are unsubscribed and will receive no further messages. Reply START to resubscribe.", "help_message": "Example Retail: email support@example.com or call +1 212 555 0123. Msg & data rates may apply. Reply STOP to unsubscribe.", "opt_in_keywords": "START,YES", "opt_out_keywords": "STOP,END,CANCEL,UNSUBSCRIBE,QUIT", "help_keywords": "HELP,INFO", "privacy_policy_link": "https://example.com/privacy", "terms_and_conditions_link": "https://example.com/terms", "volume": "1500" } ], "documents": [] }, "created_at": "2025-06-01T12:00:00+00:00" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 Malformed request #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "One or more compliance values were rejected", "details": { "compliance.phone": [ "'phone' must be a valid e164." ], "compliance.mock": [ "'mock' is set by Sent and cannot be supplied." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 A profile API key cannot create profiles #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 409 The WhatsApp account supplied is already recorded #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_007", "message": "This WhatsApp account is already recorded", "details": { "channels.whatsapp": [ "Meta registers a number to exactly one business account, so this one cannot be added twice. Supply an account no other profile or organization is using." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 422 The number type or market asked for cannot be used, or a required compliance document is missing or was rejected #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 502 Meta could not be reached to verify the WhatsApp account; nothing was created #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/sender-profiles/{id} # DELETE /v3/sender-profiles/{id} Delete a sender profile Deletes one of your sender profiles and returns `204`. The delete is **soft**: the profile stops being usable and stops appearing in reads, and its message history is kept, because deleting a profile must not delete the record of what it sent. ## What it releases Anything the profile still held goes with it. A **phone number** returns to our inventory and can be given to whoever asks next — it does not stay reserved for you, and getting the same number back afterwards is not something we can promise. A **WhatsApp account of its own** is deregistered from Meta. Its routing rules stop being used, so nothing sends through the profile after this call. A profile that only inherits from its organization holds nothing of its own and releases nothing. ## When it is refused A number the profile holds that your **WhatsApp Business Account still carries** refuses the delete with a `409 CONFLICT_012`, and nothing is deleted: it would return to our shared inventory while Meta still routes WhatsApp to it, and the next customer given it could not register it at all. Only you can take it off the account — deregister **and** delete it in WhatsApp Manager, then try again. A `409 CONFLICT_013` means we could not read the account, so we cannot tell either way. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3SenderProfilesDeleteSenderProfileEndpoint` **Tags:** Sender Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Identifier of the profile. | ## Responses ### 204 Deleted, and anything it held released ### 401 Unauthorized ### 403 The profile or your organization is suspended (`ACCOUNT_SUSPENDED`) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 404 No such profile under your organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 409 Refused, nothing deleted: a number the profile holds is still on your WhatsApp Business Account, or that account could not be read #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/sender-profiles/{id} # GET /v3/sender-profiles/{id} Get a sender profile Reads one of your sender profiles. The document mirrors `POST /v3/sender-profiles`, with three differences that follow from this being a read rather than a request. `channels.sms` is a **list**. Create takes the one market a profile starts in; a profile can go on to send in several, and this reports all of them, each with its own `status`. `compliance.brand` comes back **in full, with `inherit` saying whose it is**. On a request `{ "inherit": true }` carries no data because there is nothing to send; here it carries the data, because the point of a read is to say what the profile actually sends under. **There is no `campaigns` array.** Brand, campaign, and compliance documents are reported at the profile root in `compliance`. A profile running on your organization's campaign is asked for none of the campaign fields, so `compliance.campaign` carries `{ "inherit": true }` with no campaign data. `api_key` is **never** returned here. It is shown once, by create. A profile belonging to another organization reads as `404`, not `403`: saying which of the two it is would confirm the id exists. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3SenderProfilesGetSenderProfileEndpoint` **Tags:** Sender Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Identifier of the profile, as returned by POST /v3/sender-profiles. | ## Responses ### 200 The sender profile #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, short_name?: string, description?: string, api_key?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { customer_id?: string, sms?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, whatsapp?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, rcs?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, mms?: Array<{ country?: string, number_type?: string, sender_value?: string, status?: string }>, voice?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }> }, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> }, created_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Example Retail", "short_name": "EXAMPLE", "description": null, "billing": { "inherit": false }, "notifications": "ORGANIZATION", "channels": { "sms": [ { "country": "US", "number_type": "TEN_DLC", "sender_value": "+12125550100", "numbers": [], "status": "ACTIVE" } ], "whatsapp": null, "rcs": null, "mms": [], "voice": [] }, "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US", "website": "https://example.com" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ], "documents": [ { "key": "senderid_registration_requirements", "file_name": "sender-id-registration.pdf", "document_id": "b792e8ae-2cb4-4209-85b9-32be4c2fcdd6" } ] }, "created_at": "2025-01-15T00:00:00+00:00" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 No such profile under your organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_014", "message": "Sender profile not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/sender-profiles # GET /v3/sender-profiles List sender profiles Lists the sender profiles under your organization, newest first, paginated with `page` and `page_size`. Each entry is the same document `GET /v3/sender-profiles/{id}` returns, with one difference: **`compliance.documents` at the profile root is absent**. Working out which documents a market holds means a catalog lookup and a document read per market, and doing that for every profile on a page would turn one request into dozens to answer a question you did not ask. Read a single profile for that. Brand and campaign are still included when they exist. `compliance.documents` being **absent** is not the same as it being an **empty list**. Absent means the documents were not fetched here; an empty list means the profile holds none. `api_key` is never returned. It is shown once, by create. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3SenderProfilesGetSenderProfilesEndpoint` **Tags:** Sender Profiles ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | Page number, 1-indexed. | | `page_size` | `integer` | true | Profiles per page. Between 1 and 100. | ## Responses ### 200 A page of sender profiles #### application/json ```typescript { success?: boolean, data?: { sender_profiles?: Array<{ id?: string, organization_id?: string, name?: string, short_name?: string, description?: string, api_key?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { customer_id?: string, sms?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, whatsapp?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, rcs?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, mms?: Array<{ country?: string, number_type?: string, sender_value?: string, status?: string }>, voice?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }> }, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> }, created_at?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "sender_profiles": [ { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Example Retail", "short_name": "EXAMPLE", "description": null, "billing": { "inherit": false }, "notifications": "ORGANIZATION", "channels": { "sms": [ { "country": "US", "number_type": "TEN_DLC", "sender_value": "+12125550100", "numbers": [], "status": "ACTIVE" } ], "whatsapp": null, "rcs": null, "mms": [], "voice": [] }, "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ] }, "created_at": "2025-01-15T00:00:00+00:00" }, { "id": "880e8400-e29b-41d4-a716-446655440003", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Demo Brand", "short_name": "DEMO", "description": null, "billing": { "inherit": true }, "notifications": "ORGANIZATION_AND_SENDER_PROFILE", "channels": { "sms": [ { "country": "US", "number_type": "TEN_DLC", "sender_value": "+12125550101", "numbers": [], "status": "ACTIVE" } ], "whatsapp": null, "rcs": null, "mms": [], "voice": [] }, "created_at": "2025-03-10T00:00:00+00:00" } ], "pagination": { "page": 1, "page_size": 20, "total_count": 2, "total_pages": 1, "has_more": false, "cursors": null } }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 page or page_size out of range #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "page_size must be between 1 and 100", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 Forbidden ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/sender-profiles/{id} # PATCH /v3/sender-profiles/{id} Update a sender profile Changes a profile's own attributes: `name`, `short_name`, `description` and `notifications` (who is emailed about the profile's events — `ORGANIZATION`, `SENDER_PROFILE`, or `ORGANIZATION_AND_SENDER_PROFILE`). **Only those.** A profile's identity, its markets and its compliance each have a sub-resource of their own, because each has its own validation and its own external consequences — a brand change may need re-registering, a market change provisions a sender. Folding them in here would give those fields two writers and no way to say which one wins. Omitting a field leaves it alone; sending `null` clears it. Those are different requests, so `{}` changes nothing and is refused rather than silently accepted — a caller who misspelt every field would otherwise get a `200` and an unchanged profile. `name` and `short_name` cannot be cleared: `short_name` is the SMS sender id, so a supplied value must be 3–11 characters of letters, numbers and spaces with at least one letter. Returns the profile as `GET /v3/sender-profiles/{id}` would, so the result of the change needs no second call to see. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3SenderProfilesPatchSenderProfileEndpoint` **Tags:** Sender Profiles ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, short_name?: string, description?: string, notifications?: string } ``` ## Responses ### 200 The updated sender profile #### application/json ```typescript { success?: boolean, data?: { id?: string, organization_id?: string, name?: string, short_name?: string, description?: string, api_key?: string, billing?: { inherit?: boolean }, notifications?: string, channels?: { customer_id?: string, sms?: Array<{ country?: string, number_type?: string, numbers?: Array<{ sender_value?: string, area_code?: string, status?: string, campaign_id?: string }>, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> } }>, whatsapp?: { waba_id?: string, phone_number_id?: string, solution_id?: string, owner_business_id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string }, rcs?: { id?: string, status?: "PROVISIONING" | "ACTION_NEEDED" | "PENDING_REVIEW" | "ACTIVE" | "INACTIVE", reason_code?: string, reason?: string, phone_number?: string, display_name?: string, description?: string, agent_use_case?: string, brand_name?: string, privacy_policy_url?: string, terms_and_conditions_url?: string, website_url?: string, brand_color?: string, brand_phone_number?: string, customer_support_phone_number?: string, brand_email?: string, customer_support_email?: string, contact_name_and_title?: string, company_ein?: string, entity_type?: string, official_address?: { street?: string, city?: string, state?: string, postal_code?: string, country?: string }, brief_company_description?: string, opt_in_process_description?: string, start_message?: string, help_message?: string, stop_message?: string, sample_messages?: Array, created_at?: string }, mms?: Array<{ country?: string, number_type?: string, sender_value?: string, status?: string }>, voice?: Array<{ number?: string, status?: string, default_for_app_calls?: boolean, callback_url?: string, agent_id?: string, routes_to?: string, created_at?: string, updated_at?: string }> }, compliance?: { brand?: object, campaign?: object, campaigns?: Array, documents?: Array<{ key?: string, file_name?: string, document_id?: string }> }, created_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "770e8400-e29b-41d4-a716-446655440002", "organization_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Example Retail Renamed", "short_name": "EXMPL", "description": null, "billing": { "inherit": false }, "notifications": "ORGANIZATION", "channels": { "sms": [ { "country": "US", "number_type": "TEN_DLC", "sender_value": "+12125550100", "numbers": [], "status": "ACTIVE" } ], "whatsapp": null, "rcs": null, "mms": [], "voice": [] }, "compliance": { "brand": { "inherit": false, "legal_name": "Example Retail Inc", "entity_type": "PRIVATE_PROFIT", "country": "US", "website": "https://example.com" }, "campaign": { "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." }, "campaigns": [ { "id": "3f2a6c1e-8b4d-4e2a-9c7f-1d5b0a9e4c21", "inherit": false, "description": "Order and delivery updates for customers who opted in at checkout." } ], "documents": [ { "key": "senderid_registration_requirements", "file_name": "sender-id-registration.pdf", "document_id": "b792e8ae-2cb4-4209-85b9-32be4c2fcdd6" } ] }, "created_at": "2025-01-15T00:00:00+00:00" }, "meta": { "request_id": "req_9Z1bMq4kFy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 400 Nothing to change, or a value that is not allowed #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Supply at least one field to change", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_9Z1bMq4kFy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 401 Unauthorized ### 403 The profile or your organization is suspended (`ACCOUNT_SUSPENDED`) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 404 No such profile under your organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_014", "message": "Sender profile not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_9Z1bMq4kFy", "timestamp": "2025-06-01T12:00:00+00:00", "version": "v3" } } ``` ### 500 Server Error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** # Template Definition (/reference/api/template-definition.md) # Template Definition [#template-definition] A template definition is the JSON document that describes a template's content. It is the required `definition` field of the [Create Template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesCreateTemplateEndpoint) (`POST /v3/templates`) and [Update Template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesUpdateTemplateEndpoint) (`PUT /v3/templates/{id}`) requests. The dashboard template builder displays the same JSON via its **View JSON** action. Top-level request fields use `snake_case` (`submit_for_review`); field names inside `definition` use `camelCase` (`multiChannel`, `variableType`). ## Create template request [#create-template-request] | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `category` | string | No | `MARKETING`, `UTILITY`, or `AUTHENTICATION`. Auto-detected from the template content when omitted | | `language` | string | No | Language code (for example, `en_US`). Auto-detected from the template content when omitted | | `definition` | object | Yes | The [definition object](#definition-object) | | `creation_source` | string | No | Source label for the template. Default: `from-api` | | `submit_for_review` | boolean | No | `true` submits the template for review immediately after creation. Default: `false`, which saves the template with status `DRAFT` | | `sandbox` | boolean | No | `true` validates the request and returns a simulated template without creating anything. Default: `false`. See [Sandbox mode](/reference/api/test-mode) | There is no `name` field on create: the display name is derived from the template's content. To rename a template afterwards, send `name` on [Update Template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesUpdateTemplateEndpoint) (`PUT /v3/templates/{id}`). ### Request headers [#request-headers] Beyond the `x-api-key` header that [authenticates](/reference/api/authentication) every call, the template endpoints accept two optional headers: | Header | Accepted on | Purpose | | :--- | :--- | :--- | | `Idempotency-Key` | `POST /v3/templates`, `PUT /v3/templates/{id}` | Makes a retry safe: the first response is cached for 24 hours per key per customer and replayed instead of creating a second template. 1–255 characters matching `^[a-zA-Z0-9_-]+$`. See [Idempotency](/reference/api/idempotency) | | `x-profile-id` | Every template endpoint | Scopes the request to a child profile, so the template is created, listed, or changed under that profile rather than the key's own account. Organization API keys only, and the profile must belong to the calling organization. See [Multi-tenant architectures](/start/advanced/multi-tenant-architectures) | `GET` and `DELETE` ignore `Idempotency-Key`, which is why it is not offered on them. A profile-scoped request echoes the profile back in the `X-Profile-Id` response header, and the template's owner is reported as `customer_id` on the template itself. ## Definition object [#definition-object] | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `header` | object | No | [Header object](#header-object) | | `body` | object | Yes | [Body object](#body-object) | | `footer` | object | No | [Footer object](#footer-object) | | `buttons` | array | No | Array of [button objects](#buttons-array) | | `definitionVersion` | string | No | Version of the template definition format | | `authenticationConfig` | object | No | [Authentication configuration](#authentication-configuration), used only by `AUTHENTICATION` templates | ### Channel support [#channel-support] | Component | SMS | WhatsApp | RCS | MMS | | :--- | :--- | :--- | :--- | :--- | | Header | Not supported | Native header | Prepended to message text | Not supported; MMS has its own `subject` instead | | Body | Supported | Supported | Supported | Supported, from the `mms` body, falling back to `multiChannel` and then `sms` | | Footer | Not supported | Native footer | Appended to message text | Not supported | | Buttons | Not supported | Interactive buttons | First four shown as suggestion chips | Not supported | MMS is the one channel that renders no header, footer, or buttons at all: it is a carrier message carrying a subject, text, and attachments, with nowhere to put them. ## Header object [#header-object] | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `type` | string | No | Header type: `text` (the default), `image`, `video`, `gif`, or `document` | | `template` | string | Conditional | Header text with optional variable placeholders. Maximum 60 characters. Required for a `text` header; must be empty (`""`) for a media header | | `variables` | array | No | [Variable objects](#variable-object) used in the header. Maximum 1 | | `example_url` | string | Conditional | Media headers only. The sample asset reviewers see, as an s.dm asset URL (`https://s.dm/s/{ID}`). Required when creating a template with a media header | Text headers must not contain newlines, emojis, or formatting markup (`*`, `_`, `~`). `AUTHENTICATION` templates do not use headers; Sent excludes any header from them automatically. ### Media headers [#media-headers] An `image`, `video`, `gif`, or `document` header shows an asset instead of text. It is a WhatsApp header: RCS and SMS, which render a text header as a line of the message, leave a media header out. ```json { "header": { "type": "image", "template": "", "example_url": "https://s.dm/s/A78B2BU0" } } ``` - **The review sample must be on s.dm.** `example_url` is refused unless it is an s.dm asset URL, and only on a media header. The dashboard's template editor uploads the asset to s.dm and fills it in for you; the API has no upload endpoint. When the template is submitted for review, the sample must be a JPEG, PNG, MP4, or PDF of at most 100 MB. A `gif` header takes an MP4 file, which WhatsApp plays as a GIF. - **You don't declare the header's variable.** Sent adds a single `media` variable for the asset, named after the type: `header_image`, `header_video`, `header_gif`, or `header_document`. If you do send `variables`, it must be exactly one variable of type `media` whose `mediaType` matches the header `type`. - **The asset is supplied per message.** Pass its URL in `parameters` under the variable's name, for example `"header_image": "https://cdn.example.com/banner.png"`. Any absolute `https` URL is accepted at send time; a missing or non-`https` value is a `400`. ## Body object [#body-object] The body carries the message copy. Pick **one** of two authoring strategies: - a shared `multiChannel` body on its own, or - an explicit `sms` + `whatsapp` pair, with **both** present. `rcs` and `mms` are optional on top of either strategy. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `multiChannel` | object | Conditional | The body used for every channel. Required unless you send both `sms` and `whatsapp` | | `sms` | object | Conditional | The SMS body. Must be paired with `whatsapp`, and cannot be combined with `multiChannel` | | `whatsapp` | object | Conditional | The WhatsApp body. Must be paired with `sms`, and cannot be combined with `multiChannel` | | `rcs` | object | No | RCS-specific copy that overrides the chosen strategy for RCS only. Cannot be the only body present | | `mms` | object | No | [MMS body content object](#mms-body-content-object): the subject, copy, and attachments MMS sends. Cannot be the only body present. Without it, MMS uses the `multiChannel` or `sms` text, with no subject or template media | `sms` and `whatsapp` do not override `multiChannel`, they replace it. The API refuses a body that mixes the two strategies (`multiChannel` alongside `sms` or `whatsapp`), and it equally refuses `sms` on its own, `whatsapp` on its own, or `rcs` on its own: every template is expected to be deliverable on every channel. A body that breaks the rule fails with *"Body must have either multiChannel OR both sms and whatsapp channels (not both strategies). An rcs or mms body may accompany either, but cannot stand on its own."* ### Body content object [#body-content-object] | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `type` | string | No | The body block's type: send `text` | | `template` | string | Yes | Body text with variable placeholders. Maximum 1024 characters, or 3072 in an `rcs` body and 1600 in an [`mms` body](#mms-body-content-object), and subject to the [body content rules](#content-rules-and-limits) | | `variables` | array | No | [Variable objects](#variable-object) used in the body, one entry per `{{index:variable}}` placeholder. IDs must be unique within the body | `type` is schema-optional, but a body posted without it is stored with no `type` key at all, and the dashboard template builder has nothing to render the block from. Send `"type": "text"` on every body content object. ### MMS body content object [#mms-body-content-object] The `mms` body is the [body content object](#body-content-object) plus the two members only MMS has: a subject line and attachments. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `type` | string | No | The body block's type: send `text` | | `template` | string | Conditional | Body text with variable placeholders. Maximum 1600 characters, a wider cap than the other channels because an MMS text part is not bound by Meta's limit. Optional when `media` carries at least one item | | `variables` | array | No | [Variable objects](#variable-object) used in `template` and in `subject` | | `subject` | string | No | Subject line, maximum 80 characters, rendered above the body on most handsets and ignored by some. Variables are substituted, and the result is truncated rather than rejected if it overruns | | `media` | array | Conditional | One [MMS media item](#mms-media-item). MMS carries one attachment, so a second is rejected at authoring time. Optional when `template` carries text | An `mms` body must carry body text, at least one media item, or both. One that carries neither renders to nothing and is rejected at authoring time with *"MMS body must carry body text, at least one media item, or both."* A template saved with more than one media item before the one-attachment limit still sends, carrying only its first. Like `rcs`, MMS resolves to a shared body when it has no dedicated one: the `mms` body, then `multiChannel`, then `sms`. A template with a shared or SMS body therefore lists `mms` among its channels. The subject and media exist only on an `mms` body, so a fallback contributes text alone. An MMS still needs an attachment: without template media or `media_urls`, auto-detect skips MMS, and a send pinned with `"channel": ["mms"]` is refused with `400`. MMS with no media would be a more expensive SMS. #### MMS media item [#mms-media-item] | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `url` | string | Yes | Publicly fetchable `https` URL on a hostname. A literal IP address is refused. The carrier fetches it at send time, including on retries, so it must stay reachable and unauthenticated for the life of the send. A presigned URL is not a valid value. Sent reads the size it declares before each send, and an attachment over 600 KB is not sent as MMS (see [Media Size Limits](/start/guides/mms#media-size-limits)) | | `mediaType` | string | No | One of `image`, `video`, `document`, or `contact`. Any other value, including `audio`, is rejected. Advisory only: the carrier reads the `Content-Type` of the fetched object, not this field. It exists so an authoring UI can preview the attachment and a reviewer can see what was intended | Media URLs are never templated. A variable is substituted in `template` and `subject` but copied verbatim in `url`, so an attachment cannot be assembled from caller input. A per-send `media_urls` on `POST /v3/messages` replaces this list rather than adding to it, which lets a template hold a default creative while a caller sends something recipient-specific. See [Sending MMS](/start/guides/mms) for the sending side. ## Footer object [#footer-object] | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `type` | string | No | Footer type: `text` | | `template` | string | Yes | Footer text. Maximum 60 characters | | `variables` | array | No | Must be empty; footers cannot contain variables | Footers must not contain variables, newlines, emojis, or formatting markup (`*`, `_`, `~`). ## Buttons array [#buttons-array] A template holds a maximum of 10 buttons. Button IDs must be unique. Per-type limits: maximum 1 `COPY_CODE`, 1 `PHONE_NUMBER`, 2 `URL`, and 10 `QUICK_REPLY` buttons. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `id` | number | No* | Button identifier (1-based index), unique within the template. *Required in practice once a template has two or more buttons, see below | | `type` | string | Yes | `QUICK_REPLY`, `URL`, `VOICE_CALL`, `PHONE_NUMBER`, or `COPY_CODE` | | `props` | object | Yes | Type-specific [button properties](#button-props-object) | ### Button props object [#button-props-object] | Field | Type | Applies to | Description | | :--- | :--- | :--- | :--- | | `text` | string | All types | Button label. Maximum 25 characters, static text only (see below) | | `quickReplyType` | string | `QUICK_REPLY` | `custom` or `pre-configured` | | `urlType` | string | `URL` | `static` or `dynamic` | | `url` | string | `URL` | Destination URL. Maximum 2000 characters | | `variables` | array | `URL` (dynamic) | Exactly 1 [variable object](#variable-object); its placeholder must appear at the end of `url` | | `activeFor` | number | `VOICE_CALL` | Integer greater than 0 | | `countryCode` | string | `PHONE_NUMBER` | Country code (for example, `US`) | | `phoneNumber` | string | `PHONE_NUMBER` | Phone number in international format | | `offerCode` | string | `COPY_CODE` | Code copied to the clipboard on tap | | `otpType` | string | `AUTHENTICATION` OTP buttons | `COPY_CODE` or `ONE_TAP` | Meta allows no dynamic content in a button label, so `text` is refused when it contains a `{{...}}` variable placeholder, a newline, an emoji, or WhatsApp formatting markup (`*`, `_`, `~`). Meta reports all four as a single error (*"Buttons can't have any variables, newlines, emojis, or formatting characters."*), so Sent checks them at save time instead, one message per rule. Put the dynamic part in the body, or in a `dynamic` URL button's `url`, where placeholders are allowed. `id` is schema-optional, but it is a plain integer rather than a nullable one: a button that omits it is stored with `id: 0`. One button that way is fine, two are not: they collide, and the template is refused with *"Button IDs must be unique."* Number them from 1 in the order you want them shown, which also decides which four reach RCS. ## Variable object [#variable-object] Variables use a numbered placeholder syntax in template text: `{{0:variable}}` for text variables and `{{4:link}}` for links, where the number is the variable's `id` and the word after the colon is its `type`. This is the canonical form, and the one the dashboard builder writes. Two shorter forms are also accepted in header and body text, and resolve to the same variable: | Form | Example | Notes | | :--- | :--- | :--- | | `{{id:type}}` | `{{0:variable}}` | Canonical. Use this form | | `{{name}}` | `{{customerName}}` | Matched against the variable's `name` | | `{{id}}` | `{{0}}` | Matched against the variable's `id` | A `dynamic` [URL button](#button-props-object) is validated with a numeric-only pattern, so its `url` must end in `{{0:variable}}` or `{{0}}`. A named placeholder such as `https://example.com/orders/{{orderNumber}}` fails with *"Dynamic URL must end with a variable placeholder (e.g. `{{0:variable}}`)."* | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `id` | number | No* | Sequential ID starting from 0, unique within its section. *Required in practice once a section has two or more variables, and it is the number the `{{0:variable}}` placeholder refers to | | `name` | string | Yes | Readable identifier for the variable (for example, `orderNumber`) | | `type` | string | Yes | `variable`, `link`, or `media` | | `props` | object | Yes | [Variable properties](#variable-props-object) | The type token in a `{{index:type}}` placeholder must be `variable`, `link`, or `media`. Any other value is rejected when the template is saved: *"template contains a placeholder with an unsupported type. Placeholders must use 'variable', 'link', or 'media' (e.g. `{{0:variable}}`)."* Before this validation was enforced, an unrecognized type such as `{{0:message}}` was stored without error. At send time the placeholder could not be resolved, so the literal string was delivered to the recipient instead of the substituted value. ### Variable props object [#variable-props-object] | Field | Type | Applies to | Description | | :--- | :--- | :--- | :--- | | `variableType` | string | `variable` | Required. `text`, `link`, `image`, or `file` | | `sample` | string | `variable` | Required. Example value shown in previews and used during review | | `regex` | string | `variable` | Optional validation pattern for the variable value | | `url` | string | `link`, `media` | Required. Full HTTP or HTTPS URL | | `shortUrl` | string | `link` | Optional shortened URL | | `alt` | string | `link`, `media` | Alternative text | | `mediaType` | string | `media` | Required. `image`, `video`, `gif`, or `document` | ## Authentication configuration [#authentication-configuration] `AUTHENTICATION` templates accept an `authenticationConfig` object: | Field | Type | Description | | :--- | :--- | :--- | | `addSecurityRecommendation` | boolean | Adds the text "For your security, do not share this code." | | `codeExpirationMinutes` | number | 1–90. When set, adds the footer "This code expires in X minutes." | An `AUTHENTICATION` body must declare exactly one text variable (the code) and must not contain links or emojis. ## Content rules and limits [#content-rules-and-limits] | Rule | Limit | | :--- | :--- | | Body length | 1024 characters for the `multiChannel`, `sms` and `whatsapp` bodies; 3072 for an `rcs` body; 1600 for an `mms` body | | MMS subject length | 80 characters | | MMS media items | 10 per `mms` body | | Header and footer length | 60 characters each | | Header variables | 1 | | Buttons per template | 10 | | Button label length | 25 characters | | Button URL length | 2000 characters | | Variables in a dynamic URL button | Exactly 1, at the end of the URL | | Emojis in a `MARKETING` body | 10 (dashboard only, see below) | | Placeholder types | `variable`, `link`, or `media`. Any other type is refused at save time | The 10-emoji cap on `MARKETING` bodies is applied when a template is first created in the dashboard. The v3 API does not check it, so `POST /v3/templates` and `PUT /v3/templates/{id}` both accept a `MARKETING` body carrying more, and no update path re-checks it. Treat it as the limit to design to rather than a validation you can rely on. Length limits are validated at save time against the stored text, with `{{...}}` placeholders unsubstituted. Counting is encoding-blind: each UTF-16 code unit counts as one character (the behavior of .NET's `string.Length` and JavaScript's `String.prototype.length`), so characters in the Basic Multilingual Plane count as 1 and most emoji count as 2. There is no post-substitution validation; a body within the limit can render into a longer message once variables expand. For how rendered length maps to SMS segments, see [SMS Encoding & Message Length](/start/concepts/sms-encoding-and-length). Meta requires every variable to carry surrounding context, so body text must additionally satisfy all of these rules. A body that fails any of them is refused at save time: - At least one letter before the first variable and after the last. Trailing punctuation does not count: `... {{1:variable}}.` fails the rule. - At least (2 × variable count) + 1 words once the placeholders are removed. A word is any run of characters between whitespace, the way Meta counts it, so a symbol standing alone, such as the `|` in `{{0:variable}} | {{1:variable}}`, counts as one word. - No two variables adjacent with only whitespace between them. - The text cannot begin or end with a newline, run more than two line breaks together, or run more than four spaces together. For example, `Hello {{0:variable}}! Welcome to {{1:variable}}. We are glad to have you on board.` passes: it has two variables, so at least five words are required, and the copy after the final variable contains letters. `AUTHENTICATION` bodies are exempt from these rules and are held to [Meta's authentication format](#authentication-configuration) instead. ## Template statuses [#template-statuses] | Status | Meaning | | :--- | :--- | | `DRAFT` | Created but not submitted. Editable and testable; cannot be sent on any channel | | `PENDING` | Submitted for review; awaiting a decision | | `APPROVED` | Approved; available for sending | | `REJECTED` | Declined by the reviewer. A rejected template must be revised and resubmitted before it can send | | `PAUSED` | Paused by Meta for repeated low quality. The template stays published, but sends against it are blocked until it is reinstated | | `DISABLED` | Disabled by Meta, typically for a policy violation. Treated as a takedown: nothing sends | | `REVOKED` | Taken down on a channel by Sent or Meta. Nothing sends on that channel until it is reinstated | Review routing depends on your account: - With a connected WhatsApp Business Account, Meta reviews the template. A Meta `APPROVED` or `PENDING` verdict applies to every channel (SMS, WhatsApp, and RCS); a `REJECTED` verdict applies to the WhatsApp channel only. - Without a connected WhatsApp Business Account, Sent's compliance team reviews the template, and each channel is approved or rejected individually. Approval is tracked per channel. A message sends on a channel only when the template is approved for that channel; sends against unapproved templates return status `BLOCKED`. Status changes are delivered as `templates` [webhook events](/start/webhooks/event-types#templates) carrying the template ID, `status`, `reason`, and the `channel` leg the decision applies to. Each channel is reviewed independently and reports separately, so expect one event per leg. `channel` is omitted when the decision applies to the template as a whole rather than to one leg; that event is the broader news, because a template-wide rejection blocks every channel whatever the individual legs say. ## What a status allows you to change [#what-a-status-allows-you-to-change] [Update Template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesUpdateTemplateEndpoint) (`PUT /v3/templates/{id}`) treats `name` differently from the rest of the template. The display name is editable in every status. The content fields and resubmission are gated: | Status | `name` | `definition`, `category`, `language` | `submit_for_review` | | :--- | :--- | :--- | :--- | | `DRAFT` | Editable | Editable | Submits for review | | `REJECTED` | Editable | Editable | Resubmits for review | | `APPROVED` | Editable | Editable as a [live edit](#editing-an-approved-template) | Re-opens review | | `PENDING` | Editable | Frozen: `409` `CONFLICT_006` | Frozen: `409` `CONFLICT_006` | | `PAUSED`, `DISABLED`, `REVOKED` | Editable | Refused: `400` `VALIDATION_001` | Accepted, but does nothing | A template is also treated as in review, and so frozen, when its own status is not `PENDING` but any of its channels is still awaiting a verdict. The `409` carries the message *"This template is in review; its definition, category and language are frozen until the review completes"*. From `PAUSED`, `DISABLED`, or `REVOKED`, an edit to `definition`, `category`, or `language` is refused with a `400` whose `details.request` reads *"Template (except display name) cannot be updated unless it is in draft or rejected status"*. To change the content of a paused or taken-down template, create a new one. `submit_for_review: true` on a template in `PAUSED`, `DISABLED`, or `REVOKED` is accepted and answers `200`, but no review is opened and the status does not move. Only the reviewer can reinstate the template, so treat the `200` as a stored request rather than a resubmission, and confirm through the `templates` webhook or a follow-up `GET`. ### Editing an approved template [#editing-an-approved-template] An approved template can be edited in place; this is a live edit. The new content is stored immediately, and sending `submit_for_review: true` re-opens review, which returns the affected channels to `PENDING`. Those channels stop sending until they are approved again, and the previously approved content is **not** sent in the meantime. Plan for a gap, or keep a second approved template to send from while the edit is in review. How much of the template goes back to `PENDING` depends on how your account is reviewed, so watch the per-channel `templates` webhook events rather than reading the template-level status alone. ### Sent-provisioned templates are read-only [#sent-provisioned-templates-are-read-only] Templates that Sent provisions into your account (the pre-built OTP and verification templates that come with [light onboarding](/start/guides/working-with-templates)) are read-only. They accept only `submit_for_review`; any other field is refused with `400` `VALIDATION_001` and the detail *"This template is read-only. Only 'submit for review' is allowed."* To send different content, create your own template. Relatedly, the `sent_` prefix is reserved for these templates, so a `name` beginning with `sent_` is refused on a template of your own. Pick any other name. ## Example [#example] A complete `POST /v3/templates` request body with a header, a multi-channel body using text variables and a dynamic link, a footer, and two buttons: ```json { "category": "UTILITY", "language": "en_US", "submit_for_review": false, "definition": { "header": { "type": "text", "template": "Order {{0:variable}}: Delivery Update", "variables": [ { "id": 0, "name": "orderNumber", "type": "variable", "props": { "variableType": "text", "sample": "12345" } } ] }, "body": { "multiChannel": { "type": "text", "template": "Hi {{0:variable}},\nYour Acme order {{1:variable}} has been shipped and is expected to arrive {{2:variable}} between {{3:variable}}.\nYou can track your package or update your delivery preferences at {{4:link}} before the driver arrives.", "variables": [ { "id": 0, "name": "customerName", "type": "variable", "props": { "variableType": "text", "sample": "Lucas" } }, { "id": 1, "name": "orderNumber", "type": "variable", "props": { "variableType": "text", "sample": "#12345" } }, { "id": 2, "name": "arrivalDate", "type": "variable", "props": { "variableType": "text", "sample": "tomorrow (Oct 11)" } }, { "id": 3, "name": "arrivalTime", "type": "variable", "props": { "variableType": "text", "sample": "2 PM – 4 PM" } }, { "id": 4, "name": "orderLink", "type": "link", "props": { "url": "https://example.com", "shortUrl": "", "alt": "Tracking Page" } } ] } }, "footer": { "type": "text", "template": "Thank you for shopping with Acme.", "variables": [] }, "buttons": [ { "id": 1, "type": "URL", "props": { "text": "Track your order", "urlType": "static", "url": "https://www.example.com/track" } }, { "id": 2, "type": "PHONE_NUMBER", "props": { "text": "Acme customer support", "countryCode": "US", "phoneNumber": "+112345678" } } ] } } ``` The endpoint responds with the standard [response envelope](/reference/api/data-models#response-envelope); the created template's fields are documented on the [Create Template endpoint page](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesCreateTemplateEndpoint). method: POST route: /v3/templates # POST /v3/templates Create a new template Creates a new message template with header, body, footer, and buttons. The template can be submitted for review immediately or saved as draft for later submission. `name` is optional: when omitted or blank, a name is generated from the template's content. It can be changed afterwards with `PUT /v3/templates/{id}`. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3TemplatesCreateTemplateEndpoint` **Tags:** Templates ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, category?: string, language?: string, definition?: unknown, creation_source?: string, auto_create_for_sp?: boolean, submit_for_review?: boolean } ``` ## Responses ### 201 Template created successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, name?: string, category?: string, auto_reply_action?: string, language?: string, status?: string, channels?: Array, variables?: Array, created_at?: string, updated_at?: string, is_published?: boolean }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "customer_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Welcome Message", "category": "MARKETING", "auto_reply_action": null, "language": "en_US", "status": "DRAFT", "channels": [ "sms", "whatsapp", "rcs" ], "variables": [ "name", "company" ], "created_at": "2026-11-12T15:32:26.495734+00:00", "updated_at": "2026-11-12T15:32:26.4957424+00:00", "is_published": false }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4957603+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_004", "message": "A required field is missing", "details": { "definition": [ "Template definition is required" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4957679+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to create template", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4957684+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/templates/{id} # DELETE /v3/templates/{id} Delete a template Deletes a template by ID. Optionally, you can also delete the template from WhatsApp/Meta by setting delete_from_meta=true. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3TemplatesDeleteTemplateEndpoint` **Tags:** Templates ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Template ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, delete_from_meta?: boolean } ``` ## Responses ### 204 Template deleted successfully ### 400 Invalid template ID format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_003", "message": "Invalid identifier format", "details": { "id": [ "Invalid template ID format." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4971398+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Template not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_002", "message": "Template not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4971409+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to delete template", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4971412+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/templates/{id} # GET /v3/templates/{id} Get template by ID Retrieves a specific template by its ID. Returns template details including name, category, language, status, and definition. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3TemplatesGetTemplateEndpoint` **Tags:** Templates ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Template ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Template retrieved successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, name?: string, category?: string, auto_reply_action?: string, language?: string, status?: string, channels?: Array, variables?: Array, created_at?: string, updated_at?: string, is_published?: boolean }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "customer_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Welcome Message", "category": "MARKETING", "auto_reply_action": null, "language": "en_US", "status": "APPROVED", "channels": [ "sms", "whatsapp", "rcs" ], "variables": [ "name", "company" ], "created_at": "2026-10-13T15:32:26.4992695+00:00", "updated_at": "2026-10-28T15:32:26.4992701+00:00", "is_published": true }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4992705+00:00", "version": "v3" } } ``` ### 400 Invalid template ID format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_003", "message": "Invalid identifier format", "details": { "id": [ "Invalid template ID format." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4992735+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Template not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_002", "message": "Template not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4992739+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4992743+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/templates # GET /v3/templates Get templates list Retrieves a paginated list of message templates for the authenticated customer. Supports filtering by status, category, and search term. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3TemplatesGetTemplatesEndpoint` **Tags:** Templates ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | Page number (1-indexed) | | `page_size` | `integer` | true | Number of items per page | | `search` | `string` | false | Optional search term for filtering templates | | `status` | `string` | false | Optional status filter: APPROVED, PENDING, REJECTED | | `category` | `string` | false | Optional category filter: MARKETING, UTILITY, AUTHENTICATION | | `is_welcome_playground` | `boolean` | false | Accepted and ignored. It used to filter on the welcome-playground marker inside a template's LOB details; that filter is gone and nothing reads this value, so sending it neither narrows nor widens the result. Retained only so a client still passing is_welcome_playground keeps binding instead of the request shape changing under it. | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Templates retrieved successfully #### application/json ```typescript { success?: boolean, data?: { templates?: Array<{ id?: string, customer_id: string, name?: string, category?: string, auto_reply_action?: string, language?: string, status?: string, channels?: Array, variables?: Array, created_at?: string, updated_at?: string, is_published?: boolean }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "templates": [ { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "customer_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Welcome Message", "category": "MARKETING", "auto_reply_action": null, "language": "en_US", "status": "APPROVED", "channels": [ "sms", "whatsapp", "rcs" ], "variables": [ "name", "company" ], "created_at": "2026-10-13T15:32:26.5007631+00:00", "updated_at": "2026-10-28T15:32:26.5007636+00:00", "is_published": true } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5007828+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "page_size": [ "Page size must be between 1 and 100" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5007859+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5007863+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PUT route: /v3/templates/{id} # PUT /v3/templates/{id} Update a template Updates an existing template's name, category, language, definition, or submits it for review. While the template is in review (status PENDING, or any channel awaiting a verdict) its definition, category and language are frozen and a resubmission is refused — those requests answer 409 CONFLICT_006. The display name stays editable throughout. `definition`, `category` and `language` are editable only from status DRAFT, REJECTED or APPROVED. An edit to any of them on a template in another state (PAUSED, DISABLED or REVOKED) is refused with 400 VALIDATION_001 and the detail "Template (except display name) cannot be updated unless it is in draft or rejected status"; `name` stays editable in every state. `submit_for_review` on a PAUSED, DISABLED or REVOKED template is accepted and answers 200, but opens no review and does not move the status — only the reviewer can reinstate it. Editing an APPROVED template is a live edit: the new content is stored immediately, and sending `submit_for_review: true` re-opens review, which returns the affected channels to PENDING so they stop sending until they are approved again. The previously approved content is never sent during re-review. Watch the per-channel `templates` webhook events rather than assuming the template-level status. Templates provisioned by Sent (light-onboarding templates, whose names carry the reserved `sent_` prefix) are read-only: every field is refused with 400 VALIDATION_001 and the detail "This template is read-only. Only 'submit for review' is allowed.", and only `submit_for_review` is accepted. A `name` starting with `sent_` is refused for the same reason — the prefix is reserved. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3TemplatesUpdateTemplateEndpoint` **Tags:** Templates ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | Template ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, category?: string, language?: string, definition?: { header?: { type?: string, template?: string, variables?: Array<{ id?: integer, name: string, type: string, props: { variableType: string, sample: string, regex?: string, url: string, shortUrl?: string, alt?: string, mediaType: string } }>, example_url?: string, static_resource?: boolean, location?: { latitude?: string, longitude?: string, name?: string, address?: string } }, body?: unknown, footer?: { type?: string, template?: string, variables?: Array<{ id?: integer, name: string, type: string, props: { variableType: string, sample: string, regex?: string, url: string, shortUrl?: string, alt?: string, mediaType: string } }> }, buttons?: Array<{ id?: integer, type: string, props: unknown }>, definitionVersion?: string, authenticationConfig?: { addSecurityRecommendation?: boolean, codeExpirationMinutes?: integer } }, submit_for_review?: boolean } ``` ## Responses ### 200 Template updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, name?: string, category?: string, auto_reply_action?: string, language?: string, status?: string, channels?: Array, variables?: Array, created_at?: string, updated_at?: string, is_published?: boolean }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "customer_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Updated Welcome Message", "category": "MARKETING", "auto_reply_action": null, "language": "en_US", "status": "DRAFT", "channels": [ "sms", "whatsapp", "rcs" ], "variables": [ "name", "company" ], "created_at": "2026-10-13T15:32:26.5023813+00:00", "updated_at": "2026-11-12T15:32:26.5023818+00:00", "is_published": false }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5023823+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "category": [ "Category must be one of: MARKETING, UTILITY, AUTHENTICATION" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.502386+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Template not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_002", "message": "Template not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5023865+00:00", "version": "v3" } } ``` ### 409 Template is in review — definition, category, language and resubmission are frozen #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_006", "message": "This template is in review; its definition, category and language are frozen until the review completes", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5023868+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "Failed to update template", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.5023877+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # Sandbox Mode (/reference/api/test-mode.md) # Sandbox Mode [#sandbox-mode] Sandbox mode simulates a mutation request without executing it. When the request body of a supported endpoint contains `"sandbox": true`, the API authenticates and validates the request as usual, then returns a simulated response with sample data instead of performing the operation. For test-suite, CI, and debugging workflows built on sandbox mode, see [Testing with sandbox mode](/start/guides/testing-with-sandbox-mode). --- ## Request Field [#request-field] | Field | Type | Location | Default | |-------|------|----------|---------| | `sandbox` | boolean | JSON request body | `false` | `sandbox` must be the JSON boolean `true`; the string `"true"` is not a valid value. The API reads the field from the request body of the endpoints listed under [Supported Endpoints](#supported-endpoints), never from headers or query parameters. Two endpoints also accept a multipart form body: - `PATCH /v3/channels/sms/{country}/{type}`: send `sandbox` as its own form field with the text value `true`. - `POST /v3/sender-profiles`: include `"sandbox": true` inside the JSON document in the `profile` form field. --- ## How It Works [#how-it-works] For a request with `"sandbox": true`: 1. **Authentication runs.** An invalid or missing API key is rejected with `401`. 2. **Request validation runs.** A malformed payload returns the same `400` errors as a live request. 3. **Execution is skipped.** The database, the send queue, downstream provider APIs, and your balance are all left untouched. 4. **A simulated response is returned.** It uses the same envelope and schema as a live response, populated with sample data, and the same status code except where [Supported Endpoints](#supported-endpoints) notes otherwise. Identifiers such as `message_id` are newly generated and do not reference stored resources. Sandbox mode does not look up stored resources for most endpoints. A sandbox send referencing a nonexistent template ID still returns `202`; only request-level validation is applied. The exceptions are the channel and Sender Profile endpoints below. They read your stored account state first and return the same errors as a live request: | Endpoint | Checks run before the simulated response | |----------|------------------------------------------| | `PATCH /v3/sender-profiles/{id}` | `404` if the Sender Profile does not exist. | | `PATCH /v3/channels/voice/{number}` | `404` if the account has no such voice number, and `404` if `agent_id` is not one of the account's voice agents. | | `POST /v3/voice/agents` | `409` if the account already holds as many voice agents as it may. | | `PATCH /v3/voice/agents/{id}` | `404` if the account has no such agent, and `400` if the body changes nothing. | | `DELETE /v3/voice/agents/{id}` | `404` if the account has no such agent, and `409` if a voice number routes to it or another agent lists it in `transfer_targets`. | | `POST /v3/voice/agents/{id}/rotate-secret` | `404` if the account has no such agent. | | `PATCH /v3/channels/sms/{country}/{type}` | `404` if the account does not hold the market, plus the same `400` and `409` compliance checks as a live request. | | `POST /v3/channels/sms` | `409` if the account already holds the market, unless the request adds numbers to a held `LOCAL` market or re-asks for area codes on a held market that has no sender yet. Also runs the same `400` and `422` compliance and identity checks as a live request. | | `POST /v3/channels/rcs` | `409` if the account already has an RCS agent. | --- ## Response Headers [#response-headers] | Header | Value | |--------|-------| | `X-Sandbox` | `true` when the `sandbox` field was detected. Present on success responses and on `400` validation errors. | --- ## Example [#example] ```http POST /v3/messages Content-Type: application/json x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx { "sandbox": true, "to": ["+14155550123"], "channel": ["sms"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "name": "Test User" } } } ``` **Response:** ```http HTTP/1.1 202 Accepted X-Sandbox: true X-Request-Id: req_5f2c1b3a9d8e4f67 Content-Type: application/json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+14155550123", "channel": "sms", "body": null } ] }, "meta": { "request_id": "req_5f2c1b3a9d8e4f67", "timestamp": "2026-07-25T10:30:00Z", "version": "v3" } } ``` In the simulated response, `template_name` is empty and `body` is `null` because the template is referenced by `id` and sandbox mode performs no template lookup. `message_id` is generated per recipient and does not correspond to a stored message. --- ## Supported Endpoints [#supported-endpoints] | Endpoint | Sandbox response | |----------|------------------| | `POST /v3/messages` | `202` with `"status": "QUEUED"` and one simulated recipient per `to` entry per channel, or one per `to` entry with no channel when `channel` is omitted. Nothing is queued or sent. | | `POST /v3/messages/{id}/cancel` | `200` with a simulated message reporting `"status": "CANCELLED"`. No message is cancelled and no webhook is delivered. | | `POST /v3/contacts` | `201` with a simulated contact echoing `phone_number`. No contact is created. | | `PATCH /v3/contacts/{id}` | `200` with a simulated updated contact. | | `POST /v3/templates` | `201` with a simulated template in `DRAFT` status. | | `PUT /v3/templates/{id}` | `200` with a simulated updated template. | | `DELETE /v3/templates/{id}` | `204`. The template is not deleted. | | `POST /v3/webhooks` | `201` with a simulated webhook and a placeholder signing secret. | | `PUT /v3/webhooks/{id}` | `200` with a simulated updated webhook. | | `PATCH /v3/webhooks/{id}/toggle-status` | `200` with a simulated webhook reflecting the requested `is_active`. | | `POST /v3/webhooks/{id}/rotate-secret` | `200` with a placeholder `signing_secret`. The real secret is unchanged. | | `POST /v3/webhooks/{id}/test` | `200` with a simulated delivery result. No test event is delivered. | | `POST /v3/sender-profiles` | `201` with a simulated Sender Profile, or `202` when the body includes a `channels.sms` block. Nothing is created and no number is provisioned. | | `PATCH /v3/sender-profiles/{id}` | `200` with the stored profile and the requested changes applied. Nothing is written. | | `POST /v3/channels/sms` | `202` with a simulated market in `PROVISIONING` status. When the request adds numbers to a held `LOCAL` market or re-asks for area codes, `202` with the market as currently stored. No number is claimed and no compliance data is written. | | `PATCH /v3/channels/sms/{country}/{type}` | `200` with the stored market and the requested compliance changes applied. Nothing is written and no documents are attached. | | `POST /v3/channels/rcs` | `202` with a simulated RCS agent echoing the request. No agent is requested. | | `POST /v3/channels/voice` | `202` with a simulated voice number and a callback secret that is not stored. No number is purchased. | | `PATCH /v3/channels/voice/{number}` | `200` with the stored voice number and the requested changes applied. Nothing is written. | | `POST /v3/channels/voice/{number}/rotate-secret` | `202` (a live request returns `200`) with a new `callback_secret` that is not stored. The real secret is unchanged. | | `POST /v3/channels/voice/{number}/test` | `202` (a live request returns `200`) with a passing result and a simulated `call_id`. No test request is sent to your callback URL. | | `POST /v3/voice/tokens` | `200` with a token prefixed `voice_test_` that cannot be used to place calls. | | `POST /v3/voice/calls/{id}/hangup` | `204`. The call is not ended. | | `POST /v3/voice/calls/{id}/participants` | `202` with a simulated participant leg in `INITIATED` status. Nobody is dialed. | | `PATCH /v3/voice/calls/{id}/participants/{participantId}` | `204`. The participant is not muted or unmuted. | | `DELETE /v3/voice/calls/{id}/participants/{participantId}` | `204`. The participant is not removed. | | `DELETE /v3/voice/calls/{id}/participants` | `204`. No participants are removed. | | `POST /v3/voice/calls/{id}/recordings` | `204`. Recording is not started or stopped. | | `POST /v3/voice/agents` | `202` with the agent as it would be stored, under an id and a `signing_secret` that are not stored. No agent is created. | | `PATCH /v3/voice/agents/{id}` | `200` with the stored agent and the requested changes applied. Nothing is written. | | `DELETE /v3/voice/agents/{id}` | `204`. The agent is looked up and the answer is the one a real delete would give, but the agent is not deleted. | | `POST /v3/voice/agents/{id}/rotate-secret` | `202` (a live request returns `200`) with a new `signing_secret` that is not stored. The real secret is unchanged. | | `POST /v3/users` | `201` with a simulated invited user. No invitation is sent. | | `PATCH /v3/users/{userId}` | `200` with a simulated updated user. | | `DELETE /v3/users/{userId}` | `204`. The user is not removed. | GET endpoints do not accept the `sandbox` field. The following endpoints do not support sandbox mode and always run the operation, even if the body contains `"sandbox": true`: - `DELETE /v3/webhooks/{id}` deletes the webhook. - `DELETE /v3/sender-profiles/{id}` deletes the Sender Profile. - `POST /v3/channels/whatsapp` connects the WhatsApp account. The response still carries `X-Sandbox: true`. ### Deprecated Endpoints [#deprecated-endpoints] These endpoints are deprecated and will be removed in a future release. They still accept `"sandbox": true`, but new integrations should use the replacement. Responses from the `/v3/profiles` endpoints, sandbox or live, carry a `Deprecation: true` header and a `Link` header pointing to `/v3/sender-profiles` with `rel="successor-version"`. | Deprecated endpoint | Sandbox response | Replacement | |---------------------|------------------|-------------| | `DELETE /v3/contacts/{id}` (deprecated) | `204`. The contact is not deleted. | `PATCH /v3/contacts/{id}` with `{"opt_out": true}` | | `POST /v3/profiles` (deprecated) | `201` with a simulated profile. | `POST /v3/sender-profiles` | | `PATCH /v3/profiles/{profileId}` (deprecated) | `200` with a simulated updated profile. | `PATCH /v3/sender-profiles/{id}` | | `DELETE /v3/profiles/{profileId}` (deprecated) | `204`. The profile is not deleted. | `DELETE /v3/sender-profiles/{id}` (no sandbox support) | | `POST /v3/profiles/{profileId}/complete` (deprecated) | `202`. No completion is started. The administrator role check still runs, so a caller without the required role gets `403` as in a live request. | `/v3/sender-profiles` | | `POST /v3/profiles/{profileId}/campaigns` (deprecated) | `201` with a simulated campaign. Nothing is submitted to TCR. | `/v3/sender-profiles` | | `PUT /v3/profiles/{profileId}/campaigns/{campaignId}` (deprecated) | `200` with a simulated updated campaign. | `/v3/sender-profiles` | | `DELETE /v3/profiles/{profileId}/campaigns/{campaignId}` (deprecated) | `204`. The campaign is not deleted. | `/v3/sender-profiles` | --- ## Sandbox Mode vs Idempotency [#sandbox-mode-vs-idempotency] | Feature | Purpose | Side effects | Response data | |---------|---------|--------------|---------------| | Sandbox mode | Simulate a request | None | Sample data | | Idempotency | Execute a request at most once | On the first request only | Real data, cached for replays | Refer to [Idempotency](/reference/api/idempotency) for key format, expiry, and replay headers. --- ## Troubleshooting [#troubleshooting] | Symptom | Cause | Check | |---------|-------|-------| | Response has no `X-Sandbox` header and the operation executed | The `sandbox` field was not detected | Send `sandbox` as the JSON boolean `true`, not the string `"true"`, in the request body of a supported endpoint. Headers and query parameters are not read. | | `401` | Invalid or missing API key | Sandbox mode does not bypass authentication. The request must carry a valid key in `x-api-key` or `Authorization: Bearer`. | | `400` with `X-Sandbox: true` | The payload failed validation | Sandbox requests return the same validation errors as live requests. Correct the fields listed in the error details. | method: GET route: /v3/users/{userId} # GET /v3/users/{userId} Get user by ID Retrieves detailed information about a specific user in an organization or profile. Requires developer role or higher. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3UsersGetUserEndpoint` **Tags:** Users ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `userId` | `string` | true | User ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 User retrieved successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, email?: string, name?: string, role?: string, status?: string, invited_at?: string, last_login_at?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "880e8400-e29b-41d4-a716-446655440003", "customer_id": "00000000-0000-0000-0000-000000000000", "email": "admin@acme.com", "name": "John Admin", "role": "admin", "status": "active", "invited_at": "2026-05-12T15:32:26.4857674+00:00", "last_login_at": "2026-11-12T13:32:26.4857894+00:00", "created_at": "2026-05-12T15:32:26.4858006+00:00", "updated_at": "2026-11-11T15:32:26.4858097+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4858193+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have access to this organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "AUTH_004", "message": "You do not have access to this organization or profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4858213+00:00", "version": "v3" } } ``` ### 404 User not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_006", "message": "User not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4858217+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4858222+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/users # GET /v3/users List users Retrieves all users who have access to the organization or profile identified by the API key, including their roles and status. Shows invited users (pending acceptance) and active users. Requires developer role or higher. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3UsersGetUsersEndpoint` **Tags:** Users ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Users retrieved successfully #### application/json ```typescript { success?: boolean, data?: { users?: Array<{ id?: string, customer_id?: string, email?: string, name?: string, role?: string, status?: string, invited_at?: string, last_login_at?: string, created_at?: string, updated_at?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "users": [ { "id": "880e8400-e29b-41d4-a716-446655440003", "customer_id": "00000000-0000-0000-0000-000000000000", "email": "admin@acme.com", "name": "John Admin", "role": "admin", "status": "active", "invited_at": "2026-05-12T15:32:26.4874658+00:00", "last_login_at": "2026-11-12T13:32:26.4874666+00:00", "created_at": "2026-05-12T15:32:26.4874668+00:00", "updated_at": "2026-11-11T15:32:26.4874669+00:00" }, { "id": "990e8400-e29b-41d4-a716-446655440004", "customer_id": "00000000-0000-0000-0000-000000000000", "email": "developer@acme.com", "name": "Jane Developer", "role": "developer", "status": "invited", "invited_at": "2026-11-10T15:32:26.4874673+00:00", "last_login_at": null, "created_at": "2026-11-10T15:32:26.4874674+00:00", "updated_at": "2026-11-10T15:32:26.4874674+00:00" } ], "pagination": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4874819+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have access to this organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "AUTH_004", "message": "You do not have access to this organization or profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4874891+00:00", "version": "v3" } } ``` ### 404 Organization not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_005", "message": "Organization not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4874898+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4874901+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/users # POST /v3/users Invite a user Sends an invitation to a user to join the organization or profile with a specific role. Requires admin role. The user will receive an invitation email with a token to accept. Invitation tokens expire after 7 days. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3UsersInviteUserEndpoint` **Tags:** Users ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, email?: string, name?: string, role?: string } ``` ## Responses ### 201 User invited successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, email?: string, name?: string, role?: string, status?: string, invited_at?: string, last_login_at?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "aa0e8400-e29b-41d4-a716-446655440005", "customer_id": "00000000-0000-0000-0000-000000000000", "email": "newuser@example.com", "name": "New User", "role": "developer", "status": "invited", "invited_at": "2026-11-12T15:32:26.4907776+00:00", "last_login_at": null, "created_at": "2026-11-12T15:32:26.4907779+00:00", "updated_at": "2026-11-12T15:32:26.490778+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4907782+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "email": [ "Email must be a valid email address" ], "role": [ "Role must be one of: admin, billing, developer" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4907822+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have admin access to this organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "AUTH_004", "message": "You do not have admin access to this organization or profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4907827+00:00", "version": "v3" } } ``` ### 404 Organization not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_005", "message": "Organization not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4907831+00:00", "version": "v3" } } ``` ### 409 User already exists in organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_007", "message": "User already exists in this organization", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.490784+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4907843+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/users/{userId} # DELETE /v3/users/{userId} Remove user Removes a user's access to an organization or profile. Requires admin role. You cannot remove yourself or remove the last admin. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3UsersRemoveUserEndpoint` **Tags:** Users ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `userId` | `string` | true | User ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 User removed successfully ### 400 Invalid request - Cannot remove yourself or last admin #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "You cannot remove yourself from the organization", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4922741+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have admin access to this organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "AUTH_004", "message": "You do not have admin access to this organization or profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4922752+00:00", "version": "v3" } } ``` ### 404 User not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_006", "message": "User not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4922756+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.492281+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/users/{userId} # PATCH /v3/users/{userId} Update user role Updates a user's role in the organization or profile. Requires admin role. You cannot change your own role or demote the last admin. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3UsersUpdateUserEndpoint` **Tags:** Users ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `userId` | `string` | true | User ID from route parameter | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, role?: string } ``` ## Responses ### 200 User role updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, email?: string, name?: string, role?: string, status?: string, invited_at?: string, last_login_at?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "aa0e8400-e29b-41d4-a716-446655440005", "customer_id": "00000000-0000-0000-0000-000000000000", "email": "user@example.com", "name": "User Name", "role": "billing", "status": "active", "invited_at": "2026-10-12T15:32:26.4938866+00:00", "last_login_at": "2026-11-12T10:32:26.4938876+00:00", "created_at": "2026-10-12T15:32:26.4938878+00:00", "updated_at": "2026-11-12T15:32:26.4938879+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4938882+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters or cannot modify own role #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "role": [ "Role must be one of: admin, billing, developer" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4938917+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden - User does not have admin access to this organization #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "AUTH_004", "message": "You do not have admin access to this organization or profile", "details": null, "doc_url": "https://docs.sent.dm/reference/api/authentication" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4938922+00:00", "version": "v3" } } ``` ### 404 User not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_006", "message": "User not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4938925+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred. Please contact support with request ID: req_7X9zKp2jDw", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4938935+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # API v2 to v3 changes (/reference/api/v2-to-v3.md) # API v2 to v3 changes [#api-v2-to-v3-changes] Sent API v3 is the current major version. It replaces the v2 authentication scheme, wraps every response in a standard JSON envelope, and adds capabilities that v2 does not have. The v2 API remains available at `/v2/` paths for existing integrations; the [Legacy API reference](/reference-legacy/api) documents it in full. For step-by-step upgrade instructions, see the [API v2 to v3 migration guide](/start/advanced/migration-v2-v3). ## Changes from v2 [#changes-from-v2] | Area | v2 | v3 | Details | |------|-----|-----|---------| | Base path | `/v2/` | `/v3/` | | | Authentication | `x-sender-id` and `x-api-key` headers | `x-api-key` header, or `Authorization: Bearer`, with no sender ID | [Authentication](/reference/api/authentication) | | Success responses | No standard envelope | Envelope with `success`, `data`, `error`, and `meta` | [Data models](/reference/api/data-models) | | Error responses | FastEndpoints problem details | `error` object with prefixed `code`, `message`, `details`, and `doc_url` | [Error handling](/reference/api/errors) | | Property naming | camelCase (`messageId`) | snake_case (`message_id`) | | | Sandbox mode | Not available | `sandbox` field in the request body | [Sandbox mode](/reference/api/test-mode) | | Idempotency | Not available | `Idempotency-Key` header on `POST`, `PUT`, and `PATCH` | [Idempotency](/reference/api/idempotency) | | Sender Profiles | Not available | Full CRUD at `/v3/profiles` | [Sender Profiles](/start/concepts/sender-profiles) | | 10DLC brands and campaigns | Not available | Brand registration through Sender Profiles; campaigns at `/v3/profiles/{profileId}/campaigns` | | | User management | Not available | Organization users at `/v3/users` | | | Webhook management | Not available | `/v3/webhooks`, including secret rotation, delivery tests, status toggling, and event-type discovery | | | Webhook event payloads | Flat payload | `event` field with a nested `payload` object | [Webhook event types](/start/webhooks/event-types) | ## Version support [#version-support] The v2 API is a legacy version: it remains supported, and Sent has not announced an end-of-support date. New integrations must use v3. The [changelog](/reference/changelog) records the release history for both versions. # Voice agent protocol (/reference/api/voice-agent-protocol.md) # Voice agent protocol [#voice-agent-protocol] **Stable.** This page describes version 1.0.0 of the Sent Voice Agents protocol, spoken over the `sent.voice.v1` WebSocket subprotocol. Every 1.x release keeps these frames and only adds to them, so an agent built on this page keeps working. The canonical specification is the [sent-dm-voice-protocol](https://github.com/sentdm/sent-dm-voice-protocol) repository: `docs/protocol.md`, `asyncapi.yaml`, a JSON Schema (draft-07) per frame under `schemas/`, valid and invalid examples under `examples/`, and the conformance scenarios every Sent Voice Agents SDK passes. An agent session is one phone call while one agent is on it. Sent and the agent exchange frames over a WebSocket: JSON text messages, one frame per message, and binary messages for audio. This page is the reference for those frames. How to get connected, either way round, is in [Connect a voice agent](/start/guides/voice-agent-connect). Every frame has a `type`. Every frame about a session carries its `session_id`. Ids follow the REST API's: a session is `vs_...`, a call is `call_...`, the same id `GET /v3/voice/calls/{id}` reads, and an agent is `agent_...`. ## Frames [#frames] | Frame | Sent by | Belongs to | Session types | Fields | | :--- | :--- | :--- | :--- | :--- | | [`connection.ready`](#connectionready) | Sent | connection | | `protocol_version`, `heartbeat_interval_ms`, `max_sessions` | | [`connection.draining`](#connectiondraining) | Sent | connection | | none | | [`ping`](#ping-and-pong) | Sent | connection | | `ts` | | [`pong`](#ping-and-pong) | agent | connection | | `ts` | | [`error`](#error) | Sent | connection | | `error`, `session_id`, `frame_type` | | [`session.start`](#sessionstart) | Sent | session | text, audio | `call_id`, `agent_id`, `direction`, `from`, `to`, `session_type`, `started_at`, `language`, `audio`, `max_duration_ms`, `context`, `resume` | | [`session.end`](#sessionend) | Sent | session | text, audio | `reason`, `duration_ms` | | [`user.said`](#usersaid) | Sent | session | text | `text`, `correction` | | [`agent.say`](#agentsay) | agent | session | text | `text`, `interruptible`, `last` | | [`agent.clear`](#agentclear) | agent | session | text, audio | none | | [`tool.call`](#toolcall) | agent | session | text, audio | `call_ref`, `name`, `arguments` | | [`tool.result`](#toolresult) | Sent | session | text, audio | `call_ref`, `ok`, `error` | | [`session.resume`](#sessionresume) | agent | session | text, audio | `token`, `received` | | [`session.resumed`](#sessionresumed) | Sent | session | text, audio | `received`, `resume`, `audio` | | [binary audio](#audio-messages) | both | session | audio | a 2-byte stream number, then PCM | ### Order of frames [#order-of-frames] - Sent's first frame on a connection is `connection.ready`. - For each session, Sent's first frame is `session.start` and its last is `session.end`. After `session.end` the agent sends nothing more for that session. - On a connection a session is resumed on, Sent's first frame for it is `session.resumed`. - `ping`, `pong`, `connection.draining` and `error` belong to the connection and can come at any time. - Frames for one session arrive in the order they were sent, also across a resume. Frames for different sessions can interleave. ### Limits [#limits] - `user.said` and `agent.say` carry at most 4,096 characters of `text`. - A text frame is at most 64 KB. Sent refuses a larger one with `invalid_frame`. - An outbound call's `context` is at most 4 KB as JSON. - Each side keeps the last 32 frames it counted for a session, to send again when the session resumes. A session whose connection is lost has `window_ms` to resume, 15 seconds. ## Connection frames [#connection-frames] ### connection.ready [#connectionready] First on a connection the agent opened, and first on a connection Sent opened: the connection is authenticated, and sessions follow. | Field | Type | Description | | :--- | :--- | :--- | | `protocol_version` | string | The version of this protocol Sent speaks on the connection, such as `1.0.0` | | `heartbeat_interval_ms` | integer | How often Sent sends `ping` on the connection, 5,000 | | `max_sessions` | integer | The most sessions Sent puts on the connection at once. 1 on a connection Sent opened | ```json { "type": "connection.ready", "protocol_version": "1.0.0", "heartbeat_interval_ms": 5000, "max_sessions": 50 } ``` ### connection.draining [#connectiondraining] No new sessions start on this connection. Open a new one now, while the sessions already on this one go on, and send a `session.resume` on it for each session, with the session's latest token and your `received` count. Sent closes the drained connection with code `1001` once no session is left on it. No fields. ```json { "type": "connection.draining" } ``` ### ping and pong [#ping-and-pong] Sent sends `ping` on every connection at `heartbeat_interval_ms`. Answer each one with `pong` carrying the same `ts`, milliseconds since the Unix epoch. Three unanswered pings close the connection with code `4008`. Three intervals without a `ping` mean the connection is dead: open a new one and resume the sessions there. ```json { "type": "ping", "ts": 1792411215000 } ``` ```json { "type": "pong", "ts": 1792411215000 } ``` ### error [#error] A frame the agent sent wasn't accepted and had no effect. The connection stays open. | Field | Type | Description | | :--- | :--- | :--- | | `error.code` | string | One of the [error codes](#error-codes). Sent may add codes | | `error.message` | string | For people. It may change without notice | | `session_id` | string | The session the refused frame named, when it named one | | `frame_type` | string | The `type` of the refused frame, when it had one | ```json { "type": "error", "error": { "code": "frame_not_allowed", "message": "agent.say is not allowed in an audio session." }, "session_id": "vs_7Hq2Lm9xQa", "frame_type": "agent.say" } ``` ## Session frames [#session-frames] ### session.start [#sessionstart] First for every session: a call has reached the agent. | Field | Type | Description | | :--- | :--- | :--- | | `session_id` | string | The session, `vs_` and an id | | `call_id` | string | The call, as `GET /v3/voice/calls/{id}` knows it. It stays the same when the call moves to a person | | `agent_id` | string | The agent, as `/v3/voice/agents` knows it | | `direction` | string | `inbound` for a call to one of your numbers, `outbound` for a call the agent placed | | `from`, `to` | object | The [parties](#parties) | | `session_type` | string | `text` or `audio`, from the agent's setting | | `started_at` | string | When the session started, ISO 8601 | | `language` | string | Text sessions: the caller's language as a BCP 47 tag, from the agent's `speech.language` | | `audio` | object | Audio sessions: `stream`, the number in the header of this session's binary messages, and `sample_rate`, the Hz of the 16-bit mono PCM both ways, `8000`, `16000` or `24000` | | `max_duration_ms` | integer | When Sent ends the session with reason `max_duration`, counted from `started_at`, from the agent's `limits.max_call_seconds` | | `context` | object | What your backend passed when it placed an outbound call, at most 4 KB as JSON | | `resume` | object | `token` and `window_ms`, how to resume the session on a new connection. Absent on a connection Sent opened | ```json { "type": "session.start", "session_id": "vs_7Hq2Lm9xQa", "call_id": "call_9f2ab000-0000-4000-8000-000000000001", "agent_id": "agent_9f2ab000-0000-4000-8000-000000000001", "direction": "inbound", "from": { "kind": "number", "value": "+14155550100" }, "to": { "kind": "number", "value": "+14155550199" }, "session_type": "text", "language": "en-US", "max_duration_ms": 3600000, "resume": { "token": "vsr_example_token_000000000000000001", "window_ms": 15000 }, "started_at": "2026-10-23T12:00:00Z" } ``` ### session.end [#sessionend] Last for every session: the call has left the agent. | Field | Type | Description | | :--- | :--- | :--- | | `reason` | string | Why the call left the agent, one of the [end reasons](#end-reasons). Treat a reason you don't know as `failed` | | `duration_ms` | integer | How long the session lasted | ```json { "type": "session.end", "session_id": "vs_7Hq2Lm9xQa", "reason": "transferred", "duration_ms": 48210 } ``` #### End reasons [#end-reasons] | `reason` | When | | :--- | :--- | | `caller_hung_up` | The caller hung up | | `agent_hung_up` | The agent used `hangup` | | `transferred` | The agent used `transfer` | | `max_duration` | The session reached `max_duration_ms` from `session.start` | | `agent_unreachable` | The agent's connection was lost and the session wasn't resumed in time | | `balance_exhausted` | The account ran out of balance | | `voice_disabled` | Phone calls were turned off for the account | | `failed` | Anything else | ## Text sessions [#text-sessions] In a text session Sent runs speech-to-text and text-to-speech. When the agent has a `greeting` setting, Sent speaks it right after `session.start`. Otherwise the agent can speak first or wait for the caller. While `interruptible` is true, the default, the caller speaking stops the agent's speech and drops the speech still queued. ### user.said [#usersaid] One complete utterance from the caller, once Sent has transcribed it. There are no interim partial results. | Field | Type | Description | | :--- | :--- | :--- | | `text` | string | What the caller said, 1 to 4,096 characters | | `correction` | boolean | `true` when this replaces the session's previous `user.said`, because Sent transcribed the speech again after a pause. If you've already answered the replaced utterance, send `agent.clear` and answer the correction | ```json { "type": "user.said", "session_id": "vs_7Hq2Lm9xQa", "text": "I need to talk to a person" } ``` ### agent.say [#agentsay] Speak this to the caller. Spoken in the order it arrives. | Field | Type | Description | | :--- | :--- | :--- | | `text` | string | What to say, 1 to 4,096 characters | | `interruptible` | boolean | Whether the caller speaking stops this speech. Default `true` | | `last` | boolean | `false` when more text for the same utterance follows. Default `true`. Pieces with `last: false` and a final `last: true` are spoken as one utterance, so speech starts before a reply is complete | ```json { "type": "agent.say", "session_id": "vs_7Hq2Lm9xQa", "text": "Let me check your order", "last": false, "interruptible": false } ``` ## Audio sessions [#audio-sessions] In an audio session the agent runs its own speech. Sent sends the caller's audio and plays the audio the agent sends, as binary messages of 16-bit little-endian mono PCM at the `sample_rate` in `session.start`'s `audio`. `user.said` and `agent.say` aren't allowed and answer `frame_not_allowed`. ### Audio messages [#audio-messages] Each binary message carries audio for one session: | Bytes | Content | | :--- | :--- | | 0 to 1 | The session's `stream` from `session.start`'s `audio`, big-endian unsigned | | 2 on | Audio, a whole number of samples | The 2-byte header keeps the samples aligned, so a reader can view them as 16-bit integers without copying. Send 20 ms of audio per message, which is 640 bytes at 16,000 Hz, and no more than 200 ms. Sent sends the caller's audio for the whole session, silence included, and plays the agent's audio in the order it arrives. Audio a session has no room for is dropped, because late audio is worthless. The [sample agents](https://github.com/sentdm/sent-dm-voice-protocol/tree/main/examples) include one that plays the caller's audio back, the quickest way to hear a session work. ### agent.clear [#agentclear] Drops the speech or audio the agent sent that Sent hasn't played yet, in either session type: when the caller starts talking over the agent, or after a correction. No fields beyond `session_id`. ```json { "type": "agent.clear", "session_id": "vs_7Hq2Lm9xQa" } ``` ## Tools [#tools] The agent acts on the call with `tool.call`. Sent answers every `tool.call` with exactly one `tool.result` carrying the same `call_ref`. A tool runs after the speech or audio the agent queued before it, so an agent can say goodbye and then hang up. If the caller interrupts, the queued speech is dropped and the tool runs straight away. To act at once, send `agent.clear` before the `tool.call`. The agent's `tools` setting decides which tools it may use, and its `transfer_targets` setting decides where it may transfer. See [Tools and transfer targets](/start/guides/voice-agents#tools-and-transfer-targets). ### tool.call [#toolcall] | Field | Type | Description | | :--- | :--- | :--- | | `call_ref` | string | Chosen by the agent, 1 to 64 characters, unique within the session, and repeated in the `tool.result` | | `name` | string | The tool | | `arguments` | object | The tool's arguments, below | | `name` | `arguments` | What happens | | :--- | :--- | :--- | | `transfer` | `to`: a [party](#parties) with kind `number`, `user` or `agent`, listed in `transfer_targets` | A `number` is dialled with your number as the caller id while the caller stays with the agent. When it answers, the caller and the target are bridged, then `session.end` with `transferred`. When it doesn't connect, `ok: false` with `failed` and the message `The transfer did not connect.`, and the session goes on. A `user` or `agent` target answers `failed` with a message that says it's not available | | `hangup` | none | The call ends. Then `session.end` with `agent_hung_up` | | `send_dtmf` | `digits`: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | Sent plays the digits on the call | | `hold` | `held`: `true` to hold the caller, `false` to resume | The caller hears hold music while held | ```json { "type": "tool.call", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t1", "name": "transfer", "arguments": { "to": { "kind": "number", "value": "+12125550100" } } } ``` ```json { "type": "tool.call", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t2", "name": "send_dtmf", "arguments": { "digits": "1w2#" } } ``` ### tool.result [#toolresult] | Field | Type | Description | | :--- | :--- | :--- | | `call_ref` | string | The `tool.call` this answers | | `ok` | boolean | Whether the tool ran | | `error` | object | `code` and `message`, present when `ok` is `false` | ```json { "type": "tool.result", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t1", "ok": true } ``` ```json { "type": "tool.result", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t1", "ok": false, "error": { "code": "target_not_allowed", "message": "The agent may not transfer to this number." } } ``` ```json { "type": "tool.result", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t1", "ok": false, "error": { "code": "failed", "message": "The transfer did not connect." } } ``` #### Tool error codes [#tool-error-codes] | `error.code` | When | | :--- | :--- | | `tool_not_allowed` | The agent's `tools` setting doesn't include the tool | | `unknown_tool` | There's no tool with that name | | `invalid_arguments` | The arguments don't fit the tool | | `target_not_allowed` | The transfer target isn't in `transfer_targets` | | `call_not_live` | The call has already ended or left the agent | | `failed` | The tool was allowed but didn't work: a transfer target that was busy, didn't answer or didn't connect, a transfer to a `user` or an `agent`, or a tool the call can't take. The caller stays with the agent | ## Resume frames [#resume-frames] A session whose `session.start` carries `resume` can move to a new connection after its connection is lost or while it drains. The flow, what happens while a session is detached, and which frames count are in [Resume a session after a lost connection](/start/guides/voice-agent-connect#resume-a-session-after-a-lost-connection). ### session.resume [#sessionresume] Sent by the agent on a new connection, after `connection.ready`. | Field | Type | Description | | :--- | :--- | :--- | | `token` | string | The session's latest resume token, `vsr_` and an id. A secret that works once | | `received` | integer | How many of Sent's counted frames for the session the agent has read | ```json { "type": "session.resume", "session_id": "vs_7Hq2Lm9xQa", "token": "vsr_example_token_000000000000000001", "received": 4 } ``` A refused `session.resume` answers `error` with `connection_full` or `resume_failed`. ### session.resumed [#sessionresumed] The session is on this connection. Sent's frames the agent didn't read follow, in order. | Field | Type | Description | | :--- | :--- | :--- | | `received` | integer | How many of the agent's counted frames Sent read. Send the later ones again if they still matter | | `resume` | object | The next `token` and `window_ms`. Absent once the session has ended, in which case the replay ends with `session.end` | | `audio` | object | Audio sessions still live: `stream`, the session's stream number on this connection, which can differ from before. The sample rate doesn't change | ```json { "type": "session.resumed", "session_id": "vs_7Hq2Lm9xQa", "received": 2, "resume": { "token": "vsr_example_token_000000000000000002", "window_ms": 15000 }, "audio": { "stream": 3 } } ``` ## Parties [#parties] `from`, `to` and a transfer's `to` are parties, in the shape of the REST API's call parties and of an agent's `transfer_targets`. | `kind` | `value` | Description | | :--- | :--- | :--- | | `user` | The identity | One of your app users, registered with [`@sentdm/voice`](/sdks/voice) | | `number` | The number in E.164 format | A phone number | | `conference` | The room name | A conference room of your account | | `agent` | The agent id | One of your voice agents | | `anonymous` | absent | A caller who withheld their number | Sent may add kinds. Answer a kind you don't know as you would an `anonymous` caller. ## Error codes [#error-codes] When Sent can't accept a frame, it sends `error` and ignores the frame. The connection stays open. | `error.code` | When | | :--- | :--- | | `invalid_frame` | The frame isn't valid JSON, doesn't match its schema, or is too large | | `unknown_frame_type` | Sent doesn't know the frame's `type` | | `unknown_session` | No session with that `session_id` is on this connection | | `frame_not_allowed` | The frame isn't allowed in this session type | | `session_ended` | The session has already ended | | `connection_full` | A `session.resume` came on a connection that already carries `max_sessions` sessions | | `resume_failed` | A `session.resume` token isn't valid, or its session can no longer be resumed | ## Close codes [#close-codes] | Code | When | | :--- | :--- | | `1000` | Sent connected to the agent, and the session ended. From the agent, a close with `1000` ends its sessions at once | | `1001` | The connection drained, or Sent is shutting down | | `4003` | Phone calls were turned off for the account, the key was revoked, or the agent was deleted | | `4008` | Three pings went unanswered | A close with `1000` from the agent, or with `4003` from Sent, ends the connection's sessions. Any other close detaches them, and they wait `window_ms` for a resume. ## A text session, worked [#a-text-session-worked] An inbound call to a number bound to a text agent that connects in. Sent's frames are marked `Sent`, the agent's `agent`. The connection was opened earlier and `connection.ready` already arrived. ```json // Sent: a call has reached the agent { "type": "session.start", "session_id": "vs_7Hq2Lm9xQa", "call_id": "call_9f2ab000-0000-4000-8000-000000000001", "agent_id": "agent_9f2ab000-0000-4000-8000-000000000001", "direction": "inbound", "from": { "kind": "number", "value": "+14155550100" }, "to": { "kind": "number", "value": "+14155550199" }, "session_type": "text", "language": "en-US", "max_duration_ms": 3600000, "resume": { "token": "vsr_example_token_000000000000000001", "window_ms": 15000 }, "started_at": "2026-10-23T12:00:00Z" } // agent: the agent speaks first, because it has no greeting setting { "type": "agent.say", "session_id": "vs_7Hq2Lm9xQa", "text": "Hi, this is Acme support. How can I help?" } // Sent: a heartbeat, which the agent answers { "type": "ping", "ts": 1792411215000 } { "type": "pong", "ts": 1792411215000 } // Sent: the caller's first complete utterance { "type": "user.said", "session_id": "vs_7Hq2Lm9xQa", "text": "I need to talk to a person" } // agent: a reply in two pieces, so speech starts before the reply is complete { "type": "agent.say", "session_id": "vs_7Hq2Lm9xQa", "text": "Of course.", "last": false } { "type": "agent.say", "session_id": "vs_7Hq2Lm9xQa", "text": "I'll put you through to the support line now." } // agent: the transfer to a number in transfer_targets runs once the goodbye has played { "type": "tool.call", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t1", "name": "transfer", "arguments": { "to": { "kind": "number", "value": "+12125550100" } } } // Sent: the number answered and the caller was bridged to it { "type": "tool.result", "session_id": "vs_7Hq2Lm9xQa", "call_ref": "t1", "ok": true } // Sent: the call has left the agent { "type": "session.end", "session_id": "vs_7Hq2Lm9xQa", "reason": "transferred", "duration_ms": 48210 } ``` The call goes on between the caller and the support line, and ends as one call: `call.completed` with the call's whole duration, and `GET /v3/voice/calls/{id}` with `mode` `agent` and the agent's `agent_id`. Had the number not answered, the `tool.result` would have been `ok: false` with `failed` and the message `The transfer did not connect.`, and the session would have gone on with the agent. ## Compatibility and versions [#compatibility-and-versions] Within `sent.voice.v1`, Sent only adds: fields, frame types, tools, party kinds, `session.end` reasons and error codes. So that an agent built against this page keeps working: - Ignore fields and frame types you don't know. - Treat a `session.end` reason you don't know as `failed`, and an error code you don't know as a failure. - Answer a party kind you don't know as you would an `anonymous` caller. - Count a frame type you don't know towards `received` when it carries your session's `session_id`. `connection.ready` gives the `protocol_version` Sent speaks. Releases of the protocol are tags of the repository, such as `v1.0.0`. Release N.x is `sent.voice.vN`: every 1.x release keeps the frames of this page and only adds, so an agent built on any 1.x works on every later 1.x. a change that would break an agent gets a new major release and a new subprotocol, and Sent serves both for a deprecation period. # Voice Callback Contract (/reference/api/voice-callback.md) # Voice Callback Contract [#voice-callback-contract] When a call arrives on one of your voice numbers, or a caller presses a key on a menu, Sent POSTs a signed question to that number's callback URL and follows your answer. This page is the reference for both sides of that exchange: the question Sent sends and the answer your backend returns. For the flow around it, including signature verification, deadlines and retries, see [Answering Calls](/start/guides/answering-calls). The callback contract uses `camelCase` (`callId`, `dialTimeoutSeconds`). The REST API and the webhooks use `snake_case` (`call_id`, `duration_seconds`). Your backend reads one casing on the question and writes the same casing on the answer; the other two surfaces keep theirs. ## How the contract is used [#how-the-contract-is-used] Every exchange is one HTTP request from Sent to you. The body is a question, sent as `application/json`. Your response body is an answer: optional instructions to run in order, then exactly one action that decides where the call goes. A menu chains by answering a `call.input` question with another `playMenu` or a connect action. The same contract drives the test question from [`POST /v3/channels/voice/{number}/test`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsTestVoiceCallbackEndpoint), so a backend that passes the test answers real calls the same way. Worked examples are in [Voice Recipes](/start/guides/voice-recipes). ## The envelope [#the-envelope] Every question carries these fields. Keys are `camelCase` and null values are left out. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `type` | string | Yes | `call.request` for a new call, `call.input` for a menu keypress | | `version` | string | Yes | The contract version, always `"1"` | | `callId` | string | Yes | Sent's call id, `call_` followed by a GUID. The same id on every question for the call, on every call webhook, and on `GET /v3/voice/calls/{id}` | | `number` | string | Yes | The customer number that owns this call, in E.164 format. Verify the signature with this number's callback secret | | `timestamp` | string | Yes | When the question was asked, ISO 8601 | ## Questions [#questions] ### call.request [#callrequest] A new call, asking your backend what should happen to it. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `direction` | string | Yes | `outbound` when an app user placed the call, `inbound` when someone dialed one of your numbers. A call is outbound exactly when `from` is an app user | | `from` | object | Yes | Who placed the call, an [address](#addresses) | | `to` | object | Yes | Who the call was for, an [address](#addresses) | | `test` | boolean | No | `true` only on the question `POST /v3/channels/voice/{number}/test` sends. Real calls never carry the field, so treat its absence as "this call is live" | An app user calling a phone number: ```json { "type": "call.request", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:00+00:00", "direction": "outbound", "from": { "kind": "user", "identity": "agent-42" }, "to": { "kind": "number", "number": "+14155551234" } } ``` Someone dialing one of your numbers: ```json { "type": "call.request", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:05:00+00:00", "direction": "inbound", "from": { "kind": "number", "number": "+38344555666" }, "to": { "kind": "number", "number": "+38349111222" } } ``` A caller who withheld their number: ```json { "type": "call.request", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:06:00+00:00", "direction": "inbound", "from": { "kind": "anonymous" }, "to": { "kind": "number", "number": "+38349111222" } } ``` ### call.input [#callinput] What the caller pressed on a menu, asking what to do next. Menus chain by answering this with another `playMenu` or a connect action. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `digits` | string | Yes | The digits collected. An empty string when the menu timed out with nothing pressed | | `cookies` | object | No | Every value a `setCookie` instruction stored earlier in this call, echoed back so your backend can stay stateless. Absent when the call has no cookies | A later `setCookie` with the same key replaces the earlier value, and every later question carries the whole set. Cookies live for the life of the call. ```json { "type": "call.input", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:07+00:00", "digits": "1" } ``` With cookies stored by an earlier answer: ```json { "type": "call.input", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:07+00:00", "digits": "1", "cookies": { "step": "greeted", "department": "sales" } } ``` ### Addresses [#addresses] `from` and `to` are addresses, told apart by `kind`. Identities and room names are bare: the account prefix never reaches your backend. | `kind` | Other fields | Description | | :--- | :--- | :--- | | `user` | `identity` | One of your app users, named by the identity you minted a voice token for | | `number` | `number` | A phone number in E.164 format | | `anonymous` | none | A caller who withheld their number | | `conference` | `name` | A conference room, named within your account | ## Answers [#answers] Your response body is one JSON object: ```json { "instructions": [], "action": {} } ``` | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `instructions` | array | No | Steps to run in order before the action, for example a spoken greeting. Instructions never decide where the call goes | | `action` | object | Yes | Exactly one action, told apart by its `action` name, deciding where the call goes | Answer with a `2xx` status. A `4xx` status tells Sent you refuse the call. On a `call.request` the call ends `FAILED` with reason `rejected`; on a `call.input` the call was already answered, so it is hung up and ends `COMPLETED`. For what happens on a timeout, a `5xx` or an invalid answer, see [Answering Calls](/start/guides/answering-calls). ### Actions [#actions] | `action` | What it does | | :--- | :--- | | [`connectToUser`](#connecttouser) | Rings one of your app users | | [`connectToNumber`](#connecttonumber) | Dials a phone number | | [`connectToConference`](#connecttoconference) | Puts the call into a conference room | | [`playMenu`](#playmenu) | Plays a menu and collects keypresses | | [`park`](#park) | Holds the call | | [`hangup`](#hangup) | Ends the call | | [`reject`](#reject) | Turns the call away without connecting it | #### connectToUser [#connecttouser] Rings an app user of your account. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `identity` | string | Yes | The app user to ring. Letters, digits, `-` and `_`, up to 200 characters | | `record` | boolean | No | Accepted but never honoured: a call connected to an app user cannot be recorded. The call connects without the recording | ```json { "action": { "action": "connectToUser", "identity": "ben", "record": false } } ``` #### connectToNumber [#connecttonumber] Dials a phone number. The leg runs for at most what your balance affords at the destination's per-minute rate, but never less than one minute, and never longer than four hours. A leg to an app user or a room has no such limit, because it costs nothing. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `number` | string | Yes | The phone number to dial, in E.164 format | | `callerId` | string | No | The number shown to the callee. Must be a number you own through Sent. The call's owning number is used when omitted | | `dialTimeoutSeconds` | integer | No | How long to ring before giving up. Only phone legs have a dial timeout; omitted leaves the default in place | | `record` | boolean | No | `true` records the call from the moment the legs join. See [Calls, Recordings, and Participants](/start/guides/managing-calls) | ```json { "action": { "action": "connectToNumber", "number": "+38349123456", "callerId": "+14155551234", "dialTimeoutSeconds": 30, "record": false } } ``` #### connectToConference [#connecttoconference] Puts the call into a conference room belonging to your account. A call in a room can take participants through `POST /v3/voice/calls/{id}/participants`. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `name` | string | Yes | The room name. Letters, digits, `-` and `_`, up to 27 characters. The same name on two calls puts them in the same room | | `record` | boolean | No | `true` records the call once it joins the room | ```json { "action": { "action": "connectToConference", "name": "daily-standup", "record": false } } ``` #### playMenu [#playmenu] Plays a menu and collects keypresses. The digits come back as a [`call.input`](#callinput) question, which is how menus chain. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `prompt` | object | Yes | What to say, as `{ "text": "..." }`. Text only, and the text cannot contain `]` | | `maxDigits` | integer | No | How many digits to collect before asking you | | `timeoutSeconds` | integer | No | How long to wait between digits before treating the input as finished | | `repeats` | integer | No | How many times the prompt repeats when nothing valid is pressed | ```json { "action": { "action": "playMenu", "prompt": { "text": "Press 1 for sales, 2 for support" }, "maxDigits": 1, "timeoutSeconds": 5, "repeats": 2 } } ``` Collecting several digits, with a cookie that tells the next question which step the caller is on: ```json { "instructions": [ { "instruction": "setCookie", "key": "step", "value": "account-number" } ], "action": { "action": "playMenu", "prompt": { "text": "Enter your four digit account number" }, "maxDigits": 4, "timeoutSeconds": 8 } } ``` #### park [#park] Holds the call, playing the hold prompt until the hold runs out. One hold lasts at most 600 seconds, and the call ends when it is reached, so say how long the caller may wait in the prompts. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `introPrompt` | object | No | Played once when the call is first held, as `{ "text": "..." }` | | `holdPrompt` | object | No | Repeated until the call is connected or the hold expires, as `{ "text": "..." }` | | `maxDurationSeconds` | integer | No | How long this hold lasts, at most 600 | ```json { "action": { "action": "park", "introPrompt": { "text": "Please hold" }, "holdPrompt": { "text": "Still with you" }, "maxDurationSeconds": 600 } } ``` #### hangup [#hangup] Ends the call. No fields. ```json { "action": { "action": "hangup" } } ``` #### reject [#reject] Turns the call away without connecting it. On a `call.request` the call ends `FAILED` with reason `rejected`. On a `call.input` the call was already answered, so it is hung up and ends `COMPLETED`. | Field | Type | Required | Description | | :--- | :--- | :--- | :--- | | `reason` | string | No | `busy` or `declined`. Defaults to `declined` | ```json { "action": { "action": "reject", "reason": "busy" } } ``` ### Instructions [#instructions] Instructions are optional, run in the order given, and never decide where the call goes. Each is told apart by its `instruction` name. | `instruction` | Fields | Description | | :--- | :--- | :--- | | `say` | `text` (required), `locale` | Speaks the text to the caller. `locale` is the voice and language, as an ISO 639 locale such as `en-US` | | `play` | `url` (required) | Plays an audio file from an absolute `http` or `https` URL | | `sendDigits` | `digits` (required) | Sends DTMF tones down the line to dial an extension or enter a PIN code. `w` is a half-second pause | | `startRecording` | none | Starts recording the call. Left out when call recording is not available, and when the answer's action is `connectToUser` | | `stopRecording` | none | Stops a recording started earlier in the call | | `answer` | none | Answers the call before running the rest of the answer | | `setCookie` | `key` (required), `value` (required) | Stores a value against the call, echoed back in `cookies` on every later question for it | Every instruction in one answer: ```json { "instructions": [ { "instruction": "say", "text": "Welcome to Acme", "locale": "en-US" }, { "instruction": "play", "url": "https://cdn.acme.com/greeting.mp3" }, { "instruction": "sendDigits", "digits": "1w2" }, { "instruction": "startRecording" }, { "instruction": "stopRecording" }, { "instruction": "answer" }, { "instruction": "setCookie", "key": "step", "value": "greeted" } ], "action": { "action": "hangup" } } ``` ## Parsing rules [#parsing-rules] Sent reads your answer with these rules. An answer that breaks one is invalid, and the reason is reported as described under [Answer error reasons](#answer-error-reasons). - Fields the contract does not define are ignored. An unknown action or instruction name is an error. - An empty body, a body that is not a JSON object, or invalid JSON is `malformed_json`. - `instructions` must be an array. Each item must be an object with an `instruction` name. - There must be exactly one `action` key. None is `missing_action`. More than one, or an array of two or more, is `multiple_actions`. An array of one is `invalid_field`: "'action' must be an object, not a list." - Strings must be strings. An empty string counts as absent, so a required string that is empty fails with `'{property}' is required and must be a non-empty string.` - Integers (`dialTimeoutSeconds`, `maxDigits`, `timeoutSeconds`, `repeats`, `maxDurationSeconds`) must be whole numbers from 1 up. - Booleans must be `true` or `false`. Absent means `false`. - `park.maxDurationSeconds` over 600 is `park_duration_exceeded`: "A single hold can last at most 600 seconds. Answer the next question with another park to keep holding." - Prompts are `{ "text": "..." }` only. A `url` key is refused: "Prompts are text only. Use a 'play' instruction to play audio." The text cannot contain `]`: "Prompt text cannot contain ']'. Use a 'say' instruction for text that needs one." - An identity is up to 200 characters of letters, digits, `-` and `_`. A room name is up to 27 characters of the same set. - `play.url` must be an absolute `http` or `https` URL. ## Account rules [#account-rules] After parsing, a `connectToNumber` answer is checked against your account. The other actions have no account rules. - `number` must be in E.164 format. - A destination in a blocked country is `destination_blocked`: "Calls to this destination are not allowed." - `callerId`, when present, must be in E.164 format, otherwise `invalid_field`. A valid number this account does not own through Sent is `caller_id_not_owned`: "'callerId' must be a phone number this account owns through Sent." Ownership is read from your number inventory; the caller id does not have to be voice-enabled itself. - The answer is normalised: `number` is written in E.164, and a missing `callerId` is filled in with the call's owning number. The test endpoint returns the normalised answer under `answer`. - Connecting to a phone on a call that had no phone destination needs a balance greater than zero. A call refused for balance ends with reason `insufficient_balance`. ## Answer error reasons [#answer-error-reasons] | `reason` | What was wrong | | :--- | :--- | | `malformed_json` | The body was empty, not a JSON object, or not valid JSON | | `missing_action` | No `action` key, or no `action.action` name | | `multiple_actions` | More than one `action` key, or an array of two or more actions | | `unknown_action` | The `action` name is not one of the seven actions | | `unknown_instruction` | An instruction has no name, or a name that is not one of the seven instructions | | `park_duration_exceeded` | `park.maxDurationSeconds` is over 600 | | `invalid_field` | A field has the wrong type, is empty when required, or is out of range | | `caller_id_not_owned` | `connectToNumber.callerId` is not a number this account owns through Sent | | `destination_blocked` | `connectToNumber.number` is in a country calls are not allowed to | The test endpoint reports these in `error.reason`, with `error.path` naming the field at fault (such as `action.action`) and `error.message` saying what to fix. On a live call an invalid answer is asked for once more. If the second attempt does not produce a usable answer either, a `call.request` fails with the reason the last attempt produced, `invalid_answer` for an unusable body, and a `call.input` is hung up and ends `COMPLETED`. The call failure reasons are listed in the [Error Catalog](/reference/api/error-catalog#call-failure-reasons). ## Versioning [#versioning] Every question carries `version: "1"`, the only version today. Changes within a version are additive: a question may gain fields, so ignore fields you do not know and never rely on key order. A field is never removed or given a new meaning without a new version, and the version is sent on every question so your backend can check it. method: POST route: /v3/voice/agents # POST /v3/voice/agents Create a voice agent Creates an agent that answers phone calls through the Sent Voice Gateway. `session_type` says whether Sent carries the call as text (the caller's speech recognised for the agent, the agent's text spoken) or as audio. With `websocket_url` the gateway dials your agent for each call and signs the handshake with the `signing_secret` this response returns; without it, your agent dials in with your API key and this agent's `id`. `tools`, `transfer_targets`, `fallback` and `limits` say what the agent may do on a call. Voices and languages for text sessions come from `GET /v3/voice/voices`. Calls reach the agent once a number is bound to it on `/v3/channels/voice`. `signing_secret` is shown here and on `POST /v3/voice/agents/{id}/rotate-secret` only; store it now. With `sandbox: true` the request is validated and the agent reported with `202`; nothing is written. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceAgentsCreateVoiceAgentEndpoint` **Tags:** Voice ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer } } ``` ## Responses ### 201 The agent as stored, with signing_secret #### application/json ```typescript { success?: boolean, data?: { id?: string, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer }, signing_secret?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 202 Sandbox: the request is valid and this is what would have been written, with a secret nothing stores #### application/json ```typescript { success?: boolean, data?: { id?: string, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer }, signing_secret?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 A field is missing or out of range; details name each field #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "The agent is invalid", "details": { "tools[1]": [ "Must be one of transfer, hangup, send_dtmf, hold." ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4740026+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 409 The account already holds as many voice agents as it may #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/voice/agents/{id} # DELETE /v3/voice/agents/{id} Delete a voice agent Removes the agent. Calls it already took keep their `agent_id`. An agent that one of your voice numbers routes to, or that another of your agents lists in `transfer_targets`, is not deleted: the answer is `409` with a message naming those numbers and agents. Unbind the numbers (`PATCH /v3/channels/voice/{number}` with `"agent_id": null`), take the agent out of the others' `transfer_targets` or delete them, and try again. With `sandbox: true` nothing is written: the agent is looked up and the answer is the one a real delete would give. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceAgentsDeleteVoiceAgentEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The agent id, such as agent_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 Deleted ### 400 id is not an agent id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 This account has no such agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 409 A voice number routes to this agent, or another of your agents lists it in transfer_targets; the message names them #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_014", "message": "This voice agent is in use: voice number +12125550100 routes calls to it; agent_4c1d2e3f-0000-4000-8000-000000000002 lists it in transfer_targets. To delete it, first unbind the number with PATCH /v3/channels/voice/{number} and \"agent_id\": null, and remove it from that agent's transfer_targets or delete that agent.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.476623+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/agents/{id} # GET /v3/voice/agents/{id} Get a voice agent The agent as stored, without its signing secret. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceAgentsGetVoiceAgentEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The agent id, such as agent_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The agent #### application/json ```typescript { success?: boolean, data?: { id?: string, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer }, signing_secret?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 id is not an agent id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 This account has no such agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/agents # GET /v3/voice/agents List your voice agents Your voice agents, newest first. `page` and `page_size` (1 to 100, default 20) page the list. Signing secrets are never listed. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceAgentsGetVoiceAgentsEndpoint` **Tags:** Voice ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | Page number, from 1 | | `page_size` | `integer` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The page of agents #### application/json ```typescript { success?: boolean, data?: { agents?: Array<{ id?: string, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer }, signing_secret?: string, created_at?: string, updated_at?: string }>, pagination?: { page?: integer, page_size?: integer, total_count?: integer, total_pages?: integer, has_more?: boolean, cursors?: { after?: string, before?: string } } }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 page or page_size is out of range #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/voice/agents/{id} # PATCH /v3/voice/agents/{id} Change a voice agent Changes the fields you name and answers with the agent as stored, the same shape `GET` returns. A key left out is left alone. A key sent as `null` clears an optional field (`websocket_url` makes the agent dial in, `greeting` and `fallback` go, `speech`, `audio`, `tools`, `limits` and `transcripts` return to their defaults). A key sent with a value replaces that field whole: send the whole `limits` object, not one of its keys. Changing `session_type` drops `speech`, `audio` and `greeting` unless the body sends them, since the other type cannot carry them. The result is checked like a new agent, and a body that changes nothing is `400`. With `sandbox: true` nothing is written: the request is validated against the stored agent and the agent is reported with `200` as it would read after the change. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceAgentsPatchVoiceAgentEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The agent id, such as agent_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer } } ``` ## Responses ### 200 The agent as stored after the change #### application/json ```typescript { success?: boolean, data?: { id?: string, name?: string, session_type?: string, websocket_url?: string, speech?: { setting?: string, voice?: string, language?: string }, audio?: { sample_rate?: integer }, greeting?: string, tools?: Array, transfer_targets?: Array<{ kind?: string, value?: string }>, fallback?: { kind?: string, value?: string }, limits?: { max_call_seconds?: integer, max_concurrent_calls?: integer, allowed_countries?: Array }, transcripts?: { store?: boolean, retention_days?: integer }, signing_secret?: string, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 id is not an agent id, a field is out of range (details name each), or the body changes nothing #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 This account has no such agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/voice/agents/{id}/rotate-secret # POST /v3/voice/agents/{id}/rotate-secret Rotate a voice agent's signing secret Generates a new `signing_secret` for the agent and returns it. The previous secret stops signing immediately, so update your agent before the next call reaches it. With `sandbox: true` a secret is generated and returned with `202`, and nothing is written. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceAgentsRotateVoiceAgentSecretEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The agent id, such as agent_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 200 The new secret. The old one no longer signs anything #### application/json ```typescript { success?: boolean, data?: { signing_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "signing_secret": "whsec_MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA=" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4813882+00:00", "version": "v3" } } ``` ### 202 Sandbox: a secret that was not stored #### application/json ```typescript { success?: boolean, data?: { signing_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 400 id is not an agent id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 This account has no such agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/voice/calls/{id}/participants # POST /v3/voice/calls/{id}/participants Add a participant to a call Dials one of your app users or a phone number into a call that is in a conference room, and answers with the participant's own call record. The participant is a call of their own: it has its own id, can be looked up and hung up, and is billed and reported through call.completed and call.failed like any other call. Every participant needs a payment method on file and a positive balance. A phone participant is called from caller_id, which must be one of your numbers, or from the call's owning number when omitted, and needs a destination you may call. Only a call your answer connected to a conference can take participants: a call connected to a user or a number answers 409. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsAddCallParticipantEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, to?: unknown, caller_id?: string } ``` ## Responses ### 202 The participant is being dialed; the body is their call record #### application/json ```typescript { success?: boolean, data?: { id?: string, mode?: string, agent_id?: string, direction?: string, from?: unknown, to?: unknown, number?: string, connected_number?: string, caller_id_used?: string, status?: string, failure_reason?: string, started_at?: string, answered_at?: string, ended_at?: string, duration_seconds?: integer, price?: number, legs?: Array<{ direction?: string, number?: string, billed_minutes?: integer, cost?: number, currency?: string }>, recording_available?: boolean, timeline?: Array<{ status?: string, timestamp?: string }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "call_9f2ab000-0000-4000-8000-000000000002", "mode": "inapp", "agent_id": null, "direction": "outbound", "from": { "kind": "conference", "value": "daily-standup" }, "to": { "kind": "number", "value": "+14155551234" }, "number": "+12025550123", "connected_number": null, "caller_id_used": null, "status": "INITIATED", "failure_reason": null, "started_at": "2026-07-22T12:00:00+00:00", "answered_at": null, "ended_at": null, "duration_seconds": null, "price": null, "legs": null, "recording_available": false, "timeline": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4089876+00:00", "version": "v3" } } ``` ### 400 Invalid id, participant or caller id; a caller id you do not own; a destination country that is not allowed; or the participant could not be dialed (BUSINESS_025) #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_022", "message": "Phone number is not owned by this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4090016+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 402 Insufficient balance; checked for every participant, app user or phone #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_003", "message": "Insufficient balance", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.409002+00:00", "version": "v3" } } ``` ### 403 Forbidden #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 404 No call with this id belongs to your account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4090025+00:00", "version": "v3" } } ``` ### 409 The call has already ended, or is not in a conference #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_009", "message": "Call is not in a conference", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4090035+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while adding the participant", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4090038+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/calls/{id} # GET /v3/voice/calls/{id} Get a call Retrieves one of your calls by id: the parties, the owning number, the phone number the call was connected to and the caller id it showed, the current status with its failure reason, duration, price with the billed legs and what each cost, recording availability, and a timeline of when the call entered each status. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Call retrieved successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, mode?: string, agent_id?: string, direction?: string, from?: unknown, to?: unknown, number?: string, connected_number?: string, caller_id_used?: string, status?: string, failure_reason?: string, started_at?: string, answered_at?: string, ended_at?: string, duration_seconds?: integer, price?: number, legs?: Array<{ direction?: string, number?: string, billed_minutes?: integer, cost?: number, currency?: string }>, recording_available?: boolean, timeline?: Array<{ status?: string, timestamp?: string }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "call_9f2ab000-0000-4000-8000-000000000001", "mode": "inapp", "agent_id": null, "direction": "outbound", "from": { "kind": "user", "value": "agent-42" }, "to": { "kind": "number", "value": "+12025550142" }, "number": "+12025550123", "connected_number": "+12025550142", "caller_id_used": "+12025550123", "status": "COMPLETED", "failure_reason": null, "started_at": "2026-07-22T12:00:00+00:00", "answered_at": "2026-07-22T12:00:05+00:00", "ended_at": "2026-07-22T12:00:47+00:00", "duration_seconds": 42, "price": 0.015, "legs": [ { "direction": "outbound", "number": "+12025550142", "billed_minutes": 1, "cost": 0.015, "currency": "USD" } ], "recording_available": false, "timeline": [ { "status": "INITIATED", "timestamp": "2026-07-22T12:00:00+00:00" }, { "status": "ANSWERED", "timestamp": "2026-07-22T12:00:05+00:00" }, { "status": "COMPLETED", "timestamp": "2026-07-22T12:00:47+00:00" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4112667+00:00", "version": "v3" } } ``` ### 400 Invalid call id format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "id": [ "'id' must be a call id, such as call_9f2ab000-0000-4000-8000-000000000001" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4113075+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Call not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4113081+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving the call", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4113084+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/calls/{id}/participants # GET /v3/voice/calls/{id}/participants List the participants of a call Lists who is in the conference room one of your live calls is in: each participant's own call id, who they are, whether the room mutes them, and how long they have been connected. The call itself is one of the participants. Use a participant's id to mute or remove them; it is also a call id, so GET /v3/voice/calls/{id} accepts it. A call that has ended answers 409, as does a call that is not in a conference. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallParticipantsEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The participants of the room the call is in; empty once everyone has left #### application/json ```typescript { success?: boolean, data?: Array<{ id?: string, kind?: string, value?: string, muted?: boolean, duration_seconds?: integer }>, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": [ { "id": "call_9f2ab000-0000-4000-8000-000000000001", "kind": "user", "value": "agent-42", "muted": false, "duration_seconds": 184 }, { "id": "call_9f2ab000-0000-4000-8000-000000000002", "kind": "number", "value": "+14155551234", "muted": true, "duration_seconds": 96 } ], "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.45932+00:00", "version": "v3" } } ``` ### 400 The id is not a call id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "id": [ "'id' must be a call id, such as call_9f2ab000-0000-4000-8000-000000000001" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4593247+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 No call with this id belongs to your account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4593253+00:00", "version": "v3" } } ``` ### 409 The call has already ended, or is not in a conference #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_009", "message": "Call is not in a conference", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4593256+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while listing the participants", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4593269+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/calls/{id}/recordings # GET /v3/voice/calls/{id}/recordings List a call's recordings Returns pre-signed links to the recordings of one of your calls, each valid until its url_expires_at. A recording appears once the call was recorded, by a connect answer with record set, a startRecording instruction or the recordings command, and the call.recording_ready webhook has been sent; until then, and for a call that was never recorded, the list is empty. A call recorded more than once lists every recording, oldest first, each under the recording_id its call.recording_ready webhook carried. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallRecordingsEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The call's recordings, each with a link #### application/json ```typescript { success?: boolean, data?: { recordings?: Array<{ recording_id?: string, download_url?: string, url_expires_at?: string }> }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "recordings": [ { "recording_id": "7c1d2e3f-4a5b-4c6d-8e9f-0a1b2c3d4e5f", "download_url": "https://recordings.example.com/9f2ab000-0000-4000-8000-000000000001/7c1d2e3f4a5b4c6d8e9f0a1b2c3d4e5f.mp3?X-Amz-Expires=3600&X-Amz-Signature=...", "url_expires_at": "2026-07-22T13:00:00+00:00" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.460747+00:00", "version": "v3" } } ``` ### 400 Invalid call id format #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "id": [ "'id' must be a call id, such as call_9f2ab000-0000-4000-8000-000000000001" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4607551+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 No call with this id belongs to your account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4607557+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving the recordings", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4607561+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/calls # GET /v3/voice/calls List calls Retrieves a paginated list of your calls, most recent first. Filter by direction, status, the owning number, the mode (inapp, or agent for calls your voice agents answered), the agent that answered, and the time the call started (from and to are inclusive). Each call carries the phone number it was connected to, the caller id it showed, and the billed legs with what each cost. Use the call webhooks for real-time updates; this list is for looking calls up afterwards. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallsEndpoint` **Tags:** Voice ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | Page number (1-indexed) | | `page_size` | `integer` | true | Number of items per page | | `direction` | `string` | false | Optional direction filter: outbound for calls placed from your app, inbound for calls to one of your numbers | | `status` | `string` | false | Optional status filter: initiated, ringing, answered, completed, failed, no_answer or rejected | | `number` | `string` | false | Optional filter on the number that owns the call, one of your voice-enabled numbers in E.164 format | | `mode` | `string` | false | Optional mode filter: inapp for calls routed by your number's callback URL, agent for calls one of your voice agents answered | | `agent_id` | `string` | false | Optional filter on the voice agent that answered the call, such as agent_9f2ab000-0000-4000-8000-000000000001 | | `from` | `string` | false | Only calls started at or after this time (ISO 8601) | | `to` | `string` | false | Only calls started at or before this time (ISO 8601) | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Calls retrieved successfully #### application/json ```typescript { success?: boolean, data?: { calls?: Array<{ id?: string, mode?: string, agent_id?: string, direction?: string, from?: unknown, to?: unknown, number?: string, connected_number?: string, caller_id_used?: string, status?: string, failure_reason?: string, started_at?: string, answered_at?: string, ended_at?: string, duration_seconds?: integer, price?: number, legs?: Array<{ direction?: string, number?: string, billed_minutes?: integer, cost?: number, currency?: string }>, recording_available?: boolean, timeline?: Array<{ status?: string, timestamp?: string }> }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "calls": [ { "id": "call_9f2ab000-0000-4000-8000-000000000001", "mode": "inapp", "agent_id": null, "direction": "outbound", "from": { "kind": "user", "value": "agent-42" }, "to": { "kind": "number", "value": "+12025550142" }, "number": "+12025550123", "connected_number": "+12025550142", "caller_id_used": "+12025550123", "status": "COMPLETED", "failure_reason": null, "started_at": "2026-07-22T12:00:00+00:00", "answered_at": "2026-07-22T12:00:05+00:00", "ended_at": "2026-07-22T12:00:47+00:00", "duration_seconds": 42, "price": 0.015, "legs": [ { "direction": "outbound", "number": "+12025550142", "billed_minutes": 1, "cost": 0.015, "currency": "USD" } ], "recording_available": false, "timeline": null } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.462363+00:00", "version": "v3" } } ``` ### 400 Invalid paging, filter value, number, or time window #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "status": [ "'status' must be one of: INITIATED, RINGING, ANSWERED, COMPLETED, FAILED, NO_ANSWER, REJECTED" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4641336+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving calls", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4641344+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/voice/calls/{id}/hangup # POST /v3/voice/calls/{id}/hangup Hang up a call Ends one of your live calls. The call then ends the way any other call does once the disconnect is reported: an answered call as COMPLETED with call.completed, a call still ringing as NO_ANSWER, REJECTED or FAILED with call.failed. A call that has already ended answers 409, as do a call with no phone leg, such as one between two app users, and a call one of your voice agents answers. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsHangupCallEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 The call is being ended ### 400 The id is not a call id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 No call with this id belongs to your account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4659388+00:00", "version": "v3" } } ``` ### 409 The call has already ended, has no phone leg, or is answered by a voice agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_008", "message": "Call is no longer active", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4659397+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while hanging up the call", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4659401+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/voice/calls/{id}/participants/{participantId} # PATCH /v3/voice/calls/{id}/participants/{participantId} Update a participant Mutes or unmutes one participant of the conference room a live call is in, named by the participant's own call id from the participants list: send muted true to silence them, muted false to let them be heard again. Muting a participant who is already muted succeeds, as does unmuting one who is not. A participant who is not in this call's room answers 404. A call that has ended answers 409, as does a call that is not in a conference. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsPatchCallParticipantEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | | `participantId` | `string` | true | The participant's own call id from the route, as listed by the participants endpoint, for example call_9f2ab000-0000-4000-8000-000000000002 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, muted?: boolean } ``` ## Responses ### 204 The participant is now muted or unmuted ### 400 An id is not a call id, or muted is missing #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "muted": [ "'muted' is required" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4672618+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 No call with this id belongs to your account, or the participant is not in its room #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_017", "message": "Participant not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4672627+00:00", "version": "v3" } } ``` ### 409 The call has already ended, or is not in a conference #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_009", "message": "Call is not in a conference", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4672631+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while changing the participant", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4672634+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/voice/calls/{id}/recordings # POST /v3/voice/calls/{id}/recordings Start or stop recording a call Starts or stops recording one of your live calls. Use start to begin recording mid-call, or stop to end a recording, whether it was started here or by a connect answer with record set. A call that has already ended answers 409, as do a call with no phone leg, such as one between two app users, and a call one of your voice agents answers, neither of which can be recorded this way. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsRecordCallEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, action?: string } ``` ## Responses ### 204 The recording is being started or stopped ### 400 The id is not a call id, or the action is neither start nor stop #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "action": [ "'action' must be one of: start, stop" ] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4686367+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Call recording is not available #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_026", "message": "Call recording is not available", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4686376+00:00", "version": "v3" } } ``` ### 404 No call with this id belongs to your account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.468638+00:00", "version": "v3" } } ``` ### 409 The call has already ended, has no phone leg, or is answered by a voice agent #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_008", "message": "Call is no longer active", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4686383+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while changing the recording", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4686392+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/voice/calls/{id}/participants/{participantId} # DELETE /v3/voice/calls/{id}/participants/{participantId} Remove a participant from a call Removes one participant from the conference room a live call is in, named by the participant's own call id from the participants list. Their leg ends and is reported through call.completed like any other call; everyone else stays connected. A participant who is not in this call's room answers 404. A call that has ended answers 409, as does a call that is not in a conference. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsRemoveCallParticipantEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | | `participantId` | `string` | true | The participant's own call id from the route, as listed by the participants endpoint, for example call_9f2ab000-0000-4000-8000-000000000002 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 The participant has been removed from the room ### 400 An id is not a call id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 No call with this id belongs to your account, or the participant is not in its room #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_017", "message": "Participant not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.469828+00:00", "version": "v3" } } ``` ### 409 The call has already ended, or is not in a conference #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_009", "message": "Call is not in a conference", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.469829+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while removing the participant", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4698297+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/voice/calls/{id}/participants # DELETE /v3/voice/calls/{id}/participants Remove every participant from a call Removes every participant from the conference room a live call is in, the call itself included. Every leg ends and is reported through call.completed like any other call. A room that is already empty answers 204 as well. A call that has ended answers 409, as does a call that is not in a conference. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceCallsRemoveCallParticipantsEndpoint` **Tags:** Voice ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | The call id from the route, as carried by call webhooks and the calls list, for example call_9f2ab000-0000-4000-8000-000000000001 | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 204 Every participant has been removed from the room ### 400 The id is not a call id #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 No call with this id belongs to your account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_015", "message": "Call not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4724972+00:00", "version": "v3" } } ``` ### 409 The call has already ended, or is not in a conference #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "CONFLICT_009", "message": "Call is not in a conference", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4724984+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while removing the participants", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.4724988+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/voice/tokens # POST /v3/voice/tokens Create a voice token Mints a short-lived token for one of your app users. Call this from your backend and return the token to your app, which passes it to the voice client SDK to register. The identity is bound to the given number, or to your default app-call number when omitted, and calls placed by that identity are routed through the bound number. Minting again re-binds the identity, so an identity can move between numbers. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceTokensCreateVoiceTokenEndpoint` **Tags:** Voice ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, identity?: string, number?: string, ttl?: integer } ``` ## Responses ### 200 Token minted and identity bound to the number #### application/json ```typescript { success?: boolean, data?: { token?: string, identity?: string, number?: string, expires_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "token": "vt_eyJ2IjoxLCJjaWQiOiIzZjJlMWQwYy05YjhhLTRmN2UtOGQ2Yy01YjRhM2YyZTFkMGMiLCJzdWIiOiJhZ2VudC00MiIsIm51bSI6IiszODM0OTExMTIyMiIsImlhdCI6MTc4NDcyMzA5NiwiZXhwIjoxNzg0NzIzNjk2fQ.0za4u7CrKet0zI8VRUTnpq_rrw0ZxwMCwnC7hXURGWI", "identity": "agent-42", "number": "+12025550123", "expires_at": "2026-07-22T12:34:56+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.3040204+00:00", "version": "v3" } } ``` ### 400 Invalid identity, ttl out of range, or number not voice-enabled for this account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_024", "message": "Phone number is not voice-enabled for this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.3040217+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Phone calls are not enabled for this account #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "BUSINESS_023", "message": "Phone calls are not enabled for this account", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.3040221+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while creating the voice token", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.3040225+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/voice/voices # GET /v3/voice/voices List the voices and languages for text-session agents The names a voice agent's `speech.voice` and `speech.language` accept, with the default marked. The list grows as voices are added; a name is never removed without notice. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3VoiceVoicesGetVoicesEndpoint` **Tags:** Voice ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 The catalogue #### application/json ```typescript { success?: boolean, data?: { voices?: Array<{ name?: string, language?: string, description?: string, default?: boolean }>, languages?: Array }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/webhooks # POST /v3/webhooks Create a webhook Creates a new webhook endpoint for the authenticated customer. A webhook is version 2 unless the request sets webhook_version to 1: Svix delivers it, signed with the webhook-id, webhook-timestamp and webhook-signature headers, and retries it on its own schedule, so retry_count and timeout_seconds apply to version 1 only. sender_profile applies to version 1 only and is ignored on version 2; is_inheritable applies to version 2 only. A version 1 webhook's response returns its sender_profile selection, with an empty event_types when it is not cloned onto sender profiles; a version 2 webhook's response leaves sender_profile out. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksCreateWebhookEndpoint` **Tags:** Webhooks ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, display_name?: string, endpoint_url?: string, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, webhook_version?: integer, is_inheritable?: boolean } ``` ## Responses ### 201 Webhook created successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, display_name?: string, endpoint_url?: string, signing_secret?: string, is_active?: boolean, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, is_inheritable?: boolean, webhook_version?: integer, last_delivery_attempt_at?: string, last_successful_delivery_at?: string, consecutive_failures?: integer, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8", "customer_id": "00000000-0000-0000-0000-000000000000", "display_name": "Order Notifications", "endpoint_url": "https://example.com/webhooks/orders", "signing_secret": "whsec_a1b2c3d4e5f6g7h8i9j0", "is_active": true, "event_types": [ "contact", "message", "templates" ], "event_filters": { "message": [ "delivered", "failed" ] }, "sender_profile": null, "retry_count": 3, "timeout_seconds": 30, "is_inheritable": false, "webhook_version": 2, "last_delivery_attempt_at": null, "last_successful_delivery_at": null, "consecutive_failures": 0, "created_at": "2026-01-15T10:30:00+00:00", "updated_at": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2765558+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Endpoint URL must be a valid HTTP or HTTPS URL", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2768703+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while creating the webhook", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2768728+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: DELETE route: /v3/webhooks/{id} # DELETE /v3/webhooks/{id} Delete a webhook Deletes a webhook for the authenticated customer. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksDeleteWebhookEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 204 Webhook deleted successfully ### 400 Invalid webhook ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid webhook ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2864948+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.286496+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while deleting the webhook", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2864965+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/webhooks/{id} # GET /v3/webhooks/{id} Get a webhook Retrieves a single webhook by ID for the authenticated customer. A version 1 webhook includes its sender_profile selection. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhookEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Webhook retrieved successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, display_name?: string, endpoint_url?: string, signing_secret?: string, is_active?: boolean, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, is_inheritable?: boolean, webhook_version?: integer, last_delivery_attempt_at?: string, last_successful_delivery_at?: string, consecutive_failures?: integer, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8", "customer_id": "00000000-0000-0000-0000-000000000000", "display_name": "Order Notifications", "endpoint_url": "https://example.com/webhooks/orders", "signing_secret": null, "is_active": true, "event_types": [ "contact", "message", "templates" ], "event_filters": null, "sender_profile": null, "retry_count": 3, "timeout_seconds": 30, "is_inheritable": false, "webhook_version": 2, "last_delivery_attempt_at": null, "last_successful_delivery_at": null, "consecutive_failures": 0, "created_at": "2026-01-15T10:30:00+00:00", "updated_at": "2026-01-20T14:15:00+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2884193+00:00", "version": "v3" } } ``` ### 400 Invalid webhook ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid webhook ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2884211+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2884216+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving the webhook", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.288422+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/webhooks/event-types # GET /v3/webhooks/event-types Get available webhook event types Retrieves all available webhook event types that can be subscribed to. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhookEventTypesEndpoint` **Tags:** Webhooks ## Parameters ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Event types retrieved successfully #### application/json ```typescript { success?: boolean, data?: { event_types?: Array<{ name?: string, display_name?: string, description?: string, is_active?: boolean, event_type?: string, sub_types?: Array }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "event_types": [ { "name": "message", "display_name": "Messages", "description": "Webhook events for message status changes", "is_active": true, "event_type": null, "sub_types": [ { "name": "message.delivered", "display_name": "Message Delivered", "description": "Triggered when a message is confirmed delivered", "is_active": true, "event_type": "message", "sub_types": null }, { "name": "message.failed", "display_name": "Message Failed", "description": "Triggered when a message delivery fails", "is_active": true, "event_type": "message", "sub_types": null } ] }, { "name": "templates", "display_name": "Templates", "description": "Webhook events for template status changes", "is_active": true, "event_type": null, "sub_types": [ { "name": "templates.approved", "display_name": "Template Approved", "description": "Triggered when a template is approved and can be sent", "is_active": true, "event_type": "templates", "sub_types": null }, { "name": "templates.rejected", "display_name": "Template Rejected", "description": "Triggered when a template is rejected", "is_active": true, "event_type": "templates", "sub_types": null } ] }, { "name": "contact", "display_name": "Contacts", "description": "Signals raised by a contact — opting out, opting back in, asking for help, or sending one of your own auto-reply keywords", "is_active": true, "event_type": null, "sub_types": [ { "name": "contact.opt_in", "display_name": "Contact Opted In", "description": "Triggered when a contact opts back in to receiving messages, for example by texting START", "is_active": true, "event_type": "contact", "sub_types": null }, { "name": "contact.opt_out", "display_name": "Contact Opted Out", "description": "Triggered when a contact opts out of receiving messages, for example by texting STOP", "is_active": true, "event_type": "contact", "sub_types": null }, { "name": "contact.help", "display_name": "Contact Requested Help", "description": "Triggered when a contact asks for help, for example by texting HELP. Carries no consent change", "is_active": true, "event_type": "contact", "sub_types": null }, { "name": "contact.custom_keyword", "display_name": "Contact Custom Keyword", "description": "Triggered when a contact sends one of your own auto-reply keywords, for example BOOKING. Read template_id to see which of your templates matched. Carries no consent change", "is_active": true, "event_type": "contact", "sub_types": null } ] } ], "pagination": { "page": 1, "page_size": 3, "total_count": 3, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2924152+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving event types", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2924175+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/webhooks/{id}/events # GET /v3/webhooks/{id}/events Get webhook events Retrieves a paginated list of delivery events for the specified webhook, newest first. If the webhook is cloned onto your sender profiles (version 1) or inheritable by them (version 2, is_inheritable), the list includes their events; read payload.account_id to tell whose event it is. A sender profile may read its organization's inheritable webhook too, and gets the events about itself. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhookEventsEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | - | | `page_size` | `integer` | true | - | | `search` | `string` | false | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Webhook events retrieved successfully #### application/json ```typescript { success?: boolean, data?: { events?: Array<{ id?: string, event_type?: string, event_data?: unknown, delivery_status?: string, http_status_code?: integer, response_body?: string, delivery_attempts?: integer, error_message?: string, created_at?: string, processing_started_at?: string, processing_completed_at?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "events": [ { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "event_type": "message.delivered", "event_data": { "valueKind": "Undefined" }, "delivery_status": "delivered", "http_status_code": 200, "response_body": null, "delivery_attempts": 1, "error_message": null, "created_at": "2026-01-20T14:30:00+00:00", "processing_started_at": "2026-01-20T14:30:01+00:00", "processing_completed_at": "2026-01-20T14:30:02+00:00" } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2906816+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid webhook ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2906833+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2906836+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving webhook events", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2906841+00:00", "version": "v3" } } ``` ### 503 Webhook events are temporarily unavailable; retry after the Retry-After header #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: GET route: /v3/webhooks # GET /v3/webhooks Get webhooks list Retrieves a paginated list of webhooks for the authenticated customer. Each version 1 webhook includes its sender_profile selection. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhooksEndpoint` **Tags:** Webhooks ## Parameters ### Query Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `page` | `integer` | true | - | | `page_size` | `integer` | true | - | | `search` | `string` | false | - | | `is_active` | `boolean` | false | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Responses ### 200 Webhooks retrieved successfully #### application/json ```typescript { success?: boolean, data?: { webhooks?: Array<{ id?: string, customer_id?: string, display_name?: string, endpoint_url?: string, signing_secret?: string, is_active?: boolean, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, is_inheritable?: boolean, webhook_version?: integer, last_delivery_attempt_at?: string, last_successful_delivery_at?: string, consecutive_failures?: integer, created_at?: string, updated_at?: string }>, pagination?: unknown }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "webhooks": [ { "id": "d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8", "customer_id": "00000000-0000-0000-0000-000000000000", "display_name": "Order Notifications", "endpoint_url": "https://example.com/webhooks/orders", "signing_secret": null, "is_active": true, "event_types": [ "contact", "message", "templates" ], "event_filters": null, "sender_profile": null, "retry_count": 3, "timeout_seconds": 30, "is_inheritable": false, "webhook_version": 2, "last_delivery_attempt_at": null, "last_successful_delivery_at": null, "consecutive_failures": 0, "created_at": "2026-01-15T10:30:00+00:00", "updated_at": null } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2936691+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Page size must be between 1 and 250", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2936755+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while retrieving webhooks", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.293676+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/webhooks/{id}/rotate-secret # POST /v3/webhooks/{id}/rotate-secret Rotate webhook signing secret Generates a new signing secret for the specified webhook. A version 1 webhook's old secret stops verifying at once. A version 2 webhook's deliveries are signed with the new secret at once, and with the old one as well for the next 24 hours, so a receiver can switch over without rejecting any; after that the old secret no longer verifies. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksRotateWebhookSecretEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean } ``` ## Responses ### 200 Secret rotated successfully #### application/json ```typescript { success?: boolean, data?: { signing_secret?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "signing_secret": "whsec_n3wS3cr3tK3yG3n3r4t3d" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2950176+00:00", "version": "v3" } } ``` ### 400 Invalid webhook ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid webhook ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2950192+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2950196+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while rotating the webhook secret", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.29502+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: POST route: /v3/webhooks/{id}/test # POST /v3/webhooks/{id}/test Test a webhook Sends a test event to the specified webhook endpoint to verify connectivity. A version 1 webhook is tested at once and the answer says whether it was delivered; a version 2 webhook's test is queued with Svix, which delivers it right after, and the answer says it was queued. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksTestWebhookEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, event_type?: string } ``` ## Responses ### 200 Test completed #### application/json ```typescript { success?: boolean, data?: { success?: boolean, message?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "success": true, "message": "Test event delivered successfully" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2964318+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Event type is required", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2964336+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.296434+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while testing the webhook", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2964344+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PATCH route: /v3/webhooks/{id}/toggle-status # PATCH /v3/webhooks/{id}/toggle-status Toggle webhook status Activates or deactivates a webhook for the authenticated customer. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksToggleWebhookStatusEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, is_active?: boolean } ``` ## Responses ### 200 Webhook status updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, display_name?: string, endpoint_url?: string, signing_secret?: string, is_active?: boolean, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, is_inheritable?: boolean, webhook_version?: integer, last_delivery_attempt_at?: string, last_successful_delivery_at?: string, consecutive_failures?: integer, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8", "customer_id": "00000000-0000-0000-0000-000000000000", "display_name": "Order Notifications", "endpoint_url": "https://example.com/webhooks/orders", "signing_secret": null, "is_active": false, "event_types": [ "contact", "message", "templates" ], "event_filters": null, "sender_profile": null, "retry_count": 3, "timeout_seconds": 30, "is_inheritable": false, "webhook_version": 2, "last_delivery_attempt_at": null, "last_successful_delivery_at": null, "consecutive_failures": 0, "created_at": "2026-01-15T10:30:00+00:00", "updated_at": "2026-02-01T09:00:00+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2979186+00:00", "version": "v3" } } ``` ### 400 Invalid webhook ID #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Invalid webhook ID format.", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.29792+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2979203+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while toggling the webhook status", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2979208+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** method: PUT route: /v3/webhooks/{id} # PUT /v3/webhooks/{id} Update a webhook Updates an existing webhook for the authenticated customer. Its version does not change. sender_profile applies to a version 1 webhook and is_inheritable to a version 2 one; retry_count and timeout_seconds apply to version 1 only. A version 1 webhook's response returns its sender_profile selection as saved; a version 2 webhook's response leaves sender_profile out. **Operation ID:** `SentDmServicesEndpointsCustomerAPIv3WebhooksUpdateWebhookEndpoint` **Tags:** Webhooks ## Parameters ### Path Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | true | - | ### Header Parameters | Name | Type | Required | Description | |------|------|----------|-------------| | `Idempotency-Key` | `string` | false | Unique key to ensure idempotent request processing. Must be 1-255 alphanumeric characters, hyphens, or underscores. Responses are cached for 24 hours per key per customer. | | `x-profile-id` | `string` | false | Profile UUID to scope the request to a child profile. Only organization API keys can use this header. The profile must belong to the calling organization. | ## Request Body ### application/json ```typescript { sandbox?: boolean, display_name?: string, endpoint_url?: string, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, is_inheritable?: boolean } ``` ## Responses ### 200 Webhook updated successfully #### application/json ```typescript { success?: boolean, data?: { id?: string, customer_id?: string, display_name?: string, endpoint_url?: string, signing_secret?: string, is_active?: boolean, event_types?: Array, event_filters?: object, sender_profile?: { event_types?: Array, event_filters?: object }, retry_count?: integer, timeout_seconds?: integer, is_inheritable?: boolean, webhook_version?: integer, last_delivery_attempt_at?: string, last_successful_delivery_at?: string, consecutive_failures?: integer, created_at?: string, updated_at?: string }, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": true, "data": { "id": "d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8", "customer_id": "00000000-0000-0000-0000-000000000000", "display_name": "Updated Order Notifications", "endpoint_url": "https://example.com/webhooks/orders-v2", "signing_secret": null, "is_active": true, "event_types": [ "contact", "message", "templates" ], "event_filters": { "message": [ "delivered", "failed" ] }, "sender_profile": null, "retry_count": 5, "timeout_seconds": 60, "is_inheritable": false, "webhook_version": 2, "last_delivery_attempt_at": null, "last_successful_delivery_at": null, "consecutive_failures": 0, "created_at": "2026-01-15T10:30:00+00:00", "updated_at": "2026-02-05T16:45:00+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2995894+00:00", "version": "v3" } } ``` ### 400 Invalid request parameters #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "VALIDATION_001", "message": "Endpoint URL must be a valid HTTP or HTTPS URL", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2995907+00:00", "version": "v3" } } ``` ### 401 Unauthorized - Invalid API credentials ### 403 Forbidden ### 404 Webhook not found #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "RESOURCE_008", "message": "Webhook not found", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2995911+00:00", "version": "v3" } } ``` ### 500 Internal server error #### application/json ```typescript { success?: boolean, error?: { code?: string, message?: string, details?: object, doc_url?: string }, meta?: unknown } ``` ##### Example ```json { "success": false, "data": null, "error": { "code": "INTERNAL_001", "message": "An unexpected error occurred while updating the webhook", "details": null, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-11-12T15:32:26.2995915+00:00", "version": "v3" } } ``` ## Security - **CustomerApiKey** - **BearerAuth** # Changelog (/reference/changelog.md) # Changelog [#changelog] A chronological record of platform updates, new features, and important changes to Sent's APIs and services. For a summary of what changed between API versions, see [API v2 to v3 changes](/reference/api/v2-to-v3). --- ## 2026 [#2026] ### October 2026 [#october-2026] #### Channels, 10DLC Campaigns, Contacts, and Webhooks [#channels-10dlc-campaigns-contacts-and-webhooks] **Added: `channel.removed`.** When Sent removes a sender that had been approved, for example at your request, the webhook event is `channel.removed` with `INACTIVE`. It used to arrive as `channel.deactivated`, so a webhook subscribed to `channel.deactivated` alone no longer receives removals: add `channel.removed`, or subscribe to the `channel` parent. See [channel sub-types](/start/webhooks/event-types#channel-sub-types). **Changed: a market holds up to 49 numbers.** On a US `TEN_DLC` market the limit is the campaign's and counts every number on it, including the one each Sender Profile sharing your organization's campaign receives. `LOCAL` markets have the same limit. A request over it is `400` on `numbers`. See [Managing Channels](/start/guides/managing-channels). **Changed: a market with several numbers reports its healthiest one.** It is `ACTIVE` as soon as any of its numbers can send, and `sender_value` is a live number. Each entry in `numbers` carries its own status. **Changed: a campaign's volume tier is fixed once it is submitted to TCR.** An update that moves `volume` across `2000` after submission is refused with `409 CONFLICT_017`. Changing `volume` no longer moves money on its own. See [Update or delete a campaign](/start/advanced/10dlc-campaigns-api#update-or-delete-a-campaign). **Changed: contact search matches any phone format.** `search` on `GET /v3/contacts` compares digits, so `+12025550123`, `202-555-0123`, and `(202) 555 0123` find the same contact, and part of a number matches too. **Changed: a suspended Sender Profile can't be changed.** A request that changes or deletes it is refused with `403 BUSINESS_014`, even with your organization's key, and the message names the suspended account. **Changed: webhook signing secrets in the dashboard.** The dashboard shows a webhook's signing secret once, when you create the webhook or rotate its secret. See [Getting Started with webhooks](/start/webhooks/getting-started). #### MMS: Shared Template Bodies and an Attachment Required [#mms-shared-template-bodies-and-an-attachment-required] **Changed: MMS falls back to the shared template body.** MMS text now comes from the template's `mms` body, then its `multiChannel` body, then its `sms` body, as RCS does. A template with a shared or SMS body lists `mms` among its channels. The subject and template media still come only from an `mms` body. See [Template Definition](/reference/api/template-definition#mms-body-content-object). **Changed: a send pinned to MMS needs an attachment.** `channel: ["mms"]` with no `media_urls` and no media in the template's `mms` body is refused with `400` (`VALIDATION_001`) instead of going out as a text-only MMS. Send text-only messages on `sms`. **Changed: Meta's approval covers MMS.** When Meta approves a template, its MMS channel is approved with SMS and RCS, rather than waiting for a separate Sent review. #### Voice: Numbers Work Without a Callback URL [#voice-numbers-work-without-a-callback-url] **Changed: a voice number without a callback URL is `ACTIVE`.** It can be your default line like any other. Calls placed from your app on it connect straight to the phone number, app user, or room they dial. Calls to the number are still declined with `callback_not_configured`. See [Change a voice number](/start/guides/managing-channels#change-a-voice-number). **Changed: setting `callback_url` no longer changes status.** `PATCH /v3/channels/voice/{number}` with a `callback_url` replaces the URL and keeps the number's status and signing secret. #### Webhooks: Version 2 [#webhooks-version-2] **Added: version 2 webhooks, the new default.** Webhooks you create are signed with the [Standard Webhooks](https://www.standardwebhooks.com) headers `webhook-id`, `webhook-timestamp`, and `webhook-signature`, with the same `whsec_` signing scheme and JSON body. Send `"webhook_version": 1` on `POST /v3/webhooks` to keep the older delivery. Existing webhooks stay on version 1 and are unchanged. Every webhook response carries `webhook_version`. See [Webhook Versions](/start/webhooks/event-types#webhook-versions). **Added: `is_inheritable` on version 2 webhooks.** Your organization's inheritable webhook receives every Sender Profile's events, and each profile sees it but can't change it (`409 CONFLICT_016`). `sender_profile` clones remain on version 1. See [Inheritable webhooks](/start/webhooks/event-types#inheritable-webhooks-version-2). **Changed for version 2:** - Failed deliveries are retried automatically with increasing delays, so `retry_count` and `timeout_seconds` apply to version 1 only. - Rotating the secret signs deliveries with both the old and new secret for 24 hours. - A test is queued for delivery, and the response says it was queued rather than delivered. #### Voice Client: `@sentdm/voice-client` Replaces `@sentdm/voice` [#voice-client-sentdmvoice-client-replaces-sentdmvoice] **Changed: the browser SDK is `@sentdm/voice-client`.** `@sentdm/voice` is deprecated on npm and stays installable. [`@sentdm/voice-client`](https://www.npmjs.com/package/@sentdm/voice-client) 0.2.0 has the same client, calls, events, and errors, and the React provider and hooks moved from `@sentdm/voice/react` to [`@sentdm/voice-client-react`](https://www.npmjs.com/package/@sentdm/voice-client-react). See [Migrate From `@sentdm/voice`](/sdks/voice#migrate-from-sentdmvoice). **Changed: the SDK exchanges the voice token itself.** `tokenProvider` must return the `token` from `POST /v3/voice/tokens` unchanged. The SDK exchanges it with Sent on every register and refresh, so nothing from the calling engine passes through your backend or your app. A token Sent refuses fails `register()` with `TokenInvalidError`. **Changed: `baseURL` replaces `telemetry.baseURL`.** The option sets the Sent API origin the token exchange and telemetry use, `https://api.sent.dm` by default. `telemetry` keeps `disabled`. **Changed: the calling engine ships inside the SDK.** It loads on the first `register()`, and your app installs no package for it. #### Voice: Agents Answer Calls (Preview) [#voice-agents-answer-calls-preview] **Added: voice agents.** `POST /v3/voice/agents` creates an agent of yours that answers calls to your numbers over a WebSocket, in text or in audio, with the tools, transfer targets, fallback, and limits you give it. `GET`, `PATCH` and `DELETE /v3/voice/agents/{id}` read, change and remove it, and `POST /v3/voice/agents/{id}/rotate-secret` rotates the secret Sent signs its handshake with. See [Voice agents](/start/guides/voice-agents). - **`GET /v3/voice/voices`** lists the voices and languages a text agent's `speech` accepts. - **`agent_id` on `POST` and `PATCH /v3/channels/voice`** binds a number to an agent, and `routes_to` on every voice number says who answers it. Calls follow a binding within about an hour. - **The connect flow and the protocol are in Preview**, version 0.2.0 of `sent.voice.v1`. See [Connect a voice agent](/start/guides/voice-agent-connect) and the [voice agent protocol](/reference/api/voice-agent-protocol). **Added: `mode` and `agent_id` on calls.** Every `call.*` event and every call record carry `mode`, `inapp` or `agent`, and an agent call carries `agent_id`. `GET /v3/voice/calls` filters on both. A `call.agent_connected` event is sent once the agent's session starts. See [Call events](/start/webhooks/event-types#call). **Added: `connected_number`, `caller_id_used` and `legs` on the call record.** `GET /v3/voice/calls` and `GET /v3/voice/calls/{id}` say which number a forwarded or fallback call was connected to, which caller id the dialled leg showed, and the legs the call was billed for, each with its `direction`, `number`, `billed_minutes`, `cost` and `currency`. A forwarded or fallback call is one record with two billed legs. See [The Call Record](/start/guides/managing-calls#the-call-record). **Added: `CONFLICT_014` and `CONFLICT_015`.** Deleting an agent a number routes to, or another agent transfers to, is `409` `CONFLICT_014`. Hanging up or recording a call an agent answers through the API is `409` `CONFLICT_015`. `call.failed` gains `agent_busy` and `agent_unreachable`. See the [Error Catalog](/reference/api/error-catalog). #### Voice: Calls and Tokens Move Under `/v3/voice` [#voice-calls-and-tokens-move-under-v3voice] **Changed: the voice API lives under `/v3/voice`.** Calls moved from `/v3/calls` to `/v3/voice/calls`, with the same requests and responses, and voice tokens from `POST /v3/channels/voice/tokens` to `POST /v3/voice/tokens`. The old paths are removed, without aliases. Voice numbers stay at `/v3/channels/voice` with the other channels. See [Calls, Recordings, and Participants](/start/guides/managing-calls) and [Calls From Your App](/start/guides/in-app-calls). **Added: `mode` on every call.** Call records carry `mode`, which is `inapp` on every call. **Changed: voice tokens are opaque.** `POST /v3/voice/tokens` returns a token prefixed `vt_`, signed by Sent. Treat it as opaque and hand it to the voice client SDK unchanged. #### WhatsApp: Disconnect, Multi-Line Free Text, and Fixes [#whatsapp-disconnect-multi-line-free-text-and-fixes] **Added: disconnect a WhatsApp Business Account.** Channels > WhatsApp has a **Disconnect** button next to **Switch Account**, for organizations and Sender Profiles. See [Disconnect a WhatsApp Business Account](/start/guides/connect-whatsapp#disconnect-a-whatsapp-business-account). - **WhatsApp falls back to SMS** after a disconnect, until you connect an account again. - **A number provided by Sent has to be deregistered and deleted in WhatsApp Manager first**, because Meta offers no way to remove it for you. Until then the disconnect is refused and nothing changes. Once it is off the account, the number is released, unless it is also your SMS number. - **Accounts sharing the same WhatsApp Business Account keep working** when you disconnect yours. **Changed: free-form `text` keeps line breaks, tabs, and runs of spaces** on every channel. These were rejected with `400` before, so multi-line messages and WhatsApp list and quote formatting could not be sent. Template variable values are still refused if they contain a line break, a tab, or more than four consecutive spaces. See [Sending free-form text](/start/guides/sending-messages#sending-free-form-text-without-a-template). **Changed: a matching area code adds to match specificity.** It used to break ties only between routes that ranked equal. A route on a number in the recipient's area code now ranks ahead of one that matches as specifically without it, and numbers you held before October 9 now carry their area code too. See [Choosing the sending number](/reference/channel-routing#choosing-the-sending-number). **Changed: your US SMS number is pre-verified for WhatsApp.** Once it is on your campaign, Sent pre-verifies it with Meta and WhatsApp signup offers it first, with no verification code to enter. **Fixed:** - WhatsApp STOP, HELP, and START auto-replies go out even when the contact's previous message is older than 24 hours. - Meta-provided +1 555 numbers are accepted as WhatsApp senders in `channels.whatsapp` on `POST /v3/messages`. They are still refused for SMS, MMS, and RCS. - Template word counts match Meta's: a symbol standing alone, such as a `|` between two variables, counts as a word. See [Template Definition](/reference/api/template-definition). - WhatsApp sends are no longer blocked because your business is not yet verified with Meta. An account is treated as healthy whenever Meta reports it can send messages. #### Webhooks: WhatsApp Number Events on `channel` [#webhooks-whatsapp-number-events-on-channel] **Added: WhatsApp milestones on the `channel` family**, with `payload.channel` set to `whatsapp`. See [WhatsApp channel events](/start/webhooks/event-types#whatsapp-channel-events). - **`channel.submitted`** when you claim a number Sent supplied that can't send yet. - **`channel.activated`** when the number is registered, or when Meta approves its display name. - **`channel.changes_requested`** when Meta rejects the display name, with Meta's reason in `payload.reason` when it gave one. - **`channel.deactivated`** when the number is deregistered and returned to Sent. #### Messages: Choose the Sending Number [#messages-choose-the-sending-number] **Added: `channels` on `POST /v3/messages`.** `channels.sms` lists which of your SMS numbers a send may go out from, as a list of entries with a `from` each, for example `{"sms": [{"from": ["+12125550000", "+14155550000"]}]}`. See [Send from specific numbers](/start/guides/sending-messages#send-from-specific-numbers). - **It combines with `channel`.** `"channel": ["sms"]` with an `sms` list sends on SMS from those numbers. - **Routes pinned to a number you did not list are removed**, and routing picks among the rest as usual. The numbers from every entry apply to every recipient. - **`country` and `strategy` are optional** on each entry. Both are stored with the message but do not change routing yet. - **A malformed `channels` answers `400`**: a key that is not a channel (including `sent`), the same channel twice, an empty list, an entry with an empty `from`, or an entry that is not E.164. - **The numbers are checked per message, at send time.** The request is accepted with `202`, and a message that lists a number that is not an active SMS sender on your account ends `BLOCKED` with `BUSINESS_029`. The `reason` names the number by its position, for example `channels.sms[0].from[1]`. - **The choice stays with the message** through a scheduled or quiet-hours release, a resend, and a reroute after a delivery failure. **Changed: area code breaks ties between your SMS numbers.** When several of your SMS routes rank equal for a recipient, the one whose number has the same area code as the recipient wins. This applies whether or not the send lists numbers. It never removes a route: every number still reaches every recipient its route covers. See [Choosing the sending number](/reference/channel-routing#choosing-the-sending-number). **Added: error code `BUSINESS_029`.** A number listed in `channels` is not an active sender on your account. See the [Error Catalog](/reference/api/error-catalog#business_029-requested-sender-is-not-available-on-this-account). #### Authentication: API Key as a Bearer Token [#authentication-api-key-as-a-bearer-token] **Added: `Authorization: Bearer` on the v3 API.** Every v3 endpoint accepts your API key as `Authorization: Bearer `, as an alternative to the `x-api-key` header, for clients that can only send OAuth2 or Bearer credentials. See [Authentication](/reference/api/authentication). - **It is the same key.** There is no separate token to create. - **Send one header or the other.** If a request carries both, the API uses `x-api-key` and ignores `Authorization`. - **The `Bearer` scheme name is case-insensitive.** Any other scheme, such as `Basic`, counts as a missing key. #### Voice: Phone Calls, Voice Tokens, and Call Webhooks [#voice-phone-calls-voice-tokens-and-call-webhooks] Phone calls on the numbers you hold, driven by your own callback URL; a browser SDK for calls from your app; and a `call` webhook family. **Added: voice numbers.** `POST /v3/channels/voice` turns calls on for a number you hold, or gives you a new US number, with the `callback_url` Sent asks what to do with each call and the `callback_secret` the questions are signed with. Read them with `GET /v3/channels/voice`, change one with `PATCH /v3/channels/voice/{number}`, rotate the secret with `POST /v3/channels/voice/{number}/rotate-secret`, and check the URL with `POST /v3/channels/voice/{number}/test` before the first call. `GET /v3/channels` lists them under `voice`. See [Voice](/start/guides/managing-channels#voice). **Added: the callback contract.** When a call arrives or a caller presses a key, Sent POSTs a signed `call.request` or `call.input` question and follows your answer: `connectToUser`, `connectToNumber`, `connectToConference`, `playMenu`, `park`, `hangup` or `reject`, after any `say`, `play`, `sendDigits`, `startRecording`, `stopRecording`, `answer` and `setCookie` instructions. Version `1`, camelCase. See [Answering Calls](/start/guides/answering-calls) and the [Voice Callback Contract](/reference/api/voice-callback). **Added: calls.** Every call is a record under `/v3/voice/calls`: list and read calls, hang one up, start or stop a recording, list recordings, and add, mute, or remove conference participants. See [Calls, Recordings, and Participants](/start/guides/managing-calls). **Added: voice tokens and `@sentdm/voice`.** `POST /v3/voice/tokens` mints a short-lived token for a user of your app, and the [`@sentdm/voice`](https://www.npmjs.com/package/@sentdm/voice) browser SDK places and receives calls with it. See [Calls From Your App](/start/guides/in-app-calls) and the [Voice SDK](/sdks/voice). **Added: `call` webhooks.** `call.initiated`, `call.answered`, `call.completed` with `duration_seconds` and `price`, `call.failed` with `reason`, and `call.recording_ready` with `recording_id`. Subscribe to `call`. Payloads are snake_case like every other family; the callback contract is camelCase. See [Call events](/start/webhooks/event-types#call). **Added: error codes.** `VALIDATION_011`, `RESOURCE_015`, `RESOURCE_017`, `BUSINESS_011` for calls, `BUSINESS_022` to `BUSINESS_028`, `CONFLICT_007` to `CONFLICT_009` and `CONFLICT_011`, plus the call failure reasons. See the [Error Catalog](/reference/api/error-catalog#call-failure-reasons). **Added: voice in the server SDKs.** Every SDK exposes the voice endpoints as the `calls`, `calls.participants` and `channels.voice` resources: [`@sentdm/sentdm`](https://www.npmjs.com/package/@sentdm/sentdm) 0.42.0, [`sentdm`](https://pypi.org/project/sentdm/) 0.42.0 for Python, [Go](https://github.com/sentdm/sent-dm-go/releases/tag/v0.39.0) 0.39.0, [Java](https://github.com/sentdm/sent-dm-java/releases/tag/v0.41.0) 0.41.0, [C#](https://www.nuget.org/packages/Sentdm/0.38.0) 0.38.0, [PHP](https://github.com/sentdm/sent-dm-php/releases/tag/v0.36.0) 0.36.0 and [Ruby](https://rubygems.org/gems/sentdm/versions/0.35.0) 0.35.0. See [SDKs](/sdks). #### Messages: Cancel a Scheduled Send [#messages-cancel-a-scheduled-send] **Added: `POST /v3/messages/{id}/cancel`.** Call off a message you scheduled with `scheduled_at`, before it is released for sending. The message moves to the new terminal status `CANCELLED` and is never sent. See [Cancelling scheduled messages](/start/guides/cancelling-messages). - **Only a `SCHEDULED` message can be cancelled.** A message that has already been released, is in flight, or has finished answers **409** with `BUSINESS_006`. The release sweeper runs every 30 seconds, so a cancellation sent within about a minute of the scheduled instant can lose that race. - **One message per call.** A send to several recipients, or on several channels, is one message per recipient per channel, each with its own id. There is no bulk form. - **Cancelling is free**, and nothing had been charged: a scheduled message is priced at release. A cancelled message is excluded from your deliverability rate. - **The 200 body is the message**, in the same shape `GET /v3/messages/{id}` returns, plus `scheduled_at`. `events` is the timeline as it stood just before the cancellation; the `CANCELLED` activity entry lands a moment later. - **Repeating a cancellation answers 200**, with the same body, and publishes no second event. - `404` for an unknown id, `400` for an id that is not a UUID. **Added: the `message.cancelled` webhook sub-type.** It fires exactly once per cancellation and carries `scheduled_at`, the release instant that was called off, so a consumer that recorded a future send from `message.scheduled` can un-record it. `body` is `null`, and it carries no `schedule_reason` and no `reason_code`. - **Action required** if you subscribe with `event_filters`: add `cancelled` to the `message` list to receive it. A subscription to the `message` parent receives it with no change. **Changed: `CANCELLED` joins the message status values.** `GET /v3/messages/{id}` reports it, and keeps reporting the message's `scheduled_at` afterwards, as does `GET /v3/messages/{id}/activities`. A handler that switches on `message_status` should treat it as terminal. #### Sender Profiles: Opt-In Inheritance and a New Billing Default [#sender-profiles-opt-in-inheritance-and-a-new-billing-default] **Breaking: inheriting the organization's US 10DLC brand and campaign is opt-in.** `POST /v3/sender-profiles` used to give a profile created without `compliance` the organization's brand and campaign, so its `TEN_DLC` markets ran on the organization's registration. It now has neither, and inherits only where `compliance` says `{ "inherit": true }`. See [Dedicated, inherited, or absent](/start/advanced/sender-profiles-api#dedicated-inherited-or-absent). - **Action required** if you create profiles without `compliance` and expect their `TEN_DLC` markets to run on your registration: send `"compliance": { "brand": { "inherit": true }, "campaign": { "inherit": true } }`. - `"brand": { "inherit": true }` on its own inherits the brand only. The campaign is then the profile's own. - Inheriting the campaign while the brand is the profile's own, or `{ "inherit": false }`, is a **400** on `compliance.campaign`. - Inheriting a brand or campaign your organization doesn't have is a **400** on a `TEN_DLC` market, naming the field. It used to leave the profile waiting in `PROVISIONING`. - On a `TEN_DLC` market, an empty `compliance.brand` or `{ "inherit": false }` on its own is a **400**: it names no identity to file against. - `POST /v3/channels/sms` can now move a profile that owns and inherits nothing onto your organization's registration, with the same `{ "inherit": true }`. **Changed: omitting `billing` bills the profile first, with your organization covering the rest.** A profile created without `billing` used to pay alone. It now pays from its own balance, and your organization's balance covers what the profile's can't. `{ "inherit": false }` bills the profile alone, and `{ "inherit": true }` bills your organization. See [Billing](/start/advanced/sender-profiles-api#billing). - Existing profiles with no billing arrangement were moved to the new default, so your organization's balance can now cover their shortfalls. - Reads report the default as `{ "inherit": false }`. `settings.billing_model` on `GET /v3/account` reports `profile_and_organization` for it. **Added: `502` on `POST /v3/sender-profiles`** when Meta can't be reached to verify `channels.whatsapp`. Nothing is created, so the request can be sent again. **Added: an email when an SMS sender goes live.** "Your SMS sender for \{Country\} is now active" goes to the recipients the profile's `notifications` setting names, alongside the existing emails for a removed or declined sender. #### Fixes [#fixes] **Fixed: SMS delivery reports no longer move a message back to `QUEUED`.** On some SMS routes, a late report could move a `SENT` message back to `QUEUED` and fire a stray `message.queued` webhook. A message whose receipt never arrives now ends as `DELIVERED` when the carrier's report window closes, and a carrier report of a cancelled or deleted message ends as `FAILED`. **Fixed: template webhooks reach every account holding the template.** When Meta changes a WhatsApp template's status, category, or quality, Sent now applies it to every account that holds that template, an organization and its Sender Profiles alike, and fires `template.*` webhooks for each. Only one of them used to receive it. ### September 2026 [#september-2026] #### SMS Markets: Clear `ACTION_NEEDED` With One Call [#sms-markets-clear-action_needed-with-one-call] `PATCH /v3/channels/sms/{country}/{type}` now supplies whatever a market is waiting on, in every market you hold, not only US `TEN_DLC`. See [Correct what it holds](/start/guides/managing-channels#correct-what-it-holds). **Added: documents on the market `PATCH`.** Send `multipart/form-data` with each file in a part named after the document's key. `compliance` and `numbers` can ride in the same form as text parts holding their JSON. - A file that matches no document the market asks for is a **400** listing the expected keys. A file the upload rules refuse is a **422**. - `compliance` still applies only to a market that registers with a regime. Anywhere else it's a **400**. **Added: `numbers` on the market `PATCH`.** It takes the same list as `POST /v3/channels/sms` and replaces what a `LOCAL` or `TEN_DLC` market asks for. - A `LOCAL` market claims the new numbers from inventory straight away. A `TEN_DLC` market assigns them once its campaign is approved, and needs a campaign of the profile's own. - A list that leaves out a number already assigned is a **400**. The call never releases a number. **Changed: a registration sent back for correction is fixed with the same `PATCH`.** A filed identity used to be a **409** even when Sent had asked you to correct it. When the market reports `ACTION_NEEDED` for a correction, `compliance.brand` is now accepted, and the correction sends the registration back to Sent for review. A filed identity with no correction asked for is still a **409**. **Changed: `reason` names where to send what's owed.** An `ACTION_NEEDED` market's `reason` now points to its `PATCH`. That holds for documents and corrections too. #### Channels: `channel.rejected`, Corrected Event Timing, and Stricter SMS Market Validation [#channels-channelrejected-corrected-event-timing-and-stricter-sms-market-validation] One new `channel` sub-type, three timing fixes, and two validation changes to `POST /v3/channels/sms`, one of them breaking. **Breaking: a market that pre-registers its sender must be sent with its documents.** `POST /v3/channels/sms` for a market whose requirements include a document now answers **422** when that document isn't attached or an uploaded file is rejected, naming each missing key under `compliance`. It previously answered `201` or `202` and left a market waiting on a file the call had promised to collect. The market isn't added, so nothing needs cleaning up. - **Action required** if you add such markets with a JSON body: send the request as `multipart/form-data`, with each document as a part named after its requirement key. See [Add the market](/start/guides/managing-channels#add-the-market). **Changed: `sender_value` is required for `ALPHANUMERIC`.** `POST /v3/channels/sms` and `POST /v3/sender-profiles` answer **400** when `number_type` is `ALPHANUMERIC` and `sender_value` is missing or blank. An alphanumeric sender is one you choose, so there is nothing to provision without it. **Added: `channel.rejected`.** A market's sender that is turned down before it ever went live now has its own sub-type: The Campaign Registry rejecting its campaign, or a sender still being set up being withdrawn. `payload.reason` carries the explanation when one was given. Both used to be indistinguishable from `channel.deactivated`, which means a sender that worked stopped. Subscribe to `channel` or add the `rejected` filter to receive it. See [Channel sub-types](/start/webhooks/event-types#channel-sub-types). **Channel events: corrected timing.** - **Changed**: `channel.approved` for a 10DLC market fires when the carriers elect your campaign. It previously fired when the campaign was shared with an upstream connectivity partner, days before a verdict existed. - **Fixed**: Submitting a brand or campaign to The Campaign Registry now reports `channel.submitted`. It previously reported nothing. - **Fixed**: Requesting a sender for a market that registers with nobody reports `channel.activated` once, not twice. - **Fixed**: A market that pre-registers its sender no longer reports a `channel.deactivated` it never earned on the way to going live. #### Messages and Channels: Reason Codes for Every Non-Success Status [#messages-and-channels-reason-codes-for-every-non-success-status] A message that doesn't go out, and a channel that can't send, now say why. **Added: `reason_code` and `reason` on messages.** `message.failed`, `message.filtered` and `message.blocked` webhooks, `GET /v3/messages/{id}` (top level and on each event) and `GET /v3/messages/{id}/activities` carry both. They're omitted on every successful status. See [Message Outcome Codes](/reference/api/error-catalog#message-outcome-codes). - `reason_code` is a stable code to branch on. `reason` is a sentence to show a person, and its wording may improve. - A cause the API already rejects synchronously keeps its code: an opted-out recipient is `BUSINESS_004`, a low balance `BUSINESS_003`, an invalid number `VALIDATION_002`. - Outcomes only a message can have are `DELIVERY_001` to `DELIVERY_016`. The codes are Sent's classification and never a carrier's own code. - New `BUSINESS_017` to `BUSINESS_020`, including `BUSINESS_020` for the onboarding-stage message limit. - v2 is unchanged. **Added: `reason_code` on channels.** Every SMS market, WhatsApp account and RCS agent that isn't `ACTIVE` carries `reason_code` (`CHANNEL_001` to `CHANNEL_011`) and `reason`, on `GET /v3/channels`, the single-market reads and Sender Profiles, and on `channel.*` webhooks for SMS markets. See [Channel Status Reasons](/reference/api/error-catalog#channel-status-reasons). **Changed: `note` is replaced by `reason`.** SMS market responses no longer return `note`. The same sentence is now `reason`. **Action required** if you read `note`: read `reason`, and branch on `reason_code`. **Changed: WhatsApp reports `ACTION_NEEDED` when it's waiting on you.** A WhatsApp channel with no business account connected (`CHANNEL_006`) or no phone number (`CHANNEL_007`) used to report `PROVISIONING`. #### SMS: US Territories Reached From a US Number [#sms-us-territories-reached-from-a-us-number] A US `TEN_DLC` or `LOCAL` number now also sends to Puerto Rico, the US Virgin Islands, Guam, American Samoa, the Northern Mariana Islands and the US Minor Outlying Islands. Existing numbers were given the routes, so no action is needed. See [Channel Routing](/reference/channel-routing#how-auto-detect-resolves-a-channel). - Where a territory accepts alphanumeric senders, Sent sets one up on your first send there and tries it before your number. - A failed delivery now reroutes when the carrier refused the sender itself or no route reached the destination network. Each reroute is charged as a send. #### MMS: Inbound Attachments on `message.received` [#mms-inbound-attachments-on-messagereceived] An inbound MMS now carries a `media` array: each attachment's `url`, and its `mime_type`, `size_bytes` and `hash_sha256` when the carrier declared them. The `url` is the carrier's own link, which needs no authentication and expires on the carrier's schedule, so download the file on receipt. `media` is omitted when there are no attachments. See [Inbound MMS](/start/guides/mms#inbound-mms). #### Webhooks: Delivery Fixes [#webhooks-delivery-fixes] - **Rotated secrets apply to queued events.** Each delivery is signed with the webhook's current secret, URL and timeout when it's sent. An event queued before a rotation used to arrive signed with the old secret and fail. - **Repeated test sends are delivered.** Every test uses fresh sample ids. A second test of the same event used to be reported as failed without being sent. - **Test sends don't count toward auto-disable.** A failed test no longer moves the webhook toward being switched off. - **Your organization's event history includes its clones'.** `GET /v3/webhooks/{id}/events` on your organization's webhook also lists the events its Sender Profile clones delivered. #### Webhooks: Sender Profile Clones [#webhooks-sender-profile-clones] Your organization's webhook can be cloned onto every Sender Profile, so every profile's events reach your endpoint. **Added: `sender_profile` on webhooks.** `POST /v3/webhooks` and `PUT /v3/webhooks/{id}` accept `sender_profile`, with its own `event_types` and `event_filters`. When it selects any event, Sent clones the webhook onto every Sender Profile under your organization, including profiles you create later. Each clone is a webhook the profile owns, with your webhook's URL and signing secret, and receives the profile's events that `sender_profile` selects. See [Sender Profile Events](/start/webhooks/event-types#sender-profile-events). - Your changes to the webhook update every clone, including one a profile edited. A clone a profile deleted stays deleted. - An event a clone delivers names the profile in `payload.account_id`. - Webhook responses don't include `sender_profile`. It's a request field on create and update only. - On an update, omitting `sender_profile` keeps the clones' events. Send `"sender_profile": {"event_types": []}` to delete the clones. - `event_types` can be empty when `sender_profile.event_types` isn't, so a webhook can feed its clones alone. - A request made as a Sender Profile, with its own key or with `x-profile-id`, can't set `sender_profile` and is answered with a **400**. **Changed: your organization's webhook receives only your organization's channel events.** A webhook subscribed to `channel` used to receive its Sender Profiles' channel events as well. A profile's channel events now reach only that profile's webhooks, including clones of yours. - **Action required** if you expect your profiles' channel events at your organization's endpoint: add `"sender_profile": {"event_types": ["channel"]}` to the webhook. #### MMS: One Attachment, a 600 KB Limit, and No Audio [#mms-one-attachment-a-600-kb-limit-and-no-audio] Four changes to MMS on the v3 API. Each moves a failure that used to surface at the carrier, after the message was accepted and charged, to authoring time or to the send itself. - **One attachment per message, down from 10.** `media_urls` on `POST /v3/messages` and a template's `mms.media` each take one item, and a second is rejected with `400`. A template saved with more than one attachment before this still sends, carrying only its first. - **600 KB per attachment, checked before sending.** After accepting the message, Sent reads the size your server declares for the attachment with one `HEAD` request. Over the limit, an auto-detect send falls to SMS on the same number, with the attachment as a link when it fits, and a send pinned to `mms` fails. A size your server does not declare never blocks the send. See [Media Size Limits](/start/guides/mms#media-size-limits). - **`audio` removed from the MMS media types.** A template media item declaring `audio` is rejected. Audio was never in the supported formats, so this moves a carrier-side failure to authoring time. - **Media URLs must use a hostname.** A literal IP address is refused with `400`. #### Sender Profiles: `billing.fallback` Removed, Plus Resend, Scheduled Sends, and MMS [#sender-profiles-billingfallback-removed-plus-resend-scheduled-sends-and-mms] One removal and three additions on the v3 API, all live as of September 23, 2026. **Removed: `billing.fallback` on Sender Profiles.** The `billing` object on `POST /v3/sender-profiles` and in the `GET /v3/sender-profiles` response now carries `inherit` only. Both schemas reject unknown fields, so a create request that still sends `billing.fallback` is answered with a **400** rather than having the field ignored. If you send it, drop it before your next call. Reading it from a response returns nothing, and the two-field shape it replaced could express a state the API never acted on, which is why it went rather than being deprecated in place. - **Action required** if you call `POST /v3/sender-profiles` with an explicit `billing` object. Sending `{"inherit": ...}` alone is correct and unchanged. - The field was published on August 31, 2026, so integrations written before then were never able to send it. **Added: `scheduled_at` on `POST /v3/messages`.** Send a message at a future instant instead of now. - Requires an **explicit UTC offset**, such as `2026-10-01T09:00:00+02:00` or `2026-10-01T07:00:00Z`. A timestamp without one is rejected with `400` rather than being read in the server's zone. The offset fixes the instant only, and the value is stored and echoed in UTC. - Must be at least one minute ahead and at most 30 days ahead. - An accepted message reports `SCHEDULED` and `GET /v3/messages/{id}` returns the release time. - **Quiet hours, balance, and template approval are evaluated at release, not at acceptance.** A message accepted today can still fail at its release time, so treat `SCHEDULED` as queued rather than guaranteed. - Omit the field to send immediately, exactly as before. **Added: `mms` as a channel.** `mms` is accepted in `channel` and reported on messages and templates, and `POST /v3/messages` takes `media_urls` and `subject` alongside it. MMS is enabled per account rather than by request: until your account is enabled for it, an `mms` candidate is refused and routing falls back, so adding the channel to a send is safe to prepare ahead of time. MMS costs several times an SMS per message, which is why it is opt-in rather than inferred from a template carrying media. #### Webhooks: the `channel` Family, Per-Attempt Signatures, and Rendered Bodies [#webhooks-the-channel-family-per-attempt-signatures-and-rendered-bodies] Three changes to what a subscribed endpoint receives. A handler written against the previous behavior keeps working, but it now sees traffic and fields it did not see before. **Added: the `channel` event family can be subscribed to.** Five sub-types follow one market from filing to sendable, so watching a sender go live no longer means polling `GET /v3/channels`: `channel.submitted`, `channel.changes_requested`, `channel.approved`, `channel.activated`, and `channel.deactivated`. The subject is always one market, never the account, and `payload.status` answers a different question from the sub-type: the sub-type says what happened, the status says whether the market can send. See [Event types](/start/webhooks/event-types) and [Lifecycle events](/start/webhooks/lifecycle). - **Added**: `channel.activated` fires for every market that gains a sender, including markets that register with no regulator and senders assigned for you. Markets that previously raised no events at all raise them now, so expect volume on this family to go up rather than sideways. - **Added**: `channel.deactivated` fires when a sender ID is cancelled for you, not only when a number returns to the pool or a campaign lapses. - **Changed**: A sender ID that Sent pre-registers with the destination's regulator reports `channel.submitted` once that market's documents are in, and `channel.changes_requested` only while documents are outstanding. It previously reported `changes_requested` in both cases, which asked you to correct something that `GET /v3/compliance/requirements` reported nothing about. - **Changed**: A 10DLC activation is announced when the campaign is put to work rather than when the registry's webhook lands, so a market that inherits its organization's campaign reports `channel.activated` too. **Changed: every delivery attempt is signed at send time.** `X-Webhook-Timestamp` and `X-Webhook-Signature` are computed per attempt, so a retry carries its own timestamp and clears a 5-minute replay window however long the backoff ran before it. Both headers previously carried the event's creation time on every attempt, so a receiver enforcing that window rejected the later retries of an event that was only failing transiently. See [Signature verification](/start/webhooks/signature-verification). - **Added**: `X-Webhook-Attempt` carries the index of the attempt in hand, starting at `1`, so a receiver can tell a redelivery from a first delivery without keeping state of its own. - **Changed**: Deduplicate on `X-Webhook-Event-ID`, which holds one value for every attempt at the same event. A dedupe key built from the timestamp records one event once per attempt. See [Handling retries](/start/webhooks/handling-retries). **Added: `body` on outbound message events.** Every `message.*` status event carries `payload.body`, the rendered message text as plain text, truncated at 3072 characters. The field is always present, and it is `null` when Sent is not asserting a body: before routing resolves a channel, on a send stopped before it got one, and on a delivery report for an attempt the message has since been rerouted away from. A non-null value is always the render for that event's own `channel`, so the two fields describe one attempt. The body is plain text, so a WhatsApp or RCS header, footer and buttons are not included; `GET /v3/messages/{id}` returns the full composed message. **Added: `auto_reply_action` on templates.** `GET /v3/templates`, `GET /v3/templates/{id}` and the `templates` webhook events report which consent keyword a template answers when it is one of the auto-replies Sent creates for you: `OPT_IN`, `OPT_OUT`, `HELP`, or `OTHER` for a keyword you defined. The field is omitted for a template you authored, so its presence is the answer to whether the row or the event is about an auto-reply. Sent's three compliance auto-replies go through review like any other template, so their events arrive mixed in with your own, and nothing on the wire told them apart before. **Templates: smaller changes.** - **Fixed**: An RCS body truncated after variable substitution is cut on a character boundary, so a body with an emoji straddling the 3072-character limit no longer reaches the handset ending in a broken glyph. - **Clarified**: `channels` on a template response lists every channel the definition's body can render on, following each channel's send-time fallback, which is why an `sms` and `whatsapp` pair reports `rcs` as well. It says what the content can render on, not what may be sent: sending also needs the template approved for that channel. The body, button and editing rules are in the [template definition reference](/reference/api/template-definition). ### August 2026 [#august-2026] #### Sender Profiles, Channels, and Compliance Requirements [#sender-profiles-channels-and-compliance-requirements] A profile is now created in one call, its senders are managed per market, and what a market demands is something you can ask for before you try. **Added: `/v3/sender-profiles`.** `POST`, `GET`, and `GET`/`PATCH`/`DELETE` on `/{id}`. `POST /v3/sender-profiles` needs a `name` and a `short_name` and nothing else: identity, inbox, opt-out list, and billing come from your organization, so the profile is usable immediately with no compliance work. There is no completion step and no callback to receive. The response carries the profile's `api_key`, shown once and never returned again. Every capability is one of three things, and there is no flag per state: supply the capability's fields to make it dedicated, send `{"inherit": true}` to take the organization's, or omit the block for neither. A read returns `channels.sms` as a list, with a status and outstanding compliance per market. **Added: `/v3/channels`.** `GET /v3/channels` returns every market you send SMS in, your WhatsApp account, and your RCS agent, each with its own status. `POST /v3/channels/sms` adds a market (a country plus a sender type) and takes everything that market registers in one `compliance` object. `GET`/`PATCH /v3/channels/sms/{country}/{type}` read and correct one market; the `PATCH` is partial at every level, so an omitted key is left alone, an explicit `null` clears it, and `{}` is refused rather than silently accepted. `POST /v3/channels/whatsapp` connects an account shared through a Multi-Partner Solution, and `POST /v3/channels/rcs` requests an agent. - **Added**: Status is per channel, never flattened onto the account or the brand: `PROVISIONING`, `ACTION_NEEDED`, `PENDING_REVIEW`, `ACTIVE`. A sender live in one country and mid-registration in another reports exactly that. - **Changed**: `POST /v3/channels/whatsapp` does not accept `access_token`, `solution_id`, or `owner_business_id`. The first two are Meta's answer about provenance, and the token rotates roughly every sixty days, so all three are resolved from your organization. **Added: `GET /v3/compliance/requirements`.** Call it first. It returns what a channel, country, and sender type demand (each requirement keyed as you write it, such as `brand.legal_name` or `campaign.message_flow`), plus `setup[]`, the calls that satisfy them with a body you can copy and send as it stands. It is the same declaration that validates the calls themselves, so it cannot drift from what the API accepts. `channel` defaults to `sms`; `whatsapp` and `rcs` return `501` until their requirements are declared, because an empty requirement set would wrongly say those channels demand nothing. **Deprecated: `/v3/profiles` and the profile-campaign endpoints.** All eleven operations still behave exactly as before, so nothing breaks today. - **Deprecated**: `POST`/`GET /v3/profiles`, `GET`/`PATCH`/`DELETE /v3/profiles/{profileId}`, and `POST /v3/profiles/{profileId}/complete`. Use `/v3/sender-profiles`. - **Deprecated**: `POST`/`GET /v3/profiles/{profileId}/campaigns` and `PUT`/`DELETE /v3/profiles/{profileId}/campaigns/{campaignId}`. A campaign is a registration rather than a collection, so it now travels in `compliance.campaign` on the market call, one per market. - **Deprecated**: `DELETE /v3/contacts/{id}`. Use `PATCH /v3/contacts/{id}` with `{"opt_out": true}`, which stops every send and keeps the record of who the contact was and that they asked. **Changed: contact and template sharing between Sender Profiles is gone.** A profile sees only its own contacts and templates; the organization still sees those of every profile beneath it, through read-time widening. A tenant's customer data can no longer become visible to a sibling tenant by configuration. **Changed: sender borrowing is gone.** A profile cannot be pointed at another profile's number. Give it a dedicated sender with `channels.sms`. Where `sending_phone_number_profile_id` is still populated on a read, such as `GET /v3/me`, it reports which account holds the number in inventory rather than a sender you can choose. Six fields are now **accepted and ignored** rather than refused, because a `400` would break an integration that is otherwise working. They stay on the wire so a generated client keeps compiling, and every request carrying one is logged so they can eventually go for real: | Field | Where | Reads back | | --- | --- | --- | | `inherit_contacts`, `inherit_templates` | `POST`/`PATCH /v3/profiles`, profile and organization responses | `false` | | `allow_contact_sharing`, `allow_template_sharing` | The same | `false` | | `sending_phone_number_profile_id`, `sending_whatsapp_number_profile_id` | `PATCH /v3/profiles/{profileId}`, profile responses | `null` | - **Changed**: `is_inherited` on the contact response is always `false`. It stays on the wire so existing clients keep deserializing; do not branch on it. - **Changed**: Inherited contacts are no longer read-only. The gate that rejected an update or a delete of one is gone, along with the contact rows it protected. - **Changed**: An invalid `default_channel` on `PATCH /v3/contacts/{id}` now returns an invalid-enum error naming the accepted values rather than a generic validation failure. - **Changed**: `primary_use_case` on the brand is always `null`. The campaign's use cases replace it. - **Changed**: `is_welcome_playground` on `GET /v3/templates` is accepted and ignored. The filter it drove was removed. - **Changed**: `GET /v3/me` no longer returns a stubbed organization in sandbox mode, and the four sharing settings are gone from its `profiles` entries. - **Unchanged**: `POST /v3/messages` still has no synchronous `402`. Its declared responses are now `202`, `400`, `401`, `403`, `404`, and `500`, which matches the asynchronous balance gate the docs have described since July: the send is accepted with `202` and the affected messages are reported as `BLOCKED`. **Migration:** Nothing is required today. When you move, start from `GET /v3/compliance/requirements` for the market you need, create the profile with `POST /v3/sender-profiles`, and add its sender with `POST /v3/channels/sms`. Check existing code for the six ignored fields above: a write to any of them still returns success and does nothing, and reading the value back is how you can tell. See [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api) and [Managing channels](/start/guides/managing-channels). #### Brands: `csp_id` Deprecated [#brands-csp_id-deprecated] `csp_id` on the brand object is deprecated and will be removed in a later release. It's marked `deprecated` in the [OpenAPI specification](/reference/api/openapi-spec). The field identifies the Campaign Service Provider that registered the brand, which is Sent, so the value is the same for every brand and every account. There's no action it supports and no replacement. Stop reading it. - **Deprecated**: `csp_id` on the brand embedded in `POST /v3/profiles`, `GET /v3/profiles`, and `GET`/`PATCH /v3/profiles/{profileId}`. - **Unchanged for now**: the field is still returned and still populated, so nothing breaks today. Removal lands in a later release with its own entry here. Your own TCR identifiers are unaffected. `tcr_brand_id` and `universal_ein` stay. #### Two-Way Conversations: Free-Form Gating on SMS and RCS [#two-way-conversations-free-form-gating-on-sms-and-rcs] Free-form sends on SMS, RCS, and auto-detect are now governed by an explicit conversation rule rather than a one-time prior-inbound check. - **Added**: A contact who has **ever** replied, on any channel and at any point in the past, can be sent free-form text indefinitely. A reply is treated as consent to converse and does not expire; only an opt-out ends it. - **Added**: For a contact who has **never** replied, free-form rides on the last approved template you sent and lapses **7 days** after it. The cap exists to stop a one-sided stream of free-form content opened by a single template. Previously a contact who had never replied could not be sent free-form text at all. - **Added**: `CONVERSATION_TEMPLATE_REQUIRED`, a dedicated code for that blocked case. It replaces the `VALIDATION_004` (`'template' is required`) this case previously produced, which read as a malformed request when the request was fine. The two message variants distinguish a contact with no template ever sent from one whose template has lapsed. Like the other send-time codes, the code itself is recorded internally rather than returned in API responses or webhook payloads. - **Added**: Free-text, an account-level waiver of the conversation rule. With it enabled, free-form reaches a contact who has never replied on SMS, RCS, and auto-detect, with no template first and no 7-day window. It applies on each channel where the account has an active sender, it is set on the organization and inherited by Sender Profiles, and it changes neither Meta's 24-hour window nor opt-out enforcement. Sent enables it on request. - **Changed**: The blocked send is recorded as **`BLOCKED`, not `FAILED`**. The gate runs before routing, so nothing is handed to a carrier: these messages are excluded from your deliverability rate and fire `message.blocked` rather than `message.failed`. - **Changed**: A free-form send with `channel` omitted no longer fails when Meta's WhatsApp window is shut. WhatsApp is treated as unreachable for that send and the message falls back to RCS or SMS. A send pinned to `channel: "whatsapp"` still fails with `WHATSAPP_TEMPLATE_REQUIRED`, which remains a `FAILED` status. - **Changed**: The `message.blocked` webhook event description now covers all three of its causes (account precondition, template not approved for sending, and no open conversation) rather than account preconditions alone. Description only: no subscription changes, nothing to re-subscribe. - **Unchanged**: Meta's 24-hour customer-service window. Only an inbound WhatsApp message from the contact opens it; an outbound template never does. A send pinned to `channel: "whatsapp"` answers to that window alone. - **Unchanged**: Opt-out keywords do not count as engagement, on either leg of the exchange. `START` and `HELP` do. - **Unchanged**: `VALIDATION_004` itself. It remains the code for a genuinely missing required field, returned as `400` on the request. **Migration:** If you branch on `VALIDATION_004` to detect a blocked free-form send, that branch no longer fires. If you subscribe only to `message.failed` to catch these, subscribe to `message.blocked` as well: the send is accepted with `202` and the message finalizes as `BLOCKED`. Contacts who have replied to you at least once need no action, since free-form to them is never blocked by this rule. ### July 2026 [#july-2026] #### 10DLC: Messaging Volume Moved to Campaign (Breaking Change) [#10dlc-messaging-volume-moved-to-campaign-breaking-change] Expected messaging volume is now a per-campaign field, not a brand-level attribute. Volume drives the TCR tier classification (low-volume vs. standard) and the monthly campaign fee. These are per-campaign concerns: a brand can have multiple campaigns at different tiers. - **Removed**: `expected_messaging_volume` from `BrandComplianceInfo` (brand request body) and `BrandComplianceResponse` (brand response). The field is no longer accepted or returned on any brand endpoint. - **Removed**: The dedicated update-brand-volume endpoint has been deleted. There is no replacement at the brand level. - **Added**: `volume` field on campaign create (`POST /v3/profiles/{profileId}/campaigns`), update (`PUT /v3/profiles/{profileId}/campaigns/{campaignId}`), and get (`GET /v3/profiles/{profileId}/campaigns`) endpoints. The value is a numeric string representing expected daily message volume (for example `"1500"`). Values strictly below `2000` register the campaign at the low-volume tier (capped at 2,000 messages/day, lower monthly fee); `2000` and above register as standard. The field is optional, and omitting it registers the campaign as standard, the higher-fee tier, rather than returning an error. - **Changed**: When updating a campaign's `volume` causes a tier change, the billing delta for the current window is applied immediately rather than being deferred to the next billing sweep. **Migration:** Move `expected_messaging_volume` from brand requests to the `volume` field on each campaign request. Set `volume` explicitly on every low-volume campaign. A request that still sends the brand-level field is accepted and that field is ignored, so a campaign left without `volume` registers as standard and bills at the higher monthly fee, with nothing surfaced to flag it. | Before | After | |---|---| | `BrandComplianceInfo.expected_messaging_volume` (brand request body) | `CampaignData.volume` (campaign create/update body) | | `BrandComplianceResponse.expected_messaging_volume` (brand response) | `TcrCampaignWithUseCasesResponse.volume` (campaign response) | | Single value shared across all campaigns under a brand | Set independently per campaign | #### Message Status Model: New Values [#message-status-model-new-values] Three new `MessageStatus` values have been introduced to distinguish policy-driven suppression from delivery failures: - **Added**: `FILTERED`: message suppressed by a DENY routing rule before reaching a carrier. Policy-driven and expected. Does **not** count against your deliverability rate. The specific policy that stopped the send is recorded internally and is not returned in API responses or webhook payloads. Webhook event: `message.filtered`. - **Added**: `BLOCKED`: message gated before send evaluation due to an account-level condition such as insufficient balance, an unmet onboarding entitlement, or a template that is not approved for sending. Does **not** count against your deliverability rate. The specific condition is recorded internally and is not returned in API responses or webhook payloads. Webhook event: `message.blocked`. Sends from a suspended account are rejected at the API edge with `403` and code `BUSINESS_014` and never create a message record, so they do not produce this status. - **Added**: `SCHEDULED`: message queued for future delivery (curfew window or scheduled send). Not a terminal state; it transitions to `ROUTED` once the window opens. The release time is not exposed as an API field. Webhook event: `message.scheduled`. **Migration note:** Prior to this release, all non-delivered outcomes were surfaced as `FAILED`. If your integration filters on `FAILED` to catch all unsent messages, also handle `FILTERED` and `BLOCKED` to maintain full coverage. `FILTERED` and `BLOCKED` are excluded from the deliverability rate denominator, so only `FAILED` counts against the rate. | Old behavior | New behavior | |---|---| | `FAILED` covered all non-delivered outcomes | `FAILED` = downstream delivery attempt that failed (carrier/network) | | No equivalent | `FILTERED` = suppressed by a DENY rule, which is policy-driven rather than a failure | | No equivalent | `BLOCKED` = gated by an account condition before send | | No equivalent | `SCHEDULED` = deferred to a future window (transient, not terminal) | #### Message Scheduling & Quiet Hours [#message-scheduling--quiet-hours] - **Added**: Messages destined for a mobile network with quiet-hours restrictions are now automatically deferred (status `SCHEDULED`) instead of being sent or failed during the restricted window, and released once it ends. - **Fixed**: Quiet-hours windows that span midnight are now evaluated correctly. #### Delivery Reliability [#delivery-reliability] - **Added**: SMS messages that fail delivery on their original channel are now automatically retried on an alternate channel. This automatic fallback now also covers WhatsApp messages that can't be delivered. - **Fixed**: A delivery receipt from a carrier could occasionally be matched to the wrong send attempt after a message was retried across channels, leaving its status stuck. Delivery status now updates correctly in this case. - **Fixed**: `message.received` webhook events were not firing for some inbound WhatsApp and SMS auto-reply messages, and for messages sent to shared/ported numbers or redelivered inbound messages. These now fire correctly. #### Compliance & Consent [#compliance--consent] - **Added**: WhatsApp contacts who send a keyword command (`STOP`, `START`, `HELP`) now automatically receive a reply, and a `STOP` reply updates the contact's `opt_out` status as returned by `GET /v3/contacts/{id}`. - **Updated**: Stricter validation now applies to `AUTHENTICATION`-category WhatsApp template bodies for the SMS channel, and for link/URL variables. #### API Reliability & Security [#api-reliability--security] - **Fixed**: Sending a free-form (non-template) message with `channel` omitted (auto-detect) could bypass the conversation-window gate that normally restricts free-form SMS/RCS sends to an active conversation. Auto-detect sends are now gated the same as explicit-channel sends. - **Fixed**: Authentication-failure lockouts (`429`) are now scoped to the specific API key rather than the caller's IP address, so a customer sharing an IP with another tenant is no longer at risk of being locked out by unrelated failed attempts. - **Fixed**: `DELETE /v3/templates/{id}` could fail for templates with channel-status or WhatsApp update-history records; deletion now cleans these up first. #### Dashboard [#dashboard] - **Added**: Sign in and sign up with Google, GitHub, or Facebook, in addition to email and password. - **Added**: A new bulk-messaging tab in the Playground lets you upload a CSV of recipients and send to the whole list at once, with upfront validation of phone number formats. - **Added**: Message activity now shows a segment count (for example, "3 parts") for multi-part SMS messages. --- ### June 2026 [#june-2026] #### Conversations [#conversations] - **Added**: New `GET /v3/conversations` and `GET /v3/conversations/{id}` endpoints to list a customer's messages grouped by conversation, with pagination. #### WhatsApp Messaging [#whatsapp-messaging] - **Added**: `POST /v3/messages` now accepts a plain-text `text` field as an alternative to `template`, for free-form WhatsApp messages within the 24-hour customer-service window. Sending free-form text outside that window now returns a dedicated `WHATSAPP_TEMPLATE_REQUIRED` error. - **Added**: WhatsApp templates can now be approved and sent per channel independently. A template pending or rejected on one channel no longer blocks sending on a channel where it's approved. Sending on a channel where the template isn't active now returns a dedicated `BUSINESS_012` error. - **Fixed**: Templates approved without a connected WhatsApp Business Account (for example, compliance-approved for SMS only) can now actually be sent, instead of being blocked for lacking a WhatsApp template ID. #### Billing Accuracy [#billing-accuracy] - **Fixed**: Multi-part SMS messages (over the 160-character GSM segment limit) are now billed per segment rather than as a single message. - **Fixed**: WhatsApp messages billed directly by Meta to your WhatsApp Business Account are now only charged the difference against Sent's own price for that message, preventing double-charging. - **Updated**: The recurring per-contact messaging charge now runs on a rolling 28-day cycle from the last charge, rather than resetting on the first of each calendar month. - **Fixed**: Corrected per-network SMS cost resolution to always use the actual matching rate for a destination. #### 10DLC Compliance [#10dlc-compliance] - **Added**: `GET` campaign responses now include a `pricing` object (the resolved recurring campaign fee) and a flag indicating whether the one-time submission fee has been charged. - **Updated**: 10DLC campaign submission and recurring maintenance fees are now billed on each campaign's own activation anniversary, rather than a shared calendar cycle. - **Fixed**: Campaign submission fees that were missed on a brand resubmission are now correctly backfilled and charged. - **Fixed**: Campaign activation now reliably registers the connected phone number with the carrier, so an approved campaign is actually enabled for sending. #### Reliability [#reliability] - **Fixed**: WhatsApp Business Account health is now determined the same way across onboarding, Meta webhooks, and send-time checks, reducing inconsistent "WhatsApp degraded" errors. - **Fixed**: SMS delivery status is no longer marked `DELIVERED` as soon as a carrier accepts a message for transit. It now stays in transit until an actual delivery or failure signal arrives. - **Fixed**: Contact opt-out (`STOP`) handling is now unified onto a single consent record, so a contact's opt-out status is consistent regardless of which channel they opted out on. `HELP`/`STOP` compliance auto-replies are no longer blocked by a contact's own opt-out status. - **Fixed**: A deny routing rule with no fallback configured is now a hard block, instead of occasionally falling through to another route and sending anyway. #### Dashboard [#dashboard-1] - **Added**: Sub-account (Sender Profile) SMS configuration and pricing can now automatically inherit from the parent organization's defaults. - **Added**: Self-service auto-recharge: enable auto-charge to automatically top up your balance from a saved card when it drops below a chosen threshold. - **Added**: A restructured Brand Registration (10DLC) wizard for compliance onboarding. - **Added**: Dedicated Sender Identity requests now support uploading required registration documents directly, with document-type status shown in the flow. - **Added**: Campaign details now offer an AI-assisted quality check and rewrite of your campaign messaging. --- ### May 2026 [#may-2026] #### Pre-Send Consent Gate [#pre-send-consent-gate] **Superseded**: Consent-blocked messages are finalized as `FILTERED`, not `FAILED`, and surface on the `message.filtered` webhook. `POST /v3/messages` no longer rejects a send over recipient opt-out state: the all-recipients-opted-out case below is also accepted with `202` and blocked asynchronously per message. See the [error catalog](/reference/api/error-catalog). - **Added**: New `ERR_CONSENT_BLOCKED` send-time error code. Every outbound message now runs through a pre-routing consent check that refuses sends to recipients with `opt_out = true` or whose phone is on the customer's phone-channel suppression list. Blocked messages are finalized as `FAILED` before any provider call is made, so no carrier charge applies. Inspect `description` on the message detail or in `GET /v3/messages/{id}/activities` to see the reason. - **Updated**: `BUSINESS_004` is now scoped to the **all-recipients-opted-out** case. When *some* recipients are still reachable, the API accepts the batch and only the blocked recipients fail asynchronously with `ERR_CONSENT_BLOCKED`. See [API Errors](/reference/api/errors) and the [error catalog](/reference/api/error-catalog). #### Inbound Message Webhooks [#inbound-message-webhooks] - **Fixed**: `message.received` webhook events now fire correctly for inbound messages across all channels. Previously, subscribing to `message.received` produced no deliveries despite the event appearing in the subscription list. The webhook notification was only sent for outbound status changes. All inbound messages persisted since this release trigger a `message.received` event to your webhook endpoint. - **Updated**: `message.received` payload `channel` field now reflects the actual inbound channel (`sms` or `whatsapp`). WhatsApp replies fire the same `message.received` event shape as SMS replies. - **Fixed**: Inbound WhatsApp replies now reliably resolve to the correct account when a number has been used across multiple WhatsApp Business Accounts. #### Profile Completion API [#profile-completion-api] - **Updated**: `POST /v3/profiles/{profileId}/complete` now returns distinct typed responses: - **200**: Profile was already in a completed state. Response body: `{success: true, data: {status: "completed", message: "..."}}`. - **202**: Completion accepted and running in the background. Response body: `{success: true, data: {message: "..."}}`. The provided webhook URL is called when processing finishes. - Previously both paths returned an opaque `object` type, which made it difficult to distinguish synchronous completion from asynchronous processing in generated SDK clients. #### API Schema [#api-schema] - **Updated**: `event_data` and `metadata` fields on webhook event and message objects are now typed as open JSON objects in the OpenAPI spec. This resolves ambiguity in generated SDK clients where these fields previously appeared as untyped empty schemas. Runtime behaviour is unchanged. #### Webhook Payload Standardization [#webhook-payload-standardization] - **Updated**: Standardized the message webhook payload shape. The event-type field is now named `event` (was `sub_type`). Inbound message payloads: `from`/`to` renamed to `inbound_number`/`outbound_number`, the `provider` field was removed, and `updated_at` was added. Outbound message payloads gained `updated_at` and `template_name` fields. - **Updated**: `message.sent` now reflects successful submission to the upstream provider; provider-side acknowledgement signals that previously could report as `message.sent` now resolve to `message.delivered`, so you see one clear status after submission (a later `message.failed` can still follow). `message.read` webhooks now cover WhatsApp and RCS (previously WhatsApp only), and are never emitted for SMS. #### WhatsApp Template Reliability [#whatsapp-template-reliability] - **Fixed**: Several classes of WhatsApp template were silently stuck and never actually submitted to Meta for approval: default compliance auto-reply templates (`STOP`/`START`/`HELP`), templates copied from the template library, and templates in a bulk submission with an empty name or unresolved language. These now submit correctly, and previously stuck templates were backfilled. - **Added**: WhatsApp template URL buttons now support a dynamic variable in the button URL, for per-recipient personalization. #### Compliance & Reliability [#compliance--reliability] - **Fixed**: Inbound SMS opt-in (`START`) keywords are now only honored when the receiving number is currently assigned to your account, preventing consent from being recorded incorrectly after a number is reassigned or released. - **Fixed**: A cross-provider configuration bug could let one SMS provider's delivery/webhook settings bleed into another's, affecting delivery status and webhook routing for some numbers. Resolved. - **Fixed**: Messages that failed before a channel was selected now report the actual (or auto-routed) channel instead of the placeholder value `unknown`. --- ### April 2026 [#april-2026] #### Opt-In / Opt-Out Keyword Management [#opt-in--opt-out-keyword-management] - **Added**: Per-account keyword management for SMS opt-in and opt-out flows. You can now configure custom keywords (beyond the standard STOP/START/HELP) that trigger automatic replies and consent state changes. Contacts who send an opt-out keyword are automatically suppressed from future messages. - **Added**: Inbound keyword matches now trigger configurable auto-replies, billed as standard outbound messages. #### Inbound Message Processing [#inbound-message-processing] - **Added**: Inbound messages from contacts are now persisted and fully tracked across all supported channels. Each inbound message appears in your message history with `direction: "INBOUND"` and `status: "RECEIVED"`. - **Added**: Inbound messages generate a `message.received` webhook event. Subscribe to this event to receive real-time notifications when contacts reply to your messages. See [webhook event types](/start/webhooks/event-types) for payload details. - **Added**: The `from` field is now captured on all message activities, so you can see the sender's phone number throughout the full message lifecycle. #### Webhook Event Filtering [#webhook-event-filtering] - **Added**: Granular webhook event filtering via the `event_filters` field. When creating or updating a webhook, you can now specify which message sub-types to receive per event type (for example, only `delivered` and `failed`) instead of subscribing to all status transitions. This reduces webhook volume for high-throughput integrations. --- ### March 2026 [#march-2026] #### Template Approval Enforcement [#template-approval-enforcement] - **Added**: Messages using WhatsApp templates that have not been approved by Meta are now blocked before dispatch, with a clear error response. Previously, unapproved templates could reach the provider and produce a delayed failure. Approved templates continue to send without any change. #### OTP Delivery via WhatsApp [#otp-delivery-via-whatsapp] - **Added**: OTP codes can now be delivered via WhatsApp. The platform waits for a delivery confirmation before reporting success, and automatically falls back to SMS if WhatsApp delivery is not confirmed within the timeout window. No API changes required. Channel selection follows your normal routing configuration. #### Account Suspension [#account-suspension] - **Added**: Accounts flagged as suspended are blocked from sending messages and receive a clear `account_suspended` error response on all API calls. This applies to both the messaging API and webhook delivery. #### Error Documentation Links [#error-documentation-links] - **Updated**: All API error responses now include a `doc_url` field pointing to the relevant documentation page for that specific error code. This makes it easier to diagnose and resolve integration issues without searching the docs manually. #### Message Metadata [#message-metadata] - **Added**: Messages now carry a `metadata` object that captures origin context (for example, the API endpoint that created the message). This field is returned in message detail and activity responses as an open JSON object. --- ### February 2026 [#february-2026] #### Per-Customer Pricing [#per-customer-pricing] - **Added**: Two billing models are now supported: **Active Contact** (charged per unique contact reached in a billing period) and **Per Message** (charged per message sent). Your account's billing model is configured at account setup. Charges are deducted automatically after each successful send. #### Number Provisioning [#number-provisioning] - **Added**: Phone numbers associated with your account are now visible via the API. Use `GET /v3/numbers/lookup/{phoneNumber}` to retrieve carrier and capability information for any number. #### Playground Message Endpoint [#playground-message-endpoint] - **Added**: A dedicated endpoint for sending test messages during onboarding, without requiring a fully provisioned profile. Useful for verifying end-to-end message delivery before going live. --- ### January 2026 [#january-2026] #### Organizations & Sender Profiles (Multi-Tenancy) [#organizations--sender-profiles-multi-tenancy] - **Added**: Full multi-tenancy support via Organizations and Sender Profiles. An Organization is the top-level account; Sender Profiles are sub-accounts that can inherit or isolate contacts, templates, brands, and campaigns from the parent organization. - **Added**: Profile CRUD: create, list, retrieve, update, and delete Sender Profiles via the API. - **Added**: `POST /v3/profiles/{id}/complete`: trigger the compliance setup workflow for a profile (TCR registration, WhatsApp connection). - **Added**: Contact and template inheritance: profiles can be configured to share contacts and templates with the parent organization (`inheritContacts`, `inheritTemplates`), or to maintain their own isolated sets. - **Added**: Template sharing: templates created at the organization level can be shared with child profiles without duplication. #### User Management [#user-management] - **Added**: Full user management for your organization: - `GET /v3/users` / `GET /v3/users/{id}`: list and retrieve users - `POST /v3/users`: invite a user by email with a specified role - `PATCH /v3/users/{id}`: update a user's role - `DELETE /v3/users/{id}`: remove a user from the organization - **Added**: Role-based access: `OWNER`, `ADMIN`, and `MEMBER` roles with appropriate permission scopes. Owners have implicit `ADMIN` access across all endpoints. - **Added**: User invitation emails with organization and profile context included in the invitation link. #### WhatsApp Template Synchronization [#whatsapp-template-synchronization] - **Added**: WhatsApp templates are now automatically synchronized from your connected WhatsApp Business Account. Template status updates (approved, rejected, paused) are reflected in real time via webhook-driven sync. No manual re-import needed. - **Added**: Template soft-deletion: when a WhatsApp Business Account is disconnected or deleted, all associated templates are soft-deleted rather than permanently removed, preserving message history. - **Added**: AUTHENTICATION template category support, including OTP and COPY_CODE button types for one-time password flows. #### Error Codes [#error-codes] - **Added**: Error code system for message sending failures. Each failure now includes a machine-readable `error_code` field in the message activity, making it straightforward to programmatically distinguish temporary failures (retry) from permanent ones (suppress). --- ## 2025 [#2025] No customer-facing API changes shipped in 2025. Development during the year went into the platform capabilities released in early 2026, including multi-tenancy (Organizations and Sender Profiles), user management, WhatsApp template synchronization, and the error code system. See the [January 2026](#january-2026) entries for details. --- ## 2024 [#2024] ### December 2024 [#december-2024] #### API v3 General Availability [#api-v3-general-availability] - **Added**: Sent API v3 is now the recommended version for all integrations - **Added**: Full API documentation for v3 endpoints - **Added**: New getting started guide for v3 ### November 2024 [#november-2024] #### Webhook Endpoints [#webhook-endpoints] - **Added**: `GET /v3/webhooks/event-types` endpoint to list available event types - **Added**: `POST /v3/webhooks/{id}/test` endpoint to test webhook delivery - **Added**: `POST /v3/webhooks/{id}/rotate-secret` endpoint for security rotation - **Added**: `PATCH /v3/webhooks/{id}/toggle-status` endpoint to toggle webhook status #### User Management [#user-management-1] - **Added**: `GET /v3/users` and `GET /v3/users/{id}` for user listing and details - **Added**: `POST /v3/users` to invite users to your organization - **Added**: `PATCH /v3/users/{id}` to update user roles - **Added**: `DELETE /v3/users/{id}` to remove users ### October 2024 [#october-2024] #### 10DLC Compliance (Brands & Campaigns) [#10dlc-compliance-brands--campaigns] **Superseded**: The standalone `/v3/brands` endpoints below no longer exist. Brand registration now flows through [Sender Profiles](/start/concepts/sender-profiles), and campaigns are managed under `/v3/profiles/{profileId}/campaigns`. - **Added**: Brand registration endpoints for 10DLC compliance (superseded; brand registration now flows through Sender Profiles) - `POST /v3/brands` - Create brand - `GET /v3/brands` - List brands - `PUT /v3/brands/{id}` - Update brand - `DELETE /v3/brands/{id}` - Delete brand - **Added**: Campaign management endpoints (paths since moved under Sender Profiles) - `POST /v3/brands/{id}/campaigns` - Create campaign (now `POST /v3/profiles/{profileId}/campaigns`) - `GET /v3/brands/{id}/campaigns` - List campaigns (now `GET /v3/profiles/{profileId}/campaigns`) - `PUT /v3/brands/{id}/campaigns/{id}` - Update campaign (now `PUT /v3/profiles/{profileId}/campaigns/{campaignId}`) - `DELETE /v3/brands/{id}/campaigns/{id}` - Delete campaign (now `DELETE /v3/profiles/{profileId}/campaigns/{campaignId}`) #### Profile Management [#profile-management] - **Added**: Full profile CRUD operations - `POST /v3/profiles` - Create profile - `GET /v3/profiles` - List profiles - `GET /v3/profiles/{id}` - Get profile details - `PATCH /v3/profiles/{id}` - Update profile - `DELETE /v3/profiles/{id}` - Delete profile - **Added**: `POST /v3/profiles/{id}/complete` for profile setup completion ### September 2024 [#september-2024] #### API v3 Beta Release [#api-v3-beta-release] - **Added**: Core messaging endpoints - `POST /v3/messages` - Send messages - `GET /v3/messages/{id}` - Get message status - `GET /v3/messages/{id}/activities` - Get message activities - **Added**: Contact management - `GET /v3/contacts` - List contacts - `POST /v3/contacts` - Create contact - `GET /v3/contacts/{id}` - Get contact - `PATCH /v3/contacts/{id}` - Update contact - `DELETE /v3/contacts/{id}` - Delete contact - **Added**: Template management - `GET /v3/templates` - List templates - `POST /v3/templates` - Create template - `GET /v3/templates/{id}` - Get template - `PUT /v3/templates/{id}` - Update template - `DELETE /v3/templates/{id}` - Delete template - **Added**: Webhook management - `GET /v3/webhooks` - List webhooks - `POST /v3/webhooks` - Create webhook - `GET /v3/webhooks/{id}` - Get webhook - `PUT /v3/webhooks/{id}` - Update webhook - `DELETE /v3/webhooks/{id}` - Delete webhook - `GET /v3/webhooks/{id}/events` - List webhook events - **Added**: Number lookup - `GET /v3/numbers/lookup/{phoneNumber}` - Look up phone number information - **Added**: Account information - `GET /v3/me` - Get authenticated account details #### New Features [#new-features] - **Added**: Sandbox mode (`sandbox: true`) for all mutation endpoints - **Added**: Idempotency key support via `Idempotency-Key` header - **Added**: Consistent JSON response envelope (`success`, `data`, `error`, `meta`) - **Added**: Standardized error codes with documentation URLs - **Added**: snake_case property naming convention - **Added**: Rate limiting with detailed response headers --- ## 2023 [#2023] ### Legacy API v2 [#legacy-api-v2] The v2 API remains fully supported for existing integrations. All v2 endpoints continue to operate at `/v2/` paths. Key v2 endpoints: - `POST /v2/messages/contact` - Send message to contact - `POST /v2/messages/phone` - Send message to phone number - `GET /v2/contacts` - List contacts - `GET /v2/templates` - List templates See [Legacy API Reference](/reference-legacy/api) for complete v2 documentation. --- ## Deprecation Notices [#deprecation-notices] ### API v2 [#api-v2] - **Status**: Legacy (still supported) - **Recommendation**: New integrations should use v3 - **End of Support**: No end date announced --- Subscribe to our [API Status](https://status.sent.dm) page for real-time updates on API changes and service status. --- ## Feedback [#feedback] Have suggestions for API improvements? Contact [support@sent.dm](mailto:support@sent.dm). --- # Channel Routing and Fallback Behavior in the Sent API (/reference/channel-routing.md) # Channel Routing and Fallback Behavior in the Sent API [#channel-routing-and-fallback-behavior-in-the-sent-api] Channel routing selects the channel (`sms`, `whatsapp`, `rcs`, or `mms`) and the underlying provider for every message accepted by `POST /v3/messages`. This page defines the accepted `channel` values, the resolution rules behind the default `sent` auto-detect channel, fallback behavior, and where the resolved channel appears in API responses, message records, and webhooks. For the design rationale behind auto-detection, see [Unified Messaging Intelligence](/start/concepts/unified-messaging). For what each channel supports, see [Channels](/start/concepts/channels). --- ## Channel Values [#channel-values] `POST /v3/messages` accepts `channel` as an array of strings. Allowed values: | Value | Behavior | |-------|----------| | `sent` | Auto-detect: routing selects the channel per recipient at send time. Default when `channel` is omitted. | | `sms` | Pins the message to SMS. | | `whatsapp` | Pins the message to WhatsApp. | | `rcs` | Pins the message to RCS. | | `mms` | Pins the message to MMS. Requires an attachment; see [MMS](/start/guides/mms). | - Omitting `channel` or sending an empty array is equivalent to `["sent"]`. - Any other value fails request validation and the request is rejected with a `400` error. - The array is a broadcast list, not a fallback priority list. Each entry creates a separate message per recipient: `"channel": ["whatsapp", "sms"]` with two recipients creates four messages. There is no `fallback` field; fallback is a property of routing, described below. - The `202` response echoes the request per message in `recipients[].channel`. Auto-detect entries appear as `"sent"`. ```bash curl -X POST https://api.sent.dm/v3/messages \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "to": ["+14155551234"], "template": { "name": "order_confirmation", "parameters": { "name": "John" } } }' ``` ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+14155551234", "channel": "sent", "body": "Hi John, your order has been confirmed." } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-25T10:30:00Z", "version": "v3" } } ``` --- ## How Auto-Detect Resolves a Channel [#how-auto-detect-resolves-a-channel] A message on the `sent` channel is matched against routing rules at send time, after the request has already been accepted with `202`. Routing rules are created and maintained by the platform from your channel setup: - Connecting a WhatsApp Business account creates an account-scoped WhatsApp route. - Activating a phone number for a destination country creates account-scoped SMS routes for that country. - A US `TEN_DLC` or `LOCAL` number also carries your traffic to the six US territories: Puerto Rico (`PR`), the US Virgin Islands (`VI`), Guam (`GU`), American Samoa (`AS`), the Northern Mariana Islands (`MP`), and the US Minor Outlying Islands (`UM`). Activating it creates a route for each, on the same number. Those routes never fall back to another sender, because a 10DLC number may carry only its own brand's traffic. - Where a territory accepts alphanumeric senders, Sent sets one up for your account the first time you send there, before the message routes. It ranks ahead of the 10DLC route and falls back to it, so the alphanumeric sender is tried first and your number is the last resort. Sent never sets one up automatically in the US or Canada, because their carriers don't deliver alphanumeric traffic. - Global rules (scoped to no account) apply to all accounts. A send never matches another account's rules. A rule matches when every dimension it constrains matches the send; a dimension the rule leaves unset matches anything. Rules can constrain the recipient (country, number prefix, exact number, carrier, number type, ported state), the sender, the template (id, name, category), the channel, and whether the send is international. Matching rules form an ordered candidate list. The ordering criteria, applied in sequence: 1. Rules pinned to the exact recipient number rank ahead of all others. 2. Rules scoped to your account rank ahead of global rules. 3. Match specificity: the share of the send's attributes the rule explicitly matches, highest first. 4. Rule priority, highest first. 5. Longer (more specific) recipient number prefix. 6. Older rule first. Rules that are inactive, deleted, or expired are excluded, as are rules whose own minimum match threshold is not met. Candidates on a channel where the message's template carries an explicit non-approved review status (for example rejected, pending, or paused) are dropped; a channel with no per-channel review recorded is not blocked. The first candidate wins: the message transitions to `ROUTED`, a `message.routed` webhook fires, and the send dispatches on the winning route. The remaining candidates stay available as fallback routes. Auto-detect applies no fixed channel preference order among rules. The winner is the best-matching rule under the preceding criteria. However, before rules are ordered, the send's content decides which channels are even eligible: a message with no attachment is ineligible for MMS, and any MMS candidate is removed from its list regardless of rules. See [Media and MMS eligibility](#media-and-mms-eligibility). If no rule matches, the message fails without a channel; see [Messages with channel auto](#messages-with-channel-auto). --- ## Media and MMS Eligibility [#media-and-mms-eligibility] Routing cannot see message content, so MMS eligibility is decided before rules are ordered rather than by a rule dimension. - A message carrying **no attachment** is not eligible for MMS on auto-detect. Any MMS candidate is removed from its list, so a text-only send is never billed as MMS, even from an account with an active MMS route. - A message **with attachments**, to a recipient in a covered market, on a template approved for MMS, keeps its MMS candidate. That candidate mirrors the SMS route on the same sender at a higher priority, so auto-detect prefers MMS over SMS on that number. - If the market is not covered or the template is not approved for MMS, the candidate is dropped and the message resolves to another channel, usually SMS. An MMS candidate that fails after routing chose it, such as one whose attachment is over 600 KB, falls through the same way. - On SMS, the attachment URL is appended to the text as a link when it fits without adding a billed segment. Otherwise the SMS carries the text alone. **This filter only applies on auto-detect.** When you name a channel explicitly (`channel: ["mms"]`), a text-only send is refused with `400` when the request is made, rather than being routed to another channel. Send text-only messages on `sms`. Attachments are supplied per send with `media_urls`, or carried by the template's `mms` body (see [Template Definition](/reference/api/template-definition#mms-body-content-object)). For the full MMS sending guide, see [MMS](/start/guides/mms). --- ## Pinned Channels [#pinned-channels] A pinned entry (`sms`, `whatsapp`, `rcs`, or `mms`) restricts matching to routes on that channel. Rules without a channel constraint still match and resolve to the pinned channel. - A pinned send never falls back to a different channel. Fallback between routes on the same channel (for example, an SMS provider hop) remains possible when the rule permits it. - If no route exists on the pinned channel, the message fails with no route matched, even when another channel could deliver to the recipient. - Pinning `mms` additionally requires an attachment, from `media_urls` or the template's `mms` body. Without one, the request is refused with `400` rather than falling back to SMS. --- ## Fallback [#fallback] ### At Send Time [#at-send-time] Fallback walks the resolved candidate list in order: - The winning candidate is attempted first. Each attempted route is recorded as a delivery attempt on the same message. - If submission to the provider fails and the candidate's rule allows fallback, the next candidate is attempted, repeating down the list. - A DENY rule that allows fallback passes the send to the next candidate. - A DENY rule that does not allow fallback ends the send as `FILTERED` with `reason_code` `DELIVERY_004` (internally `ERR_ROUTE_DENIED`), as does a candidate list in which every route is denied. The message record carries the denied route's channel. ### After a Delivery Failure [#after-a-delivery-failure] A message that a provider accepted and later reported as failed can re-enter routing: - A terminal `FAILED` delivery receipt triggers a reroute only when its error signals a route or carrier failure another route might overcome: undeliverable by this route, the carrier refusing the sender itself (for example, a network that doesn't accept alphanumeric senders), no route available to the destination network, provider service unavailable, provider timeout, or a transport error. All other failures stay `FAILED`, including an invalid number, an unreachable handset, a temporary carrier error, rate limiting, and carrier filtering. - Each reroute is a separate send attempt and is charged as one. - A WhatsApp message that Meta accepts and then reports as failed for recipient-side reasons is rerouted the same way, and a recipient-scoped rule records that WhatsApp is not deliverable for that number. This is the path behind WhatsApp-to-SMS fallback on auto-detect sends. - A reroute excludes every route already attempted and re-runs the send pipeline on the same message id, so the `QUEUED` and `ROUTED` transitions and their webhooks fire again. - A message attempts at most 3 distinct routes (channel and provider pairs) across its initial send and all reroutes. - Consent gates re-apply on every reroute; an opted-out recipient never receives a rerouted message. --- ## Choosing the Sending Number [#choosing-the-sending-number] `channels.sms` on `POST /v3/messages` is a list of entries, and the numbers in each entry's `from` are the numbers an SMS route may send from. It combines with `channel`. See [Send from specific numbers](/start/guides/sending-messages#send-from-specific-numbers) for the request shape. - **It removes candidates and never adds or promotes one.** After matching, an SMS route pinned to a number you did not list is removed. The survivors keep the order described in [How auto-detect resolves a channel](#how-auto-detect-resolves-a-channel), and the first one wins. - **Routes with no number of their own are kept.** A DENY rule that doesn't name a number still blocks the send, so listing numbers cannot be used to get around it. - **If no candidate survives**, the message fails with no route matched (`DELIVERY_003`). This happens, for example, when none of the listed numbers serves the recipient's country. - **A matching area code adds to match specificity.** An SMS route on a US or Canadian number with a geographic area code records that area code. When it matches the recipient's, the route scores higher on match specificity, so it ranks ahead of a route that otherwise matches as specifically, whatever that route's priority. A miss costs nothing: the area code never removes a route, and a recipient in another area code still reaches every number its route covers. It applies whether or not the send lists numbers. - **A number gets its route when it goes live.** A number that is still being set up has no route of its own, so a send to its country routes as if you held no number there until it is active. Before routing, each message checks that every listed number is an active SMS number on your account. If one is not, the message ends `BLOCKED` with `BUSINESS_029` and no route is attempted. The reason does not say whether the number was released, belongs to another account, or never existed. The listed numbers are stored on the message. A scheduled or quiet-hours release, a resend, and a reroute after a delivery failure apply the same list. --- ## Where the Resolved Channel Appears [#where-the-resolved-channel-appears] Internally, a message that has not yet resolved a route carries the placeholder channel `auto`. Public surfaces expose it as follows: | Surface | Before a route is chosen | After a route is attempted | |---------|--------------------------|----------------------------| | `POST /v3/messages` response, `recipients[].channel` | `sent` for auto-detect entries, otherwise the pinned channel | Not updated; the response is returned at accept time | | `message.queued`, `message.routed`, and `message.scheduled` webhooks, `payload.channel` | `sent` for auto-detect sends, otherwise the pinned channel | Fire again on a reroute | | Terminal webhooks (`message.sent`, `message.delivered`, `message.read`, `message.failed`, `message.filtered`, `message.blocked`), `payload.channel` | `auto` when the send ends before any route was chosen | The channel of the attempted route | | `GET /v3/messages/{id}`, `channel` field | `auto` for auto-detect sends, otherwise the pinned channel | The channel of the attempted route | Webhook payload shapes are documented in [Webhook event types](/start/webhooks/event-types); the status lifecycle is documented in [Message status tracking](/start/guides/message-status-tracking). --- ## Messages With Channel `auto` [#messages-with-channel-auto] A terminal message whose `channel` is `auto` ended before routing chose a channel. This occurs only on auto-detect sends; a pinned send keeps its pinned channel in every state. | Terminal status | Cause | `reason_code` | |-----------------|-------|---------------| | `FAILED` | No routing rule matched the send: no route covers this recipient for your account | `DELIVERY_003` | | `FAILED` | Required template variables missing or invalid (pre-routing validation) | `VALIDATION_008` | | `FILTERED` | Pre-routing consent gate: the recipient opted out or the number is on your suppression list | `BUSINESS_004` | | `BLOCKED` | Account precondition gate: insufficient balance, an onboarding quota, or an unapproved template | `BUSINESS_003`, `BUSINESS_020` or `BUSINESS_005` | | `BLOCKED` | A number in a `channels.sms` entry's `from` is not an active sender on your account | `BUSINESS_029` | A `FAILED` message on channel `auto` with no route matched means the recipient is not covered by any channel that is set up for your account. Routes exist once the corresponding channel setup is complete; see [Channel setup](/start/quickstart/channel-setup). Persistent delivery problems are covered in [Messages not delivered](/troubleshooting/messages-not-delivered). The `reason_code` and a `reason` sentence arrive on `GET /v3/messages/{id}` and on the message's webhook. See [Error handling](/reference/api/errors#send-time-error-codes-err_) for how the internal `ERR_*` codes map to them. # Glossary of Sent Messaging, Compliance, and API Terms (/reference/glossary.md) # Glossary of Sent Messaging, Compliance, and API Terms [#glossary-of-sent-messaging-compliance-and-api-terms] Definitions of key terms and concepts used throughout the Sent platform and documentation. ## 0–9 [#09] ### 10DLC [#10dlc] 10-Digit Long Code, the registration framework required for A2P (Application-to-Person) SMS messaging in the United States. Businesses sending automated SMS to US numbers must register a brand and campaign with The Campaign Registry (TCR); Sent submits this registration on your behalf when you complete compliance onboarding. ## A [#a] ### API Key [#api-key] Authentication token passed on every API request, in the `x-api-key` header or as `Authorization: Bearer `. Keys prefixed `sk_live_` are production keys; keys prefixed `sk_test_` are sandbox keys. ### Authentication Message [#authentication-message] WhatsApp message category for OTP codes, verification messages, and login confirmations. Usually has the lowest cost per message. ### Available Channels [#available-channels] Comma-separated list of messaging channels (for example, `"sms,whatsapp,rcs"`) that can reach a specific contact based on their phone number validation. ## B [#b] ### Balance [#balance] Account credit used to pay for messages. When a send exceeds the available balance, the API still accepts the request and the message is finalized with the `BLOCKED` status. ### Brand [#brand] The business identity registered with The Campaign Registry for 10DLC compliance, grouping contact, business, and compliance (KYC) information. Each Sender Profile has a brand, created with the profile or inherited from the organization. ### Branded Sender (RCS) [#branded-sender-rcs] The visual identity displayed in the recipient's messaging app for RCS messages, including company logo, verified business name, and a checkmark. Unlike SMS, which shows a raw phone number, RCS branded sender makes the business immediately recognizable. ### Business Account [#business-account] WhatsApp Business Account (WABA) identifier required for WhatsApp messaging integration. ## C [#c] ### Campaign [#campaign] A registered 10DLC messaging use case linked to a brand. A campaign declares one or more use cases with sample messages, plus opt-in, opt-out, and help keywords and compliance links. A campaign is a registration rather than a standalone resource with a lifecycle: there is one per market, and it is written in the `compliance.campaign` object of `POST /v3/channels/sms` or `PATCH /v3/channels/sms/{country}/{type}`. The older `/v3/profiles/{profileId}/campaigns` endpoints still work and are deprecated. ### Carousel Card (RCS) [#carousel-card-rcs] An RCS-standard message format consisting of up to 10 rich cards that the recipient can scroll through horizontally. The 10-card cap is set by the RCS/RBM platform specification, not by Sent. Sent does not currently send carousel messages. ### Channel [#channel] Communication method used to deliver messages: - **SMS**: Traditional text messaging - **WhatsApp**: Business messaging via Meta's WhatsApp Business API - **RCS**: Rich Communication Services, carrier-native rich messaging for Android (Google Messages), no separate app required ### Consent [#consent] A contact's permission to receive your messages, tracked per contact through the `opt_out` field. See Opt-Out. ### Contact [#contact] A phone number recipient in your messaging system, including validation data, available channels, and formatting information. ### Contact ID [#contact-id] Unique UUID identifier for a contact within a customer's account. ### Customer [#customer] The account entity that owns an API key. Depending on account type, a customer is an organization (has child Sender Profiles), a standalone user account, or a Sender Profile; `GET /v3/me` returns the account associated with your key. Rate limits and idempotency keys are scoped per customer. ### Customer ID [#customer-id] Unique UUID identifier for a customer account. ## D [#d] ### Default Channel [#default-channel] Preferred messaging channel for a contact, determined by phone number validation and regional settings. ## E [#e] ### E.164 Format [#e164-format] International phone number standard (for example, `+1234567890`) used as the canonical format throughout the platform. ### Endpoint [#endpoint] API route handling a specific operation (for example, `POST /v3/messages`, `GET /v3/contacts/{id}`). ## F [#f] ### Formatting [#formatting] Phone number representations in various formats: - **E.164**: `+1234567890` (canonical) - **International**: `+1 234-567-890` (human-readable) - **National**: `(234) 567-890` (country-specific) - **RFC 3966**: `tel:+1-234-567-890` (URI format) ## I [#i] ### Idempotency Key [#idempotency-key] Optional `Idempotency-Key` header accepted by POST, PUT, and PATCH requests to guarantee at-most-once execution. A key is 1–255 alphanumeric characters, hyphens, or underscores; duplicate requests with the same key return the original response. Keys are scoped per customer and responses are cached for 24 hours. ## K [#k] ### KYC (Know Your Customer) [#kyc-know-your-customer] Compliance data including business information, contact details, and use case descriptions required for messaging services. Collected as part of brand registration. ## M [#m] ### Marketing Message [#marketing-message] WhatsApp message category for promotional content and campaigns. Typically has higher cost per message and requires opt-in. ### Message Activity [#message-activity] Event log recording a message's processing steps, including channel selection, sending status, and delivery confirmation. Available via `GET /v3/messages/{id}/activities`. ### Message Body [#message-body] Final rendered content of a message after template variable substitution. ### Message Status [#message-status] The current state of a message, also called delivery status. Outbound statuses are `QUEUED`, `ROUTED`, `SENT`, `DELIVERED`, `READ` (WhatsApp and RCS only), `FAILED`, `SCHEDULED` (held for a `scheduled_at` instant or until the recipient's quiet hours end), `CANCELLED` (a held send you called off with `POST /v3/messages/{id}/cancel`, which is terminal), `FILTERED` (suppressed by a policy gate such as an opt-out or a routing deny rule), and `BLOCKED` (gated by an account precondition such as insufficient balance). Inbound messages have the status `RECEIVED`. ### MMS (Multimedia Messaging Service) [#mms-multimedia-messaging-service] The carrier channel for one image, video, document, or contact card per message, sent from the same number and under the same registration as SMS. A message goes out over MMS only when it carries an attachment. An attachment must be 600 KB or smaller. API channel value: `"mms"`. See [Sending MMS](/start/guides/mms). ## O [#o] ### Opt-Out [#opt-out] A contact's withdrawal of consent to receive messages. Opt-out is per contact, not per channel, and is exposed as the `opt_out` field on the contact. Contacts opt out by replying with keywords such as `STOP` (`START` opts back in, `HELP` requests assistance). Sends to opted-out recipients are accepted by the API but suppressed and finalized with the `FILTERED` status. ### Organization [#organization] The top-level account in Sent's multi-tenancy model. An organization owns billing, compliance, and shared resources, and contains one or more Sender Profiles that can inherit those resources. Organization API keys can act on behalf of a child profile by passing the `x-profile-id` header. ## P [#p] ### Pagination [#pagination] Structure of list responses. Paginated endpoints accept the `page` query parameter (1-indexed, default `1`) and the `page_size` query parameter (default `20`, range 1–100), and return a `pagination` object with `page`, `page_size`, `total_count`, `total_pages`, `has_more`, and optional `cursors` (`after`, `before`). ### Phone Number Validation [#phone-number-validation] Process determining if a phone number is valid, possible, and identifying its type (mobile, fixed-line, etc.). ### Pricing [#pricing] Cost structure for messages varying by channel, region, and message category (especially for WhatsApp). ## R [#r] ### RCS (Rich Communication Services) [#rcs-rich-communication-services] A carrier-native messaging protocol that enables rich media, interactive buttons, and branded Sender Profiles delivered over carrier networks directly within the Android default messaging app (Google Messages). RCS requires no separate app installation by the recipient. Like WhatsApp, RCS requires account verification, a Sender Profile, and template approval before sending. Sent automatically falls back to SMS for recipients where RCS is unavailable. API channel value: `"rcs"`. ### RCS Agent [#rcs-agent] The branded sender identity used for RCS messaging. Each business has an RCS Agent that displays a company logo, verified business name, and brand color in the recipient's Google Messages inbox, instead of a phone number like SMS. Setting up an RCS Agent requires a one-time approval process with carriers; it cannot be self-activated. ### Region Code [#region-code] ISO 3166-1 alpha-2 country code (for example, `"US"`, `"CA"`) used for pricing and channel availability. ### Rich Card (RCS) [#rich-card-rcs] An RCS-standard message format that combines a title, description, image or video, and action buttons into a single structured card. Sent does not currently send rich cards; RCS messages sent through Sent render as text with suggestion chips. ## S [#s] ### Sandbox Mode [#sandbox-mode] A request mode that validates a mutation without executing it. Set `sandbox: true` in the body of any POST, PUT, or DELETE request: authentication and validation run normally, but the request stops before execution, leaving the database, the send queue, and downstream provider APIs untouched. Sandbox responses return realistic sample data and include the `X-Sandbox: true` header. ### Segment [#segment] One unit of SMS transmission. A message longer than a single SMS (160 GSM-7 or 70 Unicode characters) is split into segments of up to 153 (GSM-7) or 67 (Unicode) characters that the recipient's phone reassembles into one message. SMS is billed per segment. ### Sender ID [#sender-id] The identity displayed as the message sender on the recipient's device. Depending on the destination country, this is an alphanumeric sender ID (for example, `MyBrand`), a phone number, or a short code. The US and Canada require a numeric sender; alphanumeric sender IDs do not support replies. ### Sender Profile [#sender-profile] A messaging identity within an organization. Each Sender Profile has its own API credentials, sending identity, and configuration. Its brand, campaign, and billing can be inherited from the organization or dedicated to the profile; its contacts, templates, and sender are always dedicated. Managed via the `/v3/sender-profiles` endpoints. The older `/v3/profiles` endpoints still work and are deprecated. ### SMS [#sms] Short Message Service - traditional text messaging. ### Suggestion Chip (RCS) [#suggestion-chip-rcs] An interactive button displayed below an RCS message that the recipient can tap. Types include quick reply (sends a predefined text back), open URL (launches a browser), and dial number (initiates a call). Suggestion chips are not available on SMS. ### System User Access Token [#system-user-access-token] Long-lived access token created in Meta Business Manager for a System User; used to link a WhatsApp Business Account with direct credentials. ## T [#t] ### Template [#template] Reusable message format supporting variable substitution, with a body of up to 1,024 characters: - **WhatsApp templates**: Must be approved by Meta before use; support rich media and interactive elements - **SMS templates**: Can be used immediately without approval ### Template Category [#template-category] Classification for message templates: - **AUTHENTICATION**: OTP and verification messages - **MARKETING**: Promotional content requiring opt-in - **UTILITY**: Transactional messages and confirmations ### Template Status [#template-status] Template approval state: `PENDING`, `APPROVED`, or `REJECTED`. ### Transaction [#transaction] Financial record tracking balance changes from message costs, payments, or refunds. ## U [#u] ### Unified Messaging Intelligence [#unified-messaging-intelligence] Sent's system for automatically selecting the optimal messaging channel based on contact validation, availability, and cost. ### Utility Message [#utility-message] WhatsApp message category for transactional content like order confirmations and delivery notifications. ### UUID (Universally Unique Identifier) [#uuid-universally-unique-identifier] 128-bit identifier format used for all entity IDs throughout the platform. ## V [#v] ### Validation [#validation] Process of verifying phone number format, reachability, and available messaging channels. ### Variable Substitution [#variable-substitution] Process of replacing placeholder values (for example, `{{1}}`, `{{name}}`) in message templates with actual content. ## W [#w] ### Webhook [#webhook] HTTPS endpoint you register to receive real-time event notifications, such as message status changes and inbound messages. Each delivery is a POST request signed with HMAC-SHA256; verify the `webhook-signature` header (`X-Webhook-Signature` on version 1 webhooks) using the endpoint's signing secret before trusting the payload. ### WhatsApp Business API [#whatsapp-business-api] Meta's business messaging platform integrated for professional messaging capabilities. # Two-Way Messaging Keywords, Channel Support, and Endpoints (/reference/two-way-messaging.md) # Two-Way Messaging Keywords, Channel Support, and Endpoints [#two-way-messaging-keywords-channel-support-and-endpoints] This page documents the fixed facts of two-way messaging: the default keyword set and matching rules, per-channel feature support, SMS provider limitations, and the conversation history endpoints. For how the inbound pipeline works and why it behaves this way, see [Two-Way Conversations](/start/guides/two-way-conversations). For webhook handler code, see [Receiving Inbound Messages](/start/webhooks/receiving-inbound-messages). --- ## Default Keywords [#default-keywords] Sent seeds ten default keywords for every account, implementing CTIA/TCPA keyword handling: | Keyword | Action | |---------|--------| | `STOP` | Opts the contact out | | `CANCEL` | Opts the contact out | | `UNSUBSCRIBE` | Opts the contact out | | `QUIT` | Opts the contact out | | `END` | Opts the contact out | | `START` | Opts the contact back in | | `UNSTOP` | Opts the contact back in | | `SUBSCRIBE` | Opts the contact back in | | `HELP` | Sends the configured help auto-reply | | `INFO` | Sends the configured help auto-reply | Opt-out flips the `opt_out` flag on the contact record; the flag is contact-level and channel-agnostic, so a keyword received on any channel suppresses the contact on all channels. ## Matching Rules [#matching-rules] - The entire trimmed message body must equal a keyword. `"STOP"` matches; `"Please stop messaging me"` does not. - Case is ignored: `stop`, `Stop`, and `STOP` all match. - Partial phrases, sentences, and free-form opt-out requests never match. - Matching runs against your full keyword list (defaults plus custom keywords) on every inbound message on a two-way capable channel. ## Custom Keywords [#custom-keywords] Custom keywords are managed in the dashboard under **Compliance → Opt Keywords**. Each keyword carries one of three actions: **Opt Out**, **Opt In**, or **Help**. Custom keywords follow the same exact-match rules as the defaults, and must be a single exact token, not a sentence. Default keywords are seeded automatically for every account and remain active alongside any custom keywords you add. ## RCS STOP Chip [#rcs-stop-chip] Sent appends a STOP suggestion chip to every outbound RCS message. - Taps on the built-in STOP chip carry opt-out postback data. The consent engine processes the postback directly and sets the contact's `opt_out` flag; keyword matching is not involved. - Chip taps are delivered to your webhook as `message.received` events with the chip's reply text in `payload.text`. There is no separate event type for chip taps. - Typed RCS replies go through standard keyword matching. --- ## Channel Support [#channel-support] | Feature | SMS | RCS | WhatsApp | |---------|:---:|:---:|:--------:| | Inbound stored as `RECEIVED` | Yes* | Yes | Yes | | Reply from same sender routing | Yes* | Yes | Yes | | Keyword detection (STOP/START/HELP) | Yes* | Yes | Yes | | Auto-reply | Yes* | Yes | Yes (free-form text within Meta's 24-hour window) | | Opt-out engine | Yes* | Yes | Yes | | Free-form send window | Ever replied, else 7 days from the last template | Ever replied, else 7 days from the last template | Meta's 24-hour window | \* SMS requires an MO-capable provider and a number type with an inbound path; see [SMS Provider Support](#sms-provider-support). WhatsApp auto-replies are delivered as free-form session text inside Meta's 24-hour conversation window, and the configured STOP/START/HELP template must be approved for the reply to send. ## Free-Form Send Windows [#free-form-send-windows] Free-form sends (`text` instead of `template` on `POST /v3/messages`) are gated by two independent windows. | | Sent's conversation rule | WhatsApp's customer-service window | |---|---|---| | Applies to | SMS, RCS, and auto-detect (`channel` omitted or `["sent"]`) | `channel: "whatsapp"` only | | Allowed when | The contact has ever replied on any channel, at any time | The contact sent an inbound WhatsApp message in the last 24 hours | | If never replied | An outbound approved template on any channel in the last 7 days | Not applicable: a template never opens Meta's window | | Does not count | Your own free-form messages; an inbound opt-out keyword; the opt-out confirmation you send back | An outbound template of any kind | | Error when shut | `CONVERSATION_TEMPLATE_REQUIRED` | `WHATSAPP_TEMPLATE_REQUIRED` | | Terminal status | `BLOCKED` | `FAILED` | Neither is an HTTP error: the send is accepted with `202` and the outcome lands on the message. `START` and `HELP` inbounds count as replies; only opt-out keywords are discounted. Behaviour and worked examples: [Conversation Windows](/start/guides/two-way-conversations#conversation-windows). ## SMS Provider Support [#sms-provider-support] | Configuration | Two-way support | |---------------|-----------------| | Long codes and short codes on a route with an inbound (MO) path | Supported | | Alphanumeric sender IDs | Not supported. Send-only; contacts cannot reply, and any attempt is dropped at the carrier level | | SMPP connections without an inbound path | Not supported. Delivery receipts only; no inbound path | On an alphanumeric sender ID, or on an SMPP route with no inbound path, inbound keywords (STOP, START, HELP) never reach Sent and are not processed. --- ## Conversation History Endpoints [#conversation-history-endpoints] Two account-scoped endpoints return message history. Both return the standard v3 envelope with a `data.messages` array and a `data.pagination` object; see [Data Models](/reference/api/data-models) for the envelope and pagination shapes. ### List Conversation Messages [#list-conversation-messages] ```bash GET /v3/conversations?page=1&page_size=20 ``` Returns a paginated list of your messages across all conversations, ordered by created date, most recent first. | Parameter | In | Type | Required | Description | |-----------|----|------|----------|-------------| | `page` | query | integer | Yes | Page number. Must be greater than 0. | | `page_size` | query | integer | Yes | Results per page. Must be between 1 and 100. | | `x-profile-id` | header | string (UUID) | No | Scopes the request to a child profile. Organization API keys only. | ### List Messages for a Conversation [#list-messages-for-a-conversation] ```bash GET /v3/conversations/{id}?page=1&page_size=20 ``` Returns a paginated list of the messages in a single conversation, ordered by created date, most recent first. Accepts the same `page`, `page_size`, and `x-profile-id` parameters. | Parameter | In | Type | Required | Description | |-----------|----|------|----------|-------------| | `id` | path | string (UUID) | Yes | The conversation id. See [Conversation IDs](#conversation-ids). | | `page` | query | integer | Yes | Page number. Must be greater than 0. | | `page_size` | query | integer | Yes | Results per page. Must be between 1 and 100. | | `x-profile-id` | header | string (UUID) | No | Scopes the request to a child profile. Organization API keys only. | ```json { "success": true, "data": { "messages": [ { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "customer_id": "41681f0a-15b4-45ab-afca-d9af35b4d3a1", "contact_id": "14b278db-6db8-448f-a5db-8d6ce46a3451", "phone": "+1234567890", "phone_international": "+1 234-567-890", "region_code": "US", "template_id": null, "template_name": null, "template_category": null, "channel": "sms", "message_body": null, "status": "DELIVERED", "direction": "OUTBOUND", "created_at": "2026-07-24T15:20:20.4343024+00:00", "price": 0.0075, "active_contact_price": 0.0, "events": null } ], "pagination": { "page": 1, "page_size": 20, "total_count": 1, "total_pages": 1, "has_more": false, "cursors": null } }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-24T15:25:20.4359817+00:00", "version": "v3" } } ``` ### Message Fields [#message-fields] | Field | Type | Description | |-------|------|-------------| | `id` | string (UUID) | Message id | | `customer_id` | string (UUID) | Your account's customer id | | `contact_id` | string (UUID) | The contact the message was exchanged with | | `phone` | string | Contact number in E.164 format | | `phone_international` | string | Contact number in international display format | | `region_code` | string | Two-letter region code of the contact number | | `template_id` | string (UUID) \| null | Template used for the message, when one was used | | `template_name` | string \| null | Name of the template used | | `template_category` | string \| null | Category of the template used | | `channel` | string | `sms`, `whatsapp`, or `rcs` | | `message_body` | object \| null | Message body content | | `status` | string | Message status, for example `DELIVERED` or `RECEIVED` | | `direction` | string | `OUTBOUND` or `INBOUND` | | `created_at` | string | ISO 8601 creation timestamp | | `price` | number \| null | Provider cost for the message | | `active_contact_price` | number \| null | Active-contact price component | | `events` | array \| null | Always `null` on the conversation endpoints; per-message status history is served by [message activities](/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesGetMessageActivitiesEndpoint) | ### Errors [#errors] | Code | Meaning | Condition | |------|---------|-----------| | `400` | Invalid request parameters | `page` is less than 1, or `page_size` is outside 1–100 | | `401` | Unauthorized | Missing or invalid API key | ### Conversation IDs [#conversation-ids] A conversation id is a deterministic RFC 4122 v5 UUID computed from your account's customer id and the contact id. It identifies one continuous thread between your account and a contact across every channel; it does not depend on the sender number or channel. | Input | Value | |-------|-------| | Namespace | `9f4e6a2c-0b1d-4c3e-8a5f-2d7e6c1b0a99` | | Name | `{customer_id}:{contact_id}`, lowercase canonical UUIDs, customer id first | | Algorithm | SHA-1 name-based UUID (version 5), equivalent to PostgreSQL's `uuid_generate_v5(namespace, name)` | The same pair always yields the same id, so you can compute a conversation id from the `customer_id` and `contact_id` fields of any message without an extra lookup. The API does not return conversation ids as a separate field. # SDK Best Practices (/sdks/best-practices.md) # SDK Best Practices [#sdk-best-practices] Build production-ready messaging integrations with Sent SDKs. This guide covers patterns for error handling, retries, testing, and security that apply across all languages. These practices are recommended for production deployments. For quick prototyping, the basic SDK usage shown in the [language-specific SDK guides](/sdks) is sufficient. ## Error Handling Strategy [#error-handling-strategy] ### Handle Errors by Type [#handle-errors-by-type] Most SDKs throw typed exceptions for errors; the Go SDK returns a typed error value instead. Handle the specific type: ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); try { const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); console.log(`Sent: ${response.data.recipients[0].message_id}`); } catch (error) { if (error instanceof SentDm.BadRequestError) { console.error('Invalid request:', error.message); } else if (error instanceof SentDm.RateLimitError) { console.error('Rate limited. Retry after:', error.headers.get('retry-after')); } else if (error instanceof SentDm.AuthenticationError) { console.error('Invalid API key'); } else if (error instanceof SentDm.APIError) { console.error(`API Error ${error.status}:`, error.message); } else { console.error('Unexpected error:', error); } } ``` ```python import sent_dm from sent_dm import Sent client = Sent() try: response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) print(f"Sent: {response.data.recipients[0].message_id}") except sent_dm.BadRequestError as e: print(f"Invalid request: {str(e)}") except sent_dm.RateLimitError as e: print(f"Rate limited. Retry after: {e.response.headers.get('retry-after')}") except sent_dm.AuthenticationError as e: print("Invalid API key") except sent_dm.APIStatusError as e: print(f"API Error {e.status_code}: {str(e)}") except sent_dm.APIError as e: print(f"Unexpected error: {e}") ``` ```java import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; import dm.sent.errors.BadRequestException; import dm.sent.errors.RateLimitException; import dm.sent.errors.UnauthorizedException; import dm.sent.errors.SentException; SentClient client = SentOkHttpClient.fromEnv(); try { MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .name("welcome") .build()) .build(); var response = client.messages().send(params); System.out.println("Sent: " + response.data().recipients().get().get(0).messageId()); } catch (BadRequestException e) { System.err.println("Invalid request: " + e.getMessage()); } catch (RateLimitException e) { System.err.println("Rate limited: " + e.getMessage()); } catch (UnauthorizedException e) { System.err.println("Invalid API key"); } catch (SentException e) { System.err.println("API Error: " + e.getMessage()); } ``` ```csharp using Sentdm; using Sentdm.Models.Messages; SentClient client = new(); try { MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new Template { ID = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Name = "welcome" } }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Sent: {response.Data.Recipients[0].MessageID}"); } catch (SentBadRequestException e) { Console.WriteLine($"Invalid request: {e.Message}"); } catch (SentRateLimitException e) { Console.WriteLine("Rate limited"); } catch (SentUnauthorizedException e) { Console.WriteLine("Invalid API key"); } catch (SentApiException e) { Console.WriteLine($"API Error: {e.Message}"); } ``` ```go import ( "errors" "github.com/sentdm/sent-dm-go" ) client := sentdm.NewClient() response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), }, }) if err != nil { var apiErr *sentdm.Error if errors.As(err, &apiErr) { switch apiErr.StatusCode { case 400: fmt.Println("Invalid request:", apiErr.Error()) case 429: fmt.Println("Rate limited") case 401: fmt.Println("Invalid API key") default: fmt.Printf("API Error %d: %s\n", apiErr.StatusCode, apiErr.Error()) } } else { fmt.Println("Network error:", err) } } else { fmt.Printf("Sent: %s\n", response.Data.Recipients[0].MessageID) } ``` ### Handle Specific Error Codes [#handle-specific-error-codes] Different errors require different handling strategies: ```typescript try { const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); console.log(`Sent: ${response.data.recipients[0].message_id}`); } catch (error) { if (error instanceof SentDm.RateLimitError) { // Back off and retry const retryAfter = parseInt(error.headers.get('retry-after') || '60', 10); await delay(retryAfter * 1000); return retry(); } if (error instanceof SentDm.BadRequestError) { // Check specific error code if available in message if (error.message.includes('TEMPLATE_001')) { // Template not found - check template ID console.error('Template not found'); } else if (error.message.includes('INSUFFICIENT_CREDITS')) { // Alert operations team await alertOpsTeam('Account balance low'); } } throw error; } ``` ```python import time import sent_dm def send_welcome(client): try: return client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) except sent_dm.RateLimitError as e: # Back off and retry retry_after = int(e.response.headers.get('retry-after', 60)) time.sleep(retry_after) return retry() except sent_dm.BadRequestError as e: # Check specific error in message if 'TEMPLATE_001' in str(e): print("Template not found") elif 'INSUFFICIENT_CREDITS' in str(e): alert_ops_team('Account balance low') raise ``` ## Retry Strategies [#retry-strategies] ### Use Built-in Retries [#use-built-in-retries] All SDKs have built-in retry logic with exponential backoff: ```typescript // Configure max retries (default is 2) const client = new SentDm({ maxRetries: 3 // Retry up to 3 times }); // Or per-request await client.messages.send(params, { maxRetries: 5 }); ``` ```python from sent_dm import Sent # Configure max retries (default is 2) client = Sent(max_retries=3) # Or per-request client.with_options(max_retries=5).messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) ``` ```go // Configure max retries (default is 2) client := sentdm.NewClient( option.WithMaxRetries(3), ) ``` ```java SentClient client = SentOkHttpClient.builder() .maxRetries(3) .build(); ``` ### Custom Retry Logic [#custom-retry-logic] For app-specific retry logic: ```typescript async function sendWithRetry( client: SentDm, params: SentDm.MessageSendParams, maxRetries = 3 ): Promise { for (let attempt = 0; attempt <= maxRetries; attempt++) { try { return await client.messages.send(params); } catch (error) { // Don't retry client errors (4xx) except rate limit if (error instanceof SentDm.BadRequestError && !(error instanceof SentDm.RateLimitError)) { throw error; } // Don't retry on last attempt if (attempt === maxRetries) { throw error; } // Exponential backoff: 1s, 2s, 4s const delayMs = Math.min(1000 * Math.pow(2, attempt), 10000); await sleep(delayMs); } } throw new Error('Unreachable'); } ``` ```python import time from sent_dm import Sent def send_with_retry( client: Sent, to: list[str], template: dict, max_retries: int = 3 ): for attempt in range(max_retries + 1): try: return client.messages.send( to=to, template=template ) except Exception as e: # Don't retry client errors (4xx) except rate limit if hasattr(e, 'status_code') and e.status_code == 429: pass # Will retry elif hasattr(e, 'status_code') and 400 <= e.status_code < 500: raise # Don't retry on last attempt if attempt == max_retries: raise # Exponential backoff: 1s, 2s, 4s delay_ms = min(1000 * (2 ** attempt), 10000) time.sleep(delay_ms / 1000) ``` ## Testing Strategies [#testing-strategies] ### Use Sandbox Mode [#use-sandbox-mode] Always use `sandbox` in development and CI/CD: All SDKs support the `sandbox` parameter to validate requests without sending real messages. Use this in development and CI/CD environments. Refer to [Testing with SDKs](/sdks/testing) for complete unit, integration, and CI/CD strategies. ```typescript // Enable sandbox mode to validate without sending const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' }, sandbox: true // Validates but doesn't send }); ``` ```python # Enable sandbox mode to validate without sending response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" }, sandbox=True # Validates but doesn't send ) ``` ```go // Enable sandbox mode to validate without sending response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), }, Sandbox: sentdm.Bool(true), // Validates but doesn't send }) ``` ```java // Enable sandbox mode to validate without sending MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .name("welcome") .build()) .sandbox(true) // Validates but doesn't send .build(); var response = client.messages().send(params); ``` ```csharp // Enable sandbox mode to validate without sending MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new Template { ID = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Name = "welcome" }, Sandbox = true // Validates but doesn't send }; var response = await client.Messages.Send(parameters); ``` ```php // Enable sandbox mode to validate without sending $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome' ], sandbox: true // Validates but doesn't send ); ``` ### Mock the SDK in Unit Tests [#mock-the-sdk-in-unit-tests] Don't make real API calls in unit tests: ```typescript // jest.mock example jest.mock('@sentdm/sentdm', () => ({ default: jest.fn().mockImplementation(() => ({ messages: { send: jest.fn().mockResolvedValue({ data: { status: 'QUEUED', recipients: [{ message_id: 'msg_123', to: '+1234567890', channel: 'sms' }] } }) } })) })); // Test your business logic it('should send welcome message on signup', async () => { await userService.signup({ phone: '+1234567890' }); // Verify the SDK method was called expect(mockSend).toHaveBeenCalledWith({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); }); ``` ```python # pytest example with unittest.mock from unittest.mock import Mock, patch def test_send_welcome_message(): mock_client = Mock() mock_client.messages.send.return_value = Mock( data=Mock( status='QUEUED', recipients=[Mock(message_id='msg_123', to='+1234567890', channel='sms')] ) ) with patch('myapp.services.SentDm', return_value=mock_client): user_service.signup(phone='+1234567890') mock_client.messages.send.assert_called_with( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome' } ) ``` ## RCS Channel Considerations [#rcs-channel-considerations] When integrating RCS into your app, keep these SDK-level patterns in mind: - **Always pair RCS with SMS fallback**: Use `channel: ["rcs", "sms"]` (or the equivalent in your SDK language) rather than `["rcs"]` alone. This ensures delivery when RCS is unavailable for a recipient without extra code in your app. - **Subscribe to `message.received`**: Inbound RCS replies (including taps on the built-in STOP chip in Google Messages) are delivered as [`message.received` webhook events](/start/webhooks/event-types). Add `"received"` to your `event_filters.message` array and inspect `payload.text` for opt-out keywords (`STOP`, `UNSUBSCRIBE`, `END`, `CANCEL`, `QUIT`). The platform also automatically flips the contact's `opt_out` flag when one is received. - **Handle `READ` status for both WhatsApp and RCS**: The `message.read` event fires for both channels. Check the `channel` field in the payload before applying channel-specific business logic (for example, closing a service ticket on WhatsApp read vs. logging engagement on RCS read). - **No number provisioning needed**: RCS does not require managing phone numbers in your SDK integration. The RCS Agent is configured in the Sent dashboard during onboarding. ## Language-Specific API Patterns [#language-specific-api-patterns] Each SDK follows the idiomatic patterns of its language. Here are the key differences: ### Method Naming Conventions [#method-naming-conventions] | Language | Method Style | Example | |----------|--------------|---------| | **TypeScript** | camelCase | `client.messages.send()` | | **Python** | snake_case | `client.messages.send()` | | **Go** | PascalCase (exported) | `client.Messages.Send()` | | **Java** | camelCase | `client.messages().send()` | | **C#** | PascalCase | `client.Messages.Send()` | | **PHP** | camelCase | `$client->messages->send()` | | **Ruby** | snake_case | `client.messages.send_` | ### Error Handling Patterns [#error-handling-patterns] **Exception-based (TypeScript, Python, Java, C#, PHP, Ruby):** - SDKs throw exceptions for API errors - Catch specific exception types for different handling - Network errors throw connection exceptions **Error return (Go):** - Go returns errors as second value - Check `err != nil` before using response - API errors are typed errors ## Webhook Security [#webhook-security] ### Always Verify Signatures [#always-verify-signatures] Never process webhooks without verifying the signature. Unsigned webhooks could be spoofed. SDKs do not ship a `verifySignature` helper. Verify the HMAC signature manually. The signing secret (from the Sent Dashboard) has a `whsec_` prefix; strip it and base64-decode the remainder to get the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and the signature format is `v1,{base64(hmac)}`. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the step-by-step verification procedure. ```typescript import { createHmac, timingSafeEqual } from 'crypto'; app.post('/webhooks/sent', express.raw({ type: 'application/json' }), (req, res) => { const payload = req.body as Buffer; // Version 2 headers first, falling back to version 1 const webhookId = (req.headers['webhook-id'] ?? req.headers['x-webhook-id']) as string; const timestamp = (req.headers['webhook-timestamp'] ?? req.headers['x-webhook-timestamp']) as string; const signature = (req.headers['webhook-signature'] ?? req.headers['x-webhook-signature']) as string; // Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" const secret = process.env.SENT_DM_WEBHOOK_SECRET!; // "whsec_abc123..." const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signed = `${webhookId}.${timestamp}.${payload.toString('utf8')}`; const expected = 'v1,' + createHmac('sha256', keyBytes).update(signed).digest('base64'); // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match const expectedBuf = Buffer.from(expected); const matches = (c: string) => Buffer.byteLength(c) === expectedBuf.length && timingSafeEqual(Buffer.from(c), expectedBuf); if (!signature || !signature.trim().split(/\s+/).some(matches)) { return res.status(401).json({ error: 'Invalid signature' }); } // Process webhook const event = JSON.parse(payload.toString()); processWebhook(event); res.json({ received: true }); }); ``` ```python import hmac import hashlib import base64 @app.route('/webhooks/sent', methods=['POST']) def webhook(): # Version 2 headers first, falling back to version 1 webhook_id = request.headers.get('webhook-id') or request.headers.get('X-Webhook-ID', '') timestamp = request.headers.get('webhook-timestamp') or request.headers.get('X-Webhook-Timestamp', '') signature = request.headers.get('webhook-signature') or request.headers.get('X-Webhook-Signature', '') payload = request.get_data() # raw bytes — do NOT parse JSON first # Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" secret = os.environ['SENT_DM_WEBHOOK_SECRET'] # "whsec_abc123..." key_bytes = base64.b64decode(secret.removeprefix('whsec_')) signed = f"{webhook_id}.{timestamp}.{payload.decode('utf-8')}" digest = hmac.new(key_bytes, signed.encode('utf-8'), hashlib.sha256).digest() expected = 'v1,' + base64.b64encode(digest).decode() # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match if not any(hmac.compare_digest(candidate, expected) for candidate in signature.split()): return jsonify({'error': 'Invalid signature'}), 401 # Process webhook event = json.loads(payload) process_webhook(event) return jsonify({'received': True}) ``` ```go func webhookHandler(w http.ResponseWriter, r *http.Request) { body, _ := io.ReadAll(r.Body) // Version 2 headers first, falling back to version 1 header := func(v2, v1 string) string { if v := r.Header.Get(v2); v != "" { return v } return r.Header.Get(v1) } webhookID := header("webhook-id", "X-Webhook-ID") timestamp := header("webhook-timestamp", "X-Webhook-Timestamp") signature := header("webhook-signature", "X-Webhook-Signature") // Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" raw := os.Getenv("SENT_DM_WEBHOOK_SECRET") // "whsec_abc123..." keyStr := strings.TrimPrefix(raw, "whsec_") keyBytes, _ := base64.StdEncoding.DecodeString(keyStr) signed := webhookID + "." + timestamp + "." + string(body) mac := hmac.New(sha256.New, keyBytes) mac.Write([]byte(signed)) expected := "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil)) // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match valid := false for _, candidate := range strings.Fields(signature) { if hmac.Equal([]byte(candidate), []byte(expected)) { valid = true break } } if !valid { http.Error(w, "Invalid signature", http.StatusUnauthorized) return } // Process webhook processWebhook(body) w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(map[string]bool{"received": true}) } ``` ### Handle Webhooks Idempotently [#handle-webhooks-idempotently] Webhook events may be delivered multiple times. Handle them idempotently: ```typescript // eventId: the `webhook-id` header (`x-webhook-event-id` on version 1), identical on every retry async function processWebhook(event: WebhookEvent, eventId: string) { // Check if already processed const existing = await db.webhookEvents.findUnique({ where: { eventId } }); if (existing) { console.log(`Event ${eventId} already processed`); return { received: true }; } // Process event await handleEvent(event); // Record as processed await db.webhookEvents.create({ data: { eventId, type: event.event, processedAt: new Date() } }); return { received: true }; } ``` ### Respond Quickly [#respond-quickly] Webhook handlers should respond quickly to avoid timeouts: ```typescript app.post('/webhooks/sent', async (req, res) => { // Verify signature if (!isValidSignature(req)) { return res.status(401).end(); } // Respond immediately res.status(200).json({ received: true }); // Process asynchronously processWebhook(req.body).catch(err => { logger.error('Webhook processing failed', err); }); }); ``` ## Performance Optimization [#performance-optimization] ### Reuse Client Instances [#reuse-client-instances] Create one client instance and reuse it across your application. Don't create a new client for each request. ```typescript // config/sent.ts import SentDm from '@sentdm/sentdm'; // Create once export const sentClient = new SentDm(); // Use everywhere import { sentClient } from './config/sent'; export async function sendMessage(params) { return sentClient.messages.send(params); } ``` ```python # config/sent.py from sent_dm import Sent # Create once sent_client = Sent() # Use everywhere from config.sent import sent_client def send_message(phone_number, template_id): return sent_client.messages.send( to=[phone_number], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": template_id } ) ``` ```go // config/sent.go var Client *sentdm.Client func init() { Client = sentdm.NewClient() } // Use everywhere import "myapp/config" func sendMessage(params sentdm.MessageSendParams) error { _, err := config.Client.Messages.Send(ctx, params) return err } ``` ```java // config/SentConfig.java @Configuration public class SentConfig { @Bean public SentClient sentClient() { return SentOkHttpClient.fromEnv(); } } // Use via injection @Service public class MessageService { private final SentClient client; public MessageService(SentClient client) { this.client = client; } } ``` ### Store Message IDs [#store-message-ids] Always store message IDs for tracking: ```typescript async function sendOrderConfirmation(order: Order) { try { const response = await client.messages.send({ to: [order.customer.phone], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'order-confirmation', parameters: { order_id: order.id } } }); // Store for webhook correlation await db.messages.create({ sentMessageId: response.data.recipients[0].message_id, orderId: order.id, status: response.data.status, sentAt: new Date() }); return response; } catch (error) { // Handle error await db.messages.create({ orderId: order.id, status: 'FAILED', error: error.message, sentAt: new Date() }); throw error; } } ``` ```python def send_order_confirmation(order): try: response = client.messages.send( to=[order.customer.phone], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'order-confirmation', 'parameters': {'order_id': order.id} } ) # Store for webhook correlation db.messages.create( sent_message_id=response.data.recipients[0].message_id, order_id=order.id, status=response.data.status, sent_at=datetime.now() ) return response except Exception as e: # Handle error db.messages.create( order_id=order.id, status='FAILED', error=str(e), sent_at=datetime.now() ) raise ``` ## Environment Management [#environment-management] ### Separate Credentials by Environment [#separate-credentials-by-environment] ```typescript // config/sent.ts const configs = { development: { apiKey: process.env.SENT_DM_API_KEY_TEST }, staging: { apiKey: process.env.SENT_DM_API_KEY_TEST }, production: { apiKey: process.env.SENT_DM_API_KEY } }; const env = (process.env.NODE_ENV as keyof typeof configs) || 'development'; export const sentClient = new SentDm(configs[env]); ``` ### Validate Configuration on Startup [#validate-configuration-on-startup] ```typescript function validateSentConfig() { if (!process.env.SENT_DM_API_KEY) { throw new Error('SENT_DM_API_KEY is required'); } if (!process.env.SENT_DM_WEBHOOK_SECRET) { console.warn('SENT_DM_WEBHOOK_SECRET not set - webhooks will fail'); } } // Run on application startup validateSentConfig(); ``` ## Summary [#summary] --- Following these practices ensures your Sent integration is reliable, secure, and maintainable at scale. --- # C# / .NET SDK (/sdks/csharp.md) # C# / .NET SDK [#c--net-sdk] The official .NET SDK for Sent provides first-class C# support with native async/await, dependency injection integration, and full compatibility with .NET Standard 2.0+. ## Requirements [#requirements] This library requires .NET Standard 2.0 or later. ## Installation [#installation] ```bash dotnet add package Sentdm ``` ```powershell Install-Package Sentdm ``` ```xml ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```csharp using Sentdm; // Configured using the SENT_DM_API_KEY environment variable SentClient client = new(); ``` ### Send your first message [#send-your-first-message] ```csharp using Sentdm; using Sentdm.Models.Messages; using System.Collections.Generic; SentClient client = new(); MessageSendParams parameters = new() { To = new List { "+1234567890" }, Channel = new List { "sms", "whatsapp", "rcs" }, Template = new Sentdm.Models.Messages.Template { ID = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Name = "welcome", Parameters = new Dictionary() { { "name", "John Doe" }, { "order_id", "12345" } } } }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Sent: {response.Data.Recipients[0].MessageID}"); Console.WriteLine($"Status: {response.Data.Status}"); ``` ## Client configuration [#client-configuration] Configure the client using environment variables or explicitly: | Property | Environment variable | Required | Default value | |----------|---------------------|----------|---------------| | `ApiKey` | `SENT_DM_API_KEY` | true | - | | `BaseUrl` | `SENT_BASE_URL` | false | `"https://api.sent.dm"` | ```csharp using Sentdm; // Using environment variables SentClient client = new(); // Or explicit configuration SentClient client = new() { ApiKey = "your_api_key", }; // Or a combination SentClient client = new() { ApiKey = "your_api_key", // Explicit // Other settings from environment }; ``` ### Modifying configuration [#modifying-configuration] To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `WithOptions`: ```csharp var clientWithOptions = client.WithOptions(options => options with { BaseUrl = "https://example.com", MaxRetries = 5, } ); ``` Using a [`with` expression](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/with-expression) makes it easy to construct the modified options. ## Send Messages [#send-messages] ### Send a message [#send-a-message] ```csharp using Sentdm.Models.Messages; MessageSendParams parameters = new() { To = new List { "+1234567890" }, Channel = new List { "sms", "whatsapp", "rcs" }, Template = new Sentdm.Models.Messages.Template { ID = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Name = "welcome", Parameters = new Dictionary() { { "name", "John Doe" }, { "order_id", "12345" } } } }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Message ID: {response.Data.Recipients[0].MessageID}"); Console.WriteLine($"Status: {response.Data.Status}"); ``` ### Sandbox mode [#sandbox-mode] Use `Sandbox = true` to validate requests without sending real messages: ```csharp MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new Sentdm.Models.Messages.Template { ID = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Name = "welcome" }, Sandbox = true // Validates but doesn't send }; var response = await client.Messages.Send(parameters); // Response will have test data Console.WriteLine($"Validation passed: {response.Data.Recipients[0].MessageID}"); ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `Direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```csharp using Sentdm.Models.Messages; var status = await client.Messages.RetrieveStatus("msg-uuid"); Console.WriteLine($"Status: {status.Data.Status}"); // e.g. "DELIVERED" Console.WriteLine($"Channel: {status.Data.Channel}"); // e.g. "sms" Console.WriteLine($"Direction: {status.Data.Direction}"); // "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```csharp var activities = await client.Messages.RetrieveActivities("msg-uuid"); foreach (var activity in activities.Data.Activities) { Console.WriteLine($"{activity.Timestamp}: {activity.Status} via {activity.From}"); Console.WriteLine($" Price: {activity.Price}"); Console.WriteLine($" Active contact price: {activity.ActiveContactPrice}"); } ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```csharp var result = await client.Numbers.Lookup("+12025551234"); Console.WriteLine($"Valid: {result.Data.IsValid}"); Console.WriteLine($"Carrier: {result.Data.CarrierName}"); Console.WriteLine($"Line type: {result.Data.LineType}"); // "mobile", "landline", "voip" Console.WriteLine($"VoIP: {result.Data.IsVoip}"); ``` ## Error handling [#error-handling] The SDK throws custom unchecked exception types. `SentApiException` is the base class for all API errors; the following subclasses are thrown per HTTP status code: | Status | Exception | |--------|-----------| | 400 | `SentBadRequestException` | | 401 | `SentUnauthorizedException` | | 403 | `SentForbiddenException` | | 404 | `SentNotFoundException` | | 422 | `SentUnprocessableEntityException` | | 429 | `SentRateLimitException` | | 5xx | `Sent5xxException` | | others | `SentUnexpectedStatusCodeException` | All 4xx exceptions also inherit from `Sent4xxException`. Catch `SentApiException` to handle any API error, as the last catch block below does: ```csharp try { var response = await client.Messages.Send(parameters); Console.WriteLine($"Sent: {response.Data.Recipients[0].MessageID}"); } catch (SentNotFoundException e) { Console.WriteLine($"Not found: {e.Message}"); } catch (SentRateLimitException e) { Console.WriteLine($"Rate limited. Retry after delay"); } catch (SentApiException e) { Console.WriteLine($"API Error: {e.Message}"); } ``` ## Raw responses [#raw-responses] To access response headers, status code, or raw body, prefix any HTTP method call with `WithRawResponse`: ```csharp var response = await client.WithRawResponse.Messages.Send(parameters); var statusCode = response.StatusCode; var headers = response.Headers; // Deserialize if needed var deserialized = await response.Deserialize(); ``` ## Retries [#retries] The SDK automatically retries 2 times by default, with a short exponential backoff between requests. Only the following error types are retried: - Connection errors - 408 Request Timeout - 409 Conflict - 429 Rate Limit - 5xx Internal ```csharp using Sentdm; // Configure for all requests SentClient client = new() { MaxRetries = 3 }; // Or per-request await client .WithOptions(options => options with { MaxRetries = 3 }) .Messages.Send(parameters); ``` ## Timeouts [#timeouts] Requests time out after 1 minute by default. ```csharp using System; using Sentdm; // Configure for all requests SentClient client = new() { Timeout = TimeSpan.FromSeconds(30) }; // Or per-request await client .WithOptions(options => options with { Timeout = TimeSpan.FromSeconds(30) }) .Messages.Send(parameters); ``` ## Contacts [#contacts] Create and manage contacts: ```csharp using Sentdm.Models.Contacts; // Create a contact ContactCreateParams createParams = new() { PhoneNumber = "+1234567890" }; var contact = await client.Contacts.Create(createParams); Console.WriteLine($"Contact ID: {contact.Data.ID}"); // List contacts ContactListParams listParams = new() { Page = 1, PageSize = 100 }; var contacts = await client.Contacts.List(listParams); foreach (var c in contacts.Data.Contacts) { Console.WriteLine($"{c.PhoneNumber} - {c.AvailableChannels}"); } // Get a contact var retrieved = await client.Contacts.Retrieve("contact-uuid"); // Update a contact ContactUpdateParams updateParams = new() { PhoneNumber = "+1987654321" }; var updated = await client.Contacts.Update("contact-uuid", updateParams); // Delete a contact await client.Contacts.Delete("contact-uuid"); ``` ## Templates [#templates] List and retrieve templates: ```csharp using Sentdm.Models.Templates; // List templates var templates = await client.Templates.List(); foreach (var template in templates.Data.Templates) { Console.WriteLine($"{template.Name} ({template.Status}): {template.ID}"); } // Get a specific template var template = await client.Templates.Retrieve("template-uuid"); Console.WriteLine($"Name: {template.Data.Name}"); Console.WriteLine($"Status: {template.Data.Status}"); ``` ## Framework Integration [#framework-integration] A dedicated guide covers client registration, message sending, validation, and testing: ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-ID` and `X-Webhook-Timestamp` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and the signature format is `v1,{base64(hmac)}`. ```csharp using System.Security.Cryptography; using System.Text; using System.Text.Json; using Microsoft.AspNetCore.Mvc; [ApiController] [Route("webhooks")] public class WebhookController : ControllerBase { [HttpPost("sent")] public async Task HandleWebhook() { // 1. Read raw body — do NOT use [FromBody] here using var ms = new MemoryStream(); await Request.Body.CopyToAsync(ms); var payload = ms.ToArray(); // Version 2 headers first, falling back to version 1 (X-Webhook-*) var webhookId = Request.Headers["webhook-id"].FirstOrDefault() ?? Request.Headers["X-Webhook-ID"].ToString(); var timestamp = Request.Headers["webhook-timestamp"].FirstOrDefault() ?? Request.Headers["X-Webhook-Timestamp"].ToString(); var signature = Request.Headers["webhook-signature"].FirstOrDefault() ?? Request.Headers["X-Webhook-Signature"].ToString(); // 2. Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" var secret = Environment.GetEnvironmentVariable("SENT_DM_WEBHOOK_SECRET")!; // "whsec_..." var keyBase64 = secret.StartsWith("whsec_") ? secret[6..] : secret; var keyBytes = Convert.FromBase64String(keyBase64); var signed = Encoding.UTF8.GetBytes($"{webhookId}.{timestamp}.{Encoding.UTF8.GetString(payload)}"); var expected = $"v1,{Convert.ToBase64String(HMACSHA256.HashData(keyBytes, signed))}"; // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match var expectedBytes = Encoding.UTF8.GetBytes(expected); if (!signature.Split(' ', StringSplitOptions.RemoveEmptyEntries).Any(candidate => CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(candidate), expectedBytes))) { return Unauthorized(new { error = "Invalid signature" }); } // 3. Optional: reject replayed events older than 5 minutes if (Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - long.Parse(timestamp)) > 300) return Unauthorized(new { error = "Timestamp too old" }); // 4. Handle events — update message status in your own database var doc = JsonDocument.Parse(payload); var field = doc.RootElement.GetProperty("field").GetString(); var eventType = doc.RootElement.TryGetProperty("event", out var et) ? et.GetString() : null; var data = doc.RootElement.GetProperty("payload"); if (field == "message") { if (eventType == "message.received") { // Inbound message from a contact var inboundNumber = data.GetProperty("inbound_number").GetString(); var outboundNumber = data.GetProperty("outbound_number").GetString(); var text = data.TryGetProperty("text", out var t) ? t.GetString() : null; var channel = data.GetProperty("channel").GetString(); var receivedAt = data.GetProperty("received_at").GetString(); // await db.InboundMessages.AddAsync(new InboundMessage { From = inboundNumber, To = outboundNumber, Text = text, ... }); } else { // Outbound message status update var messageId = data.GetProperty("message_id").GetString(); var status = data.GetProperty("message_status").GetString(); // await db.Messages.Where(m => m.SentId == Guid.Parse(messageId!)).ExecuteUpdateAsync(...) } } // 5. Always return 200 quickly return Ok(new { received = true }); } } ``` See the [Webhooks reference](/start/webhooks) for the full payload schema and all status values. ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-csharp/releases) - **GitHub**: [`sentdm/sent-dm-csharp`](https://github.com/sentdm/sent-dm-csharp) - **NuGet**: [Sentdm](https://www.nuget.org/packages/Sentdm) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-csharp/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending messages from ASP.NET Core with the Sent C# SDK (/sdks/csharp/integrations/aspnet-core.md) # Sending messages from ASP.NET Core with the Sent C# SDK [#sending-messages-from-aspnet-core-with-the-sent-c-sdk] This guide shows you how to wire Sent messaging into an existing ASP.NET Core app: install the C# SDK, register the client with dependency injection, send a template message from an endpoint, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working ASP.NET Core 8 app using minimal APIs or controllers. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the package to your existing project: ```bash dotnet add package Sentdm ``` ### Register the client with dependency injection [#register-the-client-with-dependency-injection] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Register one shared client. `new SentClient()` reads `SENT_DM_API_KEY`, and `ISentClient` (shipped with the SDK) is the seam your services and tests depend on: ```csharp // Program.cs (excerpt) using Sentdm; var builder = WebApplication.CreateBuilder(args); var sentClient = new SentClient(); builder.Services.AddSingleton(typeof(ISentClient), sentClient); var app = builder.Build(); ``` ### Send a template message from an endpoint [#send-a-template-message-from-an-endpoint] Define a request record; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```csharp // Messages/SendMessageBody.cs public record SendMessageBody( string PhoneNumber, // E.164 format, for example +14155551234 string TemplateName, // reference by Name or ID, never both Dictionary? Parameters, List? Channels, // omit to let Sent pick per recipient bool Sandbox = false); // true = validate and simulate only ``` Map the endpoint that calls `Messages.Send`: ```csharp // Program.cs (excerpt) using Sentdm.Models.Messages; app.MapPost("/api/messages/send", async (SendMessageBody body, ISentClient client, CancellationToken ct) => { var parameters = new MessageSendParams { To = new List { body.PhoneNumber }, Channel = body.Channels, Template = new Sentdm.Models.Messages.Template { Name = body.TemplateName, Parameters = body.Parameters ?? new Dictionary(), }, Sandbox = body.Sandbox, }; var result = await client.Messages.Send(parameters, ct); if (result.Success != true) { return Results.BadRequest(new { error = result.Error?.Message }); } var recipient = result.Data?.Recipients?.FirstOrDefault(); return Results.Accepted(value: new { message_id = recipient?.MessageID, status = result.Data?.Status, }); }); ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`. Delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a verification helper that checks the `webhook-signature` header against the raw request body before your handler trusts any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```csharp // Webhooks/WebhookSignature.cs using System.Security.Cryptography; using System.Text; public static class WebhookSignature { // Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" public static bool Verify(string rawBody, string webhookId, string timestamp, string signature, string? secret) { // Fail closed: never accept webhooks when the secret is not configured if (string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(signature)) { return false; } // Strip the "whsec_" prefix and base64-decode to get the raw HMAC key var keyBase64 = secret.StartsWith("whsec_") ? secret["whsec_".Length..] : secret; var keyBytes = Convert.FromBase64String(keyBase64); var signed = $"{webhookId}.{timestamp}.{rawBody}"; using var hmac = new HMACSHA256(keyBytes); var expected = "v1," + Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(signed))); // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match var expectedBytes = Encoding.UTF8.GetBytes(expected); return signature.Split(' ', StringSplitOptions.RemoveEmptyEntries).Any(candidate => CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(candidate), expectedBytes)); } } ``` Map the webhook endpoint. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; return 200 quickly and do slow work elsewhere: ```csharp // Program.cs (excerpt) using System.Text.Json.Nodes; app.MapPost("/webhooks/sent", async (HttpRequest request) => { using var reader = new StreamReader(request.Body); var rawBody = await reader.ReadToEndAsync(); // Version 2 headers first, falling back to version 1 (X-Webhook-*) var webhookId = request.Headers["webhook-id"].FirstOrDefault() ?? request.Headers["X-Webhook-ID"].ToString(); var timestamp = request.Headers["webhook-timestamp"].FirstOrDefault() ?? request.Headers["X-Webhook-Timestamp"].ToString(); var signature = request.Headers["webhook-signature"].FirstOrDefault() ?? request.Headers["X-Webhook-Signature"].ToString(); var secret = Environment.GetEnvironmentVariable("SENT_DM_WEBHOOK_SECRET"); if (!WebhookSignature.Verify(rawBody, webhookId, timestamp, signature, secret)) { return Results.Unauthorized(); } // Reject replayed events older than 5 minutes if (!long.TryParse(timestamp, out var ts) || Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) > 300) { return Results.Unauthorized(); } var evt = JsonNode.Parse(rawBody); var payload = evt?["payload"]; if ((string?)evt?["field"] == "message") { var messageId = (string?)payload?["message_id"]; var status = (string?)payload?["message_status"]; switch ((string?)evt?["event"]) // sub-type; omitted when the event has no sub-type { case "message.delivered": app.Logger.LogInformation("Message {MessageId} delivered", messageId); break; case "message.failed": app.Logger.LogError("Message {MessageId} failed (status {Status})", messageId, status); break; case "message.received": app.Logger.LogInformation("Inbound {Channel} from {From}: {Text}", (string?)payload?["channel"], (string?)payload?["inbound_number"], (string?)payload?["text"]); break; default: app.Logger.LogInformation("Message {MessageId} status: {Status}", messageId, status); break; } } return Results.Ok(new { received = true }); }); ``` Keep this endpoint outside your authentication middleware, because Sent authenticates with the signature. Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "ASP.NET Core integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash dotnet run ``` Send a sandbox message through your new endpoint (adjust the port to match your launch profile). Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:5000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phoneNumber": "+14155551234", "templateName": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your application log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If your project uses controllers instead of minimal APIs, move the endpoint bodies into actions. The SDK calls are identical; read the raw body with a `StreamReader` over `Request.Body` before model binding touches it. - If you bind settings through `IOptions`, put the API key in a `Sent` configuration section and validate it at startup. The appendix below shows the pattern. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and hand off to a background service or queue so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send free-form text instead of a template, set `Text` instead of `Template`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production ASP.NET Core stack. Adapt them to your own conventions rather than adopting them wholesale. Bind and validate configuration instead of reading environment variables directly; the host maps `Sent__ApiKey` onto `Sent:ApiKey` automatically: ```csharp // Configuration/SentOptions.cs public class SentOptions { public const string SectionName = "Sent"; [Required] public string ApiKey { get; set; } = string.Empty; public string? WebhookSecret { get; set; } public int TimeoutSeconds { get; set; } = 30; public int MaxRetries { get; set; } = 3; } ``` ```csharp // Program.cs (replace the direct registration) var sentOptions = new SentOptions(); builder.Configuration.GetSection(SentOptions.SectionName).Bind(sentOptions); if (string.IsNullOrEmpty(sentOptions.ApiKey)) { throw new InvalidOperationException("Sent:ApiKey is required"); } builder.Services.AddSingleton(sentOptions); ``` Reject malformed requests before they reach the SDK by annotating the request record: ```csharp // Messages/SendMessageBody.cs (attributes added) using System.ComponentModel.DataAnnotations; public record SendMessageBody( [property: Required, RegularExpression(@"^\+[1-9]\d{1,14}$", ErrorMessage = "Phone number must be in E.164 format")] string PhoneNumber, [property: Required, MaxLength(100)] string TemplateName, Dictionary? Parameters, List? Channels, bool Sandbox = false); ``` At the top of the endpoint, run `MiniValidator.TryValidate(body, out var errors)` (from the `MiniValidation` package) and return `Results.ValidationProblem(errors)` on failure. Cap how often callers can hit your send endpoint and standardize error responses: ```csharp // Program.cs (excerpt) builder.Services.AddProblemDetails(); builder.Services.AddRateLimiter(options => { options.AddFixedWindowLimiter("sent-api", limiterOptions => { limiterOptions.PermitLimit = 100; limiterOptions.Window = TimeSpan.FromMinutes(1); }); }); app.UseRateLimiter(); // on the endpoint: .RequireRateLimiting("sent-api") ``` The [SDK testing guide](/sdks/testing) covers substituting `ISentClient` with a mock in endpoint tests. ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [C# SDK reference](/sdks/csharp) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Go SDK (/sdks/go.md) # Go SDK [#go-sdk] The official Go SDK for Sent provides a lightweight, high-performance client with minimal dependencies. Built for microservices, CLI tools, and high-throughput applications with full context support. ## Requirements [#requirements] This library requires Go 1.22 or later. ## Installation [#installation] ```bash go get github.com/sentdm/sent-dm-go ``` To pin a specific version, append a release tag from [GitHub Releases](https://github.com/sentdm/sent-dm-go/releases): ```bash go get github.com/sentdm/sent-dm-go@ ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```go import ( "github.com/sentdm/sent-dm-go" ) // Reads the SENT_DM_API_KEY environment variable client := sentdm.NewClient() ``` ### Send your first message [#send-your-first-message] ```go package main import ( "context" "fmt" "log" "github.com/sentdm/sent-dm-go" ) func main() { // Reads the SENT_DM_API_KEY environment variable client := sentdm.NewClient() ctx := context.Background() response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), Parameters: map[string]string{ "name": "John Doe", "order_id": "12345", }, }, }) if err != nil { log.Fatal(err) } fmt.Printf("Message sent: %s\n", response.Data.Recipients[0].MessageID) fmt.Printf("Status: %s\n", response.Data.Status) } ``` ## Authentication [#authentication] The client can be configured using environment variables or explicitly using functional options: ```go import ( "github.com/sentdm/sent-dm-go" "github.com/sentdm/sent-dm-go/option" ) // Using environment variables (SENT_DM_API_KEY) client := sentdm.NewClient() // Or explicit configuration client := sentdm.NewClient( option.WithAPIKey("your_api_key"), ) ``` ## Request fields [#request-fields] The `sentdm` library follows the [`omitzero`](https://tip.golang.org/doc/go1.24#encodingjsonpkgencodingjson) serialization semantics that the Go 1.24 `encoding/json` release introduced for request fields. This is a serialization convention implemented by the library itself; the minimum supported Go version remains 1.22. Required primitive fields feature the tag `json:"...,required"`. These fields are always serialized, even their zero values. Optional primitive types are wrapped in a `param.Opt[T]`. These fields can be set with the provided constructors, `sentdm.String()`, `sentdm.Int()`, etc. ```go params := sentdm.MessageSendParams{ To: []string{"+1234567890"}, // required property Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("template-id"), Name: sentdm.String("welcome"), }, Channel: []string{"rcs", "sms"}, // optional — "rcs", "sms", "whatsapp", or combinations } ``` To send `null` instead of a `param.Opt[T]`, use `param.Null[T]()`. To check if a field is omitted, use `param.IsOmitted()`. ## Send Messages [#send-messages] ### Send a message [#send-a-message] ```go response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), Parameters: map[string]string{ "name": "John Doe", "order_id": "12345", }, }, }) if err != nil { log.Fatal(err) } fmt.Printf("Sent: %s\n", response.Data.Recipients[0].MessageID) fmt.Printf("Status: %s\n", response.Data.Status) ``` ### Sandbox mode [#sandbox-mode] Use `Sandbox` to validate requests without sending real messages: ```go response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), }, Sandbox: sentdm.Bool(true), // Validates but doesn't send }) if err != nil { log.Fatal(err) } // Response will have test data fmt.Printf("Validation passed: %s\n", response.Data.Recipients[0].MessageID) ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `Direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```go status, err := client.Messages.GetStatus(ctx, "msg-uuid", sentdm.MessageGetStatusParams{}) if err != nil { log.Fatal(err) } fmt.Printf("Status: %s\n", status.Data.Status) // e.g. "DELIVERED" fmt.Printf("Channel: %s\n", status.Data.Channel) // e.g. "sms" fmt.Printf("Direction: %s\n", status.Data.Direction) // "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```go activities, err := client.Messages.GetActivities(ctx, "msg-uuid", sentdm.MessageGetActivitiesParams{}) if err != nil { log.Fatal(err) } for _, activity := range activities.Data.Activities { fmt.Printf("%s: %s via %s\n", activity.Timestamp, activity.Status, activity.From) fmt.Printf(" Price: %s | Active contact price: %s\n", activity.Price, activity.ActiveContactPrice) } ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```go result, err := client.Numbers.Lookup(ctx, "+12025551234", sentdm.NumberLookupParams{}) if err != nil { log.Fatal(err) } fmt.Printf("Valid: %v\n", result.Data.IsValid) fmt.Printf("Carrier: %s\n", result.Data.CarrierName) fmt.Printf("Line type: %s\n", result.Data.LineType) // "mobile", "landline", "voip" fmt.Printf("VoIP: %v\n", result.Data.IsVoip) ``` ## Error handling [#error-handling] When the API returns a non-success status code, the SDK returns an error of type `*sentdm.Error`: ```go response, err := client.Messages.Send(ctx, params) if err != nil { var apiErr *sentdm.Error if errors.As(err, &apiErr) { fmt.Printf("API error: %s\n", apiErr.Error()) fmt.Printf("Status: %d\n", apiErr.StatusCode) } else { fmt.Printf("Other error: %v\n", err) } } ``` ## Pagination [#pagination] Use `.List()` to fetch a page of results. Pass `Page` and `PageSize` to control pagination: ```go page, err := client.Contacts.List(ctx, sentdm.ContactListParams{ Page: 1, PageSize: 100, }) if err != nil { log.Fatal(err) } for _, contact := range page.Data.Contacts { fmt.Printf("%s\n", contact.PhoneNumber) } ``` ## Contacts [#contacts] Create and manage contacts: ```go // Create a contact response, err := client.Contacts.New(ctx, sentdm.ContactNewParams{ PhoneNumber: "+1234567890", }) if err != nil { log.Fatal(err) } fmt.Printf("Contact ID: %s\n", response.Data.ID) // List contacts page, err := client.Contacts.List(ctx, sentdm.ContactListParams{ Page: 1, PageSize: 100, }) // Get a contact contact, err := client.Contacts.Get(ctx, "contact-uuid", sentdm.ContactGetParams{}) // Update a contact response, err = client.Contacts.Update(ctx, "contact-uuid", sentdm.ContactUpdateParams{ DefaultChannel: sentdm.String("whatsapp"), }) // Delete a contact err = client.Contacts.Delete(ctx, "contact-uuid", sentdm.ContactDeleteParams{}) ``` ## Templates [#templates] List and retrieve templates: ```go // List templates templates, err := client.Templates.List(ctx, sentdm.TemplateListParams{}) if err != nil { log.Fatal(err) } for _, template := range templates.Data.Templates { fmt.Printf("%s (%s): %s\n", template.Name, template.Status, template.ID) } // Get a template template, err := client.Templates.Get(ctx, "template-uuid", sentdm.TemplateGetParams{}) fmt.Printf("Name: %s\n", template.Data.Name) fmt.Printf("Status: %s\n", template.Data.Status) ``` ## RequestOptions [#requestoptions] This library uses the functional options pattern. Functions defined in the `option` package return a `RequestOption`, which is a closure that mutates a `RequestConfig`. These options can be supplied to the client or at individual requests: ```go client := sentdm.NewClient( // Adds a header to every request made by the client option.WithHeader("X-Some-Header", "custom_header_info"), ) // Override per-request response, err := client.Messages.Send(ctx, params, option.WithHeader("X-Some-Header", "some_other_value"), option.WithJSONSet("custom.field", map[string]string{"my": "object"}), ) ``` The request option `option.WithDebugLog(nil)` may be helpful while debugging. See the [full list of request options](https://pkg.go.dev/github.com/sentdm/sent-dm-go/option). ## Framework Integration [#framework-integration] Dedicated guides cover client setup, message sending, verified webhook handling, and sandbox testing for each framework: ## Response objects [#response-objects] All fields in response structs are ordinary value types. Response structs also include a special `JSON` field containing metadata about each property. ```go response, err := client.Templates.Get(ctx, "template-uuid", sentdm.TemplateGetParams{}) if err != nil { log.Fatal(err) } fmt.Println(response.Data.Name) // Access the field directly // Check if field was present in response if response.Data.JSON.Name.Valid() { fmt.Println("Name was present") } // Access raw JSON fmt.Println(response.Data.JSON.Name.Raw()) ``` ## Concurrent Sending [#concurrent-sending] Use Go's concurrency for high-throughput: ```go func sendBulkMessages( client *sentdm.Client, phoneNumbers []string, templateID string, ) error { var wg sync.WaitGroup errChan := make(chan error, len(phoneNumbers)) // Semaphore to limit concurrency sem := make(chan struct{}, 10) for _, phone := range phoneNumbers { wg.Add(1) go func(p string) { defer wg.Done() sem <- struct{}{} defer func() { <-sem }() ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() _, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{p}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String(templateID), }, }) if err != nil { errChan <- fmt.Errorf("failed to send to %s: %w", p, err) } }(phone) } wg.Wait() close(errChan) var errs []error for err := range errChan { errs = append(errs, err) } if len(errs) > 0 { return fmt.Errorf("failed to send %d messages", len(errs)) } return nil } ``` ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` and the `webhook-signature` header carries `v1,{base64(hmac)}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook). ```go package main import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/json" "io" "math" "net/http" "os" "strconv" "strings" "time" ) func webhookHandler(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "bad request", http.StatusBadRequest) return } // Version 2 headers first, falling back to version 1 names header := func(v2, v1 string) string { if v := r.Header.Get(v2); v != "" { return v } return r.Header.Get(v1) } webhookID := header("webhook-id", "X-Webhook-ID") timestamp := header("webhook-timestamp", "X-Webhook-Timestamp") signature := header("webhook-signature", "X-Webhook-Signature") // 1. Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" raw := os.Getenv("SENT_DM_WEBHOOK_SECRET") // "whsec_abc123..." keyStr := strings.TrimPrefix(raw, "whsec_") keyBytes, _ := base64.StdEncoding.DecodeString(keyStr) signed := webhookID + "." + timestamp + "." + string(body) mac := hmac.New(sha256.New, keyBytes) mac.Write([]byte(signed)) expected := "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil)) // Version 2 sends two signatures for 24 hours after a rotation; accept any match valid := false for _, candidate := range strings.Fields(signature) { if hmac.Equal([]byte(candidate), []byte(expected)) { valid = true } } if !valid { http.Error(w, `{"error":"invalid signature"}`, http.StatusUnauthorized) return } // 2. Optional: reject replayed events older than 5 minutes ts, _ := strconv.ParseInt(timestamp, 10, 64) if math.Abs(float64(time.Now().Unix()-ts)) > 300 { http.Error(w, `{"error":"timestamp too old"}`, http.StatusUnauthorized) return } var event struct { Field string `json:"field"` Event string `json:"event"` Payload map[string]any `json:"payload"` } json.Unmarshal(body, &event) // 3. Handle events — update message status in your own database if event.Field == "message" { if event.Event == "message.received" { // Inbound message from a contact inboundNumber := event.Payload["inbound_number"] text := event.Payload["text"] channel := event.Payload["channel"] // db.CreateInboundMessage(ctx, inboundNumber.(string), text.(string), channel.(string)) _ = inboundNumber; _ = text; _ = channel } else { // Outbound message status update messageID := event.Payload["message_id"] status := event.Payload["message_status"] // db.UpdateMessageStatus(ctx, messageID.(string), status.(string)) _ = messageID; _ = status } } // 4. Always return 200 quickly w.Header().Set("Content-Type", "application/json") w.Write([]byte(`{"received":true}`)) } ``` See the [Webhooks reference](/start/webhooks) for the full payload schema and all status values. ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-go/releases) - **GitHub**: [`sentdm/sent-dm-go`](https://github.com/sentdm/sent-dm-go) - **GoDoc**: [`pkg.go.dev/github.com/sentdm/sent-dm-go`](https://pkg.go.dev/github.com/sentdm/sent-dm-go) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-go/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending messages from an Echo service with the Sent Go SDK (/sdks/go/integrations/echo.md) # Sending messages from an Echo service with the Sent Go SDK [#sending-messages-from-an-echo-service-with-the-sent-go-sdk] This guide shows you how to wire Sent messaging into an existing Echo service: install the Go SDK, configure a shared client, send a template message from a handler, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Echo v4 service on Go 1.22+ and familiarity with handlers and groups. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing module: ```bash go get github.com/sentdm/sent-dm-go ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Create one shared client at startup and pass it to your handlers: ```go // main.go (excerpt) client := sentdm.NewClient( option.WithAPIKey(os.Getenv("SENT_DM_API_KEY")), ) ``` The imports are `github.com/sentdm/sent-dm-go` and `github.com/sentdm/sent-dm-go/option`. The client is safe for concurrent use; one instance serves the whole process. ### Send a template message from a handler [#send-a-template-message-from-a-handler] Add a handler that binds the request and calls `Messages.Send`; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```go // internal/handler/message.go package handler import ( "context" "net/http" "time" "github.com/labstack/echo/v4" "github.com/sentdm/sent-dm-go" ) type SendMessageRequest struct { To []string `json:"to"` // E.164 numbers TemplateName string `json:"template_name"` // or template_id, never both Parameters map[string]string `json:"parameters,omitempty"` Channels []string `json:"channels,omitempty"` Sandbox bool `json:"sandbox"` // true = validate and simulate only } type MessageHandler struct { client *sentdm.Client } func NewMessageHandler(client *sentdm.Client) *MessageHandler { return &MessageHandler{client: client} } func (h *MessageHandler) Register(e *echo.Echo) { e.POST("/api/messages/send", h.SendMessage) } func (h *MessageHandler) SendMessage(c echo.Context) error { var req SendMessageRequest if err := c.Bind(&req); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } if len(req.To) == 0 || req.TemplateName == "" { return echo.NewHTTPError(http.StatusBadRequest, "to and template_name are required") } ctx, cancel := context.WithTimeout(c.Request().Context(), 30*time.Second) defer cancel() response, err := h.client.Messages.Send(ctx, sentdm.MessageSendParams{ To: req.To, Template: sentdm.MessageSendParamsTemplate{ Name: sentdm.String(req.TemplateName), Parameters: req.Parameters, }, Channel: req.Channels, // omit to let Sent pick per recipient Sandbox: sentdm.Bool(req.Sandbox), }) if err != nil { return echo.NewHTTPError(http.StatusBadGateway, err.Error()) } recipient := response.Data.Recipients[0] return c.JSON(http.StatusAccepted, map[string]string{ "message_id": recipient.MessageID, "status": response.Data.Status, }) } ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`: delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a webhook handler that verifies the `webhook-signature` header against the raw request body before trusting any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them: ```go // internal/handler/webhook.go package handler import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/json" "io" "log/slog" "net/http" "os" "strings" "time" "github.com/labstack/echo/v4" ) // WebhookEvent is the envelope Sent posts to your endpoint. Event names the specific // event (for example, "message.delivered"); it is omitted on events that have no sub-type. type WebhookEvent struct { Field string `json:"field"` Event string `json:"event,omitempty"` Timestamp time.Time `json:"timestamp"` Payload WebhookPayload `json:"payload"` } type WebhookPayload struct { MessageID string `json:"message_id,omitempty"` MessageStatus string `json:"message_status,omitempty"` Channel string `json:"channel,omitempty"` InboundNumber string `json:"inbound_number,omitempty"` Text string `json:"text,omitempty"` } type WebhookHandler struct { secret string logger *slog.Logger } func NewWebhookHandler(logger *slog.Logger) *WebhookHandler { return &WebhookHandler{secret: os.Getenv("SENT_DM_WEBHOOK_SECRET"), logger: logger} } func (h *WebhookHandler) Register(e *echo.Echo) { e.POST("/webhooks/sent", h.HandleWebhook) } // verifySignature: strip the "whsec_" prefix, base64-decode the remainder to get // the raw key, sign "{webhookID}.{timestamp}.{rawBody}" with HMAC-SHA256, and // compare against each "v1,{base64(hmac)}" token in the header using a constant-time // check. Version 2 sends two tokens for 24 hours after a rotation; accept any match. func (h *WebhookHandler) verifySignature(webhookID, timestamp string, body []byte, signature string) bool { if h.secret == "" { return false // fail closed when the secret is not configured } keyBytes, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(h.secret, "whsec_")) if err != nil { return false } mac := hmac.New(sha256.New, keyBytes) mac.Write([]byte(webhookID + "." + timestamp + "." + string(body))) expected := "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil)) for _, candidate := range strings.Fields(signature) { if hmac.Equal([]byte(candidate), []byte(expected)) { return true } } return false } // header reads a version 2 header, falling back to its version 1 name. func header(r *http.Request, v2, v1 string) string { if v := r.Header.Get(v2); v != "" { return v } return r.Header.Get(v1) } func (h *WebhookHandler) HandleWebhook(c echo.Context) error { body, err := io.ReadAll(c.Request().Body) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, "failed to read body") } webhookID := header(c.Request(), "webhook-id", "X-Webhook-ID") timestamp := header(c.Request(), "webhook-timestamp", "X-Webhook-Timestamp") signature := header(c.Request(), "webhook-signature", "X-Webhook-Signature") if !h.verifySignature(webhookID, timestamp, body, signature) { return echo.NewHTTPError(http.StatusUnauthorized, "invalid signature") } var event WebhookEvent if err := json.Unmarshal(body, &event); err != nil { return echo.NewHTTPError(http.StatusBadRequest, "invalid JSON") } if event.Field == "message" { switch event.Event { case "message.delivered": h.logger.Info("message delivered", slog.String("message_id", event.Payload.MessageID)) case "message.failed": h.logger.Error("message failed", slog.String("message_id", event.Payload.MessageID), slog.String("status", event.Payload.MessageStatus)) case "message.received": h.logger.Info("inbound message", slog.String("from", event.Payload.InboundNumber), slog.String("text", event.Payload.Text)) default: h.logger.Info("message status updated", slog.String("message_id", event.Payload.MessageID), slog.String("status", event.Payload.MessageStatus)) } } return c.JSON(http.StatusOK, map[string]bool{"received": true}) } ``` Register the handler outside any authentication middleware, because Sent authenticates with the signature. Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Echo integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret` (put it in `SENT_DM_WEBHOOK_SECRET`). The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the service with your credentials loaded: ```bash go run ./cmd/api ``` Send a sandbox message through your new handler. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:8080/api/messages/send \ -H "Content-Type: application/json" \ -d '{"to": ["+14155551234"], "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your service log should show a `message delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you use Echo's `Validator` interface with `go-playground/validator`, move the required-field checks into struct tags and call `c.Validate(&req)` after binding. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and process in a goroutine or job queue so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send to many recipients, pass them all in `To`. Sent creates one message per recipient-and-channel pair in a single call. - To send free-form text instead of a template, set `Text` instead of `Template`. Each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Echo service. Adapt them to your own conventions rather than adopting them wholesale. Put the SDK behind a small interface so handlers can be tested with a mock: ```go // internal/service/message.go type MessageSender interface { SendMessage(ctx context.Context, req *SendMessageRequest) (*SendMessageResult, error) } ``` Assert against the mock in handler tests; the [SDK testing guide](/sdks/testing) covers sandbox-based integration tests. Wire zap or slog through Echo's middleware chain, with recovery and request IDs: ```go // main.go (excerpt) e := echo.New() e.Use(middleware.Recover()) e.Use(middleware.RequestID()) e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ LogStatus: true, LogURI: true, LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error { logger.Info("request", slog.String("uri", v.URI), slog.Int("status", v.Status)) return nil }, })) ``` Drain in-flight requests on shutdown and ship a minimal image: ```go // main.go (excerpt) go func() { if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) { e.Logger.Fatal(err) } }() quit := make(chan os.Signal, 1) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) <-quit ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() _ = e.Shutdown(ctx) ``` ```dockerfile FROM golang:1.23-alpine AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/api FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=builder /app/main . EXPOSE 8080 CMD ["./main"] ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Go SDK reference](/sdks/go) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sending messages from a Gin service with the Sent Go SDK (/sdks/go/integrations/gin.md) # Sending messages from a Gin service with the Sent Go SDK [#sending-messages-from-a-gin-service-with-the-sent-go-sdk] This guide shows you how to wire Sent messaging into an existing Gin service: install the Go SDK, configure a shared client, send a template message from a handler, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Gin service on Go 1.22+ and familiarity with handlers and middleware. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing module: ```bash go get github.com/sentdm/sent-dm-go ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Create one shared client at startup and pass it to your handlers: ```go // main.go (excerpt) client := sentdm.NewClient( option.WithAPIKey(os.Getenv("SENT_DM_API_KEY")), ) ``` The imports are `github.com/sentdm/sent-dm-go` and `github.com/sentdm/sent-dm-go/option`. The client is safe for concurrent use; one instance serves the whole process. ### Send a template message from a handler [#send-a-template-message-from-a-handler] Add a handler that binds the request and calls `Messages.Send`; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```go // internal/handlers/message_handler.go package handlers import ( "context" "net/http" "time" "github.com/gin-gonic/gin" "github.com/sentdm/sent-dm-go" ) type SendMessageRequest struct { To []string `json:"to" binding:"required,min=1"` // E.164 numbers TemplateName string `json:"template_name" binding:"required"` // or template_id, never both Parameters map[string]string `json:"parameters,omitempty"` Channels []string `json:"channels,omitempty" binding:"dive,oneof=sms whatsapp rcs"` Sandbox bool `json:"sandbox"` // true = validate and simulate only } type MessageHandler struct { client *sentdm.Client } func NewMessageHandler(client *sentdm.Client) *MessageHandler { return &MessageHandler{client: client} } func (h *MessageHandler) SendMessage(c *gin.Context) { var req SendMessageRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second) defer cancel() response, err := h.client.Messages.Send(ctx, sentdm.MessageSendParams{ To: req.To, Template: sentdm.MessageSendParamsTemplate{ Name: sentdm.String(req.TemplateName), Parameters: req.Parameters, }, Channel: req.Channels, // omit to let Sent pick per recipient Sandbox: sentdm.Bool(req.Sandbox), }) if err != nil { c.JSON(http.StatusBadGateway, gin.H{"error": err.Error()}) return } recipient := response.Data.Recipients[0] c.JSON(http.StatusAccepted, gin.H{ "message_id": recipient.MessageID, "status": response.Data.Status, }) } ``` Register the route on your engine: ```go router.POST("/api/messages/send", messageHandler.SendMessage) ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`: delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a webhook handler that verifies the `webhook-signature` header against the raw request body before trusting any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them: ```go // internal/handlers/webhook_handler.go package handlers import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/json" "io" "log/slog" "net/http" "os" "strings" "time" "github.com/gin-gonic/gin" ) // WebhookEvent is the envelope Sent posts to your endpoint. Event names the specific // event (for example, "message.delivered"); it is omitted on events that have no sub-type. type WebhookEvent struct { Field string `json:"field"` Event string `json:"event,omitempty"` Timestamp time.Time `json:"timestamp"` Payload WebhookPayload `json:"payload"` } type WebhookPayload struct { MessageID string `json:"message_id,omitempty"` MessageStatus string `json:"message_status,omitempty"` Channel string `json:"channel,omitempty"` InboundNumber string `json:"inbound_number,omitempty"` Text string `json:"text,omitempty"` } type WebhookHandler struct { secret string logger *slog.Logger } func NewWebhookHandler(logger *slog.Logger) *WebhookHandler { return &WebhookHandler{secret: os.Getenv("SENT_DM_WEBHOOK_SECRET"), logger: logger} } // verifySignature: strip the "whsec_" prefix, base64-decode the remainder to get // the raw key, sign "{webhookID}.{timestamp}.{rawBody}" with HMAC-SHA256, and // compare against each "v1,{base64(hmac)}" token in the header using a constant-time // check. Version 2 sends two tokens for 24 hours after a rotation; accept any match. func (h *WebhookHandler) verifySignature(webhookID, timestamp string, body []byte, signature string) bool { if h.secret == "" { return false // fail closed when the secret is not configured } keyBytes, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(h.secret, "whsec_")) if err != nil { return false } mac := hmac.New(sha256.New, keyBytes) mac.Write([]byte(webhookID + "." + timestamp + "." + string(body))) expected := "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil)) for _, candidate := range strings.Fields(signature) { if hmac.Equal([]byte(candidate), []byte(expected)) { return true } } return false } // header reads a version 2 header, falling back to its version 1 name. func header(r *http.Request, v2, v1 string) string { if v := r.Header.Get(v2); v != "" { return v } return r.Header.Get(v1) } func (h *WebhookHandler) HandleWebhook(c *gin.Context) { body, err := io.ReadAll(c.Request.Body) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "failed to read body"}) return } webhookID := header(c.Request, "webhook-id", "X-Webhook-ID") timestamp := header(c.Request, "webhook-timestamp", "X-Webhook-Timestamp") signature := header(c.Request, "webhook-signature", "X-Webhook-Signature") if !h.verifySignature(webhookID, timestamp, body, signature) { c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid signature"}) return } var event WebhookEvent if err := json.Unmarshal(body, &event); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid JSON"}) return } if event.Field == "message" { switch event.Event { case "message.delivered": h.logger.Info("message delivered", slog.String("message_id", event.Payload.MessageID)) case "message.failed": h.logger.Error("message failed", slog.String("message_id", event.Payload.MessageID), slog.String("status", event.Payload.MessageStatus)) case "message.received": h.logger.Info("inbound message", slog.String("from", event.Payload.InboundNumber), slog.String("text", event.Payload.Text)) default: h.logger.Info("message status updated", slog.String("message_id", event.Payload.MessageID), slog.String("status", event.Payload.MessageStatus)) } } c.JSON(http.StatusOK, gin.H{"received": true}) } ``` Register the route outside any authentication middleware, because Sent authenticates with the signature: ```go router.POST("/webhooks/sent", webhookHandler.HandleWebhook) ``` Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Gin integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret` (put it in `SENT_DM_WEBHOOK_SECRET`). The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the service with your credentials loaded: ```bash go run ./cmd/api ``` Send a sandbox message through your new handler. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:8080/api/messages/send \ -H "Content-Type: application/json" \ -d '{"to": ["+14155551234"], "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your service log should show a `message delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If your service wraps dependencies in a service layer, move the `Messages.Send` call behind an interface so tests can mock it. The appendix below shows the seam. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and process in a goroutine or job queue so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send to many recipients, pass them all in `To`. Sent creates one message per recipient-and-channel pair in a single call. - To send free-form text instead of a template, set `Text` instead of `Template`. Each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Gin service. Adapt them to your own conventions rather than adopting them wholesale. Load typed configuration and bind the standard Sent variable names to nested keys: ```go // internal/config/config.go viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() _ = viper.BindEnv("sent.api_key", "SENT_DM_API_KEY") _ = viper.BindEnv("sent.webhook_secret", "SENT_DM_WEBHOOK_SECRET") ``` Put the SDK behind a small interface so handlers can be tested with a mock: ```go // internal/service/message_service.go type MessageSender interface { SendMessage(ctx context.Context, req *SendMessageRequest) (*SendMessageResult, error) } ``` Assert against the mock in handler tests; the [SDK testing guide](/sdks/testing) covers sandbox-based integration tests. Cap per-IP request rates with `golang.org/x/time/rate`, log with request IDs, and drain in-flight requests on shutdown: ```go // main.go (excerpt) srv := &http.Server{Addr: ":8080", Handler: router, ReadTimeout: 30 * time.Second} go func() { if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { logger.Error("server failed", slog.String("error", err.Error())) os.Exit(1) } }() quit := make(chan os.Signal, 1) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) <-quit ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() _ = srv.Shutdown(ctx) ``` Build a static binary and ship a minimal image; credentials come in as environment variables at run time: ```dockerfile FROM golang:1.23-alpine AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/api FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=builder /app/main . EXPOSE 8080 CMD ["./main"] ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Go SDK reference](/sdks/go) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sent SDKs (/sdks.md) # Sent SDKs [#sent-sdks] Build messaging into your app in minutes. The official Sent SDKs provide idiomatic, type-safe clients for every major language, with automatic retries, webhook signature verification, and intelligent error handling built in. **New to Sent?** Start with the [Quickstart Guide](/start/quickstart) to set up your account and send your first message. ## Prerequisites [#prerequisites] Before using any SDK, you'll need: 1. **A Sent account** - Sign up at [app.sent.dm](https://app.sent.dm) 2. **An API key** - Get yours from the [Sent Dashboard](https://app.sent.dm/dashboard/api-keys) 3. **A template** - Create a message template in the dashboard (WhatsApp templates require approval) **Environment Variable:** All SDKs use `SENT_DM_API_KEY` for authentication. Set this in your environment before running your application. ## Why Use the SDKs? [#why-use-the-sdks] } description="Full type definitions for TypeScript, Python, Go, Java, C#, PHP, and Ruby. Catch errors at compile time." /> } description="Automatic exponential backoff for rate limits and transient failures. Configurable retry policies." /> } description="Built-in signature verification to ensure webhook events are authentic and untampered." /> } description="Most SDKs have zero external dependencies. Just install and start sending messages." /> ## Official SDKs [#official-sdks] } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ## Quick Comparison [#quick-comparison] See how simple it is to send a message in each language: ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); // Uses SENT_DM_API_KEY env var const response = await client.messages.send({ to: ['+1234567890'], template: { id: 'your-template-id', name: 'welcome' }, // sandbox: true, // Uncomment to test without sending }); console.log(`Sent: ${response.data.recipients[0].message_id}`); ``` ```python from sent_dm import Sent client = Sent() # Uses SENT_DM_API_KEY env var response = client.messages.send( to=["+1234567890"], template={ "id": "your-template-id", "name": "welcome" }, # sandbox=True, # Uncomment to test without sending ) print(f"Sent: {response.data.recipients[0].message_id}") ``` ```go import ( "github.com/sentdm/sent-dm-go" "github.com/sentdm/sent-dm-go/option" ) client := sentdm.NewClient() // Uses SENT_DM_API_KEY env var response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("your-template-id"), Name: sentdm.String("welcome"), }, // Sandbox: sentdm.Bool(true), // Uncomment to test without sending }) ``` ```java import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; import dm.sent.models.messages.MessageSendParams; import dm.sent.models.messages.MessageSendResponse; SentClient client = SentOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("your-template-id") .build()) // .sandbox(true) // Uncomment to test without sending .build(); MessageSendResponse response = client.messages().send(params); System.out.println("Sent: " + response.data().recipients().get().get(0).messageId()); ``` ```csharp using Sentdm; using Sentdm.Models.Messages; SentClient client = new(); // Uses SENT_DM_API_KEY env var var response = await client.Messages.Send(new MessageSendParams { To = new List { "+1234567890" }, Template = new Template { ID = "your-template-id" }, // Sandbox = true, // Uncomment to test without sending }); Console.WriteLine($"Sent: {response.Data.Recipients[0].MessageID}"); ``` ```php use SentDm\Client; $client = new Client($_ENV['SENT_DM_API_KEY']); $response = $client->messages->send( to: ['+1234567890'], template: [ 'id' => 'your-template-id', 'name' => 'welcome' ], // sandbox: true, // Uncomment to test without sending ); echo "Sent: {$response->data->recipients[0]->messageID}\n"; ``` ```ruby require "sentdm" sent_dm = Sentdm::Client.new # Uses SENT_DM_API_KEY env var response = sent_dm.messages.send_( to: ['+1234567890'], template: { id: 'your-template-id', name: 'welcome' }, # sandbox: true, # Uncomment to test without sending ) puts "Sent: #{response.data.recipients[0].message_id}" ``` ```rust use sent::models::SendMessageV3Request; use sent::Client; let client = Client::from_env()?; // Reads SENT_API_KEY let request: SendMessageV3Request = serde_json::from_value(serde_json::json!({ "to": ["+1234567890"], "template": { "id": "your-template-id", "name": "welcome" } // "sandbox": true, // Uncomment to test without sending }))?; let sent = client.messages().send(&request).await?; println!("Sent: {:?}", sent.recipients.unwrap_or_default()[0].message_id); ``` **Note:** Each SDK follows its language's conventions. Method names, parameter styles, and error handling vary by language. See the individual SDK pages for detailed documentation. All SDKs support RCS via `channel: ["rcs"]` or `channel: ["rcs", "sms"]` (RCS with SMS fallback). No additional setup is needed in your code once your RCS Agent is approved. **Testing:** Use `sandbox: true` (or `sandbox=True` in Python) in development to validate requests without sending real messages. The API will validate your request but not actually send any messages. ## SDK Versions [#sdk-versions] Each SDK is versioned independently. Find the current version and changelog for each SDK on its GitHub Releases page: | Language | Package | Releases & changelog | |----------|---------|----------------------| | **TypeScript** | `@sentdm/sentdm` | [GitHub Releases](https://github.com/sentdm/sent-dm-typescript/releases) | | **Python** | `sentdm` | [GitHub Releases](https://github.com/sentdm/sent-dm-python/releases) | | **Go** | `github.com/sentdm/sent-dm-go` | [GitHub Releases](https://github.com/sentdm/sent-dm-go/releases) | | **Java** | `dm.sent:sent-java` | [GitHub Releases](https://github.com/sentdm/sent-dm-java/releases) | | **C#** | `Sentdm` | [GitHub Releases](https://github.com/sentdm/sent-dm-csharp/releases) | | **PHP** | `sentdm/sent-dm-php` | [GitHub Releases](https://github.com/sentdm/sent-dm-php/releases) | | **Ruby** | `sentdm` | [GitHub Releases](https://github.com/sentdm/sent-dm-ruby/releases) | | **Voice (Browser)** | `@sentdm/voice-client`, `@sentdm/voice-client-react` | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-typescript/releases) | | **Voice (iOS)** | `sent-dm-voice-swift` (Swift package) | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-swift/releases) | | **Voice (Android)** | `dm.sent:voice-client` | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-kotlin/releases) | | **Voice Agents (Python)** | `sentdm-voice-agents` | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-agents-python/releases) | | **Voice Agents (TypeScript)** | `@sentdm/voice-agents` | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-agents-typescript/releases) | | **Voice Agents (.NET)** | `SentDm.Voice.Agents` | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-agents-dotnet/releases) | | **Voice Agents (Go)** | `github.com/sentdm/sent-dm-voice-agents-go` | [GitHub Releases](https://github.com/sentdm/sent-dm-voice-agents-go/releases) | ## Framework Quickstarts [#framework-quickstarts] Get up and running quickly with popular frameworks: } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ## Installation [#installation] All SDKs are available through standard package managers: ```bash npm install @sentdm/sentdm ``` ```bash pip install sentdm ``` ```bash go get github.com/sentdm/sent-dm-go ``` ```xml dm.sent sent-java x.y.z ``` ```bash dotnet add package Sentdm ``` ```bash composer require sentdm/sent-dm-php ``` ```bash gem install sentdm ``` ```bash cargo add sent tokio --features tokio/full ``` ## Open Source [#open-source] All Sent SDKs are open source and available on GitHub: - [TypeScript SDK](https://github.com/sentdm/sent-dm-typescript) - [Python SDK](https://github.com/sentdm/sent-dm-python) - [Go SDK](https://github.com/sentdm/sent-dm-go) - [Java SDK](https://github.com/sentdm/sent-dm-java) - [C# SDK](https://github.com/sentdm/sent-dm-csharp) - [PHP SDK](https://github.com/sentdm/sent-dm-php) - [Ruby SDK](https://github.com/sentdm/sent-dm-ruby) **Contributions welcome!** Found a bug or want to add a feature? We accept pull requests on all SDK repositories. --- # Java SDK (/sdks/java.md) # Java SDK [#java-sdk] The official Java SDK for Sent provides an enterprise-ready client with full support for synchronous and asynchronous operations. Built for Spring Boot, Jakarta EE, and standalone applications with builder patterns throughout. ## Requirements [#requirements] This library requires Java 8 or later. ## Installation [#installation] ```xml dm.sent sent-java x.y.z ``` ```kotlin // Use the latest version from https://github.com/sentdm/sent-dm-java/releases implementation("dm.sent:sent-java:x.y.z") ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```java import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; // Configures using the `sent.dmApiKey` system property // Or configures using the `SENT_DM_API_KEY` environment variable SentClient client = SentOkHttpClient.fromEnv(); ``` ### Send your first message [#send-your-first-message] ```java import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; import dm.sent.core.JsonValue; import dm.sent.models.messages.MessageSendParams; import dm.sent.models.messages.MessageSendResponse; SentClient client = SentOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addChannel("sms") .addChannel("whatsapp") .addChannel("rcs") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .name("order_confirmation") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("name", JsonValue.from("John Doe")) .putAdditionalProperty("order_id", JsonValue.from("12345")) .build()) .build()) .build(); MessageSendResponse response = client.messages().send(params); System.out.println("Sent: " + response.data().recipients().get().get(0).messageId()); System.out.println("Status: " + response.data().status()); ``` ## Client configuration [#client-configuration] Configure the client using system properties or environment variables: | Setter | System property | Environment variable | Required | Default value | |--------|-----------------|----------------------|----------|---------------| | `apiKey` | `sent.dmApiKey` | `SENT_DM_API_KEY` | true | - | | `baseUrl` | `sent.baseUrl` | `SENT_BASE_URL` | false | `"https://api.sent.dm"` | System properties take precedence over environment variables. ```java import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; // From environment variables SentClient client = SentOkHttpClient.fromEnv(); // Or manually configure SentClient client = SentOkHttpClient.builder() .apiKey("your_api_key") .build(); // Or combine both approaches SentClient client = SentOkHttpClient.builder() .fromEnv() .apiKey("overridden_api_key") .build(); ``` Don't create more than one client in the same application. Each client has a connection pool and thread pools, which are more efficient to share between requests. ## Send Messages [#send-messages] ### Send a message [#send-a-message] ```java import dm.sent.core.JsonValue; import dm.sent.models.messages.MessageSendParams; import dm.sent.models.messages.MessageSendResponse; MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addChannel("sms") .addChannel("whatsapp") .addChannel("rcs") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .name("order_confirmation") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("name", JsonValue.from("John Doe")) .putAdditionalProperty("order_id", JsonValue.from("12345")) .build()) .build()) .build(); MessageSendResponse response = client.messages().send(params); System.out.println("Message ID: " + response.data().recipients().get().get(0).messageId()); System.out.println("Status: " + response.data().status()); ``` ### Sandbox mode [#sandbox-mode] Use `sandbox(true)` to validate requests without sending real messages: ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .name("order_confirmation") .build()) .sandbox(true) // Validates but doesn't send .build(); MessageSendResponse response = client.messages().send(params); // Response will have test data System.out.println("Validation passed: " + response.data().recipients().get().get(0).messageId()); ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```java import dm.sent.models.messages.MessageRetrieveStatusResponse; MessageRetrieveStatusResponse status = client.messages().retrieveStatus("msg-uuid"); System.out.println("Status: " + status.data().status()); // e.g. "DELIVERED" System.out.println("Channel: " + status.data().channel()); // e.g. "sms" System.out.println("Direction: " + status.data().direction()); // "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```java import dm.sent.models.messages.MessageRetrieveActivitiesResponse; MessageRetrieveActivitiesResponse activities = client.messages().retrieveActivities("msg-uuid"); activities.data().activities().forEach(activity -> { System.out.println(activity.timestamp() + ": " + activity.status() + " via " + activity.from()); System.out.println(" Price: " + activity.price()); System.out.println(" Active contact price: " + activity.activeContactPrice()); }); ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```java import dm.sent.models.numbers.NumberLookupResponse; NumberLookupResponse result = client.numbers().lookup("+12025551234"); System.out.println("Carrier: " + result.data().carrierName()); System.out.println("Line type: " + result.data().lineType()); // "mobile", "landline", "voip" System.out.println("VoIP: " + result.data().isVoip()); ``` ## Asynchronous execution [#asynchronous-execution] The default client is synchronous. To switch to asynchronous execution, call the `async()` method: ```java import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; import dm.sent.models.messages.MessageSendParams; import dm.sent.models.messages.MessageSendResponse; import java.util.concurrent.CompletableFuture; SentClient client = SentOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .build()) .build(); CompletableFuture future = client.async().messages().send(params); // Handle result future.thenAccept(response -> { System.out.println("Sent: " + response.data().recipients().get().get(0).messageId()); }).exceptionally(throwable -> { System.err.println("Failed: " + throwable.getMessage()); return null; }); ``` Or create an asynchronous client from the beginning: ```java import dm.sent.client.SentClientAsync; import dm.sent.client.okhttp.SentOkHttpClientAsync; SentClientAsync client = SentOkHttpClientAsync.fromEnv(); CompletableFuture future = client.messages().send(params); ``` ## Error handling [#error-handling] When the API returns a non-success status code, a subclass of `SentServiceException` (itself a subclass of `SentException`) will be thrown: | Status | Exception | |--------|-----------| | 400 | `BadRequestException` | | 401 | `UnauthorizedException` | | 403 | `PermissionDeniedException` | | 404 | `NotFoundException` | | 422 | `UnprocessableEntityException` | | 429 | `RateLimitException` | | >=500 | `InternalServerException` | | others | `UnexpectedStatusCodeException` | ```java try { MessageSendResponse response = client.messages().send(params); System.out.println("Sent: " + response.data().recipients().get().get(0).messageId()); } catch (NotFoundException e) { System.err.println("Contact or template not found: " + e.getMessage()); } catch (RateLimitException e) { System.err.println("Rate limited: " + e.getMessage()); } catch (UnauthorizedException e) { System.err.println("Authentication failed - check API key"); } catch (SentException e) { System.err.println("Error: " + e.getMessage()); } ``` ## Raw responses [#raw-responses] To access response headers, status code, or raw body, prefix any HTTP method call with `withRawResponse()`: ```java import dm.sent.core.http.Headers; import dm.sent.core.http.HttpResponseFor; import dm.sent.models.messages.MessageSendResponse; HttpResponseFor response = client.messages().withRawResponse().send(params); int statusCode = response.statusCode(); Headers headers = response.headers(); // Deserialize if needed MessageSendResponse parsed = response.parse(); ``` ## Contacts [#contacts] Create and manage contacts: ```java import dm.sent.models.contacts.ApiResponseOfContact; import dm.sent.models.contacts.ContactCreateParams; import dm.sent.models.contacts.ContactDeleteParams; import dm.sent.models.contacts.ContactListParams; import dm.sent.models.contacts.ContactListResponse; import dm.sent.models.contacts.ContactUpdateParams; import dm.sent.models.webhooks.MutationRequest; // Create a contact ContactCreateParams createParams = ContactCreateParams.builder() .phoneNumber("+1234567890") .build(); ApiResponseOfContact contact = client.contacts().create(createParams); System.out.println("Contact ID: " + contact.data().id()); // List contacts ContactListParams listParams = ContactListParams.builder() .page(1) .pageSize(100) .build(); ContactListResponse contacts = client.contacts().list(listParams); contacts.data().contacts().forEach(c -> System.out.println(c.phoneNumber() + " - " + c.availableChannels()) ); // Get a contact ApiResponseOfContact retrieved = client.contacts().retrieve("contact-uuid"); // Update a contact ContactUpdateParams updateParams = ContactUpdateParams.builder() .defaultChannel("whatsapp") .build(); ApiResponseOfContact updated = client.contacts().update("contact-uuid", updateParams); // Delete a contact client.contacts().delete( ContactDeleteParams.builder() .id("contact-uuid") .mutationRequest(MutationRequest.builder().build()) .build() ); ``` ## Templates [#templates] List and retrieve templates: ```java import dm.sent.models.templates.ApiResponseTemplate; import dm.sent.models.templates.TemplateListParams; import dm.sent.models.templates.TemplateListResponse; // List templates TemplateListResponse templates = client.templates().list( TemplateListParams.builder() .page(1) .pageSize(100) .build() ); templates.data().templates().forEach(template -> System.out.println(template.name() + " (" + template.status() + "): " + template.id()) ); // Get a specific template ApiResponseTemplate template = client.templates().retrieve("template-uuid"); System.out.println("Name: " + template.data().name()); System.out.println("Status: " + template.data().status()); ``` ## Framework Integration [#framework-integration] A dedicated guide covers client configuration, message sending, verified webhook handling, and sandbox testing: ## Client customization [#client-customization] To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()`: ```java import dm.sent.client.SentClient; SentClient clientWithOptions = client.withOptions(optionsBuilder -> { optionsBuilder.baseUrl("https://example.com"); optionsBuilder.maxRetries(5); }); ``` The `withOptions()` method does not affect the original client. ## Immutability [#immutability] Each class in the SDK has an associated builder for constructing it. Each class is immutable once constructed. If the class has an associated builder, then it has a `toBuilder()` method for making a modified copy. ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("template-id") .build()) .build(); // Create a modified copy MessageSendParams modified = params.toBuilder() .addTo("+0987654321") .build(); ``` ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` and the `webhook-signature` header carries `v1,{base64(hmac)}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook). ```java import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.HttpHeaders; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.time.Instant; import java.util.Base64; import java.util.Collections; import java.util.Map; @RestController public class WebhookController { private final ObjectMapper objectMapper = new ObjectMapper(); @PostMapping("/webhooks/sent") public ResponseEntity handleWebhook( @RequestBody byte[] payload, // raw bytes — do NOT use @RequestBody String @RequestHeader HttpHeaders headers ) throws Exception { // Version 2 headers first, falling back to version 1 names String webhookId = header(headers, "webhook-id", "X-Webhook-ID"); String timestamp = header(headers, "webhook-timestamp", "X-Webhook-Timestamp"); String signature = header(headers, "webhook-signature", "X-Webhook-Signature"); if (webhookId == null || timestamp == null || signature == null) { return ResponseEntity.status(401).body(Collections.singletonMap("error", "Missing signature headers")); } // 1. Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" String secret = System.getenv("SENT_DM_WEBHOOK_SECRET"); // "whsec_abc123..." String keyBase64 = secret.startsWith("whsec_") ? secret.substring(6) : secret; byte[] keyBytes = Base64.getDecoder().decode(keyBase64); String signed = webhookId + "." + timestamp + "." + new String(payload, StandardCharsets.UTF_8); Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(keyBytes, "HmacSHA256")); String expected = "v1," + Base64.getEncoder().encodeToString( mac.doFinal(signed.getBytes(StandardCharsets.UTF_8)) ); // Version 2 sends two signatures for 24 hours after a rotation; accept any match boolean valid = false; for (String candidate : signature.trim().split("\\s+")) { valid |= MessageDigest.isEqual(expected.getBytes(), candidate.getBytes()); } if (!valid) { return ResponseEntity.status(401).body(Collections.singletonMap("error", "Invalid signature")); } // 2. Optional: reject replayed events older than 5 minutes if (Math.abs(Instant.now().getEpochSecond() - Long.parseLong(timestamp)) > 300) { return ResponseEntity.status(401).body(Collections.singletonMap("error", "Timestamp too old")); } // 3. Handle events — update message status in your own database Map event = objectMapper.readValue(payload, Map.class); if ("message".equals(event.get("field"))) { Map p = (Map) event.get("payload"); // messageRepository.updateStatus((String) p.get("message_id"), (String) p.get("message_status")); } // 4. Always return 200 quickly return ResponseEntity.ok(Collections.singletonMap("received", true)); } private static String header(HttpHeaders headers, String v2, String v1) { String value = headers.getFirst(v2); return value != null ? value : headers.getFirst(v1); } } ``` See the [Webhooks reference](/start/webhooks) for the full payload schema and all status values. ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-java/releases) - **GitHub**: [`sentdm/sent-dm-java`](https://github.com/sentdm/sent-dm-java) - **Maven Central**: [dm.sent:sent-java](https://central.sonatype.com/artifact/dm.sent/sent-java) - **Javadoc**: [javadoc.io](https://javadoc.io/doc/dm.sent/sent-java) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-java/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending messages from Spring Boot with the Sent Java SDK (/sdks/java/integrations/spring-boot.md) # Sending messages from Spring Boot with the Sent Java SDK [#sending-messages-from-spring-boot-with-the-sent-java-sdk] This guide shows you how to wire Sent messaging into an existing Spring Boot app: install the Java SDK, register a client bean, send a template message from a controller, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Spring Boot 3.x app and familiarity with beans and controllers. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK dependency to your build: ```xml dm.sent sent-java 0.30.0 ``` For Gradle, use `implementation("dm.sent:sent-java:0.30.0")` instead. ### Configure the client bean [#configure-the-client-bean] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Register one shared client bean; `fromEnv()` reads `SENT_DM_API_KEY` (or the `sent.dmApiKey` system property): ```java // config/SentConfig.java package com.example.sent.config; import dm.sent.client.SentClient; import dm.sent.client.okhttp.SentOkHttpClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class SentConfig { @Bean public SentClient sentClient() { return SentOkHttpClient.fromEnv(); } } ``` ### Send a template message from a controller [#send-a-template-message-from-a-controller] Define a validated request record; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```java // dto/SendMessageRequest.java package com.example.sent.dto; import jakarta.validation.constraints.*; import java.util.List; import java.util.Map; public record SendMessageRequest( @NotEmpty List<@Pattern(regexp = "^\\+[1-9]\\d{1,14}$") String> to, // E.164 numbers @NotBlank String templateName, // reference by name or id, never both Map parameters, List<@Pattern(regexp = "^(whatsapp|sms|rcs)$") String> channels, boolean sandbox // true = validate and simulate only ) {} ``` Add the controller that builds the params and calls `messages().send`: ```java // controller/MessageController.java package com.example.sent.controller; import com.example.sent.dto.SendMessageRequest; import dm.sent.client.SentClient; import dm.sent.core.JsonValue; import dm.sent.models.messages.MessageSendParams; import dm.sent.models.messages.MessageSendResponse; import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.Map; @RestController @RequestMapping("/api/messages") public class MessageController { private final SentClient sentClient; public MessageController(SentClient sentClient) { this.sentClient = sentClient; } @PostMapping("/send") public ResponseEntity> sendMessage(@Valid @RequestBody SendMessageRequest request) { var parameters = MessageSendParams.Template.Parameters.builder(); if (request.parameters() != null) { request.parameters().forEach((k, v) -> parameters.putAdditionalProperty(k, JsonValue.from(v))); } var builder = MessageSendParams.builder() .to(request.to()) .template(MessageSendParams.Template.builder() .name(request.templateName()) .parameters(parameters.build()) .build()) .sandbox(request.sandbox()); if (request.channels() != null) { request.channels().forEach(builder::addChannel); // omit to let Sent pick per recipient } MessageSendResponse response = sentClient.messages().send(builder.build()); MessageSendResponse.Data data = response.data().orElseThrow(); var recipient = data.recipients().orElseThrow().get(0); return ResponseEntity.status(HttpStatus.ACCEPTED).body(Map.of( "message_id", recipient.messageId().orElse(""), "status", data.status().orElse("") )); } } ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`. Delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Define a record for the event envelope. Every event carries `field`, `event`, `timestamp`, and `payload`, and template events omit `event`: ```java // dto/WebhookEvent.java package com.example.sent.dto; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import java.time.Instant; @JsonIgnoreProperties(ignoreUnknown = true) public record WebhookEvent(String field, String event, Instant timestamp, Payload payload) { @JsonIgnoreProperties(ignoreUnknown = true) public record Payload( @JsonProperty("message_id") String messageId, @JsonProperty("message_status") String messageStatus, @JsonProperty("inbound_number") String inboundNumber, String channel, String text ) {} } ``` Add a controller that verifies the `webhook-signature` header against the raw request body before trusting any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```java // controller/WebhookController.java package com.example.sent.controller; import com.example.sent.dto.WebhookEvent; import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.Base64; import java.util.Map; @RestController @RequestMapping("/webhooks") public class WebhookController { private static final Logger logger = LoggerFactory.getLogger(WebhookController.class); private final ObjectMapper mapper; private final String webhookSecret; public WebhookController(ObjectMapper mapper, @Value("${SENT_DM_WEBHOOK_SECRET:}") String webhookSecret) { this.mapper = mapper; this.webhookSecret = webhookSecret; } @PostMapping("/sent") public ResponseEntity> handleWebhook( @RequestBody String payload, @RequestHeader HttpHeaders headers) throws Exception { // Version 2 headers first, falling back to version 1 names String webhookId = header(headers, "webhook-id", "X-Webhook-ID"); String timestamp = header(headers, "webhook-timestamp", "X-Webhook-Timestamp"); String signature = header(headers, "webhook-signature", "X-Webhook-Signature"); if (!verifySignature(payload, webhookId, timestamp, signature)) { return ResponseEntity.status(401).body(Map.of("error", "invalid signature")); } WebhookEvent event = mapper.readValue(payload, WebhookEvent.class); if ("message".equals(event.field())) { var p = event.payload(); switch (event.event() != null ? event.event() : "") { case "message.delivered" -> logger.info("Message {} delivered", p.messageId()); case "message.failed" -> logger.error("Message {} failed (status {})", p.messageId(), p.messageStatus()); case "message.received" -> logger.info("Inbound {} from {}: {}", p.channel(), p.inboundNumber(), p.text()); default -> logger.info("Message {} status: {}", p.messageId(), p.messageStatus()); } } return ResponseEntity.ok(Map.of("received", true)); } private boolean verifySignature(String payload, String webhookId, String timestamp, String signature) { // Fail closed: never accept webhooks when the secret is not configured if (webhookSecret == null || webhookSecret.isBlank()) return false; if (webhookId == null || timestamp == null || signature == null) return false; try { // Strip the "whsec_" prefix and base64-decode to get the raw HMAC key String keyBase64 = webhookSecret.startsWith("whsec_") ? webhookSecret.substring(6) : webhookSecret; byte[] keyBytes = Base64.getDecoder().decode(keyBase64); // Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" String signed = webhookId + "." + timestamp + "." + payload; Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(keyBytes, "HmacSHA256")); String expected = "v1," + Base64.getEncoder().encodeToString( mac.doFinal(signed.getBytes(StandardCharsets.UTF_8))); // Version 2 sends two signatures for 24 hours after a rotation; accept any match boolean valid = false; for (String candidate : signature.trim().split("\\s+")) { valid |= MessageDigest.isEqual( expected.getBytes(StandardCharsets.UTF_8), candidate.getBytes(StandardCharsets.UTF_8)); } return valid; } catch (Exception e) { return false; } } private static String header(HttpHeaders headers, String v2, String v1) { String value = headers.getFirst(v2); return value != null ? value : headers.getFirst(v1); } } ``` Keep this endpoint outside Spring Security's authenticated routes, because Sent authenticates with the signature. Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Spring Boot integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash ./mvnw spring-boot:run ``` Send a sandbox message through your new endpoint. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:8080/api/messages/send \ -H "Content-Type: application/json" \ -d '{"to": ["+14155551234"], "templateName": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your application log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If webhook processing does slow work (database writes, downstream calls), verify the signature synchronously, return 200, and hand the event to an `@Async` executor so retries do not pile up. The appendix below has the executor; see also [handling webhook retries](/start/webhooks/handling-retries). - If you process each event exactly once, key on the `webhook-id` header (`X-Webhook-Event-ID` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and skip duplicates. The appendix shows the pattern. - To send to many recipients, pass them all in `to`. Sent creates one message per recipient-and-channel pair in a single call. - To send free-form text instead of a template, use `.text(...)` instead of `.template(...)`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Spring Boot stack. Adapt them to your own conventions rather than adopting them wholesale. Process events on a dedicated thread pool after acknowledging the delivery: ```java // config/AsyncConfig.java @Configuration @EnableAsync public class AsyncConfig { @Bean(name = "webhookTaskExecutor") public Executor webhookTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.setMaxPoolSize(10); executor.setQueueCapacity(100); executor.setThreadNamePrefix("webhook-"); executor.initialize(); return executor; } } ``` Annotate the processing method with `@Async("webhookTaskExecutor")`. The `webhook-id` header (`X-Webhook-Event-ID` on version 1) identifies the event and carries the same value on every delivery attempt at that event, so it is the key to store. Message events can be narrowed further to the sub-type plus `message_id`, which also collapses the same status transition re-sent as a separate event: ```java private static String buildEventId(String eventType, WebhookEvent event, String eventId) { if (event.payload() != null && event.payload().messageId() != null) { return eventType + ":" + event.payload().messageId(); } return "evt:" + eventId; } ``` Store the key in a unique column and skip events that already exist. Return RFC 7807 problem details for validation and security failures: ```java // exception/GlobalExceptionHandler.java @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(MethodArgumentNotValidException.class) public ProblemDetail handleValidation(MethodArgumentNotValidException ex) { ProblemDetail problem = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST); problem.setTitle("Validation Failed"); return problem; } } ``` The [SDK testing guide](/sdks/testing) covers mocking `SentClient` in controller tests. ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Java SDK reference](/sdks/java) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # PHP SDK (/sdks/php.md) # PHP SDK [#php-sdk] The official PHP SDK for Sent provides a clean, object-oriented interface for sending messages. Built with modern PHP 8.1+ features. ## Requirements [#requirements] PHP 8.1.0 or higher. ## Installation [#installation] ```bash composer require sentdm/sent-dm-php ``` To install a specific version: ```bash composer require "sentdm/sent-dm-php 0.26.0" ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```php ### Send your first message [#send-your-first-message] ```php messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome', 'parameters' => [ 'name' => 'John Doe', 'order_id' => '12345' ] ], channel: ['sms', 'whatsapp', 'rcs'] // Optional ); var_dump($result->data->recipients[0]->messageID); var_dump($result->data->status); ``` ## Authentication [#authentication] The client accepts an API key as the first parameter. ```php use SentDm\Client; // Using API key directly $client = new Client('your_api_key'); // Or from environment variable $client = new Client($_ENV['SENT_DM_API_KEY']); ``` ## Send Messages [#send-messages] This library uses named parameters to specify optional arguments. Parameters with a default value must be set by name. ### Send a message [#send-a-message] ```php $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome', 'parameters' => [ 'name' => 'John Doe', 'order_id' => '12345' ] ], channel: ['sms', 'whatsapp', 'rcs'] ); var_dump($result->data->recipients[0]->messageID); var_dump($result->data->status); ``` ### Sandbox mode [#sandbox-mode] Use `sandbox: true` to validate requests without sending real messages: ```php $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome' ], sandbox: true // Validates but doesn't send ); // Response will have test data var_dump($result->data->recipients[0]->messageID); var_dump($result->data->status); ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```php $status = $client->messages->retrieveStatus('msg-uuid'); var_dump($status->data->status); // e.g. "DELIVERED" var_dump($status->data->channel); // e.g. "sms" var_dump($status->data->direction); // "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```php $activities = $client->messages->retrieveActivities('msg-uuid'); foreach ($activities->data->activities as $activity) { echo $activity->timestamp . ': ' . $activity->status . ' via ' . $activity->from . "\n"; echo ' Price: ' . $activity->price . "\n"; echo ' Active contact price: ' . $activity->activeContactPrice . "\n"; } ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```php $result = $client->numbers->lookup('+12025551234'); var_dump($result->data->isValid); // bool var_dump($result->data->carrierName); // e.g. "T-Mobile" var_dump($result->data->lineType); // "mobile", "landline", "voip" var_dump($result->data->isVoip); // bool ``` ## Handling errors [#handling-errors] When the library is unable to connect to the API, or if the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of `SentDm\Core\Exceptions\APIException` will be thrown: ```php use SentDm\Core\Exceptions\APIConnectionException; use SentDm\Core\Exceptions\RateLimitException; use SentDm\Core\Exceptions\APIStatusException; try { $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome' ] ); } catch (APIConnectionException $e) { echo "The server could not be reached", PHP_EOL; var_dump($e->getPrevious()); } catch (RateLimitException $e) { echo "A 429 status code was received; we should back off a bit.", PHP_EOL; } catch (APIStatusException $e) { echo "Another non-200-range status code was received", PHP_EOL; echo $e->getMessage(); } ``` Error codes are as follows: | Cause | Error Type | |-------|------------| | HTTP 400 | `BadRequestException` | | HTTP 401 | `AuthenticationException` | | HTTP 403 | `PermissionDeniedException` | | HTTP 404 | `NotFoundException` | | HTTP 409 | `ConflictException` | | HTTP 422 | `UnprocessableEntityException` | | HTTP 429 | `RateLimitException` | | HTTP >= 500 | `InternalServerException` | | Other HTTP error | `APIStatusException` | | Timeout | `APITimeoutException` | | Network error | `APIConnectionException` | ## Retries [#retries] Certain errors will be automatically retried 2 times by default, with a short exponential backoff. ```php // Configure the default for all requests: $client = new Client($_ENV['SENT_DM_API_KEY'], requestOptions: ['maxRetries' => 0]); // Or, configure per-request: $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome' ], requestOptions: ['maxRetries' => 5], ); ``` ## Value Objects [#value-objects] Sent recommends the static `with` constructor and named parameters to initialize value objects. ```php use SentDm\Models\TemplateDefinition; $definition = TemplateDefinition::with( body: [...], header: [...], ); ``` However, builders are also provided: ```php $definition = (new TemplateDefinition)->withBody([...]); ``` ## Contacts [#contacts] Create and manage contacts: ```php // Create a contact $result = $client->contacts->create(phoneNumber: '+1234567890'); var_dump($result->data->id); // List contacts $result = $client->contacts->list(page: 1, pageSize: 100); foreach ($result->data->contacts as $contact) { echo $contact->phoneNumber . " - " . $contact->availableChannels . "\n"; } // Get a contact $result = $client->contacts->retrieve('contact-uuid'); // Update a contact $result = $client->contacts->update('contact-uuid', defaultChannel: 'whatsapp'); // Delete a contact $client->contacts->delete('contact-uuid'); ``` ## Templates [#templates] List and retrieve templates: ```php // List templates $result = $client->templates->list(page: 1, pageSize: 100); foreach ($result->data->templates as $template) { echo $template->name . " (" . $template->status . "): " . $template->id . "\n"; echo " Category: " . $template->category . "\n"; } // Get a specific template $result = $client->templates->retrieve('template-uuid'); echo "Name: " . $result->data->name . "\n"; echo "Status: " . $result->data->status . "\n"; ``` ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-ID` and `X-Webhook-Timestamp` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and the signature format is `v1,{base64(hmac)}`. The following example uses plain PHP (`php://input` and `$_SERVER`) and works in any PHP app: ```php hash_equals($expected, $candidate)); if (!$matches) { http_response_code(401); echo json_encode(['error' => 'Invalid signature']); exit; } // 3. Optional: reject replayed events older than 5 minutes if (abs(time() - intval($timestamp)) > 300) { http_response_code(401); echo json_encode(['error' => 'Timestamp too old']); exit; } $event = json_decode($payload); // 4. Handle events — update message status in your own database if ($event->field === 'message') { if ($event->event === 'message.received') { // Inbound message from a contact: // $event->payload->inbound_number, $event->payload->text, $event->payload->channel } else { // Outbound status update: // $event->payload->message_id, $event->payload->message_status } } // 5. Always return 200 quickly http_response_code(200); echo json_encode(['received' => true]); ``` Framework-specific handlers are available in the [Laravel integration guide](/sdks/php/integrations/laravel) and the [Symfony integration guide](/sdks/php/integrations/symfony). See the [Webhooks reference](/start/webhooks) for the full payload schema and all status values. ## Making custom or undocumented requests [#making-custom-or-undocumented-requests] ### Undocumented properties [#undocumented-properties] You can send undocumented parameters to any endpoint using the `extra*` parameters: ```php $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name' => 'welcome' ], requestOptions: [ 'extraQueryParams' => ['my_query_parameter' => 'value'], 'extraBodyParams' => ['my_body_parameter' => 'value'], 'extraHeaders' => ['my-header' => 'value'], ], ); ``` ### Undocumented endpoints [#undocumented-endpoints] To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on: ```php $response = $client->request( method: 'post', path: '/undocumented/endpoint', query: ['dog' => 'woof'], headers: ['useful-header' => 'interesting-value'], body: ['hello' => 'world'] ); ``` ## Framework Integration [#framework-integration] Dedicated guides cover client setup, message sending, verified webhook handling, and testing for each framework: ## Source & Issues [#source--issues] - **Version**: 0.26.0 - **GitHub**: [`sentdm/sent-dm-php`](https://github.com/sentdm/sent-dm-php) - **Packagist**: [`sentdm/sent-dm-php`](https://packagist.org/packages/sentdm/sent-dm-php) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-php/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending messages from Laravel with the Sent PHP SDK (/sdks/php/integrations/laravel.md) # Sending messages from Laravel with the Sent PHP SDK [#sending-messages-from-laravel-with-the-sent-php-sdk] This guide shows you how to wire Sent messaging into an existing Laravel app: install the PHP SDK, bind a shared client in the container, send a template message from a controller, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Laravel 11 app and familiarity with controllers, middleware, and the service container. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing project: ```bash composer require sentdm/sent-dm-php ``` ### Configure and bind the client [#configure-and-bind-the-client] Add the credentials to `.env`; the webhook secret arrives in step 4: ```bash # .env SENT_DM_API_KEY=your_api_key_here SENT_DM_WEBHOOK_SECRET=whsec_your_signing_secret ``` Expose them through a config file so `config:cache` works in production: ```php env('SENT_DM_API_KEY'), 'webhook_secret' => env('SENT_DM_WEBHOOK_SECRET'), ]; ``` Bind one shared client in the container: ```php app->singleton(Client::class, function ($app) { $apiKey = $app['config']['sent-dm.api_key']; if (empty($apiKey)) { throw new \InvalidArgumentException('Sent API key not configured.'); } return new Client(apiKey: $apiKey); }); ``` ### Send a template message from a controller [#send-a-template-message-from-a-controller] Add a controller that calls `messages->send`; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```php validate([ 'phone_number' => ['required', 'regex:/^\+[1-9]\d{1,14}$/'], // E.164 format 'template_name' => ['required', 'string', 'max:100'], 'parameters' => ['array'], 'channels' => ['array'], 'sandbox' => ['boolean'], ]); $response = $this->client->messages->send( to: [$validated['phone_number']], template: [ 'name' => $validated['template_name'], // reference by name or id, never both 'parameters' => $validated['parameters'] ?? [], ], channel: $validated['channels'] ?? null, // omit to let Sent pick per recipient sandbox: $validated['sandbox'] ?? false, // true = validate and simulate only ); $recipient = $response->data->recipients[0]; return response()->json([ 'message_id' => $recipient->messageID, 'status' => $response->data->status, ], 202); } } ``` Route it behind your existing API authentication: ```php post('/messages/send', [MessageController::class, 'send']); ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`. Delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add middleware that verifies the `webhook-signature` header against the raw request body before any handler runs. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```php header('webhook-signature') ?? $request->header('X-Webhook-Signature', ''); $secret = config('sent-dm.webhook_secret'); if (empty($secret)) { Log::error('Webhook secret not configured'); return response()->json(['error' => 'Webhook not configured'], 500); } if (empty($signature)) { return response()->json(['error' => 'Missing signature'], 401); } $payload = $request->getContent(); $webhookId = $request->header('webhook-id') ?? $request->header('X-Webhook-ID', ''); $timestamp = $request->header('webhook-timestamp') ?? $request->header('X-Webhook-Timestamp', ''); // Strip the "whsec_" prefix and base64-decode to get the raw HMAC key $keyBase64 = str_starts_with($secret, 'whsec_') ? substr($secret, 6) : $secret; $keyBytes = base64_decode($keyBase64); // Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" $signed = "{$webhookId}.{$timestamp}.{$payload}"; $expected = 'v1,' . base64_encode(hash_hmac('sha256', $signed, $keyBytes, true)); // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match $matches = array_filter(preg_split('/\s+/', trim($signature)), fn ($candidate) => hash_equals($expected, $candidate)); if (!$matches) { Log::warning('Invalid webhook signature', ['ip' => $request->ip()]); return response()->json(['error' => 'Invalid signature'], 401); } return $next($request); } } ``` Register the alias in `bootstrap/app.php`: ```php ->withMiddleware(function (Middleware $middleware) { $middleware->alias(['sent.webhook' => \App\Http\Middleware\VerifySentWebhook::class]); }) ``` Add the controller. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; return 200 quickly and do slow work in a queued job: ```php getContent(), true) ?? []; $subType = $event['event'] ?? null; // omitted when the event has no sub-type $payload = $event['payload'] ?? []; if (($event['field'] ?? null) === 'message') { match ($subType) { 'message.delivered' => Log::info("Message {$payload['message_id']} delivered"), 'message.failed' => Log::error("Message {$payload['message_id']} failed", ['status' => $payload['message_status'] ?? null]), 'message.received' => Log::info("Inbound message from {$payload['inbound_number']}", ['text' => $payload['text'] ?? null]), default => Log::info("Message {$payload['message_id']} status: " . ($payload['message_status'] ?? $subType)), }; } return response()->json(['received' => true]); } } ``` Route it with the verification middleware and without session authentication, because Sent authenticates with the signature: ```php middleware('sent.webhook'); ``` Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Laravel integration", "endpoint_url": "https://your-domain.example/api/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash php artisan serve ``` Send a sandbox message through your new endpoint (include your API token if the route requires it). Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:8000/api/messages/send \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{"phone_number": "+14155551234", "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 422 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your Laravel log (`storage/logs/laravel.log`) should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - Sent retries non-2xx webhook responses with backoff, so make processing idempotent. Keying status updates on `payload.message_id` achieves this naturally; see [handling webhook retries](/start/webhooks/handling-retries). - If webhook processing does slow work (database writes, notifications), dispatch a queued job from the controller and return 200 immediately. The appendix below has the job. - If you audit webhook traffic, persist each envelope in a `webhook_logs` table before processing. The appendix has the migration. - To send free-form text instead of a template, pass `text` instead of `template`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Laravel stack. Adapt them to your own conventions rather than adopting them wholesale. Persist every event for replay and debugging: ```php id(); $table->string('event_type', 100)->index(); // e.g. "message.delivered" $table->uuid('message_id')->nullable()->index(); $table->string('status', 50)->nullable(); $table->json('payload'); $table->timestamp('processed_at')->nullable(); $table->timestamps(); }); ``` ```php 'array', 'processed_at' => 'datetime']; } ``` Move slow processing off the webhook request path: ```php event['payload'] ?? []; // Update your own records keyed by $payload['message_id'] Log::info('Processed Sent event', ['event' => $this->event['event'] ?? null]); } } ``` In the webhook controller, replace the `match` block with `ProcessSentEvent::dispatch($event);`. Cap how often each user can trigger sends: ```php [ Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()), ]); ``` Apply it with `->middleware('throttle:sent-dm')` on the send route. The [SDK testing guide](/sdks/testing) covers faking the client in feature tests. ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [PHP SDK reference](/sdks/php) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sending messages from Symfony with the Sent PHP SDK (/sdks/php/integrations/symfony.md) # Sending messages from Symfony with the Sent PHP SDK [#sending-messages-from-symfony-with-the-sent-php-sdk] This guide shows you how to wire Sent messaging into an existing Symfony app: install the PHP SDK, register a shared client service, send a template message from a controller, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Symfony 7 app and familiarity with controllers, services, and attributes. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing project: ```bash composer require sentdm/sent-dm-php ``` ### Register the client service [#register-the-client-service] Add the credentials to `.env.local`; the webhook secret arrives in step 4: ```bash # .env.local SENT_DM_API_KEY=your_api_key_here SENT_DM_WEBHOOK_SECRET=whsec_your_signing_secret ``` Register one shared client so it autowires into any service or controller: ```yaml # config/services.yaml (additions) services: SentDm\Client: arguments: $apiKey: '%env(SENT_DM_API_KEY)%' ``` ### Send a template message from a controller [#send-a-template-message-from-a-controller] Define a validated payload DTO; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```php // src/Dto/SendMessageDto.php namespace App\Dto; use Symfony\Component\Validator\Constraints as Assert; class SendMessageDto { #[Assert\NotBlank] #[Assert\Regex(pattern: '/^\+[1-9]\d{1,14}$/', message: 'Phone number must be in E.164 format')] public string $phoneNumber; #[Assert\NotBlank] #[Assert\Length(min: 1, max: 100)] public string $templateName; public ?array $parameters = null; #[Assert\All([new Assert\Choice(choices: ['sms', 'whatsapp', 'rcs'])])] public ?array $channels = null; public bool $sandbox = false; // true = validate and simulate only } ``` Add the controller that maps the payload and calls `messages->send`: ```php // src/Controller/MessagesController.php namespace App\Controller; use App\Dto\SendMessageDto; use SentDm\Client; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; use Symfony\Component\Routing\Attribute\Route; #[Route('/api/messages')] class MessagesController extends AbstractController { public function __construct(private readonly Client $client) {} #[Route('/send', methods: ['POST'])] public function send(#[MapRequestPayload] SendMessageDto $dto): JsonResponse { $response = $this->client->messages->send( to: [$dto->phoneNumber], template: [ 'name' => $dto->templateName, // reference by name or id, never both 'parameters' => $dto->parameters ?? [], ], channel: $dto->channels, // omit to let Sent pick per recipient sandbox: $dto->sandbox, ); $recipient = $response->data->recipients[0]; return $this->json([ 'message_id' => $recipient->messageID, 'status' => $response->data->status, ], 202); } } ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`. Delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a webhook controller that verifies the `webhook-signature` header against the raw request body before trusting any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them: ```php // src/Controller/WebhookController.php namespace App\Controller; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class WebhookController { public function __construct( #[Autowire(env: 'SENT_DM_WEBHOOK_SECRET')] private readonly ?string $webhookSecret, private readonly LoggerInterface $logger, ) {} #[Route('/webhooks/sent', methods: ['POST'])] public function handle(Request $request): JsonResponse { if (empty($this->webhookSecret)) { // Fail closed: never accept webhooks without a configured secret return new JsonResponse(['error' => 'Webhook not configured'], 500); } // Version 2 headers first, falling back to version 1 (X-Webhook-*) $signature = $request->headers->get('webhook-signature') ?? $request->headers->get('X-Webhook-Signature'); if (!$signature) { return new JsonResponse(['error' => 'Missing signature'], 401); } $payload = $request->getContent(); $webhookId = $request->headers->get('webhook-id') ?? $request->headers->get('X-Webhook-ID', ''); $timestamp = $request->headers->get('webhook-timestamp') ?? $request->headers->get('X-Webhook-Timestamp', ''); // Strip the "whsec_" prefix and base64-decode to get the raw HMAC key $keyBase64 = str_starts_with($this->webhookSecret, 'whsec_') ? substr($this->webhookSecret, 6) : $this->webhookSecret; $keyBytes = base64_decode($keyBase64); // Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" $signed = "{$webhookId}.{$timestamp}.{$payload}"; $expected = 'v1,' . base64_encode(hash_hmac('sha256', $signed, $keyBytes, true)); // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match $matches = array_filter(preg_split('/\s+/', trim($signature)), fn ($candidate) => hash_equals($expected, $candidate)); if (!$matches) { $this->logger->warning('Invalid webhook signature', ['ip' => $request->getClientIp()]); return new JsonResponse(['error' => 'Invalid signature'], 401); } $event = json_decode($payload, true) ?? []; $subType = $event['event'] ?? null; // omitted when the event has no sub-type $data = $event['payload'] ?? []; if (($event['field'] ?? null) === 'message') { match ($subType) { 'message.delivered' => $this->logger->info('Message delivered', ['message_id' => $data['message_id'] ?? null]), 'message.failed' => $this->logger->error('Message failed', ['message_id' => $data['message_id'] ?? null, 'status' => $data['message_status'] ?? null]), 'message.received' => $this->logger->info('Inbound message', ['from' => $data['inbound_number'] ?? null, 'text' => $data['text'] ?? null]), default => $this->logger->info('Message status updated', ['message_id' => $data['message_id'] ?? null, 'status' => $data['message_status'] ?? null]), }; } return new JsonResponse(['received' => true]); } } ``` Keep this route outside your firewall's authenticated area (`config/packages/security.yaml`), because Sent authenticates with the signature. Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Symfony integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash symfony server:start ``` Send a sandbox message through your new endpoint. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:8000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phoneNumber": "+14155551234", "templateName": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 422 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your application log should show a `Message delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - Sent retries non-2xx webhook responses with backoff, so make processing idempotent. Keying status updates on `payload.message_id` achieves this naturally; see [handling webhook retries](/start/webhooks/handling-retries). - If you send outside the request cycle, dispatch a Messenger command and let a worker call the API. The appendix below has the pattern. - If you rate-limit send endpoints, use Symfony's `rate_limiter` component. The appendix has the configuration. - To send free-form text instead of a template, pass `text` instead of `template`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Symfony stack. Adapt them to your own conventions rather than adopting them wholesale. Move the API call out of the request cycle: ```php // src/Message/SendMessageCommand.php namespace App\Message; final readonly class SendMessageCommand { public function __construct( public string $phoneNumber, public string $templateName, public array $parameters = [], public ?array $channels = null, ) {} } ``` ```php // src/MessageHandler/SendMessageHandler.php namespace App\MessageHandler; use App\Message\SendMessageCommand; use SentDm\Client; use Symfony\Component\Messenger\Attribute\AsMessageHandler; #[AsMessageHandler] final readonly class SendMessageHandler { public function __construct(private Client $client) {} public function __invoke(SendMessageCommand $command): void { $this->client->messages->send( to: [$command->phoneNumber], template: ['name' => $command->templateName, 'parameters' => $command->parameters], channel: $command->channels, ); } } ``` Dispatch with `$bus->dispatch(new SendMessageCommand(...))` and run a worker with `php bin/console messenger:consume`. Cap how often each user can trigger sends: ```yaml # config/packages/rate_limiter.yaml framework: rate_limiter: sent_message: policy: 'sliding_window' limit: 100 interval: '1 minute' ``` Inject `RateLimiterFactory $sentMessageLimiter` into the controller and call `$limiter->consume(1)->isAccepted()` before sending. This PHPUnit helper signs payloads exactly the way Sent does, so you can test verification offline; the [SDK testing guide](/sdks/testing) covers mocking the client: ```php // tests/Controller/WebhookControllerTest.php (excerpt) private function signedHeaders(string $payload, string $secret): array { $webhookId = '550e8400-e29b-41d4-a716-446655440000'; $timestamp = (string) time(); $keyBytes = base64_decode(substr($secret, 6)); // strip "whsec_" $signed = "{$webhookId}.{$timestamp}.{$payload}"; $signature = 'v1,' . base64_encode(hash_hmac('sha256', $signed, $keyBytes, true)); return [ 'HTTP_X-Webhook-ID' => $webhookId, 'HTTP_X-Webhook-Timestamp' => $timestamp, 'HTTP_X-Webhook-Signature' => $signature, ]; } ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [PHP SDK reference](/sdks/php) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Python SDK (/sdks/python.md) # Python SDK [#python-sdk] The official Python SDK for Sent provides a clean, Pythonic interface to the Sent API. Built for developers who value readability, with optional async support for high-performance applications. ## Requirements [#requirements] This library requires Python 3.9 or later. ## Installation [#installation] ```bash pip install sentdm ``` ```bash poetry add sentdm ``` ```bash uv pip install sentdm ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```python from sent_dm import Sent client = Sent() # Uses SENT_DM_API_KEY env var by default ``` ### Send your first message [#send-your-first-message] ```python response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome", "parameters": { "name": "John Doe" } } ) print(f"Message sent: {response.data.recipients[0].message_id}") print(f"Status: {response.data.status}") ``` ## Authentication [#authentication] While you can provide an `api_key` keyword argument, Sent recommends using `python-dotenv` to add `SENT_DM_API_KEY="your_api_key"` to your `.env` file so that your API Key is not stored in source control. ```python from sent_dm import Sent # Using environment variables (recommended) client = Sent() # Or explicit configuration client = Sent( api_key="your_api_key", ) ``` ## Async usage [#async-usage] Import `AsyncSent` instead of `Sent` and use `await` with each API call: ```python import asyncio from sent_dm import AsyncSent client = AsyncSent() async def main(): response = await client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome", "parameters": { "name": "John Doe" } } ) print(f"Sent: {response.data.recipients[0].message_id}") asyncio.run(main()) ``` Functionality between the synchronous and asynchronous clients is otherwise identical. ### With aiohttp [#with-aiohttp] By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend. ```bash pip install sentdm[aiohttp] ``` ```python import asyncio from sent_dm import DefaultAioHttpClient from sent_dm import AsyncSent async def main(): async with AsyncSent( http_client=DefaultAioHttpClient(), ) as client: response = await client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome", "parameters": {"name": "John Doe"} } ) print(f"Sent: {response.data.recipients[0].message_id}") asyncio.run(main()) ``` ## Send Messages [#send-messages] ### Send a message [#send-a-message] ```python from sent_dm import Sent client = Sent() response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome", "parameters": { "name": "John Doe", "order_id": "12345" } }, channel=["whatsapp", "sms", "rcs"] # Optional. Defaults to ["sent"], which auto-detects the channel per recipient ) print(f"Message ID: {response.data.recipients[0].message_id}") print(f"Status: {response.data.status}") ``` ### Sandbox mode [#sandbox-mode] Use `sandbox=True` to validate requests without sending real messages: ```python response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" }, sandbox=True # Validates but doesn't send ) # Response will have test data print(f"Validation passed: {response.data.recipients[0].message_id}") ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```python status = client.messages.retrieve_status("msg-uuid") print(f"Status: {status.data.status}") # e.g. "DELIVERED" print(f"Channel: {status.data.channel}") # e.g. "sms" print(f"Direction: {status.data.direction}") # "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```python activities = client.messages.retrieve_activities("msg-uuid") for activity in activities.data.activities: print(f"{activity.timestamp}: {activity.status} via {activity.from_}") print(f" Price: {activity.price}") print(f" Active contact price: {activity.active_contact_price}") ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```python result = client.numbers.lookup("+12025551234") print(f"Valid: {result.data.is_valid}") print(f"Carrier: {result.data.carrier_name}") print(f"Line type: {result.data.line_type}") # "mobile", "landline", "voip" print(f"VoIP: {result.data.is_voip}") ``` ## Handling errors [#handling-errors] When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `sent_dm.APIConnectionError` is raised. When the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of `sent_dm.APIStatusError` is raised, containing `status_code` and `response` properties. ```python import sent_dm from sent_dm import Sent client = Sent() try: response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) print(f"Sent: {response.data.recipients[0].message_id}") except sent_dm.APIConnectionError as e: print("The server could not be reached") print(e.__cause__) # an underlying Exception, likely raised within httpx. except sent_dm.RateLimitError as e: print("A 429 status code was received; we should back off a bit.") except sent_dm.APIStatusError as e: print("Another non-200-range status code was received") print(e.status_code) print(e.response) ``` Error codes are as follows: | Status Code | Error Type | |-------------|--------------------------| | 400 | `BadRequestError` | | 401 | `AuthenticationError` | | 403 | `PermissionDeniedError` | | 404 | `NotFoundError` | | 422 | `UnprocessableEntityError` | | 429 | `RateLimitError` | | >=500 | `InternalServerError` | | N/A | `APIConnectionError` | ## Retries [#retries] Certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors are all retried by default. ```python from sent_dm import Sent # Configure the default for all requests: client = Sent( max_retries=0, # default is 2 ) # Or, configure per-request: client.with_options(max_retries=5).messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) ``` ## Timeouts [#timeouts] By default requests time out after 1 minute. You can configure this with a `timeout` option: ```python import httpx from sent_dm import Sent # Configure the default for all requests: client = Sent( timeout=20.0, # 20 seconds (default is 1 minute) ) # More granular control: client = Sent( timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0), ) # Override per-request: client.with_options(timeout=5.0).messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) ``` ## Contacts [#contacts] Create and manage contacts: ```python # Create a contact response = client.contacts.create( phone_number="+1234567890" ) print(f"Contact ID: {response.data.id}") # List contacts responses = client.contacts.list(page=1, page_size=100) for contact in responses.data.contacts: print(f"{contact.phone_number} - {contact.available_channels}") # Get a contact response = client.contacts.retrieve("contact-uuid") # Update a contact response = client.contacts.update( "contact-uuid", default_channel="whatsapp" ) # Delete a contact client.contacts.delete("contact-uuid") ``` ## Templates [#templates] List and retrieve templates: ```python # List all templates response = client.templates.list(page=1, page_size=100) for template in response.data.templates: print(f"{template.name} ({template.status}): {template.id}") # Get a specific template response = client.templates.retrieve("template-uuid") print(f"Name: {response.data.name}") print(f"Status: {response.data.status}") ``` ## Framework Integration [#framework-integration] Dedicated guides cover client setup, message sending, verified webhook handling, and sandbox testing for each framework: ## Raw responses [#raw-responses] To access response headers, status code, or raw body, prefix any HTTP method call with `.with_raw_response.`: ```python response = client.with_raw_response.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) print(response.status_code) # 200 print(response.headers.get("x-request-id")) # Request ID for support # Deserialize the body data = response.parse() print(data.data.recipients[0].message_id) ``` ## Streaming responses [#streaming-responses] The async client supports streaming responses for large data: ```python from sent_dm import AsyncSent client = AsyncSent() async with client.messages.with_streaming_response.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" } ) as response: async for chunk in response.iter_bytes(): print(chunk) ``` ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` and the signature format is `v1,{base64(hmac)}`. A [version 1](/start/webhooks/event-types#webhook-versions) webhook sends the same values in `X-Webhook-ID`, `X-Webhook-Timestamp`, and `X-Webhook-Signature`. ```python import base64 import hashlib import hmac import json import os import time from flask import Flask, request, jsonify app = Flask(__name__) @app.post('/webhooks/sent') def handle_webhook(): payload = request.get_data() # raw bytes — do NOT parse JSON first # Version 2 headers first, falling back to version 1 (X-Webhook-*) webhook_id = request.headers.get('webhook-id') or request.headers.get('X-Webhook-ID', '') timestamp = request.headers.get('webhook-timestamp') or request.headers.get('X-Webhook-Timestamp', '') signature = request.headers.get('webhook-signature') or request.headers.get('X-Webhook-Signature', '') # 1. Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" secret = os.environ['SENT_DM_WEBHOOK_SECRET'] # "whsec_abc123..." key_bytes = base64.b64decode(secret.removeprefix('whsec_')) signed = f"{webhook_id}.{timestamp}.{payload.decode('utf-8')}" digest = hmac.new(key_bytes, signed.encode('utf-8'), hashlib.sha256).digest() expected = 'v1,' + base64.b64encode(digest).decode() # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match if not any(hmac.compare_digest(sig, expected) for sig in signature.split()): return jsonify({'error': 'Invalid signature'}), 401 # 2. Optional: reject replayed events older than 5 minutes if abs(time.time() - int(timestamp)) > 300: return jsonify({'error': 'Timestamp too old'}), 401 event = json.loads(payload) # 3. Handle events — update message status in your own database if event.get('field') == 'message': event_type = event.get('event') msg = event['payload'] if event_type == 'message.received': # Inbound message from a contact print(f"Inbound {msg['channel']} from {msg['inbound_number']}: {msg.get('text')}") # db.inbound_messages.create(from_number=msg['inbound_number'], text=msg.get('text'), ...) else: # Outbound message status update # db.messages.filter(sent_id=msg['message_id']).update(status=msg['message_status']) print(f"Message {msg['message_id']} → {msg['message_status']}") # 4. Always return 200 quickly return jsonify({'received': True}) ``` See the [Webhooks reference](/start/webhooks) for the full payload schema and all status values. ## Logging [#logging] The SDK uses the standard library [`logging`](https://docs.python.org/3/library/logging.html) module. You can enable logging by setting the environment variable `SENT_LOG` to `info`: ```bash export SENT_LOG=info ``` Or to `debug` for more verbose logging. ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-python/releases) - **GitHub**: [`sentdm/sent-dm-python`](https://github.com/sentdm/sent-dm-python) - **PyPI**: [`sentdm`](https://pypi.org/project/sentdm/) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-python/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending Sent messages from Celery background tasks (/sdks/python/integrations/celery.md) # Sending Sent messages from Celery background tasks [#sending-sent-messages-from-celery-background-tasks] This guide shows you how to move Sent message sending into Celery: install the Python SDK, share one client per worker process, add a send task with retry handling, process webhook events off the request path, and verify the task in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Celery setup (broker running, worker starting) inside a Python web project. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A web framework endpoint for webhooks. The [Flask](/sdks/python/integrations/flask), [Django](/sdks/python/integrations/django), and [FastAPI](/sdks/python/integrations/fastapi) guides each build one; Celery workers do not receive HTTP requests themselves ### Install the SDK [#install-the-sdk] Add the `sentdm` package to the environment your workers run in: ```bash pip install sentdm ``` ### Configure a worker-safe client [#configure-a-worker-safe-client] Export the API key where the worker can read it: ```bash export SENT_DM_API_KEY="your-api-key" ``` Create the client lazily inside a base task class, so each worker process builds exactly one client after forking instead of sharing one across processes: ```python # celery_app/base_task.py import os from celery import Task class SentTask(Task): abstract = True max_retries = 3 default_retry_delay = 60 retry_backoff = True # 60s, 120s, 240s, ... between retries retry_jitter = True _sent_client = None @property def sent_client(self): if self._sent_client is None: from sent_dm import Sent api_key = os.getenv("SENT_DM_API_KEY") if not api_key: raise RuntimeError("SENT_DM_API_KEY not configured") self._sent_client = Sent(api_key=api_key) return self._sent_client ``` ### Add a send task [#add-a-send-task] Write the task that calls `messages.send`. Retry on transient failures, but never on validation errors (a request that was invalid once is invalid every time): ```python # tasks/messages.py import logging from celery import shared_task from sent_dm import APIStatusError, APIConnectionError, RateLimitError from celery_app.base_task import SentTask logger = logging.getLogger(__name__) @shared_task(base=SentTask, bind=True, name="tasks.messages.send_message", queue="messages") def send_message(self, phone_number: str, template_name: str, parameters: dict | None = None, channels: list | None = None, sandbox: bool = False) -> dict: try: response = self.sent_client.messages.send( to=[phone_number], # E.164 format, for example +14155551234 template={ "name": template_name, # reference by "name" or "id", never both "parameters": parameters or {}, }, channel=channels, # omit to let Sent pick per recipient sandbox=sandbox, # True = validate and simulate only ) except RateLimitError as exc: # Back off and retry when the API rate limit is hit raise self.retry(exc=exc, countdown=60 * (2 ** self.request.retries)) except APIConnectionError as exc: # Network problems are transient: retry with backoff raise self.retry(exc=exc) except APIStatusError as exc: if exc.status_code and exc.status_code < 500: logger.error("Non-retryable send failure (%s): %s", exc.status_code, exc) raise # 4xx: the request itself is wrong; retrying cannot fix it raise self.retry(exc=exc) recipient = response.data.recipients[0] logger.info("Message queued: %s", recipient.message_id) return {"message_id": recipient.message_id, "status": response.data.status} ``` Call it from your web code with `.delay(...)`. The request returns immediately and the worker does the sending: ```python send_message.delay("+14155551234", "welcome", {"name": "Ada"}) ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id` from the task result, since delivery outcomes arrive as webhooks rather than in this response. ### Process webhook events off the request path [#process-webhook-events-off-the-request-path] Keep your webhook endpoint fast by acknowledging immediately and handing the verified event envelope (`field`, `event`, `timestamp`, `payload`) to a task. Signature verification must stay in the web endpoint, where the raw request bytes are available. See [webhook signature verification](/start/webhooks/signature-verification): ```python # tasks/webhooks.py import logging from celery import shared_task logger = logging.getLogger(__name__) @shared_task(name="tasks.webhooks.process_event", queue="webhooks") def process_event(event: dict) -> None: payload = event.get("payload", {}) if event.get("field") != "message": return match event.get("event"): case "message.delivered": logger.info("Message %s delivered", payload.get("message_id")) case "message.failed": logger.error("Message %s failed (status %s)", payload.get("message_id"), payload.get("message_status")) case "message.received": logger.info("Inbound %s from %s: %s", payload.get("channel"), payload.get("inbound_number"), payload.get("text")) case _: logger.info("Message %s status: %s", payload.get("message_id"), payload.get("message_status")) ``` In the webhook endpoint from your framework guide, replace the inline processing with one line after verification succeeds: ```python process_event.delay(event) ``` ### Verify the task [#verify-the-task] Start a worker on the messages queue: ```bash celery -A celery_app.app worker --queues=messages --loglevel=info ``` Trigger a sandbox send from a shell. Full validation runs, but nothing is delivered and no credits are consumed: ```python # python manage.py shell, flask shell, or plain python from tasks.messages import send_message result = send_message.delay("+14155551234", "welcome", {"name": "Ada"}, sandbox=True) print(result.get(timeout=30)) ``` The result should contain a `message_id` and `"status": "QUEUED"`, and the worker log should show a `Message queued: ...` line. A `BadRequestError` in the worker log means the request shape is wrong: sandbox requests return real validation errors. If the task never runs, confirm the worker is consuming the `messages` queue named in the task decorator. ## Adapt this to your app [#adapt-this-to-your-app] - If you send campaigns to large lists, fan out one task per recipient rather than looping inside a single task. The appendix below shows the batch pattern. - If you schedule recurring sends, drive them with Celery beat and call the same `send_message` task from the schedule. - If your workers hit API rate limits under load, lower worker concurrency for the `messages` queue or set a Celery `rate_limit` on the task before adding custom throttling. - To send free-form text instead of a template, pass `text` instead of `template`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Celery deployment. Adapt them to your own conventions rather than adopting them wholesale. Route message traffic to dedicated queues so a bulk campaign cannot starve transactional sends: ```python # celery_app/config.py import os class CeleryConfig: broker_url = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0") result_backend = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/1") task_serializer = "json" accept_content = ["json"] task_acks_late = True # re-deliver if a worker dies mid-task worker_prefetch_multiplier = 1 # fair scheduling for slow API-bound tasks task_time_limit = 300 task_soft_time_limit = 240 task_routes = { "tasks.messages.*": {"queue": "messages"}, "tasks.webhooks.*": {"queue": "webhooks"}, } ``` Queue one task per recipient so retries and failures stay per-message: ```python # tasks/bulk.py from celery import shared_task from tasks.messages import send_message @shared_task(name="tasks.bulk.send_batch", queue="messages") def send_batch(recipients: list[dict], template_name: str) -> dict: queued, failed = 0, [] for r in recipients: try: send_message.delay(r["phone_number"], template_name, r.get("parameters")) queued += 1 except Exception as e: failed.append({"recipient": r.get("phone_number"), "error": str(e)}) return {"queued": queued, "failed": len(failed), "errors": failed} ``` Run the broker, worker, and beat scheduler as one stack; credentials come in as environment variables: ```yaml # docker-compose.yml services: redis: image: redis:7-alpine worker: build: . command: celery -A celery_app.app worker --queues=messages,webhooks --loglevel=info environment: - SENT_DM_API_KEY=${SENT_DM_API_KEY} - CELERY_BROKER_URL=redis://redis:6379/0 depends_on: [redis] beat: build: . command: celery -A celery_app.app beat --loglevel=info environment: - CELERY_BROKER_URL=redis://redis:6379/0 depends_on: [redis] ``` The [SDK testing guide](/sdks/testing) covers mocking `messages.send` in task tests. ## Next steps [#next-steps] - Build the webhook endpoint in your web framework: [Flask](/sdks/python/integrations/flask), [Django](/sdks/python/integrations/django), or [FastAPI](/sdks/python/integrations/fastapi) - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Explore the [Python SDK reference](/sdks/python) for error types and client options - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sending messages from Django with the Sent Python SDK (/sdks/python/integrations/django.md) # Sending messages from Django with the Sent Python SDK [#sending-messages-from-django-with-the-sent-python-sdk] This guide shows you how to wire Sent messaging into an existing Django project: install the Python SDK, configure a shared client, send a template message from a view, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Django 4.2+ project and familiarity with views and URL configuration. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the `sentdm` package to your existing environment: ```bash pip install sentdm ``` ### Configure the client [#configure-the-client] Read the credentials in `settings.py` so every module gets them from one place; the webhook secret arrives in step 4: ```python # settings.py import os SENT_DM_API_KEY = os.environ.get("SENT_DM_API_KEY") SENT_DM_WEBHOOK_SECRET = os.environ.get("SENT_DM_WEBHOOK_SECRET") if not SENT_DM_API_KEY: raise ValueError("SENT_DM_API_KEY environment variable is required.") ``` Create one cached client for the whole process instead of building a new one per request: ```python # sent_integration/client.py from functools import lru_cache from django.conf import settings from sent_dm import Sent @lru_cache(maxsize=1) def get_sent_client() -> Sent: return Sent(api_key=settings.SENT_DM_API_KEY) ``` ### Send a template message from a view [#send-a-template-message-from-a-view] Add a JSON view that calls `messages.send`; the pass-through `sandbox` flag lets callers exercise the view without delivering anything. Protect the route with your existing API authentication (it is left open here for brevity): ```python # sent_integration/views.py import json from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from .client import get_sent_client @csrf_exempt @require_POST def send_message(request): data = json.loads(request.body) response = get_sent_client().messages.send( to=[data["phone_number"]], # E.164 format, for example +14155551234 template={ "name": data["template_name"], # reference by "name" or "id", never both "parameters": data.get("parameters", {}), }, channel=data.get("channels"), # omit to let Sent pick per recipient sandbox=data.get("sandbox", False), # True = validate and simulate only ) recipient = response.data.recipients[0] return JsonResponse( {"message_id": recipient.message_id, "status": response.data.status}, status=202, ) ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`. Delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a webhook view that verifies the `webhook-signature` header against the raw request body before trusting any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```python # sent_integration/webhooks.py import base64 import hashlib import hmac import json import logging import time from django.conf import settings from django.http import JsonResponse from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.csrf import csrf_exempt logger = logging.getLogger(__name__) @method_decorator(csrf_exempt, name="dispatch") class WebhookView(View): http_method_names = ["post"] def post(self, request, *args, **kwargs): webhook_secret = getattr(settings, "SENT_DM_WEBHOOK_SECRET", None) if not webhook_secret: return JsonResponse({"error": "Webhook secret not configured"}, status=500) # Version 2 headers first, falling back to version 1 (X-Webhook-*) signature = request.headers.get("webhook-signature") or request.headers.get("X-Webhook-Signature", "") webhook_id = request.headers.get("webhook-id") or request.headers.get("X-Webhook-ID", "") timestamp = request.headers.get("webhook-timestamp") or request.headers.get("X-Webhook-Timestamp", "") if not signature: return JsonResponse({"error": "Missing signature"}, status=401) # Strip the "whsec_" prefix and base64-decode to get the raw HMAC key key_bytes = base64.b64decode(webhook_secret.removeprefix("whsec_")) # Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" signed = f"{webhook_id}.{timestamp}.{request.body.decode('utf-8')}" digest = hmac.new(key_bytes, signed.encode("utf-8"), hashlib.sha256).digest() expected = "v1," + base64.b64encode(digest).decode() # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match if not any(hmac.compare_digest(sig, expected) for sig in signature.split()): return JsonResponse({"error": "Invalid signature"}, status=401) # Reject replayed events older than 5 minutes try: if abs(time.time() - int(timestamp)) > 300: return JsonResponse({"error": "Timestamp too old"}, status=401) except ValueError: return JsonResponse({"error": "Invalid timestamp"}, status=401) event = json.loads(request.body.decode("utf-8")) payload = event.get("payload", {}) # Envelope: {"field": ..., "event": ..., "timestamp": ..., "payload": {...}} if event.get("field") != "message": return JsonResponse({"received": True}) match event.get("event"): case "message.delivered": logger.info("Message %s delivered", payload.get("message_id")) case "message.failed": logger.error("Message %s failed (status %s)", payload.get("message_id"), payload.get("message_status")) case "message.received": logger.info("Inbound %s from %s: %s", payload.get("channel"), payload.get("inbound_number"), payload.get("text")) case _: logger.info("Message %s status: %s", payload.get("message_id"), payload.get("message_status")) return JsonResponse({"received": True}) ``` Route both views in your URL configuration: ```python # urls.py from django.urls import path from sent_integration import views, webhooks urlpatterns = [ path("api/messages/send", views.send_message), path("webhooks/sent/", webhooks.WebhookView.as_view()), ] ``` Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Django integration", "endpoint_url": "https://your-domain.example/webhooks/sent/", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the development server with your credentials loaded: ```bash python manage.py runserver ``` Send a sandbox message through your new view. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:8000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phone_number": "+14155551234", "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your Django log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you track delivery state, persist a record keyed by `message_id` when you send, then update it from the webhook handlers. The appendix below has a model for this. - If you send in bulk or on a schedule, move the `messages.send` call into a background worker; the [Celery integration guide](/sdks/python/integrations/celery) shows the pattern. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and hand off to a task queue so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send free-form text instead of a template, pass `text` instead of `template`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Django stack. Adapt them to your own conventions rather than adopting them wholesale. Persist one row per send and update it from webhook events, keyed by the `message_id` Sent returned: ```python # sent_integration/models.py from django.db import models class SentMessage(models.Model): sent_id = models.CharField(max_length=64, unique=True, null=True) phone_number = models.CharField(max_length=20) template_name = models.CharField(max_length=100) status = models.CharField(max_length=20, default="pending") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) ``` In the webhook handlers, replace the log lines with an update: ```python SentMessage.objects.filter(sent_id=payload.get("message_id")).update( status=(payload.get("message_status") or "").lower() ) ``` If your project exposes its API through DRF, wrap the send call in a serializer-validated `APIView` instead of the plain view: ```python # sent_integration/serializers.py from rest_framework import serializers class SendMessageSerializer(serializers.Serializer): phone_number = serializers.RegexField(r"^\+[1-9]\d{1,14}$") template_name = serializers.CharField(max_length=100) parameters = serializers.DictField(child=serializers.CharField(), required=False) channels = serializers.ListField(child=serializers.ChoiceField(["sms", "whatsapp", "rcs"]), required=False) sandbox = serializers.BooleanField(default=False) ``` Keep webhook views outside DRF authentication. Sent authenticates with the signature, not a session or token. Fail fast at boot when configuration is missing instead of at first send: ```python # sent_integration/apps.py import warnings from django.apps import AppConfig from django.conf import settings class SentIntegrationConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "sent_integration" def ready(self): if not getattr(settings, "SENT_DM_WEBHOOK_SECRET", None): warnings.warn("SENT_DM_WEBHOOK_SECRET is not set. Webhook verification will fail.", RuntimeWarning, stacklevel=2) ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Python SDK reference](/sdks/python) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sending messages from FastAPI with the Sent Python SDK (/sdks/python/integrations/fastapi.md) # Sending messages from FastAPI with the Sent Python SDK [#sending-messages-from-fastapi-with-the-sent-python-sdk] This guide shows you how to wire Sent messaging into an existing FastAPI app: install the Python SDK, manage an async client with the app lifespan, send a template message from a route, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working FastAPI app and familiarity with dependencies and Pydantic models. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the `sentdm` package to your existing environment: ```bash pip install sentdm ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Open one `AsyncSent` client at startup and close it at shutdown, so every request shares the same connection pool; `AsyncSent()` reads `SENT_DM_API_KEY` by default: ```python # app/sent_client.py from contextlib import asynccontextmanager from typing import AsyncGenerator from fastapi import FastAPI from sent_dm import AsyncSent class SentClientManager: def __init__(self) -> None: self._client: AsyncSent | None = None async def startup(self) -> None: self._client = AsyncSent() await self._client.__aenter__() async def shutdown(self) -> None: if self._client: await self._client.__aexit__(None, None, None) self._client = None @property def client(self) -> AsyncSent: if self._client is None: raise RuntimeError("Sent client not initialized") return self._client sent_manager = SentClientManager() @asynccontextmanager async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: await sent_manager.startup() yield await sent_manager.shutdown() ``` Attach the lifespan and expose the client as a dependency: ```python # app/main.py (excerpt) from fastapi import FastAPI from sent_dm import AsyncSent from app.sent_client import lifespan, sent_manager app = FastAPI(lifespan=lifespan) def get_sent_client() -> AsyncSent: return sent_manager.client ``` ### Send a template message from a route [#send-a-template-message-from-a-route] Add a validated route that calls `messages.send`; the pass-through `sandbox` flag lets callers exercise the route without delivering anything: ```python # app/routers/messages.py from fastapi import APIRouter, Depends, status from pydantic import BaseModel, Field from sent_dm import AsyncSent from app.main import get_sent_client router = APIRouter(prefix="/api/messages", tags=["Messages"]) class SendMessageRequest(BaseModel): phone_number: str = Field(pattern=r"^\+[1-9]\d{1,14}$") # E.164 format template_name: str parameters: dict[str, str] = Field(default_factory=dict) channels: list[str] | None = None # omit to let Sent pick per recipient sandbox: bool = False # True = validate and simulate only @router.post("/send", status_code=status.HTTP_202_ACCEPTED) async def send_message( request: SendMessageRequest, client: AsyncSent = Depends(get_sent_client), ) -> dict[str, str]: response = await client.messages.send( to=[request.phone_number], template={ "name": request.template_name, # reference by "name" or "id", never both "parameters": request.parameters, }, channel=request.channels, sandbox=request.sandbox, ) recipient = response.data.recipients[0] return {"message_id": recipient.message_id, "status": response.data.status} ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`. Delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a dependency that verifies the `webhook-signature` header against the raw request body before your handler trusts any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. For the full scheme, refer to [webhook signature verification](/start/webhooks/signature-verification): ```python # app/dependencies.py import base64 import hashlib import hmac import os import time from fastapi import Request, Header, HTTPException, status async def verify_webhook_signature( request: Request, # Version 2 headers (webhook-*); version 1 webhooks send X-Webhook-* instead webhook_signature: str | None = Header(None), webhook_id: str | None = Header(None), webhook_timestamp: str | None = Header(None), x_webhook_signature: str | None = Header(None), x_webhook_id: str | None = Header(None), x_webhook_timestamp: str | None = Header(None), ) -> bytes: signature = webhook_signature or x_webhook_signature webhook_id = webhook_id or x_webhook_id or "" timestamp = webhook_timestamp or x_webhook_timestamp or "" if not signature: raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Missing webhook-signature header") webhook_secret = os.environ.get("SENT_DM_WEBHOOK_SECRET") if not webhook_secret: raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR, "Webhook secret not configured") payload = await request.body() # Strip the "whsec_" prefix and base64-decode to get the raw HMAC key key_bytes = base64.b64decode(webhook_secret.removeprefix("whsec_")) # Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" signed = f"{webhook_id}.{timestamp}.{payload.decode('utf-8')}" digest = hmac.new(key_bytes, signed.encode("utf-8"), hashlib.sha256).digest() expected = "v1," + base64.b64encode(digest).decode() # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match if not any(hmac.compare_digest(sig, expected) for sig in signature.split()): raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Invalid webhook signature") # Reject replayed events older than 5 minutes try: if abs(time.time() - int(timestamp)) > 300: raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Timestamp outside tolerance") except ValueError: raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Invalid timestamp") from None return payload ``` Add the endpoint itself. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; `BackgroundTasks` returns 200 immediately and processes the event after the response: ```python # app/routers/webhooks.py import json import logging from typing import Any from fastapi import APIRouter, BackgroundTasks, Depends, status from app.dependencies import verify_webhook_signature logger = logging.getLogger(__name__) router = APIRouter(prefix="/webhooks", tags=["Webhooks"]) async def process_webhook_event(event: dict[str, Any]) -> None: payload = event.get("payload", {}) if event.get("field") != "message": logger.info("Unhandled webhook field: %s", event.get("field")) return match event.get("event"): case "message.delivered": logger.info("Message %s delivered", payload.get("message_id")) case "message.failed": logger.error("Message %s failed (status %s)", payload.get("message_id"), payload.get("message_status")) case "message.received": logger.info("Inbound %s from %s: %s", payload.get("channel"), payload.get("inbound_number"), payload.get("text")) case _: logger.info("Message %s status: %s", payload.get("message_id"), payload.get("message_status")) @router.post("/sent", status_code=status.HTTP_200_OK) async def handle_webhook( background_tasks: BackgroundTasks, payload: bytes = Depends(verify_webhook_signature), ) -> dict[str, bool]: background_tasks.add_task(process_webhook_event, json.loads(payload)) return {"received": True} ``` Include both routers in your app, then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "FastAPI integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Set `SENT_DM_WEBHOOK_SECRET` to that value. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash uvicorn app.main:app --reload ``` Send a sandbox message through your new route, which runs full validation but delivers nothing and consumes no credits: ```bash curl -X POST http://localhost:8000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phone_number": "+14155551234", "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 422 or 400 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your application log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you already manage settings with `pydantic-settings`, read `SENT_DM_API_KEY` and `SENT_DM_WEBHOOK_SECRET` there and pass them explicitly. The appendix below shows the pattern. - If a webhook event triggers slow work beyond a `BackgroundTasks` call (fan-out, long database writes), hand it to a task queue instead; see [handling webhook retries](/start/webhooks/handling-retries). - To send to many recipients, pass them all in `to`; Sent creates one message per recipient-and-channel pair in a single call. - To send free-form text instead of a template, pass `text` instead of `template`, since each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production FastAPI stack. Adapt them to your own conventions rather than adopting them wholesale. Fail fast at boot when required variables are missing instead of at first send: ```python # app/config.py from functools import lru_cache from pydantic_settings import BaseSettings class Settings(BaseSettings): sent_dm_api_key: str sent_dm_webhook_secret: str = "" rate_limit: str = "10/minute" @lru_cache def get_settings() -> Settings: return Settings() ``` Cap how often callers can hit your send route: ```python # app/dependencies.py (addition) from slowapi import Limiter from slowapi.util import get_remote_address limiter = Limiter(key_func=get_remote_address) # in main.py: app.state.limiter = limiter # on the route: @limiter.limit("10/minute") ``` Collect successes and failures separately when looping over many sends: ```python # app/services/batch.py async def send_batch(client, requests: list[SendMessageRequest]) -> dict: messages, errors = [], [] for req in requests: try: response = await client.messages.send( to=[req.phone_number], template={"name": req.template_name, "parameters": req.parameters}, sandbox=req.sandbox, ) messages.append(response.data.recipients[0].message_id) except Exception as e: errors.append({"recipient": req.phone_number, "error": str(e)}) return {"successful": len(messages), "failed": len(errors), "message_ids": messages, "errors": errors} ``` The [SDK testing guide](/sdks/testing) covers mocking `messages.send` in pytest. ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Python SDK reference](/sdks/python) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sending messages from Flask with the Sent Python SDK (/sdks/python/integrations/flask.md) # Sending messages from Flask with the Sent Python SDK [#sending-messages-from-flask-with-the-sent-python-sdk] This guide shows you how to wire Sent messaging into an existing Flask app: install the Python SDK, configure a shared client, send a template message from a route, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Flask 3.x app and familiarity with blueprints. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the `sentdm` package to your existing environment: ```bash pip install sentdm ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Create one shared client and cache it on Flask's request context; `Sent()` reads `SENT_DM_API_KEY` by default: ```python # app/sent_client.py from flask import g from sent_dm import Sent def get_sent_client() -> Sent: if "sent_client" not in g: g.sent_client = Sent() return g.sent_client ``` ### Send a template message from a route [#send-a-template-message-from-a-route] Add a blueprint route that calls `messages.send`; the pass-through `sandbox` flag lets callers exercise the route without delivering anything: ```python # app/messages.py from flask import Blueprint, jsonify, request from app.sent_client import get_sent_client messages_bp = Blueprint("messages", __name__, url_prefix="/api/messages") @messages_bp.post("/send") def send_message(): data = request.get_json(force=True) response = get_sent_client().messages.send( to=[data["phone_number"]], # E.164 format, for example +14155551234 template={ "name": data["template_name"], # reference by "name" or "id", never both "parameters": data.get("parameters", {}), }, channel=data.get("channels"), # omit to let Sent pick per recipient sandbox=data.get("sandbox", False), # True = validate and simulate only ) recipient = response.data.recipients[0] return jsonify({"message_id": recipient.message_id, "status": response.data.status}), 202 ``` Register the blueprint wherever you create your app: ```python app.register_blueprint(messages_bp) ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`: delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a decorator that verifies the `webhook-signature` header against the raw request body before your handler trusts any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. See [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```python # app/webhook_auth.py import base64 import functools import hashlib import hmac import os import time from flask import request, jsonify def verify_webhook_signature(f): @functools.wraps(f) def decorated_function(*args, **kwargs): # Version 2 headers first, falling back to version 1 (X-Webhook-*) signature = request.headers.get('webhook-signature') or request.headers.get('X-Webhook-Signature') if not signature: return jsonify({'error': 'Missing webhook signature'}), 401 webhook_secret = os.environ.get('SENT_DM_WEBHOOK_SECRET') if not webhook_secret: return jsonify({'error': 'Webhook secret not configured'}), 500 webhook_id = request.headers.get('webhook-id') or request.headers.get('X-Webhook-ID', '') timestamp = request.headers.get('webhook-timestamp') or request.headers.get('X-Webhook-Timestamp', '') # Strip the "whsec_" prefix and base64-decode to get the raw HMAC key key_bytes = base64.b64decode(webhook_secret.removeprefix('whsec_')) # Signed content = "{webhookId}.{timestamp}.{rawBody}"; signature format = "v1,{base64(hmac)}" signed = f"{webhook_id}.{timestamp}.{request.get_data().decode('utf-8')}" digest = hmac.new(key_bytes, signed.encode('utf-8'), hashlib.sha256).digest() expected = 'v1,' + base64.b64encode(digest).decode() # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match if not any(hmac.compare_digest(sig, expected) for sig in signature.split()): return jsonify({'error': 'Invalid signature'}), 401 # Reject replayed events older than 5 minutes try: if abs(time.time() - int(timestamp)) > 300: return jsonify({'error': 'Timestamp too old'}), 401 except ValueError: return jsonify({'error': 'Invalid timestamp'}), 401 return f(*args, **kwargs) return decorated_function ``` Add the endpoint itself. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; return 200 quickly and do slow work elsewhere: ```python # app/webhooks.py import logging from flask import Blueprint, jsonify, request from app.webhook_auth import verify_webhook_signature logger = logging.getLogger(__name__) webhooks_bp = Blueprint("webhooks", __name__, url_prefix="/webhooks") @webhooks_bp.post("/sent") @verify_webhook_signature def handle_sent_webhook(): event = request.get_json(force=True) payload = event.get("payload", {}) if event.get("field") != "message": logger.info("Unhandled webhook field: %s", event.get("field")) return jsonify({"received": True}), 200 match event.get("event"): case "message.delivered": logger.info("Message %s delivered", payload.get("message_id")) case "message.failed": logger.error("Message %s failed (status %s)", payload.get("message_id"), payload.get("message_status")) case "message.received": logger.info("Inbound %s from %s: %s", payload.get("channel"), payload.get("inbound_number"), payload.get("text")) case _: logger.info("Message %s status: %s", payload.get("message_id"), payload.get("message_status")) return jsonify({"received": True}), 200 ``` Register `webhooks_bp` the same way as the messages blueprint, then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Flask integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`, which goes in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash flask run ``` Send a sandbox message through your new route (full validation runs, but nothing is delivered and no credits are consumed): ```bash curl -X POST http://localhost:5000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phone_number": "+14155551234", "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 here means the request shape is wrong. Sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your Flask log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you send in bulk or on a schedule, move the `messages.send` call into a background worker; the [Celery integration guide](/sdks/python/integrations/celery) shows the pattern. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and process asynchronously so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send free-form text instead of a template, pass `text` instead of `template`, since each send carries exactly one of the two. - If you need request validation, rate limiting, or security headers around these routes, the appendix below has the scaffolding. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional deployment scaffolding for a Flask stack. Adapt them to your own conventions rather than adopting them wholesale. Load per-environment settings from a config object instead of scattered `os.getenv` calls: ```python # app/config.py import os class Config: SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key') SENT_DM_API_KEY = os.getenv('SENT_DM_API_KEY') SENT_DM_WEBHOOK_SECRET = os.getenv('SENT_DM_WEBHOOK_SECRET') class DevelopmentConfig(Config): DEBUG = True class TestingConfig(Config): TESTING = True SENT_DM_API_KEY = 'test-api-key' # whsec_ + base64("test-webhook-secret") — matches the documented secret format SENT_DM_WEBHOOK_SECRET = 'whsec_dGVzdC13ZWJob29rLXNlY3JldA==' class ProductionConfig(Config): DEBUG = False ``` Wire the blueprints into an application factory if your project uses one: ```python # app/__init__.py from flask import Flask from app.messages import messages_bp from app.webhooks import webhooks_bp def create_app(config_object="app.config.ProductionConfig"): app = Flask(__name__) app.config.from_object(config_object) app.register_blueprint(messages_bp) app.register_blueprint(webhooks_bp) return app ``` Flask-Limiter caps how often callers can hit your send route; Flask-Talisman adds security headers such as `Strict-Transport-Security` and `Content-Security-Policy`: ```python # app/extensions.py from flask_limiter import Limiter from flask_limiter.util import get_remote_address from flask_talisman import Talisman limiter = Limiter(key_func=get_remote_address, default_limits=["100 per minute"]) talisman = Talisman() # in create_app(): # limiter.init_app(app) # talisman.init_app(app, force_https=False, strict_transport_security=True) # per route: @limiter.limit("10 per minute") ``` Point `RATELIMIT_STORAGE_URI` at Redis (for example `redis://redis:6379/0`) when you run more than one worker. Run Flask behind Gunicorn in production: ```python # gunicorn.conf.py import multiprocessing import os bind = os.getenv('GUNICORN_BIND', '0.0.0.0:8000') workers = multiprocessing.cpu_count() * 2 + 1 timeout = 30 accesslog = '-' errorlog = '-' ``` Containerize with a minimal image; credentials come in as environment variables at run time: ```dockerfile FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD ["gunicorn", "-c", "gunicorn.conf.py", "wsgi:app"] ``` This pytest helper signs payloads exactly the way Sent does, so you can test the verification decorator offline; the [SDK testing guide](/sdks/testing) covers mocking `messages.send`: ```python # tests/test_webhooks.py import base64, hashlib, hmac, json, time def signed_headers(payload: str, secret: str) -> dict: webhook_id = '550e8400-e29b-41d4-a716-446655440000' timestamp = str(int(time.time())) key_bytes = base64.b64decode(secret.removeprefix('whsec_')) signed = f"{webhook_id}.{timestamp}.{payload}" digest = hmac.new(key_bytes, signed.encode('utf-8'), hashlib.sha256).digest() return { 'X-Webhook-Signature': 'v1,' + base64.b64encode(digest).decode(), 'X-Webhook-ID': webhook_id, 'X-Webhook-Timestamp': timestamp, } def test_webhook_valid_signature(client, app): payload = json.dumps({'field': 'message', 'event': 'message.delivered', 'payload': {'message_id': 'msg_123', 'message_status': 'DELIVERED'}}) response = client.post('/webhooks/sent', data=payload, headers=signed_headers(payload, app.config['SENT_DM_WEBHOOK_SECRET'])) assert response.status_code == 200 ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Python SDK reference](/sdks/python) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Ruby SDK (/sdks/ruby.md) # Ruby SDK [#ruby-sdk] The official Ruby SDK for Sent provides an elegant, Ruby-idiomatic interface for sending messages. Designed for Rails applications, with Yard docstrings and RBS and RBI type signatures. ## Requirements [#requirements] Ruby 3.2.0 or later. ## Installation [#installation] To use this gem, install via Bundler by adding the following to your app's `Gemfile`: ```ruby gem "sentdm" ``` Then run: ```bash bundle install ``` Or install directly: ```bash gem install sentdm ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```ruby require "sentdm" sent_dm = Sentdm::Client.new( api_key: ENV["SENT_DM_API_KEY"] # This is the default and can be omitted ) ``` ### Send your first message [#send-your-first-message] ```ruby require "sentdm" sent_dm = Sentdm::Client.new result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome", parameters: { name: "John Doe", order_id: "12345" } }, channel: ["sms", "whatsapp", "rcs"] ) puts(result.data.recipients[0].message_id) puts(result.data.status) ``` ## Authentication [#authentication] The client reads `SENT_DM_API_KEY` from the environment by default, or you can pass it explicitly: ```ruby require "sentdm" # Using environment variables sent_dm = Sentdm::Client.new # Or explicit configuration sent_dm = Sentdm::Client.new( api_key: "your_api_key" ) ``` ## Send Messages [#send-messages] The Ruby SDK uses `send_` (with trailing underscore) instead of `send` because `send` is a reserved method in Ruby's Object class. ### Send a message [#send-a-message] ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome", parameters: { name: "John Doe", order_id: "12345" } }, channel: ["sms", "whatsapp", "rcs"] ) puts(result.data.recipients[0].message_id) puts(result.data.status) ``` ### Sandbox mode [#sandbox-mode] Use `sandbox: true` to validate requests without sending real messages: ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome" }, sandbox: true # Validates but doesn't send ) # Response will have test data puts(result.data.recipients[0].message_id) puts(result.data.status) ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```ruby status = sent_dm.messages.retrieve_status("msg-uuid") puts status.data.status # e.g. "DELIVERED" puts status.data.channel # e.g. "sms" puts status.data.direction # "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```ruby activities = sent_dm.messages.retrieve_activities("msg-uuid") activities.data.activities.each do |activity| puts "#{activity.timestamp}: #{activity.status} via #{activity.from}" puts " Price: #{activity.price}" puts " Active contact price: #{activity.active_contact_price}" end ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```ruby result = sent_dm.numbers.lookup("+12025551234") puts result.data.is_valid # true/false puts result.data.carrier_name # e.g. "T-Mobile" puts result.data.line_type # "mobile", "landline", "voip" puts result.data.is_voip # true/false ``` ## Handling errors [#handling-errors] When the library is unable to connect to the API, or if the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of `Sentdm::Errors::APIError` will be thrown: ```ruby begin result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome", parameters: {name: "John Doe", order_id: "12345"} } ) rescue Sentdm::Errors::APIConnectionError => e puts("The server could not be reached") puts(e.cause) # an underlying Exception, likely raised within `net/http` rescue Sentdm::Errors::RateLimitError => e puts("A 429 status code was received; we should back off a bit.") rescue Sentdm::Errors::APIStatusError => e puts("Another non-200-range status code was received") puts(e.status) end ``` Error codes are as follows: | Cause | Error Type | |-------|------------| | HTTP 400 | `BadRequestError` | | HTTP 401 | `AuthenticationError` | | HTTP 403 | `PermissionDeniedError` | | HTTP 404 | `NotFoundError` | | HTTP 409 | `ConflictError` | | HTTP 422 | `UnprocessableEntityError` | | HTTP 429 | `RateLimitError` | | HTTP >= 500 | `InternalServerError` | | Other HTTP error | `APIStatusError` | | Timeout | `APITimeoutError` | | Network error | `APIConnectionError` | ## Retries [#retries] Certain errors will be automatically retried 2 times by default, with a short exponential backoff. ```ruby # Configure the default for all requests: sent_dm = Sentdm::Client.new( max_retries: 0 # default is 2 ) # Or, configure per-request: sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome" }, request_options: {max_retries: 5} ) ``` ## Timeouts [#timeouts] Requests time out after 60 seconds by default. Set `timeout` (in seconds) on the client or per request; `timeout: nil` disables the timeout entirely. ```ruby # Configure the default for all requests: sent_dm = Sentdm::Client.new( timeout: 20 # seconds (default is 60; nil disables the timeout) ) # Or, configure per-request: sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome" }, request_options: {timeout: 5} ) ``` ## BaseModel [#basemodel] All parameter and response objects inherit from `Sentdm::Internal::Type::BaseModel`, which provides several conveniences: 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax 2. Structural equivalence for equality 3. Both instances and classes can be pretty-printed 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml` ```ruby result = sent_dm.templates.list(page: 1, page_size: 100) # Access fields template = result.data.templates.first template.name template[:name] # Same thing # Convert to hash template.to_h # Serialize to JSON template.to_json # Pretty print puts template.inspect ``` ## Contacts [#contacts] Create and manage contacts: ```ruby # Create a contact result = sent_dm.contacts.create( phone_number: "+1234567890" ) puts "Contact ID: #{result.data.id}" puts "Channels: #{result.data.available_channels}" # List contacts result = sent_dm.contacts.list(page: 1, page_size: 100) result.data.contacts.each do |contact| puts "#{contact.phone_number} - #{contact.available_channels}" end # Get a contact result = sent_dm.contacts.retrieve("contact-uuid") # Update a contact result = sent_dm.contacts.update( "contact-uuid", default_channel: "whatsapp" ) # Delete a contact sent_dm.contacts.delete("contact-uuid") ``` ## Templates [#templates] List and retrieve templates: ```ruby # List templates result = sent_dm.templates.list(page: 1, page_size: 100) result.data.templates.each do |template| puts "#{template.name} (#{template.status}): #{template.id}" puts " Category: #{template.category}" puts " Channels: #{template.channels.join(', ')}" end # Get a specific template result = sent_dm.templates.retrieve("template-uuid") puts "Name: #{result.data.name}" puts "Status: #{result.data.status}" ``` ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-ID` and `X-Webhook-Timestamp` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and the signature format is `v1,{base64(hmac)}`. Complete verified webhook handlers are available in the [Rails integration guide](/sdks/ruby/integrations/rails) and the [Sinatra integration guide](/sdks/ruby/integrations/sinatra); the [Webhooks reference](/start/webhooks) documents the full payload schema and all status values. ## Making custom or undocumented requests [#making-custom-or-undocumented-requests] ### Undocumented properties [#undocumented-properties] You can send undocumented parameters to any endpoint using `extra_*` options: ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome" }, request_options: { extra_query: {my_query_parameter: value}, extra_body: {my_body_parameter: value}, extra_headers: {"my-header" => value} } ) puts(result[:my_undocumented_property]) ``` ### Undocumented endpoints [#undocumented-endpoints] To make requests to undocumented endpoints: ```ruby response = sent_dm.request( method: :post, path: '/undocumented/endpoint', query: {"dog" => "woof"}, headers: {"useful-header" => "interesting-value"}, body: {"hello" => "world"} ) ``` ## Concurrency & connection pooling [#concurrency--connection-pooling] The `Sentdm::Client` instances are thread-safe, but are only fork-safe when there are no in-flight HTTP requests. Each instance of `Sentdm::Client` has its own HTTP connection pool with a default size of 99 (or the number of CPU cores, if greater). As such, Sent recommends instantiating the client once per app in most settings. When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout. ## Framework Integration [#framework-integration] Dedicated guides cover client setup, message sending, verified webhook handling, and testing for each framework: ## Sorbet [#sorbet] This library provides [RBI](https://sorbet.org/start/rbi) definitions and has no dependency on sorbet-runtime. You can provide typesafe request parameters: ```ruby sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", name: "welcome", parameters: {name: "John Doe"} } ) ``` ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-ruby/releases) - **GitHub**: [`sentdm/sent-dm-ruby`](https://github.com/sentdm/sent-dm-ruby) - **RubyGems**: [`sentdm`](https://rubygems.org/gems/sentdm) - **RubyDoc**: [`gemdocs.org/gems/sentdm`](https://gemdocs.org/gems/sentdm) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-ruby/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending messages from Rails with the Sent Ruby SDK (/sdks/ruby/integrations/rails.md) # Sending messages from Rails with the Sent Ruby SDK [#sending-messages-from-rails-with-the-sent-ruby-sdk] This guide shows you how to wire Sent messaging into an existing Rails app: install the Ruby SDK, configure a shared client, send a template message from a controller, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Rails 7.1+ app and familiarity with controllers, concerns, and initializers. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the gem to your `Gemfile` and install: ```ruby gem "sentdm", "~> 0.25.0" ``` ```bash bundle install ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Create an initializer that validates configuration at boot and memoizes one client for the whole process: ```ruby # config/initializers/sentdm.rb module SentDmConfig class ConfigurationError < StandardError; end class << self def configure raise ConfigurationError, 'SENT_DM_API_KEY required' if ENV['SENT_DM_API_KEY'].blank? client # eagerly initialize and memoize end def client @client ||= Sentdm::Client.new(api_key: ENV.fetch('SENT_DM_API_KEY')) end end end SentDmConfig.configure ``` ### Send a template message from a controller [#send-a-template-message-from-a-controller] Add a controller that calls `messages.send_`; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything. Protect the route with your existing API authentication: ```ruby # app/controllers/messages_controller.rb class MessagesController < ApplicationController skip_before_action :verify_authenticity_token # JSON API endpoint; use your own auth def create response = SentDmConfig.client.messages.send_( to: [params.require(:phone_number)], # E.164 format, for example +14155551234 template: { name: params.require(:template_name), # reference by name or id, never both parameters: params.fetch(:parameters, {}).permit!.to_h }, channel: params[:channels], # omit to let Sent pick per recipient sandbox: ActiveModel::Type::Boolean.new.cast(params[:sandbox]) # true = simulate only ) recipient = response.data.recipients[0] render json: { message_id: recipient.message_id, status: response.data.status }, status: :accepted rescue Sentdm::Errors::UnprocessableEntityError, Sentdm::Errors::BadRequestError => e render json: { error: e.message }, status: :unprocessable_entity end end ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`: delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a concern that verifies the `webhook-signature` header against the raw request body before any handler runs. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```ruby # app/controllers/concerns/webhook_verifiable.rb module WebhookVerifiable extend ActiveSupport::Concern class SignatureVerificationError < StandardError; end TIMESTAMP_TOLERANCE = 300 # seconds; reject replayed events included do skip_before_action :verify_authenticity_token, only: [:create] before_action :verify_webhook_signature, only: [:create] rescue_from SignatureVerificationError, with: :handle_invalid_signature end private def verify_webhook_signature # Version 2 headers first, falling back to version 1 (X-Webhook-*) webhook_id = request.headers['webhook-id'].presence || request.headers['X-Webhook-ID'] timestamp = request.headers['webhook-timestamp'].presence || request.headers['X-Webhook-Timestamp'] signature = request.headers['webhook-signature'].presence || request.headers['X-Webhook-Signature'] payload = request.body.read; request.body.rewind raise SignatureVerificationError, 'Missing signature headers' if [webhook_id, timestamp, signature].any?(&:blank?) raise SignatureVerificationError, 'Timestamp outside tolerance' if (Time.now.to_i - timestamp.to_i).abs > TIMESTAMP_TOLERANCE # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match expected = expected_signature(webhook_id, timestamp, payload) raise SignatureVerificationError, 'Invalid signature' unless signature.split.any? { |candidate| secure_compare(expected, candidate) } end def expected_signature(webhook_id, timestamp, payload) secret = ENV.fetch('SENT_DM_WEBHOOK_SECRET') # "whsec_..." key_bytes = Base64.strict_decode64(secret.delete_prefix('whsec_')) digest = OpenSSL::HMAC.digest('SHA256', key_bytes, "#{webhook_id}.#{timestamp}.#{payload}") "v1,#{Base64.strict_encode64(digest)}" end def secure_compare(a, b) = ActiveSupport::SecurityUtils.secure_compare(a.to_s, b.to_s) def handle_invalid_signature = render json: { error: 'Unauthorized' }, status: :unauthorized end ``` Add the controller. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; return 200 quickly and do slow work in a job: ```ruby # app/controllers/webhooks_controller.rb class WebhooksController < ApplicationController include WebhookVerifiable def create payload = request.body.read; request.body.rewind event = JSON.parse(payload) data = event['payload'] || {} if event['field'] == 'message' case event['event'] # sub-type; omitted when the event has no sub-type when 'message.delivered' Rails.logger.info "Message #{data['message_id']} delivered" when 'message.failed' Rails.logger.error "Message #{data['message_id']} failed (status #{data['message_status']})" when 'message.received' Rails.logger.info "Inbound #{data['channel']} from #{data['inbound_number']}: #{data['text']}" else Rails.logger.info "Message #{data['message_id']} status: #{data['message_status']}" end end render json: { received: true } rescue JSON::ParserError render json: { error: 'Invalid JSON' }, status: :bad_request end end ``` Route both controllers: ```ruby # config/routes.rb post "/api/messages/send", to: "messages#create" post "/webhooks/sent", to: "webhooks#create" ``` Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Rails integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret` (put it in `SENT_DM_WEBHOOK_SECRET`). The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash bin/rails server ``` Send a sandbox message through your new endpoint. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:3000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phone_number": "+14155551234", "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 422 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your Rails log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you track delivery state, persist a `Message` record keyed by the returned `message_id` and update it from webhook events. The appendix below has the model and handler. - If you send in bulk or on user lifecycle events, move the `send_` call into an ActiveJob. The appendix has the job. - If a webhook references a `message_id` you do not recognize, acknowledge it with 200 anyway; failing causes Sent to retry the delivery. - To send free-form text instead of a template, pass `text` instead of `template`. Each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Rails stack. Adapt them to your own conventions rather than adopting them wholesale. Persist one row per send and update it from webhook events; the API reports statuses in uppercase (for example `QUEUED`), so downcase before matching your enum: ```ruby # app/models/message.rb class Message < ApplicationRecord enum :status, { pending: 'pending', queued: 'queued', sent: 'sent', delivered: 'delivered', read: 'read', failed: 'failed' } end ``` ```ruby # in the webhook controller, replace the log lines: message = Message.find_by(external_id: data['message_id']) message&.update!(status: data['message_status'].to_s.downcase) ``` Move sends off the request path with retries on transient API errors: ```ruby # app/jobs/send_message_job.rb class SendMessageJob < ApplicationJob queue_as :messages retry_on Sentdm::Errors::RateLimitError, wait: :polynomially_longer, attempts: 5 discard_on Sentdm::Errors::UnprocessableEntityError # invalid requests never succeed def perform(phone_number:, template_name:, parameters: {}) SentDmConfig.client.messages.send_( to: [phone_number], template: { name: template_name, parameters: parameters } ) end end ``` Sign test payloads exactly the way Sent does, so request specs exercise the verification path; the [SDK testing guide](/sdks/testing) covers mocking the client: ```ruby # spec/support/webhook_signature_helper.rb module WebhookSignatureHelper def signed_webhook_headers(payload, secret: ENV.fetch('SENT_DM_WEBHOOK_SECRET')) webhook_id = SecureRandom.uuid timestamp = Time.now.to_i.to_s key_bytes = Base64.strict_decode64(secret.delete_prefix('whsec_')) digest = OpenSSL::HMAC.digest('SHA256', key_bytes, "#{webhook_id}.#{timestamp}.#{payload}") { 'X-Webhook-ID' => webhook_id, 'X-Webhook-Timestamp' => timestamp, 'X-Webhook-Signature' => "v1,#{Base64.strict_encode64(digest)}", 'Content-Type' => 'application/json' } end end ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Ruby SDK reference](/sdks/ruby) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Sending messages from Sinatra with the Sent Ruby SDK (/sdks/ruby/integrations/sinatra.md) # Sending messages from Sinatra with the Sent Ruby SDK [#sending-messages-from-sinatra-with-the-sent-ruby-sdk] This guide shows you how to wire Sent messaging into an existing Sinatra app: install the Ruby SDK, configure a shared client, send a template message from a route, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Sinatra app (classic or modular) and familiarity with routes and helpers. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the gem to your `Gemfile` and install: ```ruby gem "sentdm", "~> 0.25.0" ``` ```bash bundle install ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Memoize one client for the whole process: ```ruby # lib/sent_client.rb require 'sentdm' module SentClient def self.client @client ||= Sentdm::Client.new(api_key: ENV.fetch('SENT_DM_API_KEY')) end end ``` ### Send a template message from a route [#send-a-template-message-from-a-route] Add a route that calls `messages.send_`; the pass-through `sandbox` flag lets callers exercise the route without delivering anything: ```ruby # app.rb require 'sinatra/base' require 'json' require_relative 'lib/sent_client' class App < Sinatra::Base post '/api/messages/send' do content_type :json data = JSON.parse(request.body.read, symbolize_names: true) response = SentClient.client.messages.send_( to: [data.fetch(:phone_number)], # E.164 format, for example +14155551234 template: { name: data.fetch(:template_name), # reference by name or id, never both parameters: data.fetch(:parameters, {}) }, channel: data[:channels], # omit to let Sent pick per recipient sandbox: data.fetch(:sandbox, false) # true = validate and simulate only ) recipient = response.data.recipients[0] status 202 { message_id: recipient.message_id, status: response.data.status }.to_json rescue Sentdm::Errors::BadRequestError, Sentdm::Errors::UnprocessableEntityError => e halt 422, { error: e.message }.to_json rescue JSON::ParserError, KeyError halt 400, { error: 'phone_number and template_name are required' }.to_json end end ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`: delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a helper that verifies the `webhook-signature` header against the raw request body before your route trusts any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```ruby # lib/webhook_helpers.rb require 'openssl' require 'base64' module WebhookHelpers TIMESTAMP_TOLERANCE = 300 # seconds; reject replayed events # Signing secret is "whsec_{base64Key}"; signed content is "{webhookId}.{timestamp}.{rawBody}"; # signature header is "v1,{base64(hmac)}" (version 2 sends two, space-separated, for 24 hours after a rotation). def verify_webhook_signature!(payload, webhook_id, timestamp, signature) secret = ENV['SENT_DM_WEBHOOK_SECRET'] # Fail closed: never accept webhooks without a configured secret halt 500, { error: 'Webhook not configured' }.to_json if secret.to_s.empty? key_bytes = Base64.strict_decode64(secret.delete_prefix('whsec_')) digest = OpenSSL::HMAC.digest('SHA256', key_bytes, "#{webhook_id}.#{timestamp}.#{payload}") expected = "v1,#{Base64.strict_encode64(digest)}" matched = signature.to_s.split.any? { |candidate| Rack::Utils.secure_compare(expected, candidate) } halt 401, { error: 'Invalid webhook signature' }.to_json unless matched halt 401, { error: 'Webhook timestamp too old' }.to_json if (Time.now.to_i - timestamp.to_i).abs > TIMESTAMP_TOLERANCE end end ``` Add the route. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; return 200 quickly and do slow work elsewhere: ```ruby # app.rb (additions) require_relative 'lib/webhook_helpers' class App < Sinatra::Base helpers WebhookHelpers configure { enable :logging } post '/webhooks/sent' do content_type :json payload = request.body.read request.body.rewind # Version 2 headers first, falling back to version 1 (X-Webhook-*) verify_webhook_signature!(payload, env['HTTP_WEBHOOK_ID'] || env['HTTP_X_WEBHOOK_ID'] || '', env['HTTP_WEBHOOK_TIMESTAMP'] || env['HTTP_X_WEBHOOK_TIMESTAMP'] || '', env['HTTP_WEBHOOK_SIGNATURE'] || env['HTTP_X_WEBHOOK_SIGNATURE'] || '') event = JSON.parse(payload) data = event['payload'] || {} if event['field'] == 'message' case event['event'] # sub-type; omitted when the event has no sub-type when 'message.delivered' logger.info "Message #{data['message_id']} delivered" when 'message.failed' logger.error "Message #{data['message_id']} failed (status #{data['message_status']})" when 'message.received' logger.info "Inbound #{data['channel']} from #{data['inbound_number']}: #{data['text']}" else logger.info "Message #{data['message_id']} status: #{data['message_status']}" end end { received: true }.to_json rescue JSON::ParserError halt 400, { error: 'Invalid JSON' }.to_json end end ``` Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Sinatra integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret` (put it in `SENT_DM_WEBHOOK_SECRET`). The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash bundle exec rackup ``` Send a sandbox message through your new route. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:9292/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phone_number": "+14155551234", "template_name": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `message_id` and `"status": "QUEUED"`. A 400 or 422 here means the request shape is wrong: sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your application log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you track delivery state, persist a record keyed by `message_id` when you send, then update it from the webhook route. The appendix below has a Sequel model sketch. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and hand off to a job queue such as Sidekiq so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - If you run the app behind Puma with multiple workers, the memoized client is created once per worker process, which is the intended pattern. - To send free-form text instead of a template, pass `text` instead of `template`. Each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Sinatra stack. Adapt them to your own conventions rather than adopting them wholesale. Persist one row per send and update it from webhook events: ```ruby # db/migrations/001_create_messages.rb Sequel.migration do change do create_table(:messages) do primary_key :id String :sent_id, index: true # message_id returned by Sent String :phone_number, null: false String :template_name String :status, default: 'pending' Time :created_at Time :updated_at end end end ``` In the webhook route, replace the log lines with an update keyed on `data['message_id']`. Serve the app with Puma in production: ```ruby # config.ru require_relative 'app' run App ``` ```ruby # puma.rb workers Integer(ENV.fetch('WEB_CONCURRENCY', 2)) threads_count = Integer(ENV.fetch('MAX_THREADS', 5)) threads threads_count, threads_count port ENV.fetch('PORT', 9292) environment ENV.fetch('RACK_ENV', 'production') ``` Sign test payloads exactly the way Sent does, so specs exercise the verification path; the [SDK testing guide](/sdks/testing) covers mocking the client: ```ruby # spec/support/webhook_signature_helper.rb def signed_webhook_headers(payload, secret: ENV.fetch('SENT_DM_WEBHOOK_SECRET')) webhook_id = SecureRandom.uuid timestamp = Time.now.to_i.to_s key_bytes = Base64.strict_decode64(secret.delete_prefix('whsec_')) digest = OpenSSL::HMAC.digest('SHA256', key_bytes, "#{webhook_id}.#{timestamp}.#{payload}") { 'HTTP_X_WEBHOOK_ID' => webhook_id, 'HTTP_X_WEBHOOK_TIMESTAMP' => timestamp, 'HTTP_X_WEBHOOK_SIGNATURE' => "v1,#{Base64.strict_encode64(digest)}", 'CONTENT_TYPE' => 'application/json' } end ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [Ruby SDK reference](/sdks/ruby) for retries, timeouts, and error types - Read the [SDK best practices guide](/sdks/best-practices) for production deployments # Rust SDK (/sdks/rust.md) # Rust SDK [#rust-sdk] [`sent`](https://crates.io/crates/sent) is the Sent REST API from Rust: SMS, WhatsApp, RCS, and voice through one API, with routing and compliance handled by Sent. Every operation is a typed async method, every response a struct, and the resources carry the same names as in the other Sent SDKs, so `contacts.list` and `webhooks.rotate_secret` read here as they do in Python or Go. The crate is in Preview. It is generated from Sent's published OpenAPI document and every release passes two checks: the API's own response examples decode into the crate's types, and every operation runs against a mock of the API. The crate's own API may still change between minor versions until its 1.0. ## Requirements [#requirements] Rust 1.85 or later, on Tokio. ## Installation [#installation] ```bash cargo add sent tokio --features tokio/full ``` The client is `reqwest` with rustls, so nothing links against the system's TLS. The types are `serde`. ## Quick Start [#quick-start] ### Create the client [#create-the-client] ```rust use sent::Client; // Reads SENT_API_KEY let client = Client::from_env()?; ``` `Client::new("sk_live_...")` takes the key directly. Use `sk_test_...` keys for the sandbox. ### Send your first message [#send-your-first-message] ```rust use sent::models::SendMessageV3Request; use sent::Client; #[tokio::main] async fn main() -> sent::Result<()> { let client = Client::from_env()?; let request: SendMessageV3Request = serde_json::from_value(serde_json::json!({ "to": ["+14155551234"], "channel": ["sms"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "name": "Ada", "order_id": "12345" } } }))?; let sent = client.messages().send(&request).await?; for recipient in sent.recipients.unwrap_or_default() { println!("{}: {:?}", recipient.to.unwrap_or_default(), recipient.message_id); } Ok(()) } ``` A request type is a plain struct with `Default`, so `SendMessageV3Request { to: vec!["+14155551234".into()], ..Default::default() }` builds the same request without JSON. ## Authentication [#authentication] The client sends the key as `x-api-key` on every request. `Client::from_env()` reads `SENT_API_KEY`, and falls back to `SENT_DM_API_KEY` where that older name is still set. For more than a key, use the builder: ```rust use std::time::Duration; use sent::Client; let client = Client::builder("sk_live_...") .profile_id("3fa85f64-5717-4562-b3fc-2c963f66afa6") // x-profile-id: scope every request to a child profile .timeout(Duration::from_secs(30)) .max_retries(3) .build()?; ``` Keep the key on the server. Never ship it in a client app. ## Requests and retries [#requests-and-retries] Every non-GET request carries an `Idempotency-Key` the client generates, and keeps the same key when it sends the request again, so a retried send is performed once. The client retries on 429 and on 5xx, twice by default, with a backoff that honours `Retry-After`. `max_retries(0)` turns that off. Request types that support the sandbox carry `sandbox: Option`. Set it to `Some(true)` to simulate an operation without side effects. ## Error handling [#error-handling] A refused request is `Error::Api`, with what Sent said: ```rust use sent::Error; match client.messages().send(&request).await { Ok(sent) => println!("{:?}", sent.status), Err(Error::Api(failure)) => { eprintln!("{} {}: {}", failure.status, failure.code, failure.message); if let Some(details) = &failure.details { for (field, problems) in details { eprintln!(" {field}: {}", problems.join(", ")); } } if let Some(id) = &failure.request_id { eprintln!(" request {id}, for support"); } } Err(Error::Transport(error)) => eprintln!("could not reach Sent: {error}"), Err(error) => eprintln!("{error}"), } ``` `Error::Transport` is a request that never got an answer. `Error::Decode` is a 2xx whose body is not what the API documents. `Error::Config` is a client that cannot send anything, such as an empty key. `error.api()` returns the failure when the error is one, for code that only cares about that case. ## Pagination [#pagination] List methods take a params struct and return a `Page` with the items and what the API says about the pages around it. The `list_all` twin walks every page: ```rust use sent::resources::contacts::ContactsListParams; let params = ContactsListParams { search: Some("ada".into()), page_size: Some(50), ..Default::default() }; let page = client.contacts().list(¶ms).await?; println!("{} of {:?} contacts, more: {}", page.items.len(), page.pagination.total_count, page.has_more()); let every_contact = client.contacts().list_all(¶ms).await?; ``` Pages are one-indexed. Leave `page` unset for the first. ## Contacts [#contacts] ```rust use sent::models::CreateContactRequest; let contact = client.contacts().create(&CreateContactRequest { phone_number: "+14155551234".into(), ..Default::default() }).await?; let again = client.contacts().retrieve(&contact.id.clone().unwrap_or_default()).await?; ``` ## Messages [#messages] ```rust let message = client.messages().retrieve_status("8ba7b830-9dad-11d1-80b4-00c04fd430c8").await?; let activities = client.messages().retrieve_activities("8ba7b830-9dad-11d1-80b4-00c04fd430c8").await?; ``` ## Webhooks [#webhooks] Subscriptions are managed through `client.webhooks()`: `create`, `list`, `retrieve`, `update`, `delete`, `rotate_secret`, `test`, `toggle_status`, and `list_event_types`. The events Sent POSTs to your endpoint have types too, under `sent::models`: `MessageEvent`, `InboundMessageEvent`, `TemplateEvent`, `ChannelEvent`, `ContactEvent` and `CallEvent`, each with a typed `payload`. Decode the body your handler receives with `serde_json::from_slice::(&body)`. ## Compatibility [#compatibility] Sent adds fields, enum values, and resources without a major version. The crate is built for that: structs ignore fields they do not know, and every enum has an `Other(String)` variant, so a value Sent adds later decodes rather than failing the whole response. ## Source & Issues [#source--issues] The crate is rendered from the API document by Sent's SDK pipeline. The source lives at [`sentdm/sent-dm-rust`](https://github.com/sentdm/sent-dm-rust), where issues and pull requests are welcome. Generated files are regenerated on every API change. The client, errors, and pagination are written by hand. ## Getting Help [#getting-help] - [API reference](/reference/api) - [Error catalog](/reference/api/error-catalog) - Support: support@sent.dm # Testing with SDKs (/sdks/testing.md) # Testing with SDKs [#testing-with-sdks] Build reliable messaging features with testing strategies for Sent SDKs. This guide covers unit testing, integration testing, mocking, and CI/CD best practices. ## Testing Pyramid [#testing-pyramid] For messaging integrations, follow this testing strategy: 1. **Unit Tests (70%)** - Mock the SDK, test business logic 2. **Integration Tests (20%)** - Use a dedicated API key for your test environment, with sandbox mode to avoid side effects 3. **E2E Tests (10%)** - Full flow with webhook handling ## Unit Testing [#unit-testing] ### Mock the SDK [#mock-the-sdk] Don't make real API calls in unit tests: ```typescript // __mocks__/@sentdm/sentdm.ts import { jest } from '@jest/globals'; export const mockSend = jest.fn(); export default jest.fn().mockImplementation(() => ({ messages: { send: mockSend } })); // notification.service.test.ts import { mockSend } from './__mocks__/@sentdm/sentdm'; import { NotificationService } from './notification.service'; describe('NotificationService', () => { beforeEach(() => { jest.clearAllMocks(); }); it('should send welcome message on user signup', async () => { // Arrange mockSend.mockResolvedValue({ data: { recipients: [{ message_id: 'msg_123' }], status: 'QUEUED', price: 0.0125 } }); const service = new NotificationService(); const user = { phone: '+1234567890', name: 'John' }; // Act await service.sendWelcomeMessage(user); // Assert expect(mockSend).toHaveBeenCalledWith({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome', parameters: { name: 'John' } } }); }); it('should handle send failures gracefully', async () => { // Arrange const error = new Error('Template not found'); error.status = 400; mockSend.mockRejectedValue(error); const service = new NotificationService(); const user = { phone: '+1234567890', name: 'John' }; // Act & Assert await expect(service.sendWelcomeMessage(user)) .rejects.toThrow('Failed to send message'); }); }); ``` ```python # conftest.py import pytest from unittest.mock import Mock @pytest.fixture def mock_sent(): mock = Mock() mock.messages.send.return_value = Mock( data=Mock( recipients=[Mock(message_id='msg_123')], status='QUEUED', price=0.0125 ) ) return mock # test_notification_service.py import pytest from unittest.mock import patch def test_send_welcome_message(mock_sent): # Arrange with patch('myapp.services.SentDm', return_value=mock_sent): from myapp.services import NotificationService service = NotificationService() user = {'phone': '+1234567890', 'name': 'John'} # Act service.send_welcome_message(user) # Assert mock_sent.messages.send.assert_called_once_with( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome', 'parameters': {'name': 'John'} } ) def test_handle_send_failure(mock_sent): # Arrange from sent_dm import BadRequestError mock_sent.messages.send.side_effect = BadRequestError( message='Template not found', response=Mock(status_code=400), body=None ) with patch('myapp.services.SentDm', return_value=mock_sent): from myapp.services import NotificationService service = NotificationService() user = {'phone': '+1234567890', 'name': 'John'} # Act & Assert with pytest.raises(Exception) as exc_info: service.send_welcome_message(user) assert 'Template not found' in str(exc_info.value) ``` ```go // mocks/sent_client.go package mocks import ( "context" "github.com/sentdm/sent-dm-go" ) type MockMessagesService struct { SendFunc func(ctx context.Context, params sentdm.MessageSendParams) (*sentdm.MessageSendResponse, error) } func (m *MockMessagesService) Send(ctx context.Context, params sentdm.MessageSendParams) (*sentdm.MessageSendResponse, error) { return m.SendFunc(ctx, params) } // notification_service_test.go func TestSendWelcomeMessage(t *testing.T) { // Arrange mockMessages := &mocks.MockMessagesService{ SendFunc: func(ctx context.Context, params sentdm.MessageSendParams) (*sentdm.MessageSendResponse, error) { // Verify parameters if len(params.To) != 1 || params.To[0] != "+1234567890" { t.Errorf("Expected phone +1234567890, got %v", params.To) } return &sentdm.MessageSendResponse{ Data: sentdm.MessageSendResponseData{ Recipients: []sentdm.MessageSendResponseDataRecipient{ {MessageID: "msg_123"}, }, Status: "QUEUED", }, }, nil }, } service := NewNotificationService(mockMessages) user := User{Phone: "+1234567890", Name: "John"} // Act err := service.SendWelcomeMessage(context.Background(), user) // Assert assert.NoError(t, err) } ``` ### Testing Error Scenarios [#testing-error-scenarios] Test all error paths: ```typescript const errorScenarios = [ { name: 'AuthenticationError', status: 401, message: 'Should throw on invalid API key', shouldRetry: false }, { name: 'RateLimitError', status: 429, message: 'Should retry on rate limit', shouldRetry: true }, { name: 'BadRequestError', status: 400, message: 'Should not retry on 4xx', shouldRetry: false } ]; errorScenarios.forEach(({ name, status, message, shouldRetry }) => { it(message, async () => { const error = new Error('Test error'); (error as any).status = status; mockSend.mockRejectedValue(error); const result = await service.sendMessage({...}); expect(result.retryAttempted).toBe(shouldRetry); }); }); ``` ## Integration Testing [#integration-testing] ### Use a Dedicated API Key per Environment [#use-a-dedicated-api-key-per-environment] Use a separate API key for your test/CI environment. There is only one key type, but keeping keys isolated per environment lets you revoke or rotate them independently: ```typescript // integration/message.test.ts import SentDm from '@sentdm/sentdm'; describe('Message Integration Tests', () => { let client: SentDm; beforeAll(() => { // Use test API key client = new SentDm({ apiKey: process.env.SENT_DM_API_KEY_TEST! }); }); it('should validate message request structure with sandbox mode', async () => { // Use sandbox mode to validate without sending real messages const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' }, sandbox: true // Validates but doesn't send }); // Response will have test data expect(response.data.recipients[0].message_id).toBeDefined(); expect(response.data.status).toBeDefined(); }); it('should handle invalid template', async () => { try { await client.messages.send({ to: ['+1234567890'], template: { id: 'non-existent-template', name: 'invalid' } }); fail('Should have thrown'); } catch (error) { expect(error).toBeInstanceOf(SentDm.BadRequestError); } }); }); ``` ```python # integration/test_messages.py import os import pytest from sent_dm import Sent, BadRequestError @pytest.fixture def test_client(): return Sent(api_key=os.environ['SENT_DM_API_KEY_TEST']) def test_validate_message_structure_with_sandbox_mode(test_client): """Test that valid message structure is accepted using sandbox mode""" # Use sandbox mode to validate without sending real messages response = test_client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "name": "welcome" }, sandbox=True # Validates but doesn't send ) # Response will have test data assert response.data.recipients[0].message_id is not None assert response.data.status is not None def test_invalid_template_error(test_client): """Test that invalid template throws error""" with pytest.raises(BadRequestError) as exc_info: test_client.messages.send( to=["+1234567890"], template={ "id": "non-existent-template", "name": "invalid" } ) assert exc_info.value is not None ``` ```go // integration/message_test.go func TestSendMessageIntegrationWithSandbox(t *testing.T) { client := sentdm.NewClient( option.WithAPIKey(os.Getenv("SENT_DM_API_KEY_TEST")), ) ctx := context.Background() // Use Sandbox to validate without sending real messages response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), }, Sandbox: sentdm.Bool(true), // Validates but doesn't send }) // Should succeed with test data require.NoError(t, err) assert.NotEmpty(t, response.Data.Recipients[0].MessageID) assert.NotEmpty(t, response.Data.Status) } func TestInvalidTemplateIntegration(t *testing.T) { client := sentdm.NewClient( option.WithAPIKey(os.Getenv("SENT_DM_API_KEY_TEST")), ) ctx := context.Background() _, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("non-existent-template"), Name: sentdm.String("invalid"), }, }) require.Error(t, err) var apiErr *sentdm.Error require.True(t, errors.As(err, &apiErr)) assert.Equal(t, 400, apiErr.StatusCode) } ``` ### Test Webhooks Locally [#test-webhooks-locally] Use tools like ngrok or localtunnel for webhook testing. Refer to the [local development guide](/start/webhooks/local-development) for tunnel setup. To assert on your handler, replay a canonical event envelope with the three signature headers your handler verifies, as described in [webhook signature verification](/start/webhooks/signature-verification): ```typescript // webhook.test.ts describe('Webhook Integration', () => { let server: Server; let webhookUrl: string; beforeAll(async () => { // Start local server server = app.listen(3001); // Create tunnel (using ngrok or similar) webhookUrl = await createTunnel(3001); }); afterAll(async () => { server.close(); await closeTunnel(); }); it('should verify webhook signature', async () => { const payload = JSON.stringify({ field: 'message', event: 'message.delivered', timestamp: '2026-07-25T10:10:42Z', payload: { message_id: 'msg_123', message_status: 'DELIVERED', channel: 'sms' } }); const webhookId = 'wh_test_123'; const timestamp = String(Math.floor(Date.now() / 1000)); // Signed content = "{webhookId}.{timestamp}.{rawBody}" const signature = generateTestSignature(webhookId, timestamp, payload); const response = await request(app) .post('/webhooks/sent') .set('X-Webhook-ID', webhookId) .set('X-Webhook-Timestamp', timestamp) .set('X-Webhook-Signature', signature) .set('Content-Type', 'application/json') .send(payload); expect(response.status).toBe(200); }); }); ``` ## CI/CD Testing [#cicd-testing] ### Environment Setup [#environment-setup] Configure separate environments for CI/CD: ```yaml # .github/workflows/test.yml name: Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' - name: Install dependencies run: npm ci - name: Run unit tests run: npm test - name: Run integration tests env: SENT_DM_API_KEY_TEST: ${{ secrets.SENT_DM_API_KEY_TEST }} run: npm run test:integration ``` ### Test Data Management [#test-data-management] Use consistent test data: ```typescript // test/fixtures.ts export const testFixtures = { validPhoneNumber: '+15555551234', // test number invalidPhoneNumber: 'invalid', validTemplateId: 'test-welcome-template', invalidTemplateId: 'non-existent-template', mockRecipient: { message_id: 'msg_test_123', to: '+15555551234', channel: 'sms' } }; // Use in tests import { testFixtures } from './fixtures'; it('should send to valid number', async () => { mockSend.mockResolvedValue({ data: { status: 'QUEUED', recipients: [testFixtures.mockRecipient] } }); const result = await service.sendMessage({ phone: testFixtures.validPhoneNumber }); expect(mockSend).toHaveBeenCalledWith({ to: [testFixtures.validPhoneNumber], template: { id: expect.any(String), name: expect.any(String) } }); }); ``` ### Parallel Test Execution [#parallel-test-execution] Ensure tests can run in parallel: ```typescript // Use unique identifiers per test it('should send message', async () => { const testId = `test-${Date.now()}-${Math.random()}`; const phoneNumber = `+1555${testId.slice(-7)}`; mockSend.mockResolvedValue({ data: { recipients: [{ message_id: `msg_${testId}` }], status: 'QUEUED' } }); const result = await service.sendMessage({ phone: phoneNumber }); expect(result.data.recipients[0].message_id).toBe(`msg_${testId}`); }); ``` ## Load Testing [#load-testing] Test SDK behavior under load: Keep `sandbox: true` in this script. Without it, every run sends (and bills) 100 real messages. ```typescript // load-test.ts import SentDm from '@sentdm/sentdm'; async function loadTest() { const client = new SentDm({ apiKey: process.env.SENT_DM_API_KEY_TEST! }); const concurrency = 10; const totalRequests = 100; console.log(`Starting load test: ${totalRequests} requests at ${concurrency} concurrency`); const startTime = Date.now(); let successCount = 0; let errorCount = 0; for (let batch = 0; batch < totalRequests / concurrency; batch++) { const promises = Array(concurrency).fill(null).map((_, i) => client.messages.send({ to: [`+1555555${String(batch * concurrency + i).padStart(4, '0')}`], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' }, sandbox: true // Validates but doesn't send }).then(() => { successCount++; }).catch(err => { errorCount++; console.log('Error:', err.message); }) ); await Promise.all(promises); } const duration = Date.now() - startTime; console.log(`\nResults:`); console.log(`Duration: ${duration}ms`); console.log(`Success: ${successCount}`); console.log(`Errors: ${errorCount}`); console.log(`RPS: ${(totalRequests / (duration / 1000)).toFixed(2)}`); } loadTest(); ``` ## Test Coverage Checklist [#test-coverage-checklist] Use this checklist to ensure comprehensive test coverage for your messaging integration. ### Core Functionality [#core-functionality] - [ ] Send message with template - [ ] Send message with variables - [ ] Create contact - [ ] Handle successful response - [ ] Handle error response ### Error Scenarios [#error-scenarios] - [ ] Invalid API key - [ ] Rate limiting - [ ] Invalid template ID - [ ] Template not approved - [ ] Insufficient credits - [ ] Invalid phone number - [ ] Contact opted out ### Webhooks [#webhooks] - [ ] Verify webhook signature - [ ] Handle message.delivered - [ ] Handle message.failed - [ ] Handle message.received (inbound replies) - [ ] Handle duplicate events (idempotency) - [ ] Handle invalid signatures ### Retry Logic [#retry-logic] - [ ] Retry on rate limit - [ ] Don't retry on 4xx errors - [ ] Exponential backoff - [ ] Max retry attempts ### Edge Cases [#edge-cases] - [ ] Empty variables object - [ ] Special characters in message - [ ] Very long messages - [ ] Unicode/emojis - [ ] Concurrent requests ## Next Steps [#next-steps] - Apply [SDK best practices](/sdks/best-practices) for production error handling, retries, and webhook security - Resolve common integration errors with the [troubleshooting guide](/sdks/troubleshooting) - Set up [webhooks](/start/webhooks/getting-started) to assert on delivery status in end-to-end tests - Review the [language-specific SDK guides](/sdks) for idiomatic examples in your stack --- Comprehensive testing ensures your messaging integration works reliably in production. Aim for 80%+ code coverage with a good mix of unit and integration tests. --- # SDK Troubleshooting (/sdks/troubleshooting.md) # SDK Troubleshooting [#sdk-troubleshooting] Resolve common issues with Sent SDKs. This guide covers frequent errors, debugging strategies, and solutions organized by symptom. ## Quick Diagnostics [#quick-diagnostics] Before diving into specific issues, check these common causes: ## Common Error Codes [#common-error-codes] ### Authentication Errors [#authentication-errors] #### `401 Unauthorized` - Invalid API key [#401-unauthorized---invalid-api-key] **Symptoms:** ``` AuthenticationError: 401 - Invalid API key ``` **Solutions:** 1. Verify your API key from the [Sent Dashboard](https://app.sent.dm/dashboard/api-keys) 2. Check for extra whitespace or copy-paste errors 3. Ensure you're using the right environment variable (`SENT_DM_API_KEY`) 4. Verify the key hasn't been revoked ```typescript // Debug: Log first 8 characters console.log('API Key:', process.env.SENT_DM_API_KEY?.substring(0, 8) + '...'); ``` --- ### Contact Errors [#contact-errors] #### `404 Not Found` - Contact not found [#404-not-found---contact-not-found] **Symptoms:** ``` NotFoundError: 404 - Contact not found ``` **Solutions:** ```typescript // Create contact first try { const contact = await client.contacts.create({ phone_number: '+1234567890' }); console.log('Created contact:', contact.data.id); } catch (error) { console.error('Failed to create contact:', error.message); } ``` ```python # Create contact first try: contact = client.contacts.create( phone_number='+1234567890' ) print(f'Created contact: {contact.data.id}') except Exception as e: print(f'Failed to create contact: {e}') ``` ```go // Create contact first response, err := client.Contacts.New(ctx, sentdm.ContactNewParams{ PhoneNumber: "+1234567890", }) if err != nil { log.Printf("Failed to create contact: %v", err) } else { log.Printf("Created contact: %s", response.Data.ID) } ``` You can send messages directly to a phone number without creating a contact first: ```typescript // Send directly to phone number const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); ``` ```python # Send directly to phone number response = client.messages.send( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome' } ) ``` ```go // Send directly to phone number response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Name: sentdm.String("welcome"), }, }) ``` #### Contacts opted out [#contacts-opted-out] Opt-out blocks are asynchronous. `POST /v3/messages` is accepted with `202` even when every recipient has opted out, so the send call itself never raises an error. Each blocked recipient's message is finalized as `FILTERED` inside the pipeline, before any provider call, and you are not charged for it. Detect the block from the message status, not from the send response: - The `message.filtered` webhook event - `GET /v3/messages/{id}`: `status` is `FILTERED` - `GET /v3/messages/{id}/activities`: a `FILTERED` activity Sent records the reason code `ERR_CONSENT_BLOCKED` internally and does not return it in API responses or webhook payloads. `FILTERED` also covers routing deny rules, so read the contact's `opt_out` field to confirm a consent block. Either way, respect the recipient's preference and do not retry. ```typescript // The send is accepted even when the recipient has opted out. const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); const messageId = response.data.recipients[0].message_id; // The block arrives on the message.filtered webhook. For a one-off check, // read the status back once the message is finalized. const message = await client.messages.retrieveStatus(messageId); if (message.data.status === 'FILTERED') { // FILTERED also covers routing deny rules, so confirm the opt-out on the // contact record before mirroring it into your own database. const contacts = await client.contacts.list({ phone: '+1234567890' }); if (contacts.data.contacts[0]?.opt_out) { await db.users.update({ where: { phone: '+1234567890' }, data: { messagingOptOut: true } }); console.log('Recipient opted out, skipping future sends'); } } ``` ```python # The send is accepted even when the recipient has opted out. response = client.messages.send( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome' } ) message_id = response.data.recipients[0].message_id # The block arrives on the message.filtered webhook. For a one-off check, # read the status back once the message is finalized. message = client.messages.retrieve_status(message_id) if message.data.status == 'FILTERED': # FILTERED also covers routing deny rules, so confirm the opt-out on the # contact record before mirroring it into your own database. contacts = client.contacts.list(phone='+1234567890') if contacts.data.contacts and contacts.data.contacts[0].opt_out: db.users.update( phone='+1234567890', messaging_opt_out=True ) print('Recipient opted out, skipping future sends') ``` --- ### Template Errors [#template-errors] #### `400 Bad Request` - Template not found [#400-bad-request---template-not-found] **Symptoms:** ``` BadRequestError: 400 - Template not found ``` **Solutions:** ```typescript // List all templates to find the correct ID try { const templates = await client.templates.list({ page: 1, page_size: 100 }); templates.data.templates.forEach(t => { console.log(`${t.name}: ${t.id} (${t.status})`); }); } catch (error) { console.error('Failed to list templates:', error.message); } ``` ```python # List all templates to find the correct ID try: templates = client.templates.list(page=1, page_size=100) for t in templates.data.templates: print(f'{t.name}: {t.id} ({t.status})') except Exception as e: print(f'Failed to list templates: {e}') ``` ```typescript try { const template = await client.templates.retrieve('your-template-id'); console.log('Status:', template.data.status); // DRAFT, PENDING, APPROVED, REJECTED console.log('Channels:', template.data.channels); } catch (error) { console.error('Template not found:', error.message); } ``` ```python try: template = client.templates.retrieve('your-template-id') print(f'Status: {template.data.status}') # DRAFT, PENDING, APPROVED, REJECTED print(f'Channels: {template.data.channels}') except Exception as e: print(f'Template not found: {e}') ``` #### `400 Bad Request` - WhatsApp template pending [#400-bad-request---whatsapp-template-pending] **Symptoms:** ``` BadRequestError: 400 - Template is not approved for WhatsApp ``` **Solutions:** 1. **Check template status in dashboard** - WhatsApp templates need Meta approval (can take hours) - SMS templates work immediately 2. **Use SMS as fallback** ```typescript // Try sending (may throw if template not approved) try { const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); console.log('Sent:', response.data.recipients[0].message_id); } catch (error) { if (error instanceof SentDm.BadRequestError && error.message.includes('not approved')) { console.log('Template not approved yet'); // Queue for later or use alternative channel await db.queuedMessages.create({ phoneNumber: '+1234567890', templateId: 'welcome-template', retryAfter: new Date(Date.now() + 3600000), // 1 hour status: 'pending_approval' }); } } ``` ```python from sent_dm import BadRequestError # Try sending (may raise if template not approved) try: response = client.messages.send( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome' } ) print(f'Sent: {response.data.recipients[0].message_id}') except BadRequestError as e: if 'not approved' in str(e): print('Template not approved yet') # Queue for later or use alternative channel db.queued_messages.create( phone_number='+1234567890', template_id='welcome-template', retry_after=datetime.now() + timedelta(hours=1), status='pending_approval' ) ``` --- ### Rate Limiting [#rate-limiting] #### `429 Rate Limit` - Too many requests [#429-rate-limit---too-many-requests] **Symptoms:** ``` RateLimitError: 429 - Rate limit exceeded Retry-After: 60 ``` **Solutions:** SDKs have built-in retry logic, but you can also handle it manually: ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm({ maxRetries: 3 // Built-in retry with exponential backoff }); // Or handle manually try { const response = await client.messages.send(params); } catch (error) { if (error instanceof SentDm.RateLimitError) { const retryAfter = parseInt( error.headers.get('retry-after') || '60', 10 ); console.log(`Rate limited. Retrying after ${retryAfter}s...`); await sleep(retryAfter * 1000); // Retry const response = await client.messages.send(params); } } ``` ```python import time from sent_dm import Sent, RateLimitError client = Sent(max_retries=3) # Built-in retry with exponential backoff # Or handle manually try: response = client.messages.send(...) except RateLimitError as e: retry_after = int(e.response.headers.get('retry-after', 60)) print(f'Rate limited. Retrying after {retry_after}s...') time.sleep(retry_after) # Retry response = client.messages.send(...) ``` ```typescript import pLimit from 'p-limit'; // Limit to 5 concurrent requests const limit = pLimit(5); const results = await Promise.all( recipients.map(phone => limit(() => client.messages.send({ to: [phone], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'notification' } })) ) ); ``` Default rate limits per customer account: - **Standard endpoints** (including `POST /v3/messages`): 10,000 requests per minute - **Sensitive endpoints** (webhook secret rotation and test delivery): 10 requests per minute Limits are enforced over a rolling 60-second window, so bursts and sustained traffic draw from the same budget: 10,000 requests in the first second uses the full minute's allowance, and later requests receive `429` responses until earlier requests age out of the window. Refer to the [rate limits reference](/reference/api/rate-limits) for headers, tiers, and backoff strategies. Contact support if you need higher limits. --- ### Billing Errors [#billing-errors] #### Payment Required - Account balance too low [#payment-required---account-balance-too-low] **Symptoms:** ``` BadRequestError: 400 - Insufficient credits to send message ``` **Solutions:** 1. **Add credits in the dashboard** - Go to [Billing](https://app.sent.dm/dashboard/billing) 2. **Graceful degradation** ```typescript try { const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); } catch (error) { if (error instanceof SentDm.BadRequestError && error.message.includes('credits')) { // Queue for later await db.messageQueue.create({ ...messageData, status: 'pending_credits' }); await notifyOpsTeam('Account balance low'); } } ``` ```python from sent_dm import BadRequestError try: response = client.messages.send( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome' } ) except BadRequestError as e: if 'credits' in str(e): # Queue for later db.message_queue.create( status='pending_credits', **message_data ) notify_ops_team('Account balance low') ``` --- ## Webhook Issues [#webhook-issues] ### Webhook not receiving events [#webhook-not-receiving-events] ```bash # Test if your endpoint is reachable curl -X POST https://your-app.com/webhooks/sent \ -H "Content-Type: application/json" \ -d '{"test": true}' ``` Make sure your endpoint: - Is publicly accessible (not localhost) - Uses HTTPS (required) - Returns 200 OK quickly Common mistakes: - Using the wrong secret - Not using raw request body - Case-sensitive header names - Comparing the whole `webhook-signature` header instead of each space-separated signature in it SDKs do not ship a `verifySignature` helper: verify the HMAC signature manually. The signing secret (from the Sent Dashboard) has a `whsec_` prefix; strip it and base64-decode the remainder to get the raw HMAC key. The signed content is `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) and the signature format is `v1,{base64(hmac)}`. ```typescript import { createHmac, timingSafeEqual } from 'crypto'; // ❌ Wrong - use raw body, not parsed JSON app.post('/webhooks/sent', (req, res) => { const payload = req.body; // Parsed JSON won't work // ... }); // ✅ Correct - use raw body app.post('/webhooks/sent', express.raw({ type: 'application/json' }), (req, res) => { const payload = req.body as Buffer; // Raw bytes // Version 2 headers first, falling back to version 1 const webhookId = (req.headers['webhook-id'] ?? req.headers['x-webhook-id']) as string; const timestamp = (req.headers['webhook-timestamp'] ?? req.headers['x-webhook-timestamp']) as string; const signature = (req.headers['webhook-signature'] ?? req.headers['x-webhook-signature']) as string; const secret = process.env.SENT_DM_WEBHOOK_SECRET!; const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signed = `${webhookId}.${timestamp}.${payload.toString('utf8')}`; const expected = 'v1,' + createHmac('sha256', keyBytes).update(signed).digest('base64'); // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match const expectedBuf = Buffer.from(expected); const matches = (c: string) => Buffer.byteLength(c) === expectedBuf.length && timingSafeEqual(Buffer.from(c), expectedBuf); if (!signature || !signature.trim().split(/\s+/).some(matches)) { return res.status(401).json({ error: 'Invalid signature' }); } res.json({ received: true }); } ); ``` ```python import hmac import hashlib import base64 @app.route('/webhooks/sent', methods=['POST']) def webhook(): # Version 2 headers first, falling back to version 1 webhook_id = request.headers.get('webhook-id') or request.headers.get('X-Webhook-ID', '') timestamp = request.headers.get('webhook-timestamp') or request.headers.get('X-Webhook-Timestamp', '') signature = request.headers.get('webhook-signature') or request.headers.get('X-Webhook-Signature', '') payload = request.get_data() # Raw bytes, not parsed JSON secret = os.environ['SENT_DM_WEBHOOK_SECRET'] key_bytes = base64.b64decode(secret.removeprefix('whsec_')) signed = f"{webhook_id}.{timestamp}.{payload.decode('utf-8')}" digest = hmac.new(key_bytes, signed.encode('utf-8'), hashlib.sha256).digest() expected = 'v1,' + base64.b64encode(digest).decode() # Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match if not any(hmac.compare_digest(candidate, expected) for candidate in signature.split()): return jsonify({'error': 'Invalid signature'}), 401 return jsonify({'received': True}) ``` Make sure your webhook subscription covers the events you expect. Sent publishes several parent event types; each delivery carries the parent in the `field` property and, for message and channel events, the granular sub-type in the `event` property: - `message`: outbound status updates (`message.queued`, `message.routed`, `message.scheduled`, `message.sent`, `message.delivered`, `message.read`, `message.failed`, `message.filtered`, `message.blocked`) and inbound messages (`message.received`) - `templates`: template status changes such as WhatsApp approval or rejection, with the outcome in `payload.status` - `channel`: where one of your markets stands in provisioning and compliance (`channel.submitted`, `channel.changes_requested`, `channel.approved`, `channel.rejected`, `channel.activated`, `channel.deactivated`, `channel.removed`), with the market's current state in `payload.status` There is no `message.status.updated` event. Subscribe to the `message` parent to receive every message event, or filter to specific sub-types. Refer to the [events reference](/start/webhooks/event-types) for the full catalog and payload schemas. ### Duplicate webhook events [#duplicate-webhook-events] Webhook events may be delivered multiple times. Handle them idempotently: ```typescript // eventId: the `webhook-id` header (`x-webhook-event-id` on version 1), identical on every retry async function handleWebhook(event: WebhookEvent, eventId: string) { // Check if already processed const existing = await db.processedEvents.findUnique({ where: { eventId } }); if (existing) { console.log(`Event ${eventId} already processed`); return { received: true }; } // Process event... // Mark as processed await db.processedEvents.create({ data: { eventId, processedAt: new Date() } }); } ``` --- ## Connection Issues [#connection-issues] ### Timeout errors [#timeout-errors] **Symptoms:** ``` APIConnectionError: Request timeout after 30000ms ``` **Solutions:** 1. **Increase timeout** ```typescript const client = new SentDm({ timeout: 60000 // 60 seconds }); ``` ```python from sent_dm import Sent client = Sent(timeout=60.0) # 60 seconds ``` ```go client := sentdm.NewClient( option.WithTimeout(60 * time.Second), ) ``` 2. **Check network connectivity** ```bash # Test API reachability (liveness probe, no authentication required) curl https://api.sent.dm/health/live ``` 3. **Implement circuit breaker** ```typescript class CircuitBreaker { private failures = 0; private lastFailureTime?: number; private readonly threshold = 5; private readonly timeout = 60000; async execute(fn: () => Promise): Promise { if (this.isOpen()) { throw new Error('Circuit breaker is open'); } try { const result = await fn(); this.onSuccess(); return result; } catch (error) { this.onFailure(); throw error; } } private isOpen(): boolean { if (this.failures < this.threshold) return false; if (!this.lastFailureTime) return false; return Date.now() - this.lastFailureTime < this.timeout; } private onSuccess() { this.failures = 0; } private onFailure() { this.failures++; this.lastFailureTime = Date.now(); } } ``` --- ## Debugging Tips [#debugging-tips] ### Enable Debug Logging [#enable-debug-logging] Most SDKs support debug logging via environment variables: ```bash # Set environment variable export SENT_LOG=debug ``` Or configure in code: ```typescript const client = new SentDm({ logLevel: 'debug' // 'debug', 'info', 'warn', 'error', 'off' }); ``` ```bash # Set environment variable export SENT_LOG=debug ``` Or use Python logging: ```python import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger('sent_dm') logger.setLevel(logging.DEBUG) ``` ```go // Use the debug option client := sentdm.NewClient( option.WithDebugLog(nil), ) ``` ```bash # Set the SENT_LOG environment variable SENT_LOG=debug java -jar myapp.jar ``` ### Log Request IDs [#log-request-ids] Always log information for support tickets: ```typescript try { const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); console.log('Message sent:', response.data.recipients[0].message_id); } catch (error) { if (error instanceof SentDm.APIError) { console.log('Request ID:', error.headers.get('x-request-id')); console.log('Status:', error.status); console.log('Message:', error.message); // Include these in support tickets! } } ``` ```python from sent_dm import APIStatusError try: response = client.messages.send( to=['+1234567890'], template={ 'id': '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'name': 'welcome' } ) print(f'Message sent: {response.data.recipients[0].message_id}') except APIStatusError as e: print(f'Request ID: {e.response.headers.get("x-request-id")}') print(f'Status: {e.status_code}') print(f'Message: {str(e)}') # Include these in support tickets! ``` ```go response, err := client.Messages.Send(ctx, params) if err != nil { var apiErr *sentdm.Error if errors.As(err, &apiErr) { fmt.Printf("Request ID: %s\n", apiErr.Response.Header.Get("x-request-id")) fmt.Printf("Status: %d\n", apiErr.StatusCode) fmt.Printf("Message: %s\n", apiErr.Error()) // Include these in support tickets! } } else { fmt.Printf("Message sent: %s\n", response.Data.Recipients[0].MessageID) } ``` ### Test with cURL [#test-with-curl] Compare SDK behavior with raw API calls: ```bash # Test authentication curl -X GET https://api.sent.dm/v3/templates \ -H "x-api-key: YOUR_API_KEY" # Test message sending curl -X POST https://api.sent.dm/v3/messages \ -H "x-api-key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": {"id": "your-template-id"} }' ``` --- ## Frequently Asked Questions [#frequently-asked-questions] ### Q: Why is a message stuck in "QUEUED" status? [#q-why-is-a-message-stuck-in-queued-status] **A:** Outbound messages start as `QUEUED` and transition through: 1. `QUEUED` → Message accepted and queued for processing 2. `PROCESSED` → Message processed and queued for sending 3. `ROUTED` → Message routed to a channel provider 4. `SENT` → Dispatched to carrier/WhatsApp 5. `DELIVERED` → Confirmed delivery 6. `READ` → (WhatsApp & RCS) Opened by recipient Messages that cannot be delivered end in `FAILED`. Webhooks are recommended over polling for tracking status changes. If you need to check a single message, you can poll `GET /v3/messages/{id}` (`client.messages.retrieveStatus()` in the SDKs). ### Q: Can you use the same API key for multiple environments? [#q-can-you-use-the-same-api-key-for-multiple-environments] **A:** Yes, but it's not recommended. Use separate keys for different environments and explicitly pass them to the SDK: ```typescript // Choose key based on environment const apiKey = process.env.NODE_ENV === 'production' ? process.env.SENT_DM_API_KEY : process.env.SENT_DM_API_KEY_TEST; const client = new SentDm({ apiKey }); ``` This prevents accidental sends from test environments. Note: The SDK only automatically reads `SENT_DM_API_KEY` - you must implement the environment switching logic yourself. ### Q: Why do 401 errors appear in production but not locally? [#q-why-do-401-errors-appear-in-production-but-not-locally] **A:** Common causes: 1. Different API keys (check environment variables) 2. Key not set in production environment 3. Key was revoked/rotated 4. Whitespace or encoding issues Debug by logging the key prefix: ```typescript console.log('Key prefix:', process.env.SENT_DM_API_KEY?.substring(0, 8)); ``` ### Q: How do you handle webhook failures? [#q-how-do-you-handle-webhook-failures] **A:** Sent retries failed deliveries automatically with increasing delays. On a version 1 webhook, retries stop at the configured retry count (1–5 attempts, default 3). Once the retry budget is exhausted, the event is marked `FAILED` and can be inspected in the Sent Dashboard. Ensure your endpoint is idempotent and responds quickly. Refer to [handling retries](/start/webhooks/handling-retries) for the full retry model. ### Q: Can you send messages from the browser? [#q-can-you-send-messages-from-the-browser] **A:** No. Never expose your API key in client-side code. API keys should only be used server-side. For browser-based messaging, route through your backend API. --- ## Getting Help [#getting-help] If you're still stuck: 1. **Check the [API Reference](/reference/api)** for detailed endpoint documentation 2. **Review [SDK Guides](/sdks)** for language-specific examples 3. **Contact Support** with your request ID: - email: support@sent.dm - Include: Request ID from error response (in `x-request-id` header) - Include: Timestamp of the failed request - Include: Code snippet (remove API keys!) When contacting support, always include the request ID from the API response headers (`x-request-id`). This lets Sent support trace the exact request in the delivery logs. --- ## SDK-Specific Error Patterns [#sdk-specific-error-patterns] Different SDKs handle errors differently. Here's a quick reference: | SDK | Error Pattern | Key Exception Types | |-----|---------------|---------------------| | **TypeScript** | Throws exceptions | `APIError`, `BadRequestError`, `RateLimitError`, `AuthenticationError` | | **Python** | Throws exceptions | `APIError`, `BadRequestError`, `RateLimitError`, `AuthenticationError` | | **Go** | Returns error value | `*sentdm.Error` with `StatusCode`, `Error()`, `RawJSON()` | | **Java** | Throws exceptions | `SentException`, `BadRequestException`, `RateLimitException` | | **C#** | Throws exceptions | `SentApiException`, `SentBadRequestException`, `SentRateLimitException` | | **PHP** | Throws exceptions | `APIException`, `BadRequestException`, `RateLimitException` | | **Ruby** | Throws exceptions | `APIError`, `BadRequestError`, `RateLimitError` | --- # Your first Sent integration with the TypeScript SDK (/sdks/typescript/first-integration.md) # Your first Sent integration with the TypeScript SDK [#your-first-sent-integration-with-the-typescript-sdk] In this tutorial, you build a small TypeScript project that exercises the full Sent messaging loop: send a free-form text message, send a template message, receive `message.delivered` and `message.failed` webhooks on your own machine, and look up a message with the SDK. It takes about 30 minutes. Every send in this tutorial runs in [sandbox mode](/reference/api/test-mode): the API validates and simulates each request but delivers nothing and consumes no credits. You can complete every step on a brand-new Sent account. ## Prerequisites [#prerequisites] Before you begin, make sure you have: - **Node.js 20 or later**: check with `node --version` - **A Sent API key**: copy an existing key, or generate one, on the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - **ngrok**: install it with `npm install -g @ngrok/ngrok`; you use it to receive webhooks locally, and the [webhook local development guide](/start/webhooks/local-development) explains why you need a tunnel - **curl**: preinstalled on macOS, Linux, and Windows 10+ ### Set up the project [#set-up-the-project] First, create a new project and install the SDK, Express (for the webhook receiver), and tsx (to run TypeScript files directly): ```bash mkdir sent-first-integration cd sent-first-integration npm init -y npm install @sentdm/sentdm express npm install -D tsx ``` Now export your API key so the SDK can find it. The client reads the `SENT_DM_API_KEY` environment variable by default: ```bash export SENT_DM_API_KEY="your-api-key" ``` Let's check the install worked: ```bash npm ls @sentdm/sentdm ``` The output should look something like: ``` sent-first-integration@1.0.0 └── @sentdm/sentdm@0.32.0 ``` Keep API keys out of version control. Environment variables are the pattern we use throughout this tutorial. ### Send a free-form text message [#send-a-free-form-text-message] Now we send our first message. Create a file named `send-text.ts`: ```typescript title="send-text.ts" import SentDm from '@sentdm/sentdm'; const client = new SentDm(); // reads SENT_DM_API_KEY async function main() { const response = await client.messages.send({ to: ['+14155551234'], // replace with your own number in E.164 format text: 'Hello from my first Sent integration!', sandbox: true, // validate and simulate: nothing is delivered }); console.log(JSON.stringify(response, null, 2)); } main(); ``` Replace `+14155551234` with your own mobile number in E.164 format, then run it: ```bash npx tsx send-text.ts ``` The output should look something like: ```json { "success": true, "data": { "status": "QUEUED", "template_id": "00000000-0000-0000-0000-000000000000", "template_name": "", "recipients": [ { "message_id": "3f2b8c41-6a0e-4c8f-9b7d-2a1e5c9d0f36", "to": "+14155551234", "channel": null, "body": null } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-25T09:30:00.0000000+00:00", "version": "v3" } } ``` Copy the `message_id` value from your output. We use it again in the final step. Notice three things in the response: - `status` is `QUEUED`: the API accepts sends asynchronously (HTTP 202) and reports delivery later, through webhooks. - `channel` is `null` because we did not pick one. Sent auto-detects the best channel per recipient at send time. - `template_id` is all zeros and `template_name` is empty because this was a free-form `text` send. Every request must carry exactly one of `text` or `template`. Validation runs on sandbox requests too, so a malformed payload returns a real 400 error. ### Send a template message [#send-a-template-message] Channels like WhatsApp and RCS require approved templates for production messaging, so let's send one. Create `send-template.ts`: ```typescript title="send-template.ts" import SentDm from '@sentdm/sentdm'; const client = new SentDm(); async function main() { const response = await client.messages.send({ to: ['+14155551234'], // your number again channel: ['sms'], template: { name: 'welcome', parameters: { name: 'Ada' }, }, sandbox: true, }); console.log(JSON.stringify(response.data, null, 2)); } main(); ``` Run it: ```bash npx tsx send-template.ts ``` The output should look something like: ```json { "status": "QUEUED", "template_id": "00000000-0000-0000-0000-000000000000", "template_name": "welcome", "recipients": [ { "message_id": "9c41d2aa-7b3f-4e58-8f06-5d2e91c7ab10", "to": "+14155551234", "channel": "sms", "body": null } ] } ``` Notice that this time each recipient carries `channel: "sms"`. When you list several channels, Sent creates a separate message (with its own `message_id`) for every recipient-and-channel pair. We reference the template by `name` here; a template reference takes either `id` or `name`, never both. In sandbox mode the template is not looked up, so any name passes. A live send requires a template that exists on your account, and returns a 404 `RESOURCE_002` (template not found) error otherwise. You have now sent messages both ways the API supports. Next, let's find out what happens to a message after it is queued. ### Start a local webhook receiver [#start-a-local-webhook-receiver] Sent reports delivery progress by POSTing events to your server. We start with a minimal receiver. Create `webhook-server.ts`: ```typescript title="webhook-server.ts" import express from 'express'; const app = express(); // Raw body: signature verification in production needs the exact bytes app.post('/webhooks/sent', express.raw({ type: 'application/json' }), (req, res) => { const event = JSON.parse(req.body.toString('utf8')); console.log(`--- ${event.event} ---`); console.log(JSON.stringify(event, null, 2)); res.status(200).json({ received: true }); }); app.listen(3000, () => { console.log('Webhook receiver listening on http://localhost:3000'); }); ``` Run it in its own terminal and leave it running: ```bash npx tsx webhook-server.ts ``` The output should look something like: ``` Webhook receiver listening on http://localhost:3000 ``` We parse the raw body instead of using `express.json()` because production handlers must verify the `webhook-signature` header (`X-Webhook-Signature` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook) against the exact request bytes, as shown in [webhook signature verification](/start/webhooks/signature-verification). We skip verification here to stay focused on the flow. ### Open a tunnel with ngrok [#open-a-tunnel-with-ngrok] Sent cannot reach `localhost`, and it rejects webhook URLs that resolve to private or loopback addresses. A tunnel gives your local server a public HTTPS URL. In a second terminal, run: ```bash ngrok http 3000 ``` The output should include a forwarding line like: ``` https://abc123.ngrok.io -> http://localhost:3000 ``` Copy your `https://` forwarding URL. We register it with Sent in the next step. Keep this terminal running too. ### Register the webhook [#register-the-webhook] Now we tell Sent where to deliver events. In a third terminal, call the webhooks API with your forwarding URL: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "First integration tutorial", "endpoint_url": "https://abc123.ngrok.io/webhooks/sent", "event_types": ["message"] }' ``` The output should look something like: ```json { "success": true, "data": { "id": "d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8", "display_name": "First integration tutorial", "endpoint_url": "https://abc123.ngrok.io/webhooks/sent", "signing_secret": "whsec_a1b2c3d4e5f6g7h8i9j0", "is_active": true, "event_types": ["message"], "retry_count": 3, "timeout_seconds": 30 }, "error": null } ``` Copy the `id` from your response. We need it in the next step. Notice that `event_types` takes parent categories: `message` covers every message event, from `message.queued` through `message.delivered`, `message.failed`, and inbound `message.received` (the [webhook event types page](/start/webhooks/event-types) has the full list). The `signing_secret` is what production code uses to verify the `webhook-signature` header; treat it like a password. ### Deliver message.delivered and message.failed events [#deliver-messagedelivered-and-messagefailed-events] With the receiver, the tunnel, and the registration in place, we can ask Sent to deliver a test event. Replace the webhook ID in the URL with the `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/d4f5a6b7-c8d9-4e0f-a1b2-c3d4e5f6a7b8/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` The curl output should look something like: ```json { "success": true, "data": { "success": true, "message": "Test event delivered successfully" } } ``` Now look at the terminal running `webhook-server.ts`. The output should look something like: ``` --- message.delivered --- { "field": "message", "event": "message.delivered", "timestamp": "2026-07-25T09:30:00Z", "payload": { "updated_at": "2026-07-25T09:30:00Z", "account_id": "00000000-0000-0000-0000-000000000000", "message_id": "00000000-0000-0000-0000-000000000001", "template_id": "00000000-0000-0000-0000-000000000002", "template_name": "Test Template", "outbound_number": "+0987654321", "message_status": "DELIVERED", "channel": "sms" } } ``` Sent just made a round trip to your laptop. Run the same command again with `{"event_type": "message.failed"}` in the body. Your receiver prints a second event, identical in shape but with `"message_status": "FAILED"`. Notice that test events carry placeholder IDs (the zero-padded values above). Events for real sends carry the same `message_id` your send call returned; that ID is how your application matches a delivery report back to the message it sent. Sent attempts a test event exactly once, and retries real events up to the webhook's `retry_count` on failure. ### Look up a message with the SDK [#look-up-a-message-with-the-sdk] Finally, let's read a message back. Create `check-status.ts`: ```typescript title="check-status.ts" import SentDm from '@sentdm/sentdm'; const client = new SentDm(); async function main() { const messageId = process.argv[2]; try { const status = await client.messages.retrieveStatus(messageId); console.log('Status:', status.data.status); console.log('Channel:', status.data.channel); console.log('Direction:', status.data.direction); } catch (err) { if (err instanceof SentDm.APIError) { console.log(`${err.constructor.name} (${err.status})`); } else { throw err; } } } main(); ``` Run it with the `message_id` you copied in the free-form text step: ```bash npx tsx check-status.ts 3f2b8c41-6a0e-4c8f-9b7d-2a1e5c9d0f36 ``` The output should be: ``` NotFoundError (404) ``` That 404 is expected, and it is the last lesson of this tutorial. Sandbox messages are simulated, never stored, so there is nothing to look up. The `catch` block you just wrote is the same `APIError` handling your production code needs for every SDK call. For a live (non-sandbox) message, the identical script prints the real delivery state: ``` Status: DELIVERED Channel: sms Direction: OUTBOUND ``` Remember that webhooks, not lookups, are the recommended way to track delivery: store the `message_id` when you send, then update your records as events arrive instead of polling this endpoint. ## What you have built [#what-you-have-built] You have built a working end-to-end Sent integration: a project that sends free-form and template messages through the TypeScript SDK, a webhook receiver that accepts signed delivery events from Sent's servers on your own machine, and a status lookup with real error handling. You have also learned the ideas that carry into production (asynchronous sends, per-recipient message IDs, parent event types, and webhook-first delivery tracking) without spending a credit. ## Next steps [#next-steps] Take the loop you built here to production: - Swap `sandbox: true` for real sends once your [account setup](/start/quickstart/account-setup) is complete; the code doesn't change - Work through the [webhooks production checklist](/start/webhooks/production-checklist) and add [signature verification](/start/webhooks/signature-verification) to your receiver - Wire the client into your framework with the [Express](/sdks/typescript/integrations/express), [NestJS](/sdks/typescript/integrations/nestjs), or [Next.js](/sdks/typescript/integrations/nextjs) integration guides - Read the [error handling reference](/reference/api/errors) and the [sandbox mode reference](/reference/api/test-mode) for what you used today # TypeScript SDK (/sdks/typescript.md) # TypeScript SDK [#typescript-sdk] The official TypeScript SDK for Sent provides type-safe access to the entire Sent API. Built for modern Node.js applications with native ESM and CommonJS support, automatic retries, and error handling. ## Installation [#installation] ```bash npm install @sentdm/sentdm ``` ```bash yarn add @sentdm/sentdm ``` ```bash pnpm add @sentdm/sentdm ``` ```bash bun add @sentdm/sentdm ``` ## Quick Start [#quick-start] ### Initialize the client [#initialize-the-client] ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); // Uses SENT_DM_API_KEY env var by default ``` ### Send your first message [#send-your-first-message] ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome', parameters: { name: 'John Doe' } } }); console.log('Message sent:', response.data.recipients[0].message_id); console.log('Status:', response.data.status); ``` **New to Sent?** Follow [Your first Sent integration with the TypeScript SDK](/sdks/typescript/first-integration), a guided tutorial that takes you from an empty project to a sandbox send, delivery webhooks on your own machine, and a status lookup. ## Authentication [#authentication] The client can be configured using environment variables or explicitly: ```typescript import SentDm from '@sentdm/sentdm'; // Using environment variables (recommended) // SENT_DM_API_KEY=your_api_key const client = new SentDm(); // Or explicit configuration const client = new SentDm({ apiKey: 'your_api_key', }); ``` ## Send Messages [#send-messages] ### Send a message [#send-a-message] ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome', parameters: { name: 'John Doe', order_id: '12345' } }, channel: ['whatsapp', 'sms', 'rcs'] // Optional. Defaults to ["sent"], which auto-detects the channel per recipient }); console.log('Message ID:', response.data.recipients[0].message_id); console.log('Status:', response.data.status); ``` ### Sandbox mode [#sandbox-mode] Use `sandbox: true` to validate requests without sending real messages: ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' }, sandbox: true // Validates but doesn't send }); // Response will have test data console.log('Validation passed:', response.data.recipients[0].message_id); ``` ## Check message status [#check-message-status] Retrieve the current status of a sent message. The `direction` field indicates whether the message is `"OUTBOUND"` (sent by you) or `"INBOUND"` (a reply or opt-out keyword received from an end user): ```typescript const status = await client.messages.retrieveStatus('msg-uuid'); console.log('Status:', status.data.status); // e.g. "DELIVERED" console.log('Channel:', status.data.channel); // e.g. "sms" console.log('Direction:', status.data.direction); // "OUTBOUND" | "INBOUND" ``` ## Message activities [#message-activities] Retrieve the full activity log for a message, useful for auditing delivery attempts across carriers: ```typescript const activities = await client.messages.retrieveActivities('msg-uuid'); for (const activity of activities.data.activities) { console.log(`${activity.timestamp}: ${activity.status} via ${activity.from}`); console.log(' Price:', activity.price); console.log(' Active contact price:', activity.active_contact_price); } ``` ## Numbers [#numbers] Look up carrier and line-type information for any phone number before sending: ```typescript const result = await client.numbers.lookup('+12025551234'); console.log('Valid:', result.data.is_valid); console.log('Carrier:', result.data.carrier_name); console.log('Line type:', result.data.line_type); // "mobile", "landline", "voip" console.log('VoIP:', result.data.is_voip); ``` ## Handle errors [#handle-errors] When the library is unable to connect to the API, or if the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of `APIError` will be thrown: ```ts try { const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', name: 'welcome' } }); } catch (err) { if (err instanceof SentDm.APIError) { console.log(err.status); // 400 console.log(err.constructor.name); // BadRequestError console.log(err.headers); // {server: 'nginx', ...} } else { throw err; } } ``` Error codes are as follows: | Cause | Error Type | |-------|--------------------------| | HTTP 400 | `BadRequestError` | | HTTP 401 | `AuthenticationError` | | HTTP 403 | `PermissionDeniedError` | | HTTP 404 | `NotFoundError` | | HTTP 409 | `ConflictError` | | HTTP 422 | `UnprocessableEntityError` | | HTTP 429 | `RateLimitError` | | HTTP >= 500 | `InternalServerError` | | Timeout | `APIConnectionTimeoutError` | | Network error | `APIConnectionError` | ## Retries [#retries] Certain errors will be automatically retried 2 times by default, with a short exponential backoff. Connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default. ```js // Configure the default for all requests: const client = new SentDm({ maxRetries: 0, // default is 2 }); // Or, configure per-request: await client.messages.send({ to: ['+1234567890'], template: { id: 'welcome-template', name: 'welcome' } }, { maxRetries: 5, }); ``` ## Timeouts [#timeouts] Requests time out after 1 minute by default. You can configure this with a `timeout` option: ```ts // Configure the default for all requests: const client = new SentDm({ timeout: 20 * 1000, // 20 seconds (default is 1 minute) }); // Override per-request: await client.messages.send({ to: ['+1234567890'], template: { id: 'welcome-template', name: 'welcome' } }, { timeout: 5 * 1000, }); ``` ## Contacts [#contacts] Create and manage contacts: ```typescript // Create a contact const contact = await client.contacts.create({ phone_number: '+1234567890', }); console.log('Contact ID:', contact.data.id); // List contacts const contacts = await client.contacts.list({ page: 1, page_size: 100, }); console.log('Total:', contacts.data.contacts.length); // Get a contact const retrieved = await client.contacts.retrieve('contact-uuid'); // Update a contact const updated = await client.contacts.update('contact-uuid', { default_channel: 'whatsapp', }); // Delete a contact await client.contacts.delete('contact-uuid', {}); ``` ## Templates [#templates] List and retrieve templates: ```typescript // List all templates const templates = await client.templates.list({ page: 1, page_size: 100 }); for (const template of templates.data.templates) { console.log(`${template.name} (${template.status}): ${template.id}`); } // Get a specific template const template = await client.templates.retrieve('template-uuid'); console.log('Template name:', template.data.name); console.log('Status:', template.data.status); ``` ## Framework Integration [#framework-integration] ### NestJS [#nestjs] See the [NestJS Integration](/sdks/typescript/integrations/nestjs) guide for complete dependency injection, module setup, and testing examples. ```typescript // messages/messages.service.ts import { Injectable, Inject } from '@nestjs/common'; import SentDm from '@sentdm/sentdm'; import { SENT_CLIENT } from '../sent/sent.module'; @Injectable() export class MessagesService { constructor( @Inject(SENT_CLIENT) private readonly sentClient: SentDm, ) {} async sendWelcomeMessage(phoneNumber: string, name: string) { const response = await this.sentClient.messages.send({ to: [phoneNumber], template: { id: 'welcome-template', name: 'welcome', parameters: { name } } }); return response.data.recipients[0]; } } ``` ### Next.js (App Router) [#nextjs-app-router] See the [Next.js Integration](/sdks/typescript/integrations/nextjs) guide for complete Server Actions, Route Handlers, and Edge Runtime examples. ```typescript // app/api/send-message/route.ts import SentDm from '@sentdm/sentdm'; import { NextResponse } from 'next/server'; const client = new SentDm(); export async function POST(request: Request) { const { phoneNumber, templateId, variables } = await request.json(); try { const response = await client.messages.send({ to: [phoneNumber], template: { id: templateId, name: 'welcome', parameters: variables } }); return NextResponse.json({ messageId: response.data.recipients[0].message_id, status: response.data.status, }); } catch (error) { if (error instanceof SentDm.APIError) { return NextResponse.json( { error: error.message }, { status: error.status } ); } throw error; } } ``` ### Express.js [#expressjs] See the [Express.js Integration](/sdks/typescript/integrations/express) guide for complete dependency injection, validation, and structured logging examples. ```typescript import express from 'express'; import SentDm from '@sentdm/sentdm'; const app = express(); const client = new SentDm(); app.use(express.json()); app.post('/send-message', async (req, res) => { const { phoneNumber, templateId, variables } = req.body; try { const response = await client.messages.send({ to: [phoneNumber], template: { id: templateId, name: 'welcome', parameters: variables } }); res.json({ success: true, message: response.data, }); } catch (error) { if (error instanceof SentDm.APIError) { res.status(error.status).json({ error: error.message }); } else { res.status(500).json({ error: 'Internal server error' }); } } }); app.listen(3000); ``` ## Webhooks [#webhooks] **Recommended pattern:** Webhooks are the primary way to track message delivery, so don't poll the API. Save the message ID when you send, then update your database as webhook events arrive. Sent delivers signed POST requests to your endpoint for every status change. Two event types exist: - **`message`**: Message status changes (`QUEUED`, `ROUTED`, `SCHEDULED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED`, `RECEIVED`); each fires as a sub-type (for example, `message.delivered`, `message.filtered`). Use `message.received` to receive inbound messages from contacts. - **`templates`**: WhatsApp template approval/rejection Every request includes these headers, named by the webhook's [version](/start/webhooks/event-types#webhook-versions): | Version 2 (default) | Version 1 | Description | |---------------------|-----------|-------------| | `webhook-id` | `X-Webhook-ID` | Message ID on version 2 (stable across retries); UUID of the webhook configuration on version 1 | | `webhook-timestamp` | `X-Webhook-Timestamp` | Unix timestamp (seconds) when the event was created | | `webhook-signature` | `X-Webhook-Signature` | `v1,{base64}`: HMAC-SHA256 of `{webhookId}.{timestamp}.{rawBody}`. Version 2 sends two space-separated signatures for 24 hours after a secret rotation | | None: read `event` from the body | `X-Webhook-Event-Type` | `message` (for example, `message.delivered`) or `templates` | The signing secret (from the Sent Dashboard) has a `whsec_` prefix. Strip it and **base64-decode** the remainder to obtain the raw HMAC key. ```typescript import express from 'express'; import { createHmac, timingSafeEqual } from 'crypto'; const app = express(); // Must use raw body — do NOT use express.json() for this route app.post('/webhooks/sent', express.raw({ type: 'application/json' }), (req, res) => { const payload = req.body as Buffer; // Version 2 headers first, falling back to version 1 const webhookId = (req.headers['webhook-id'] ?? req.headers['x-webhook-id']) as string; const timestamp = (req.headers['webhook-timestamp'] ?? req.headers['x-webhook-timestamp']) as string; const signature = (req.headers['webhook-signature'] ?? req.headers['x-webhook-signature']) as string; // 1. Verify: signed content = "{webhookId}.{timestamp}.{rawBody}" const secret = process.env.SENT_DM_WEBHOOK_SECRET!; // "whsec_abc123..." const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signed = `${webhookId}.${timestamp}.${payload.toString('utf8')}`; const expected = 'v1,' + createHmac('sha256', keyBytes).update(signed).digest('base64'); // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match const expectedBuf = Buffer.from(expected); const matches = (c: string) => Buffer.byteLength(c) === expectedBuf.length && timingSafeEqual(Buffer.from(c), expectedBuf); if (!signature || !signature.trim().split(/\s+/).some(matches)) { return res.status(401).json({ error: 'Invalid signature' }); } // 2. Optional: reject replayed events older than 5 minutes if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) { return res.status(401).json({ error: 'Timestamp too old' }); } const event = JSON.parse(payload.toString()); // 3. Handle events — update message status in your own database if (event.field === 'message') { if (event.event === 'message.received') { // Inbound message from a contact const { inbound_number, outbound_number, text, channel, received_at } = event.payload; console.log(`Inbound ${channel} from ${inbound_number}: ${text}`); // await db.inboundMessages.create({ from: inbound_number, to: outbound_number, text, channel, receivedAt: received_at }); } else { // Outbound message status update const { message_id, message_status, channel } = event.payload; // await db.messages.update({ where: { sentId: message_id }, data: { status: message_status } }) console.log(`Message ${message_id} → ${message_status} (${channel})`); } } // 4. Always return 200 quickly res.json({ received: true }); }); ``` See the [Webhooks reference](/start/webhooks) for the full payload schema and all status values. ## Logging [#logging] The log level can be configured via the `SENT_LOG` environment variable or using the `logLevel` client option: ```ts import SentDm from '@sentdm/sentdm'; const client = new SentDm({ logLevel: 'debug', // Show all log messages }); ``` Available log levels: `'debug'`, `'info'`, `'warn'` (default), `'error'`, `'off'` ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-typescript/releases) - **GitHub**: [`sentdm/sent-dm-typescript`](https://github.com/sentdm/sent-dm-typescript) - **NPM**: [`@sentdm/sentdm`](https://www.npmjs.com/package/@sentdm/sentdm) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-typescript/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Sending messages from Express with the Sent TypeScript SDK (/sdks/typescript/integrations/express.md) # Sending messages from Express with the Sent TypeScript SDK [#sending-messages-from-express-with-the-sent-typescript-sdk] This guide shows you how to wire Sent messaging into an existing Express app: install the TypeScript SDK, configure a shared client, send a template message from a route, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Express 5 app with TypeScript. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing project: ```bash npm install @sentdm/sentdm ``` ### Configure the client [#configure-the-client] Set your credentials as environment variables so they stay out of code; the webhook secret arrives in step 4: ```bash export SENT_DM_API_KEY="your-api-key" export SENT_DM_WEBHOOK_SECRET="whsec_your_signing_secret" ``` Create one shared client for the whole process; `new SentDm()` reads `SENT_DM_API_KEY` by default: ```typescript // src/sent.ts import SentDm from '@sentdm/sentdm'; export const sent = new SentDm(); ``` ### Send a template message from a route [#send-a-template-message-from-a-route] Add a router that calls `messages.send`; the pass-through `sandbox` flag lets callers exercise the route without delivering anything: ```typescript // src/routes/messages.ts import { Router } from 'express'; import { sent } from '../sent'; export const messagesRouter = Router(); messagesRouter.post('/send', async (req, res, next) => { try { const { phoneNumber, templateName, parameters, channels, sandbox } = req.body; const response = await sent.messages.send({ to: [phoneNumber], // E.164 format, for example +14155551234 template: { name: templateName, parameters }, // reference by name or id, never both channel: channels, // omit to let Sent pick per recipient sandbox: sandbox ?? false, // true = validate and simulate only }); const recipient = response.data.recipients[0]; res.status(202).json({ messageId: recipient.message_id, status: response.data.status }); } catch (err) { next(err); } }); ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`, because delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a verification helper that checks the `webhook-signature` header against the raw request body before your handler trusts any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme: ```typescript // src/webhook-signature.ts import { createHmac, timingSafeEqual } from 'crypto'; // Signature format: "v1,{base64(hmac)}" over "{webhookId}.{timestamp}.{rawBody}". // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match. export function verifyWebhookSignature( payload: Buffer, webhookId: string, timestamp: string, signature: string, secret: string, ): boolean { const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signedContent = `${webhookId}.${timestamp}.${payload.toString('utf8')}`; const expected = 'v1,' + createHmac('sha256', keyBytes).update(signedContent).digest('base64'); const expectedBuffer = Buffer.from(expected); return signature.trim().split(/\s+/).some((candidate) => { const candidateBuffer = Buffer.from(candidate); return candidateBuffer.length === expectedBuffer.length && timingSafeEqual(candidateBuffer, expectedBuffer); }); } ``` Add the endpoint itself. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them; return 200 quickly and do slow work elsewhere: ```typescript // src/routes/webhooks.ts import { Router } from 'express'; import { verifyWebhookSignature } from '../webhook-signature'; export const webhooksRouter = Router(); webhooksRouter.post('/sent', (req, res) => { // Version 2 headers first, falling back to version 1 const webhookId = req.header('webhook-id') ?? req.header('x-webhook-id') ?? ''; const timestamp = req.header('webhook-timestamp') ?? req.header('x-webhook-timestamp') ?? ''; const signature = req.header('webhook-signature') ?? req.header('x-webhook-signature') ?? ''; const secret = process.env.SENT_DM_WEBHOOK_SECRET ?? ''; if (!signature || !secret || !verifyWebhookSignature(req.body, webhookId, timestamp, signature, secret)) { return res.status(401).json({ error: 'Invalid webhook signature' }); } // Reject replayed events older than 5 minutes if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) { return res.status(401).json({ error: 'Webhook timestamp too old' }); } const event = JSON.parse(req.body.toString('utf8')); const payload = event.payload ?? {}; if (event.field === 'message') { switch (event.event) { case 'message.delivered': console.log(`Message ${payload.message_id} delivered`); break; case 'message.failed': console.error(`Message ${payload.message_id} failed (status ${payload.message_status})`); break; case 'message.received': console.log(`Inbound ${payload.channel} from ${payload.inbound_number}: ${payload.text}`); break; default: console.log(`Message ${payload.message_id} status: ${payload.message_status}`); } } res.json({ received: true }); }); ``` Mount both routers. The webhook path must receive the raw body. Signature verification needs the exact bytes, so register `express.raw` for it, not `express.json`: ```typescript // src/app.ts (excerpt) app.use('/api/messages', express.json(), messagesRouter); app.use('/webhooks', express.raw({ type: 'application/json' }), webhooksRouter); ``` Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Express integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded (for example, `npm run dev`). Then send a sandbox message through your new route. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:3000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phoneNumber": "+14155551234", "templateName": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `messageId` and `"status": "QUEUED"`. A 400 here means the request shape is wrong; sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your server log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If your app already parses JSON globally with `app.use(express.json())`, scope it away from the webhook path, because verification fails on re-serialized bodies. - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and process asynchronously so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send free-form text instead of a template, pass `text` instead of `template`. Each send carries exactly one of the two. - If you need input validation, rate limiting, or structured logging around these routes, the appendix below has the scaffolding. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Express stack. Adapt them to your own conventions rather than adopting them wholesale. Fail fast at boot when required variables are missing instead of at first send: ```typescript // src/config/env.ts import { z } from 'zod'; const envSchema = z.object({ NODE_ENV: z.enum(['development', 'production', 'test']).default('development'), PORT: z.string().transform(Number).default('3000'), SENT_DM_API_KEY: z.string().min(1, 'SENT_DM_API_KEY is required'), SENT_DM_WEBHOOK_SECRET: z.string().min(1, 'SENT_DM_WEBHOOK_SECRET is required'), }); const parsed = envSchema.safeParse(process.env); if (!parsed.success) { console.error('Invalid environment variables:', parsed.error.format()); process.exit(1); } export const env = parsed.data; ``` Validate request bodies with the same library before they reach the SDK: ```typescript // src/types.ts import { z } from 'zod'; export const SendMessageSchema = z.object({ phoneNumber: z.string().regex(/^\+[1-9]\d{1,14}$/, 'Invalid E.164 format'), templateName: z.string().min(1).max(100), parameters: z.record(z.string()).optional(), channels: z.array(z.enum(['sms', 'whatsapp', 'rcs'])).optional(), sandbox: z.boolean().optional(), }); ``` Cap how often callers can hit your send route and add standard hardening middleware: ```typescript // src/app.ts (excerpt) import helmet from 'helmet'; import cors from 'cors'; import rateLimit from 'express-rate-limit'; app.use(helmet()); app.use(cors({ origin: env.NODE_ENV === 'production' ? [/\.your-domain\.example$/] : true })); app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100, standardHeaders: true, legacyHeaders: false })); ``` Close the HTTP server on SIGTERM so in-flight webhook deliveries finish instead of failing and retrying: ```typescript // src/server.ts (excerpt) const server = app.listen(env.PORT); const shutdown = () => { server.close(() => process.exit(0)); setTimeout(() => process.exit(1), 10_000); }; process.on('SIGTERM', shutdown); process.on('SIGINT', shutdown); ``` This vitest helper signs payloads exactly the way Sent does, so you can test verification offline; the [SDK testing guide](/sdks/testing) covers mocking `messages.send`: ```typescript // src/routes/webhooks.spec.ts import { createHmac } from 'crypto'; import request from 'supertest'; function signedHeaders(payload: string, secret: string) { const webhookId = '550e8400-e29b-41d4-a716-446655440000'; const timestamp = String(Math.floor(Date.now() / 1000)); const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signature = 'v1,' + createHmac('sha256', keyBytes) .update(`${webhookId}.${timestamp}.${payload}`).digest('base64'); return { 'x-webhook-id': webhookId, 'x-webhook-timestamp': timestamp, 'x-webhook-signature': signature }; } it('accepts a correctly signed event', async () => { const payload = JSON.stringify({ field: 'message', event: 'message.delivered', timestamp: new Date().toISOString(), payload: { message_id: 'msg_123', message_status: 'DELIVERED' } }); const res = await request(app).post('/webhooks/sent') .set(signedHeaders(payload, process.env.SENT_DM_WEBHOOK_SECRET!)) .set('content-type', 'application/json') .send(payload); expect(res.status).toBe(200); }); ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [TypeScript SDK reference](/sdks/typescript) for retries, timeouts, and error types - New to Sent? The [first integration tutorial](/sdks/typescript/first-integration) walks the same loop from scratch # Sending messages from NestJS with the Sent TypeScript SDK (/sdks/typescript/integrations/nestjs.md) # Sending messages from NestJS with the Sent TypeScript SDK [#sending-messages-from-nestjs-with-the-sent-typescript-sdk] This guide shows you how to wire Sent messaging into an existing NestJS app: install the TypeScript SDK, register the client as a provider, send a template message from a controller, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working NestJS app that uses `@nestjs/config`. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing project: ```bash npm install @sentdm/sentdm ``` ### Configure the client provider [#configure-the-client-provider] Add the credentials to your `.env`; the webhook secret arrives in step 4: ```bash # .env SENT_DM_API_KEY=your_api_key_here SENT_DM_WEBHOOK_SECRET=whsec_your_signing_secret ``` Register one shared client as a global provider so any service can inject it: ```typescript // sent/sent.module.ts import { Global, Module } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import SentDm from '@sentdm/sentdm'; export const SENT_CLIENT = Symbol('SENT_CLIENT'); @Global() @Module({ providers: [ { provide: SENT_CLIENT, useFactory: (config: ConfigService) => new SentDm({ apiKey: config.getOrThrow('SENT_DM_API_KEY') }), inject: [ConfigService], }, ], exports: [SENT_CLIENT], }) export class SentModule {} ``` Import `SentModule` in your `AppModule` alongside `ConfigModule.forRoot({ isGlobal: true })`. ### Send a template message from a controller [#send-a-template-message-from-a-controller] Wrap the SDK call in a service; the pass-through `sandbox` flag lets callers exercise the endpoint without delivering anything: ```typescript // messages/messages.service.ts import { Inject, Injectable, Logger } from '@nestjs/common'; import SentDm from '@sentdm/sentdm'; import { SENT_CLIENT } from '../sent/sent.module'; export interface SendMessageDto { phoneNumber: string; // E.164 format, for example +14155551234 templateName: string; // reference by name or id, never both parameters?: Record; channels?: string[]; // omit to let Sent pick per recipient sandbox?: boolean; // true = validate and simulate only } @Injectable() export class MessagesService { private readonly logger = new Logger(MessagesService.name); constructor(@Inject(SENT_CLIENT) private readonly sentClient: SentDm) {} async sendMessage(dto: SendMessageDto) { const response = await this.sentClient.messages.send({ to: [dto.phoneNumber], template: { name: dto.templateName, parameters: dto.parameters ?? {} }, channel: dto.channels, sandbox: dto.sandbox ?? false, }); const recipient = response.data.recipients[0]; this.logger.log(`Message queued: ${recipient.message_id}`); return { messageId: recipient.message_id, status: response.data.status }; } } ``` Expose it through a controller: ```typescript // messages/messages.controller.ts import { Body, Controller, HttpCode, Post } from '@nestjs/common'; import { MessagesService, SendMessageDto } from './messages.service'; @Controller('api/messages') export class MessagesController { constructor(private readonly messagesService: MessagesService) {} @Post('send') @HttpCode(202) sendMessage(@Body() dto: SendMessageDto) { return this.messagesService.sendMessage(dto); } } ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`, because delivery outcomes arrive on your webhook endpoint instead of in this response. ### Receive delivery webhooks [#receive-delivery-webhooks] Enable raw body capture first, because signature verification needs the exact request bytes: ```typescript // main.ts (excerpt) const app = await NestFactory.create(AppModule, { rawBody: true }); ``` Add a controller that verifies the `webhook-signature` header before trusting any event. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them: ```typescript // webhooks/webhooks.controller.ts import { BadRequestException, Controller, Headers, Logger, Post, Req, UnauthorizedException, } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { createHmac, timingSafeEqual } from 'crypto'; import type { Request } from 'express'; // With rawBody enabled, Nest exposes the unparsed bytes on the request type RawBodyRequest = Request & { rawBody?: Buffer }; interface WebhookEvent { field: 'message' | 'templates'; event?: string; // granular sub-type; omitted when the event has no sub-type timestamp: string; payload: Record; } @Controller('webhooks') export class WebhooksController { private readonly logger = new Logger(WebhooksController.name); constructor(private readonly configService: ConfigService) {} @Post('sent') async handleWebhook( @Headers() headers: Record, @Req() req: RawBodyRequest, ): Promise<{ received: boolean }> { // Version 2 headers first, falling back to version 1 const webhookId = headers['webhook-id'] ?? headers['x-webhook-id']; const timestamp = headers['webhook-timestamp'] ?? headers['x-webhook-timestamp']; const signature = headers['webhook-signature'] ?? headers['x-webhook-signature']; const rawBody = req.rawBody; if (!rawBody) { throw new BadRequestException('Raw body unavailable; enable rawBody in NestFactory.create'); } const webhookSecret = this.configService.get('SENT_DM_WEBHOOK_SECRET'); if (!webhookSecret) { // Fail closed: never process an event you cannot verify throw new UnauthorizedException('Webhook secret not configured'); } if (!this.verifySignature(webhookId, timestamp, rawBody, signature, webhookSecret)) { throw new UnauthorizedException('Invalid webhook signature'); } // Reject replayed events older than 5 minutes if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) { throw new UnauthorizedException('Webhook timestamp too old'); } const event = JSON.parse(rawBody.toString('utf8')) as WebhookEvent; await this.handleEvent(event); return { received: true }; } // The HMAC key is the signing secret after stripping the "whsec_" prefix // and base64-decoding the remainder. Version 2 sends two space-separated // signatures for 24 hours after a rotation; accept any match. private verifySignature( webhookId: string, timestamp: string, rawBody: Buffer, signature: string, secret: string, ): boolean { if (!webhookId || !timestamp || !signature) { return false; } const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signedContent = `${webhookId}.${timestamp}.${rawBody.toString('utf8')}`; const expected = 'v1,' + createHmac('sha256', keyBytes).update(signedContent).digest('base64'); const expectedBuffer = Buffer.from(expected); return signature.trim().split(/\s+/).some((candidate) => { const candidateBuffer = Buffer.from(candidate); return candidateBuffer.length === expectedBuffer.length && timingSafeEqual(candidateBuffer, expectedBuffer); }); } private async handleEvent(event: WebhookEvent): Promise { if (event.field !== 'message') { this.logger.log(`Unhandled webhook field: ${event.field}`); return; } switch (event.event) { case 'message.delivered': this.logger.log(`Message ${event.payload.message_id} delivered`); break; case 'message.failed': this.logger.error(`Message ${event.payload.message_id} failed (status ${event.payload.message_status})`); break; case 'message.received': this.logger.log(`Inbound message from ${event.payload.inbound_number}: ${event.payload.text}`); break; default: this.logger.log(`Message ${event.payload.message_id} status: ${event.payload.message_status}`); } } } ``` Register the controller in a module, import it in `AppModule`, then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "NestJS integration", "endpoint_url": "https://your-domain.example/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash npm run start:dev ``` Send a sandbox message through your new endpoint. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:3000/api/messages/send \ -H "Content-Type: application/json" \ -d '{"phoneNumber": "+14155551234", "templateName": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `messageId` and `"status": "QUEUED"`. A 400 here means the request shape is wrong; sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your Nest log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you validate request bodies with `class-validator`, turn `SendMessageDto` into a decorated class (the appendix below has the schema). - If webhook processing does slow work (database writes, downstream calls), acknowledge with 200 first and hand off to a queue such as BullMQ so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - If you package the client for reuse across apps, wrap the provider in a `DynamicModule` with `forRootAsync` options instead of the global module shown here. - To send free-form text instead of a template, pass `text` instead of `template`. Each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production NestJS stack. Adapt them to your own conventions rather than adopting them wholesale. Reject malformed requests before they reach the SDK: ```typescript // messages/dto/send-message.dto.ts import { IsArray, IsBoolean, IsIn, IsObject, IsOptional, IsString, Matches, MaxLength } from 'class-validator'; export class SendMessageDto { @Matches(/^\+[1-9]\d{1,14}$/, { message: 'phoneNumber must be E.164 format' }) phoneNumber: string; @IsString() @MaxLength(100) templateName: string; @IsOptional() @IsObject() parameters?: Record; @IsOptional() @IsArray() @IsIn(['sms', 'whatsapp', 'rcs'], { each: true }) channels?: string[]; @IsOptional() @IsBoolean() sandbox?: boolean; } ``` Enable it globally with `app.useGlobalPipes(new ValidationPipe({ whitelist: true }))`. Map SDK errors to consistent HTTP responses instead of leaking stack traces: ```typescript // common/filters/sent-exception.filter.ts import { ArgumentsHost, Catch, ExceptionFilter, HttpStatus, Logger } from '@nestjs/common'; import SentDm from '@sentdm/sentdm'; import type { Response } from 'express'; @Catch(SentDm.APIError) export class SentExceptionFilter implements ExceptionFilter { private readonly logger = new Logger(SentExceptionFilter.name); catch(exception: InstanceType, host: ArgumentsHost) { const response: Response = host.switchToHttp().getResponse(); const status = exception.status ?? HttpStatus.INTERNAL_SERVER_ERROR; this.logger.error(`Sent API error (${status}): ${exception.message}`); response.status(status >= 500 ? 502 : status).json({ error: { code: exception.constructor.name, message: exception.message }, }); } } ``` Register it in `main.ts` with `app.useGlobalFilters(new SentExceptionFilter())`. Inject a mock in place of `SENT_CLIENT`; the [SDK testing guide](/sdks/testing) covers the wider strategy: ```typescript // messages/messages.service.spec.ts const mockClient = { messages: { send: jest.fn().mockResolvedValue({ data: { status: 'QUEUED', recipients: [{ message_id: 'msg_123' }] }, }), }, }; const module = await Test.createTestingModule({ providers: [MessagesService, { provide: SENT_CLIENT, useValue: mockClient }], }).compile(); ``` ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [TypeScript SDK reference](/sdks/typescript) for retries, timeouts, and error types - New to Sent? The [first integration tutorial](/sdks/typescript/first-integration) walks the same loop from scratch # Sending messages from Next.js with the Sent TypeScript SDK (/sdks/typescript/integrations/nextjs.md) # Sending messages from Next.js with the Sent TypeScript SDK [#sending-messages-from-nextjs-with-the-sent-typescript-sdk] This guide shows you how to wire Sent messaging into an existing Next.js app: install the TypeScript SDK, configure a server-side client, send a template message from a route handler, receive delivery webhooks, and verify the whole loop in sandbox mode. ## Prerequisites [#prerequisites] This guide assumes a working Next.js 14+ app using the App Router. You also need: - A Sent API key from the [API Keys page in your Sent Dashboard](https://app.sent.dm/dashboard/api-keys) - A public HTTPS URL for webhook delivery. For local work, open a tunnel as described in the [webhook local development guide](/start/webhooks/local-development) ### Install the SDK [#install-the-sdk] Add the SDK to your existing project: ```bash npm install @sentdm/sentdm ``` ### Configure a server-side client [#configure-a-server-side-client] Add the credentials to `.env.local`. Do not prefix them with `NEXT_PUBLIC_`; the API key must never reach the browser: ```bash # .env.local SENT_DM_API_KEY=your_api_key_here SENT_DM_WEBHOOK_SECRET=whsec_your_signing_secret ``` Create one shared client module for all server code (route handlers, Server Actions, Server Components): ```typescript // lib/sent/client.ts import SentDm from '@sentdm/sentdm'; const apiKey = process.env.SENT_DM_API_KEY; if (!apiKey && process.env.NODE_ENV === 'production') { throw new Error('SENT_DM_API_KEY is required in production'); } export const sentClient = new SentDm({ apiKey: apiKey || 'test-key', maxRetries: 2, timeout: 30 * 1000, }); ``` ### Send a template message from a route handler [#send-a-template-message-from-a-route-handler] Add a route handler that calls `messages.send`; the pass-through `sandbox` flag lets callers exercise the route without delivering anything: ```typescript // app/api/messages/route.ts import { NextRequest, NextResponse } from 'next/server'; import { sentClient } from '@/lib/sent/client'; export async function POST(request: NextRequest) { const { phoneNumber, templateName, parameters, channels, sandbox } = await request.json(); const response = await sentClient.messages.send({ to: [phoneNumber], // E.164 format, for example +14155551234 template: { name: templateName, parameters }, // reference by name or id, never both channel: channels, // omit to let Sent pick per recipient sandbox: sandbox ?? false, // true = validate and simulate only }); const recipient = response.data.recipients[0]; return NextResponse.json( { messageId: recipient.message_id, status: response.data.status }, { status: 202 }, ); } ``` Sent accepts sends asynchronously: the API responds with status `QUEUED` and one `message_id` per recipient-and-channel pair. Store the `message_id`, because delivery outcomes arrive on your webhook endpoint instead of in this response. Client Components must call this route (or a Server Action); they can never hold the SDK client. ### Receive delivery webhooks [#receive-delivery-webhooks] Add a webhook route handler that verifies the `webhook-signature` header against the raw body before trusting any event; `request.text()` gives you the exact bytes. The scheme is HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` (`X-Webhook-*` headers on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), keyed with the base64-decoded secret after stripping its `whsec_` prefix. Refer to [webhook signature verification](/start/webhooks/signature-verification) for the full scheme. Every event arrives in the same envelope (`field`, `event`, `timestamp`, `payload`), so one handler routes all of them: ```typescript // app/api/webhooks/sent/route.ts import { NextRequest, NextResponse } from 'next/server'; import { createHmac, timingSafeEqual } from 'crypto'; const WEBHOOK_SECRET = process.env.SENT_DM_WEBHOOK_SECRET; // The HMAC key is the signing secret after stripping the "whsec_" prefix // and base64-decoding the remainder; signature format is "v1,{base64(hmac)}". // Version 2 sends two space-separated signatures for 24 hours after a rotation; accept any match. function verifySignature(webhookId: string, timestamp: string, rawBody: string, signature: string, secret: string): boolean { const keyBytes = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const signedContent = `${webhookId}.${timestamp}.${rawBody}`; const expected = 'v1,' + createHmac('sha256', keyBytes).update(signedContent).digest('base64'); const expectedBuffer = Buffer.from(expected); return signature.trim().split(/\s+/).some((candidate) => { const candidateBuffer = Buffer.from(candidate); return candidateBuffer.length === expectedBuffer.length && timingSafeEqual(candidateBuffer, expectedBuffer); }); } export async function POST(request: NextRequest) { // Version 2 headers first, falling back to version 1 const webhookId = request.headers.get('webhook-id') ?? request.headers.get('x-webhook-id'); const timestamp = request.headers.get('webhook-timestamp') ?? request.headers.get('x-webhook-timestamp'); const signature = request.headers.get('webhook-signature') ?? request.headers.get('x-webhook-signature'); if (!webhookId || !timestamp || !signature) { return NextResponse.json({ error: 'Missing webhook headers' }, { status: 401 }); } if (!WEBHOOK_SECRET) { // Fail closed: never process an event you cannot verify return NextResponse.json({ error: 'Webhook not configured' }, { status: 500 }); } const rawBody = await request.text(); if (!verifySignature(webhookId, timestamp, rawBody, signature, WEBHOOK_SECRET)) { return NextResponse.json({ error: 'Invalid signature' }, { status: 401 }); } // Reject replayed events older than 5 minutes if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) { return NextResponse.json({ error: 'Timestamp too old' }, { status: 401 }); } const event = JSON.parse(rawBody); const payload = event.payload ?? {}; if (event.field === 'message') { switch (event.event) { case 'message.delivered': console.log(`Message ${payload.message_id} delivered`); break; case 'message.failed': console.error(`Message ${payload.message_id} failed (status ${payload.message_status})`); break; case 'message.received': console.log(`Inbound ${payload.channel} from ${payload.inbound_number}: ${payload.text}`); break; default: console.log(`Message ${payload.message_id} status: ${payload.message_status}`); } } return NextResponse.json({ received: true }); } ``` Keep this route on the default Node.js runtime, because it uses the `crypto` module. Then tell Sent where to deliver events. If you prefer a UI, use the [webhooks getting started guide](/start/webhooks/getting-started); otherwise register over the API: ```bash curl -X POST https://api.sent.dm/v3/webhooks \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "display_name": "Next.js integration", "endpoint_url": "https://your-domain.example/api/webhooks/sent", "event_types": ["message"] }' ``` Copy two values from the response: the webhook `id` (used to test delivery in the next step) and `signing_secret`. Put the secret in `SENT_DM_WEBHOOK_SECRET`. The `message` event type covers every message event; the [webhook event types reference](/start/webhooks/event-types) lists all payload fields. ### Verify the integration [#verify-the-integration] Start the app with your credentials loaded: ```bash npm run dev ``` Send a sandbox message through your new route. Full validation runs, but nothing is delivered and no credits are consumed: ```bash curl -X POST http://localhost:3000/api/messages \ -H "Content-Type: application/json" \ -d '{"phoneNumber": "+14155551234", "templateName": "welcome", "parameters": {"name": "Ada"}, "sandbox": true}' ``` The response should contain a `messageId` and `"status": "QUEUED"`. A 400 here means the request shape is wrong; sandbox requests return real validation errors. Now confirm webhook delivery end to end. Ask Sent to deliver a signed test event, replacing the ID with the webhook `id` you copied: ```bash curl -X POST https://api.sent.dm/v3/webhooks/YOUR_WEBHOOK_ID/test \ -H "x-api-key: $SENT_DM_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.delivered"}' ``` Your dev server log should show a `Message ... delivered` line, and the endpoint should have answered 200 `{"received": true}`. Test events travel the same signed delivery pipeline as real events, so a 401 in your log means the signing secret or verification code is wrong. Sent attempts a test event exactly once, so re-run the command after each fix. ## Adapt this to your app [#adapt-this-to-your-app] - If you send from a form, use a Server Action instead of the route handler. The appendix below shows the pattern; the SDK call is identical. - If you deploy on the Edge runtime, create the client inside the edge route with lower `timeout` and `maxRetries` values, and keep the webhook route on Node.js. - If webhook processing does slow work (database writes, downstream calls), return 200 first and hand off to a queue so retries do not pile up; see [handling webhook retries](/start/webhooks/handling-retries). - To send free-form text instead of a template, pass `text` instead of `template`. Each send carries exactly one of the two. ## Appendix: production scaffolding [#appendix-production-scaffolding] The numbered steps stay on the core messaging tasks. The blocks below are optional scaffolding for a production Next.js stack. Adapt them to your own conventions rather than adopting them wholesale. Call the SDK directly from a Server Action when the sender is a form in your own app: ```typescript // app/actions/messages.ts 'use server'; import { sentClient } from '@/lib/sent/client'; export async function sendMessage(formData: FormData) { const response = await sentClient.messages.send({ to: [formData.get('phoneNumber') as string], template: { name: formData.get('templateName') as string, parameters: JSON.parse((formData.get('parameters') as string) || '{}'), }, sandbox: formData.get('sandbox') === 'true', }); const recipient = response.data.recipients[0]; return { messageId: recipient.message_id, status: response.data.status }; } ``` Reject malformed requests before they reach the SDK: ```typescript // lib/sent/schemas.ts import { z } from 'zod'; export const sendMessageSchema = z.object({ phoneNumber: z.string().regex(/^\+[1-9]\d{1,14}$/, 'Phone number must be in E.164 format'), templateName: z.string().min(1), parameters: z.record(z.string()).optional(), channels: z.array(z.enum(['sms', 'whatsapp', 'rcs'])).optional(), sandbox: z.boolean().optional(), }); ``` In the route handler, replace the destructuring with `sendMessageSchema.safeParse(await request.json())` and return 400 with `validated.error.errors` when parsing fails. Convert SDK errors into consistent JSON responses: ```typescript // lib/sent/errors.ts import SentDm from '@sentdm/sentdm'; export function handleSentError(error: unknown) { if (error instanceof SentDm.APIError) { return { message: error.message, status: error.status ?? 500, code: error.constructor.name }; } return { message: 'An unexpected error occurred', status: 500, code: 'UnknownError' }; } ``` Wrap route handler bodies in `try/catch` and pass failures through this helper. The [SDK testing guide](/sdks/testing) covers mocking `messages.send` in route tests. ## Next steps [#next-steps] - Review the [webhook event types reference](/start/webhooks/event-types) for every payload field - Work through the [webhook production checklist](/start/webhooks/production-checklist) before going live - Explore the [TypeScript SDK reference](/sdks/typescript) for retries, timeouts, and error types - New to Sent? The [first integration tutorial](/sdks/typescript/first-integration) walks the same loop from scratch # Voice Agents SDK for .NET (/sdks/voice-agents/dotnet.md) # Voice Agents SDK for .NET [#voice-agents-sdk-for-net] [`SentDm.Voice.Agents`](https://www.nuget.org/packages/SentDm.Voice.Agents) lets a .NET process serve calls as a Sent voice agent: it connects to Sent with your account API key, receives each call as a session, and gives your code the ways to act on it. Speech, heartbeats, reconnects and resumes are the SDK's; your code sees calls. The agent record itself, its tools, transfer targets and fallback, is set up in [Voice agents](/start/guides/voice-agents); what the SDK exchanges with Sent is the [voice agent protocol](/reference/api/voice-agent-protocol), which the SDK implements at version 1.0.0 and passes the protocol's conformance scenarios for before every release. The protocol is stable at 1.0: within `sent.voice.v1` Sent only adds frames and fields, so an agent built today keeps working. The SDK is at 0.x, so its own API may still change between minor versions until its 1.0. ## Installation [#installation] ```sh dotnet add package SentDm.Voice.Agents ``` .NET 8 or later. The package depends on nothing outside the runtime: `System.Net.WebSockets` carries the connection and `System.Text.Json` the frames. ## Quick Start [#quick-start] ### Create the agent on Sent [#create-the-agent-on-sent] Create a voice agent with `POST /v3/voice/agents` and bind a number to it, as [Voice agents](/start/guides/voice-agents) describes, and leave `websocket_url` out: the SDK connects to Sent, and an agent created with a `websocket_url` is dialled by Sent instead, so it never reaches your process. Give it the tools it may use, `["hangup", "transfer"]` for the sample below, with the sample's number in `transfer_targets`. Note its `agent_id`. Choose a text session, where Sent runs speech-to-text and text-to-speech, or an audio session, where your agent handles raw audio. ### Serve calls [#serve-calls] ```csharp using SentDm.Voice.Agents; class Support : Agent { public Support(AgentOptions options) : base(options) { } public override Task OnSessionStartAsync(Session session) { session.Say("Hi, this is Acme support. How can I help?"); return Task.CompletedTask; } public override async Task OnUserSaidAsync(Session session, UserSaid said) { if (said.Text.Contains("person")) { session.Say("Transferring you now."); await session.TransferAsync("+14155550100"); } else { session.Say($"You said {said.Text}"); } } } await new Support(new AgentOptions { ApiKey = Environment.GetEnvironmentVariable("SENT_API_KEY")!, AgentId = "agent_...", }).ServeAsync(); ``` `ServeAsync()` connects to Sent and serves calls until SIGINT or SIGTERM; `RunAsync()` does the same without the signal handlers and `Stop()` ends it. Keep the API key on the server the agent runs on, never in a client. ## Handlers [#handlers] Override the ones you need. Each session's handlers run in order on their own chain, so sessions never wait for one another, and a slow handler delays its own session only. | Handler | When | |---------|------| | `OnSessionStartAsync(session)` | A call reached the agent. In a text session, `Say()` to speak; an audio session waits for audio | | `OnUserSaidAsync(session, said)` | Text sessions: the caller said something. `said.Correction` is true when it replaces the previous utterance; `Clear()` and answer again | | `OnAudioAsync(session, samples)` | Audio sessions: the caller's audio, 16-bit little-endian mono PCM at `session.SampleRate` | | `OnToolResultAsync(session, result)` | Sent answered a tool call. The awaiting task gets the same result | | `OnSessionEndAsync(session, end)` | The call left the agent; `end.Reason` says why | | `OnSessionLostAsync(session)` | The connection was lost and the session could not be resumed; Sent ends the call with `agent_unreachable` | | `OnErrorAsync(error)` | Sent refused a frame; the connection stays open | ## The session [#the-session] | Method | What it does | |--------|--------------| | `Say(text, last, interruptible)` | Text sessions: speak to the caller. Stream a reply in pieces with `last: false` and finish with `last: true` | | `Clear()` | Drop the speech or audio the agent sent that Sent has not played yet | | `SendAudio(samples)` | Audio sessions: play 16-bit mono PCM at the session's sample rate; 20 ms per call, at most 200 ms | | `TransferAsync(to)` | Move the call to a number, a user of your app, or another agent; completes with Sent's `ToolResult` | | `HangupAsync()` | End the call, after the speech queued before it | | `SendDtmfAsync(digits)` | Play digits on the call: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | | `HoldAsync(held = true)` | Put the caller on hold, or take them off it | `session.From`, `To`, `Direction`, `SessionType`, `Language`, `Context` (what your backend passed when it placed an outbound call) and `SampleRate` carry what the call started with. A tool refused or failed completes with `Ok` false and an `Error.Code` such as `tool_not_allowed` or `target_not_allowed`; the agent's tools and transfer targets settings decide what it may do. ## Resilience [#resilience] The SDK answers Sent's heartbeats, opens a new connection when Sent drains one, reconnects with backoff when a connection is lost, and resumes the sessions that can move so the callers stay on the line. It keeps the last 32 frames it sent per session and sends again the ones Sent did not read. A session that cannot be resumed reaches `OnSessionLostAsync`. Nothing in your handlers needs to know. ## Frames [#frames] `Frames.cs` holds every frame of the protocol as a record, with `Protocol.Decode()` and `Protocol.Encode()` that check the protocol's rules. It is generated from the protocol and regenerated on every protocol release. ## Other languages [#other-languages] The [Python](/sdks/voice-agents/python), [TypeScript](/sdks/voice-agents/typescript), [Go](/sdks/voice-agents/go), [Rust](/sdks/voice-agents/rust) and [Java](/sdks/voice-agents/java) SDKs are the same agent in those languages, each on the same protocol and the same conformance scenarios. Any language with a WebSocket client can build an agent on the [protocol](/reference/api/voice-agent-protocol) directly. # Voice Agents SDK for Go (/sdks/voice-agents/go.md) # Voice Agents SDK for Go [#voice-agents-sdk-for-go] [`github.com/sentdm/sent-dm-voice-agents-go`](https://pkg.go.dev/github.com/sentdm/sent-dm-voice-agents-go) lets a Go process serve calls as a Sent voice agent: it connects to Sent with your account API key, receives each call as a session, and gives your code the ways to act on it. Speech, heartbeats, reconnects and resumes are the SDK's; your code sees calls. The agent record itself, its tools, transfer targets and fallback, is set up in [Voice agents](/start/guides/voice-agents); what the SDK exchanges with Sent is the [voice agent protocol](/reference/api/voice-agent-protocol), which the SDK implements at version 1.0.0 and passes the protocol's conformance scenarios for before every release. The protocol is stable at 1.0: within `sent.voice.v1` Sent only adds frames and fields, so an agent built today keeps working. The SDK is at 0.x, so its own API may still change between minor versions until its 1.0. ## Installation [#installation] ```sh go get github.com/sentdm/sent-dm-voice-agents-go ``` Go 1.23 or later. The one dependency is `github.com/coder/websocket`, which depends on nothing. ## Quick Start [#quick-start] ### Create the agent on Sent [#create-the-agent-on-sent] Create a voice agent with `POST /v3/voice/agents` and bind a number to it, as [Voice agents](/start/guides/voice-agents) describes, and leave `websocket_url` out: the SDK connects to Sent, and an agent created with a `websocket_url` is dialled by Sent instead, so it never reaches your process. Give it the tools it may use, `["hangup", "transfer"]` for the sample below, with the sample's number in `transfer_targets`. Note its `agent_id`. Choose a text session, where Sent runs speech-to-text and text-to-speech, or an audio session, where your agent handles raw audio. ### Serve calls [#serve-calls] ```go package main import ( "context" "os" "strings" voiceagents "github.com/sentdm/sent-dm-voice-agents-go" ) type support struct{ voiceagents.BaseHandler } func (support) OnSessionStart(ctx context.Context, session *voiceagents.Session) { session.Say("Hi, this is Acme support. How can I help?") } func (support) OnUserSaid(ctx context.Context, session *voiceagents.Session, said *voiceagents.UserSaid) { if strings.Contains(said.Text, "person") { session.Say("Transferring you now.") session.TransferNumber(ctx, "+14155550100") } else { session.Say("You said " + said.Text) } } func main() { agent := voiceagents.New(voiceagents.Options{ APIKey: os.Getenv("SENT_API_KEY"), AgentID: "agent_...", Handler: support{}, }) if err := agent.Serve(); err != nil { panic(err) } } ``` `Serve()` connects to Sent and serves calls until SIGINT or SIGTERM; `Run(ctx)` does the same until `ctx` ends or `Stop()` is called. Keep the API key on the server the agent runs on, never in a client. ## Handlers [#handlers] Embed `voiceagents.BaseHandler` and override the methods you need. Each session's handlers run in order on their own goroutine, so sessions never wait for one another, and a slow handler delays its own session only. | Handler | When | |---------|------| | `OnSessionStart(ctx, session)` | A call reached the agent. In a text session, `Say` to speak; an audio session waits for audio | | `OnUserSaid(ctx, session, said)` | Text sessions: the caller said something. `said.Correction` is true when it replaces the previous utterance; `Clear()` and answer again | | `OnAudio(ctx, session, samples)` | Audio sessions: the caller's audio, 16-bit little-endian mono PCM at `session.SampleRate` | | `OnToolResult(ctx, session, result)` | Sent answered a tool call. The waiting `Tool` call gets the same result | | `OnSessionEnd(ctx, session, end)` | The call left the agent; `end.Reason` says why | | `OnSessionLost(ctx, session)` | The connection was lost and the session could not be resumed; Sent ends the call with `agent_unreachable` | | `OnError(ctx, err)` | Sent refused a frame; the connection stays open | ## The session [#the-session] | Method | What it does | |--------|--------------| | `Say(text, opts...)` | Text sessions: speak to the caller. Stream a reply in pieces with `Last(false)` and finish with `Last(true)` | | `Clear()` | Drop the speech or audio the agent sent that Sent has not played yet | | `SendAudio(samples)` | Audio sessions: play 16-bit mono PCM at the session's sample rate; 20 ms per call, at most 200 ms | | `Transfer(ctx, party)`, `TransferNumber(ctx, number)` | Move the call to a number, a user of your app, or another agent; returns Sent's `ToolResult` | | `Hangup(ctx)` | End the call, after the speech queued before it | | `SendDTMF(ctx, digits)` | Play digits on the call: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | | `Hold(ctx, held)` | Put the caller on hold, or take them off it | `session.From`, `To`, `Direction`, `SessionType`, `Language`, `Context` (what your backend passed when it placed an outbound call) and `SampleRate` carry what the call started with. A tool refused or failed returns a result with `Ok` false and an `Error.Code` such as `tool_not_allowed` or `target_not_allowed`; the agent's tools and transfer targets settings decide what it may do. Every method returns `ErrSessionEnded` once the call has left the agent. ## Resilience [#resilience] The SDK answers Sent's heartbeats, opens a new connection when Sent drains one, reconnects with backoff when a connection is lost, and resumes the sessions that can move so the callers stay on the line. It keeps the last 32 frames it sent per session and sends again the ones Sent did not read. A session that cannot be resumed reaches `OnSessionLost`. Nothing in your handlers needs to know. ## Frames [#frames] `frames.go` holds every frame of the protocol as a type, with `Decode` and `Encode` that check the protocol's rules. It is generated from the protocol and regenerated on every protocol release. ## Other languages [#other-languages] The [Python](/sdks/voice-agents/python), [TypeScript](/sdks/voice-agents/typescript), [.NET](/sdks/voice-agents/dotnet), [Rust](/sdks/voice-agents/rust) and [Java](/sdks/voice-agents/java) SDKs are the same agent in those languages, each on the same protocol and the same conformance scenarios. Any language with a WebSocket client can build an agent on the [protocol](/reference/api/voice-agent-protocol) directly. # Voice Agents SDK for Java (/sdks/voice-agents/java.md) # Voice Agents SDK for Java [#voice-agents-sdk-for-java] [`dm.sent:voice-agents`](https://central.sonatype.com/artifact/dm.sent/voice-agents) lets a Java process serve calls as a Sent voice agent: it connects to Sent with your account API key, receives each call as a session, and gives your code the ways to act on it. Speech, heartbeats, reconnects and resumes are the SDK's; your code sees calls. The agent record itself, its tools, transfer targets and fallback, is set up in [Voice agents](/start/guides/voice-agents); what the SDK exchanges with Sent is the [voice agent protocol](/reference/api/voice-agent-protocol), which the SDK implements at version 1.0.0 and passes the protocol's conformance scenarios for before every release. The protocol is stable at 1.0: within `sent.voice.v1` Sent only adds frames and fields, so an agent built today keeps working. The SDK is at 0.x, so its own API may still change between minor versions until its 1.0. ## Installation [#installation] ```kotlin // Gradle implementation("dm.sent:voice-agents:0.2.0") ``` ```xml dm.sent voice-agents 0.2.0 ``` Java 17 or later. The connection is the JDK's `java.net.http.WebSocket`; the one dependency is `jackson-databind`, for the frames. ## Quick Start [#quick-start] ### Create the agent on Sent [#create-the-agent-on-sent] Create a voice agent with `POST /v3/voice/agents` and bind a number to it, as [Voice agents](/start/guides/voice-agents) describes, and leave `websocket_url` out: the SDK connects to Sent, and an agent created with a `websocket_url` is dialled by Sent instead, so it never reaches your process. Give it the tools it may use, `["hangup", "transfer"]` for the sample below, with the sample's number in `transfer_targets`. Note its `agent_id`. Choose a text session, where Sent runs speech-to-text and text-to-speech, or an audio session, where your agent handles raw audio. ### Serve calls [#serve-calls] ```java import dm.sent.voice.agents.Agent; import dm.sent.voice.agents.Handler; import dm.sent.voice.agents.Options; import dm.sent.voice.agents.Session; import dm.sent.voice.agents.frames.UserSaid; public class Support implements Handler { @Override public void onSessionStart(Session session) { session.say("Hi, this is Acme support. How can I help?"); } @Override public void onUserSaid(Session session, UserSaid said) { if (said.text().contains("person")) { session.say("Transferring you now."); session.transfer("+14155550100").join(); } else { session.say("You said " + said.text()); } } public static void main(String[] args) { Options options = new Options(System.getenv("SENT_API_KEY"), "agent_..."); new Agent(options, new Support()).serve(); } } ``` `serve()` connects to Sent and serves calls until SIGINT or SIGTERM; `run()` does the same and returns a future that completes on `stop()`. Keep the API key on the server the agent runs on, never in a client. ## Handlers [#handlers] Implement `Handler` and write the methods you need; each one has a default that does nothing. Each session's handlers run in order on their own chain, so sessions never wait for one another, and a slow handler delays its own session only. A handler may block on a tool's future with `join()` without holding the other sessions up. | Handler | When | |---------|------| | `onSessionStart(session)` | A call reached the agent. In a text session, `say` to speak; an audio session waits for audio | | `onUserSaid(session, said)` | Text sessions: the caller said something. `said.correction()` is true when it replaces the previous utterance; `clear()` and answer again | | `onAudio(session, samples)` | Audio sessions: the caller's audio, 16-bit little-endian mono PCM at `session.sampleRate()` | | `onToolResult(session, result)` | Sent answered a tool call. The waiting future gets the same result | | `onSessionEnd(session, end)` | The call left the agent; `end.reason()` says why | | `onSessionLost(session)` | The connection was lost and the session could not be resumed; Sent ends the call with `agent_unreachable` | | `onError(error)` | Sent refused a frame; the connection stays open | ## The session [#the-session] | Method | What it does | |--------|--------------| | `say(text)`, `say(text, last, interruptible)` | Text sessions: speak to the caller. Stream a reply in pieces with `last` false and finish with `last` true | | `clear()` | Drop the speech or audio the agent sent that Sent has not played yet | | `sendAudio(samples)` | Audio sessions: play 16-bit mono PCM at the session's sample rate; 20 ms per call, at most 200 ms | | `transfer(party)`, `transfer(number)` | Move the call to a number, a user of your app, or another agent; a `CompletableFuture` of Sent's `ToolResult` | | `hangup()` | End the call, after the speech queued before it | | `sendDtmf(digits)` | Play digits on the call: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | | `hold(held)` | Put the caller on hold, or take them off it | `session.from()`, `to()`, `direction()`, `sessionType()`, `language()`, `context()` (what your backend passed when it placed an outbound call) and `sampleRate()` carry what the call started with. A tool refused or failed completes with a result whose `ok()` is false and an `error().code()` such as `tool_not_allowed` or `target_not_allowed`; the agent's tools and transfer targets settings decide what it may do. Every method throws `SessionEndedException`, or fails its future with it, once the call has left the agent. ## Resilience [#resilience] The SDK answers Sent's heartbeats, opens a new connection when Sent drains one, reconnects with backoff when a connection is lost, and resumes the sessions that can move so the callers stay on the line. It keeps the last frames it sent per session and sends again the ones Sent did not read. A session that cannot be resumed reaches `onSessionLost`. Nothing in your handlers needs to know. ## Frames [#frames] The `dm.sent.voice.agents.frames` package holds every frame of the protocol as a record, with `Protocol.decode()` and `Protocol.encode()` that check the protocol's rules. It is generated from the protocol and regenerated on every protocol release. ## Other languages [#other-languages] The [Python](/sdks/voice-agents/python), [TypeScript](/sdks/voice-agents/typescript), [.NET](/sdks/voice-agents/dotnet), [Go](/sdks/voice-agents/go) and [Rust](/sdks/voice-agents/rust) SDKs are the same agent in those languages, each on the same protocol and the same conformance scenarios. Any language with a WebSocket client can build an agent on the [protocol](/reference/api/voice-agent-protocol) directly. # Voice Agents SDK for Python (/sdks/voice-agents/python.md) # Voice Agents SDK for Python [#voice-agents-sdk-for-python] [`sentdm-voice-agents`](https://pypi.org/project/sentdm-voice-agents/) lets a Python process serve calls as a Sent voice agent: it connects to Sent with your account API key, receives each call as a session, and gives your code the ways to act on it. Speech, heartbeats, reconnects and resumes are the SDK's; your code sees calls. The agent record itself, its tools, transfer targets and fallback, is set up in [Voice agents](/start/guides/voice-agents); what the SDK exchanges with Sent is the [voice agent protocol](/reference/api/voice-agent-protocol), which the SDK implements at version 1.0.0 and passes the protocol's conformance scenarios for before every release. The protocol is stable at 1.0: within `sent.voice.v1` Sent only adds frames and fields, so an agent built today keeps working. The SDK is at 0.x, so its own API may still change between minor versions until its 1.0. ## Installation [#installation] ```sh pip install sentdm-voice-agents ``` Python 3.11 or later. The one dependency is `websockets`. ## Quick Start [#quick-start] ### Create the agent on Sent [#create-the-agent-on-sent] Create a voice agent with `POST /v3/voice/agents` and bind a number to it, as [Voice agents](/start/guides/voice-agents) describes, and leave `websocket_url` out: the SDK connects to Sent, and an agent created with a `websocket_url` is dialled by Sent instead, so it never reaches your process. Give it the tools it may use, `["hangup", "transfer"]` for the sample below, with the sample's number in `transfer_targets`. Note its `agent_id`. Choose a text session, where Sent runs speech-to-text and text-to-speech, or an audio session, where your agent handles raw audio. ### Serve calls [#serve-calls] ```python import os from sentdm_voice_agents import Agent, Session class Support(Agent): async def on_session_start(self, session: Session) -> None: await session.say("Hi, this is Acme support. How can I help?") async def on_user_said(self, session: Session, said) -> None: if "person" in said.text: await session.say("Transferring you now.") await session.transfer("+14155550100") else: await session.say(f"You said {said.text}") Support(api_key=os.environ["SENT_API_KEY"], agent_id="agent_...").serve() ``` `serve()` connects to Sent and serves calls until SIGINT or SIGTERM; `await agent.run()` does the same inside your own event loop. Keep the API key on the server the agent runs on, never in a client. ## Handlers [#handlers] Override the ones you need. Each session's handlers run in order on their own task, so sessions never wait for one another, and a slow handler delays its own session only. | Handler | When | |---------|------| | `on_session_start(session)` | A call reached the agent. In a text session, `say()` to speak; an audio session waits for audio | | `on_user_said(session, said)` | Text sessions: the caller said something. `said.correction` is true when it replaces the previous utterance; send `clear()` and answer again | | `on_audio(session, samples)` | Audio sessions: the caller's audio, 16-bit little-endian mono PCM at `session.sample_rate` | | `on_tool_result(session, result)` | Sent answered a tool call. The awaiting call gets the same result | | `on_session_end(session, end)` | The call left the agent; `end.reason` says why | | `on_session_lost(session)` | The connection was lost and the session could not be resumed; Sent ends the call with `agent_unreachable` | | `on_error(error)` | Sent refused a frame; the connection stays open | ## The session [#the-session] | Method | What it does | |--------|--------------| | `say(text, last=True, interruptible=True)` | Text sessions: speak to the caller. Stream a reply in pieces with `last=False` and finish with `last=True` | | `clear()` | Drop the speech or audio the agent sent that Sent has not played yet | | `send_audio(samples)` | Audio sessions: play 16-bit mono PCM at the session's sample rate; 20 ms per call, at most 200 ms | | `transfer(to)` | Move the call to a number, a user of your app, or another agent; returns Sent's `ToolResult` | | `hangup()` | End the call, after the speech queued before it | | `send_dtmf(digits)` | Play digits on the call: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | | `hold(held=True)` | Put the caller on hold, or take them off it | `session.from_`, `to`, `direction`, `session_type`, `language`, `context` (what your backend passed when it placed an outbound call) and `sample_rate` carry what the call started with. A tool refused or failed answers `ok=False` with an `error.code` such as `tool_not_allowed` or `target_not_allowed`; the agent's tools and transfer targets settings decide what it may do. ## Resilience [#resilience] The SDK answers Sent's heartbeats, opens a new connection when Sent drains one, reconnects with backoff when a connection is lost, and resumes the sessions that can move so the callers stay on the line. It keeps the last 32 frames it sent per session and sends again the ones Sent did not read. A session that cannot be resumed reaches `on_session_lost`. Nothing in your handlers needs to know. ## Frames [#frames] `sentdm_voice_agents.frames` holds every frame of the protocol as a type, with `decode()` and `encode()` that check the protocol's rules. It is generated from the protocol and regenerated on every protocol release. ## Other languages [#other-languages] The [TypeScript](/sdks/voice-agents/typescript), [.NET](/sdks/voice-agents/dotnet), [Go](/sdks/voice-agents/go), [Rust](/sdks/voice-agents/rust) and [Java](/sdks/voice-agents/java) SDKs are the same agent in those languages, each on the same protocol and the same conformance scenarios. Any language with a WebSocket client can build an agent on the [protocol](/reference/api/voice-agent-protocol) directly; the protocol repository's sample agents show how. # Voice Agents SDK for Rust (/sdks/voice-agents/rust.md) # Voice Agents SDK for Rust [#voice-agents-sdk-for-rust] [`sentdm-voice-agents`](https://crates.io/crates/sentdm-voice-agents) lets a Rust process serve calls as a Sent voice agent: it connects to Sent with your account API key, receives each call as a session, and gives your code the ways to act on it. Speech, heartbeats, reconnects and resumes are the SDK's; your code sees calls. The agent record itself, its tools, transfer targets and fallback, is set up in [Voice agents](/start/guides/voice-agents); what the SDK exchanges with Sent is the [voice agent protocol](/reference/api/voice-agent-protocol), which the SDK implements at version 1.0.0 and passes the protocol's conformance scenarios for before every release. The protocol is stable at 1.0: within `sent.voice.v1` Sent only adds frames and fields, so an agent built today keeps working. The SDK is at 0.x, so its own API may still change between minor versions until its 1.0. ## Installation [#installation] ```sh cargo add sentdm-voice-agents tokio --features tokio/full ``` Rust 1.85 or later. The runtime is Tokio, the connection is `tokio-tungstenite` with rustls, and the frames are `serde_json`. ## Quick Start [#quick-start] ### Create the agent on Sent [#create-the-agent-on-sent] Create a voice agent with `POST /v3/voice/agents` and bind a number to it, as [Voice agents](/start/guides/voice-agents) describes, and leave `websocket_url` out: the SDK connects to Sent, and an agent created with a `websocket_url` is dialled by Sent instead, so it never reaches your process. Give it the tools it may use, `["hangup", "transfer"]` for the sample below, with the sample's number in `transfer_targets`. Note its `agent_id`. Choose a text session, where Sent runs speech-to-text and text-to-speech, or an audio session, where your agent handles raw audio. ### Serve calls [#serve-calls] ```rust use sentdm_voice_agents::{Agent, Handler, Options, Session, UserSaid}; use std::sync::Arc; struct Support; impl Handler for Support { async fn on_session_start(&self, session: Arc) { session.say("Hi, this is Acme support. How can I help?").ok(); } async fn on_user_said(&self, session: Arc, said: UserSaid) { if said.text.contains("person") { session.say("Transferring you now.").ok(); session.transfer_number("+14155550100").await.ok(); } else { session.say(&format!("You said {}", said.text)).ok(); } } } #[tokio::main] async fn main() { let options = Options::new(std::env::var("SENT_API_KEY").unwrap(), "agent_..."); Agent::new(options, Support).serve().await.unwrap(); } ``` `serve()` connects to Sent and serves calls until SIGINT or SIGTERM; `run()` does the same without the signal handlers, and `stop()` ends it. Keep the API key on the server the agent runs on, never in a client. ## Handlers [#handlers] Implement `Handler` for your type and write the methods you need; each one has a default that does nothing. Each session's handlers run in order on their own task, so sessions never wait for one another, and a slow handler delays its own session only. | Handler | When | |---------|------| | `on_session_start(session)` | A call reached the agent. In a text session, `say` to speak; an audio session waits for audio | | `on_user_said(session, said)` | Text sessions: the caller said something. `said.correction` is true when it replaces the previous utterance; `clear()` and answer again | | `on_audio(session, samples)` | Audio sessions: the caller's audio, 16-bit little-endian mono PCM at `session.sample_rate` | | `on_tool_result(session, result)` | Sent answered a tool call. The waiting tool call gets the same result | | `on_session_end(session, end)` | The call left the agent; `end.reason` says why | | `on_session_lost(session)` | The connection was lost and the session could not be resumed; Sent ends the call with `agent_unreachable` | | `on_error(error)` | Sent refused a frame; the connection stays open | ## The session [#the-session] | Method | What it does | |--------|--------------| | `say(text)`, `say_with(text, last, interruptible)` | Text sessions: speak to the caller. Stream a reply in pieces with `last` false and finish with `last` true | | `clear()` | Drop the speech or audio the agent sent that Sent has not played yet | | `send_audio(samples)` | Audio sessions: play 16-bit mono PCM at the session's sample rate; 20 ms per call, at most 200 ms | | `transfer(party)`, `transfer_number(number)` | Move the call to a number, a user of your app, or another agent; resolves with Sent's `ToolResult` | | `hangup()` | End the call, after the speech queued before it | | `send_dtmf(digits)` | Play digits on the call: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | | `hold(held)` | Put the caller on hold, or take them off it | `session.from`, `to`, `direction`, `session_type`, `language`, `context` (what your backend passed when it placed an outbound call) and `sample_rate` carry what the call started with. A tool refused or failed resolves with a result whose `ok` is false and an `error.code` such as `tool_not_allowed` or `target_not_allowed`; the agent's tools and transfer targets settings decide what it may do. Every method returns `Error::SessionEnded` once the call has left the agent. ## Resilience [#resilience] The SDK answers Sent's heartbeats, opens a new connection when Sent drains one, reconnects with backoff when a connection is lost, and resumes the sessions that can move so the callers stay on the line. It keeps the last frames it sent per session and sends again the ones Sent did not read. A session that cannot be resumed reaches `on_session_lost`. Nothing in your handlers needs to know. ## Frames [#frames] `sentdm_voice_agents::frames` holds every frame of the protocol as a type, with `decode` and `encode` that check the protocol's rules. It is generated from the protocol and regenerated on every protocol release. ## Other languages [#other-languages] The [Python](/sdks/voice-agents/python), [TypeScript](/sdks/voice-agents/typescript), [.NET](/sdks/voice-agents/dotnet), [Go](/sdks/voice-agents/go) and [Java](/sdks/voice-agents/java) SDKs are the same agent in those languages, each on the same protocol and the same conformance scenarios. Any language with a WebSocket client can build an agent on the [protocol](/reference/api/voice-agent-protocol) directly. # Voice Agents SDK for TypeScript (/sdks/voice-agents/typescript.md) # Voice Agents SDK for TypeScript [#voice-agents-sdk-for-typescript] [`@sentdm/voice-agents`](https://www.npmjs.com/package/@sentdm/voice-agents) lets a Node process serve calls as a Sent voice agent: it connects to Sent with your account API key, receives each call as a session, and gives your code the ways to act on it. Speech, heartbeats, reconnects and resumes are the SDK's; your code sees calls. The agent record itself, its tools, transfer targets and fallback, is set up in [Voice agents](/start/guides/voice-agents); what the SDK exchanges with Sent is the [voice agent protocol](/reference/api/voice-agent-protocol), which the SDK implements at version 1.0.0 and passes the protocol's conformance scenarios for before every release. The protocol is stable at 1.0: within `sent.voice.v1` Sent only adds frames and fields, so an agent built today keeps working. The SDK is at 0.x, so its own API may still change between minor versions until its 1.0. ## Installation [#installation] ```sh npm install @sentdm/voice-agents ``` Node 20.19 or later. The one dependency is `ws`. The package is ES modules; `require()` works on the Node versions it supports. ## Quick Start [#quick-start] ### Create the agent on Sent [#create-the-agent-on-sent] Create a voice agent with `POST /v3/voice/agents` and bind a number to it, as [Voice agents](/start/guides/voice-agents) describes, and leave `websocket_url` out: the SDK connects to Sent, and an agent created with a `websocket_url` is dialled by Sent instead, so it never reaches your process. Give it the tools it may use, `["hangup", "transfer"]` for the sample below, with the sample's number in `transfer_targets`. Note its `agent_id`. Choose a text session, where Sent runs speech-to-text and text-to-speech, or an audio session, where your agent handles raw audio. ### Serve calls [#serve-calls] ```ts import { Agent, Session, UserSaid } from '@sentdm/voice-agents'; class Support extends Agent { override async onSessionStart(session: Session) { session.say('Hi, this is Acme support. How can I help?'); } override async onUserSaid(session: Session, said: UserSaid) { if (said.text.includes('person')) { session.say('Transferring you now.'); await session.transfer('+14155550100'); } else { session.say(`You said ${said.text}`); } } } await new Support({ apiKey: process.env.SENT_API_KEY!, agentId: 'agent_...' }).serve(); ``` `serve()` connects to Sent and serves calls until SIGINT or SIGTERM; `run()` does the same without the signal handlers and `stop()` ends it. Keep the API key on the server the agent runs on, never in a client. ## Handlers [#handlers] Override the ones you need. Each session's handlers run in order on their own chain, so sessions never wait for one another, and a slow handler delays its own session only. | Handler | When | |---------|------| | `onSessionStart(session)` | A call reached the agent. In a text session, `say()` to speak; an audio session waits for audio | | `onUserSaid(session, said)` | Text sessions: the caller said something. `said.correction` is true when it replaces the previous utterance; `clear()` and answer again | | `onAudio(session, samples)` | Audio sessions: the caller's audio, a `Buffer` of 16-bit little-endian mono PCM at `session.sampleRate` | | `onToolResult(session, result)` | Sent answered a tool call. The awaiting promise gets the same result | | `onSessionEnd(session, end)` | The call left the agent; `end.reason` says why | | `onSessionLost(session)` | The connection was lost and the session could not be resumed; Sent ends the call with `agent_unreachable` | | `onError(error)` | Sent refused a frame; the connection stays open | ## The session [#the-session] | Method | What it does | |--------|--------------| | `say(text, { last, interruptible })` | Text sessions: speak to the caller. Stream a reply in pieces with `last: false` and finish with `last: true` | | `clear()` | Drop the speech or audio the agent sent that Sent has not played yet | | `sendAudio(samples)` | Audio sessions: play 16-bit mono PCM at the session's sample rate; 20 ms per call, at most 200 ms | | `transfer(to)` | Move the call to a number, a user of your app, or another agent; resolves with Sent's `ToolResult` | | `hangup()` | End the call, after the speech queued before it | | `sendDtmf(digits)` | Play digits on the call: `0` to `9`, `*`, `#`, `A` to `D`, and `w` to wait half a second | | `hold(held = true)` | Put the caller on hold, or take them off it | `session.from`, `to`, `direction`, `sessionType`, `language`, `context` (what your backend passed when it placed an outbound call) and `sampleRate` carry what the call started with. A tool refused or failed resolves with `ok: false` and an `error.code` such as `tool_not_allowed` or `target_not_allowed`; the agent's tools and transfer targets settings decide what it may do. ## Resilience [#resilience] The SDK answers Sent's heartbeats, opens a new connection when Sent drains one, reconnects with backoff when a connection is lost, and resumes the sessions that can move so the callers stay on the line. It keeps the last 32 frames it sent per session and sends again the ones Sent did not read. A session that cannot be resumed reaches `onSessionLost`. Nothing in your handlers needs to know. ## Frames [#frames] `@sentdm/voice-agents/frames` holds every frame of the protocol as a type, with `decode()` and `encode()` that check the protocol's rules. It is generated from the protocol and regenerated on every protocol release. ## Other languages [#other-languages] The [Python](/sdks/voice-agents/python), [.NET](/sdks/voice-agents/dotnet), [Go](/sdks/voice-agents/go), [Rust](/sdks/voice-agents/rust) and [Java](/sdks/voice-agents/java) SDKs are the same agent in those languages, each on the same protocol and the same conformance scenarios. Any language with a WebSocket client can build an agent on the [protocol](/reference/api/voice-agent-protocol) directly. # Voice SDK for Android (/sdks/voice/android.md) # Voice SDK for Android [#voice-sdk-for-android] [`dm.sent:voice-client`](https://central.sonatype.com/artifact/dm.sent/voice-client) lets an Android app place Sent Voice calls: to a phone number, to another user of your app, or into a conference. Your backend mints a short-lived voice token for each user with the Sent API. The SDK registers the device with it, places calls, and reports how they go. What rings when a user calls is decided by your callback, as for every call; see [Answering Calls](/start/guides/answering-calls). This SDK places calls. Receiving calls on a phone is not part of it; the [browser SDK](/sdks/voice) receives calls. ## Installation [#installation] From Maven Central, for Android 8.0 (API 26) or later: ```kotlin dependencies { implementation("dm.sent:voice-client:0.1.0") } ``` `dm.sent:voice-client-core` comes with it. Calls use the microphone: the library declares `RECORD_AUDIO`, and your app asks the user for it at runtime before the first call. ## Quick Start [#quick-start] ### Mint voice tokens on your backend [#mint-voice-tokens-on-your-backend] Mint tokens on your server with your Sent API key, never in the app, for the user who is signed in: ```ts // On your server, behind a route such as GET /api/voice-token const response = await fetch('https://api.sent.dm/v3/voice/tokens', { method: 'POST', headers: { 'x-api-key': process.env.SENT_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ identity: user.id }), }); const { data } = await response.json(); return data.token; ``` `identity` names the user in calls: letters, digits, `-` and `_`, up to 200 characters. The user is bound to your default voice number unless you pass `number`, one of the numbers you turned voice on for with `POST /v3/channels/voice`, and the token lasts `ttl` seconds (600 by default, at most 3600). Return the token as text from an endpoint of your own, such as `/api/voice-token`. The token is opaque: read the identity, number, and expiry from the minting response, not from the token. The token endpoint and the binding rules are covered in [Calls From Your App](/start/guides/in-app-calls). ### Register and call [#register-and-call] ```kotlin import dm.sent.voice.SentVoice import dm.sent.voice.core.CallEvent import dm.sent.voice.core.SentVoiceOptions val client = SentVoice.client(applicationContext, SentVoiceOptions(tokenProvider = { myBackend.voiceToken() })) // From a coroutine: register and connect suspend client.register() val call = client.connect("+14155551234") val listener = call.on { event -> when (event) { is CallEvent.Connected -> Log.i("voice", "Connected") is CallEvent.Disconnected -> Log.i("voice", "The call ended as ${event.state}") else -> Unit } } ``` Keep one client for the life of the app. `register()` fetches a token through `tokenProvider`, registers with it, and refreshes it before it expires. Events arrive on the thread that reported them, so hop to the main thread before touching views. A listener stays until you call `cancel()` on the token `on` returns. ## Client Options [#client-options] `SentVoiceOptions` takes the following options. Only `tokenProvider` is required. | Option | Description | |--------|-------------| | `tokenProvider` | A suspend function that returns a voice token from your backend, which mints it with `POST /v3/voice/tokens`. Called by `register()` and again before each token expires | | `registerRetries` | How many more times registering or refreshing the token is retried after a temporary failure, such as a network error. Default `3` | | `baseUrl` | The Sent API origin the token exchange and telemetry use. Default `https://api.sent.dm` | | `telemetryDisabled` | Turns off the call quality and error reports the SDK sends to Sent. Default `false` | | `log` | A function that receives the SDK's log lines with their level. Voice tokens never appear in them | ## Client [#client] The client holds one registration and the call that runs on it. | Property | Description | |----------|-------------| | `state` | `UNREGISTERED`, `REGISTERING`, `REGISTERED`, `OFFLINE` or `DESTROYED`. After `destroy()` the state is `DESTROYED` and every method throws | | `identity` | The identity the current token was minted for. `null` until registered | | `number` | The number the identity is bound to. `null` until registered | | `activeCall` | The call in progress, or `null` | | Method | Description | |--------|-------------| | `register()` | Fetches a token from `tokenProvider`, registers with it, and keeps it refreshed. Returns once the client is `REGISTERED` | | `unregister()` | Drops the registration and leaves a call in progress alone | | `destroy()` | Ends the call and tears the client down for good | | `connect(to)` | Calls a phone number in E.164 format or another user of your app by identity. See [Calls](#calls) | | `joinConference(name)` | Joins one of your account's rooms by name | | `on(listener)` | Adds a listener for the events below and returns a token; `cancel()` on it removes the listener | `register()`, `unregister()`, `destroy()`, `connect()` and `joinConference()` are suspend functions. | Event | Fires | |-------|-------| | `ClientEvent.Registering` | `register()` started | | `ClientEvent.Registered` | The client is registered and ready for calls | | `ClientEvent.Unregistered` | `unregister()` finished | | `ClientEvent.ActiveCallChanged` | A call was placed, or the call in progress ended | | `ClientEvent.TokenWillExpire` | The token is about to expire and the next refresh is due | | `ClientEvent.Offline` | The refresh retries ran out. The client tries again about every 30 seconds; `register()` tries at once | | `ClientEvent.Error` | Something failed outside a method call, such as a refresh | ## Calls [#calls] `connect(to)` and `joinConference(name)` return a `Call` once the provider accepted it; the call then moves through `RINGING`, `ANSWERED` and `CONNECTED` to `COMPLETED`, `FAILED`, `BUSY` or `NO_ANSWER`. One call at a time: a second `connect` while one is in progress throws `CALL_IN_PROGRESS`. | Property | Description | |----------|-------------| | `id`, `direction`, `from`, `to`, `startedAtMs` | What the call is | | `state` | The call's state, as above | | `isMuted` | Whether the microphone is muted | | `connectedTimeMs`, `endedTimeMs` | When the parties were joined, and when the call ended | | `error` | The exception that ended the call, when one did | | Method | Description | |--------|-------------| | `hangup()` | Ends the call. A suspend function | | `mute(muted)` | Mutes or unmutes the microphone | | `sendDigits(digits)` | Sends DTMF digits, for example to a phone menu | | `on(listener)` | Adds a listener for the events below and returns a token | | Event | Fires | |-------|-------| | `CallEvent.Ringing`, `Answered`, `Connected` | The call progressed | | `CallEvent.Reconnecting`, `Reconnected` | The media path dropped and came back | | `CallEvent.Disconnected` | The call ended in `state`, with the `error` that ended it when there is one | | `CallEvent.MuteChanged` | `mute()` took effect | | `CallEvent.Quality` | The media quality degraded | | `CallEvent.Error` | Something failed on the call | ## Errors [#errors] Every failure is a `SentVoiceException` with a `code`, a `category`, whether it is `retriable`, and a `message` you can show. The codes are the same on every platform: | Code | Meaning | |------|---------| | `TOKEN_INVALID` | The value from `tokenProvider` is not a voice token, or Sent refused it | | `TOKEN_EXPIRED` | The token expired and could not be refreshed | | `NOT_REGISTERED` | A call was placed while the client was not `REGISTERED` | | `MEDIA_PERMISSION_DENIED` | The user refused the microphone | | `INVALID_ADDRESS` | `to` is neither an E.164 number nor an identity, or a room name is malformed | | `CALL_IN_PROGRESS` | A call was placed while one was in progress | | `CALL_REJECTED` | The other party, or your callback, declined the call | | `CALL_FAILED` | The call could not be placed or dropped. Calls to a phone number need a number on the token; the message says so when there is none | | `NETWORK` | Sent or the provider could not be reached. Retriable | | `CAPABILITY_UNSUPPORTED` | The device or the SDK version cannot do what was asked | | `UNKNOWN` | Anything else; `message` says what | ## Telemetry [#telemetry] The SDK reports call quality and errors to Sent so support can see what a user saw, batched and sent in the background. Set `telemetryDisabled` to turn it off. Nothing in the reports identifies the person beyond the identity your backend minted the token for. # Voice SDK (/sdks/voice.md) # Voice SDK [#voice-sdk] [`@sentdm/voice-client`](https://www.npmjs.com/package/@sentdm/voice-client) lets a web app place and receive Sent Voice calls in the browser. React bindings ship separately as [`@sentdm/voice-client-react`](https://www.npmjs.com/package/@sentdm/voice-client-react). Your backend mints a short-lived voice token for each user with the Sent API. The SDK registers the browser with it, then places calls, receives them, and reports how they go. What rings when a user calls is decided by your callback, as for every call; see [Answering Calls](/start/guides/answering-calls). `@sentdm/voice` is deprecated on npm. Install `@sentdm/voice-client` instead, and `@sentdm/voice-client-react` for the React bindings. See [Migrate From `@sentdm/voice`](#migrate-from-sentdmvoice). ## Installation [#installation] ```bash npm install @sentdm/voice-client ``` ```bash yarn add @sentdm/voice-client ``` ```bash pnpm add @sentdm/voice-client ``` ```bash bun add @sentdm/voice-client ``` ## Quick Start [#quick-start] ### Mint voice tokens on your backend [#mint-voice-tokens-on-your-backend] Mint tokens on your server with your Sent API key, never in the browser, for the user who is signed in: ```ts // On your server, behind a route such as GET /api/voice-token const response = await fetch('https://api.sent.dm/v3/voice/tokens', { method: 'POST', headers: { 'x-api-key': process.env.SENT_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ identity: user.id }), }); const { data } = await response.json(); return data.token; ``` `identity` names the user in calls: letters, digits, `-` and `_`, up to 200 characters. The user is bound to your default voice number unless you pass `number`, one of the numbers you turned voice on for with `POST /v3/channels/voice`, and the token lasts `ttl` seconds (600 by default, at most 3600). Return the token as text from an endpoint of your own, such as `/api/voice-token`. The token is opaque: read the identity, number, and expiry from the minting response, not from the token. The token endpoint and the binding rules are covered in [Calls From Your App](/start/guides/in-app-calls). ### Serve the service worker [#serve-the-service-worker] Incoming calls reach the browser as push messages, through a service worker your app serves. Copy the one this package ships next to your pages, for example: ```sh cp node_modules/@sentdm/voice-client/sw.js public/sw.js ``` The SDK registers `sw.js` relative to the page. If you serve it elsewhere, or your app already has a service worker, give it a path and scope of its own so it does not replace yours: ```ts import SentVoice from '@sentdm/voice-client'; const client = new SentVoice({ tokenProvider: () => fetch('/api/voice-token').then((response) => response.text()), serviceWorker: { url: '/voice/sw.js', scope: '/voice/' }, }); ``` ### Register and call [#register-and-call] ```ts import SentVoice from '@sentdm/voice-client'; const client = new SentVoice({ tokenProvider: () => fetch('/api/voice-token').then((response) => response.text()), }); // From a click handler: the browser asks for the notification permission here await client.register(); const call = await client.connect({ to: '+14155551234' }); call.on('connected', () => console.log('Connected')); call.on('disconnected', ({ state }) => console.log(`The call ended as ${state}`)); ``` The first `register()` asks the user to allow notifications, which the browser needs to deliver incoming calls. Firefox and Safari only show that prompt after a user gesture, so call it from a click handler. It rejects when notifications are blocked or the service worker cannot be registered. ## Client Options [#client-options] `new SentVoice(options)` takes the following options. Only `tokenProvider` is required. | Option | Description | |--------|-------------| | `tokenProvider` | Returns a voice token from your backend, which mints it with `POST /v3/voice/tokens`. Called by `register()` and again before each token expires | | `registerRetries` | How many more times registering or refreshing the token is retried after a temporary failure, such as a network error. Default `2` | | `logLevel` | `off`, `error`, `warn`, `info` or `debug`. Default `warn` | | `logger` | An object with `error`, `warn`, `info` and `debug` methods. Default `console`. Voice tokens are redacted from every message | | `serviceWorker` | `{ url, scope }` of the worker that delivers incoming calls, a copy of `@sentdm/voice-client/sw.js`. `url` is resolved against the page and defaults to `sw.js`; `scope` defaults to the worker's folder | | `audio` | `inputDeviceId` and `outputDeviceId` to start with, as listed by `client.audio`, and `element`, an `HTMLAudioElement` that plays the other party instead of one the SDK creates | | `baseURL` | The Sent API origin the token exchange and telemetry use. Default `https://api.sent.dm` | | `telemetry` | `{ disabled }`. See [Telemetry](#telemetry) | ## Client [#client] The client holds one registration and the calls that run on it. | Property | Description | |----------|-------------| | `state` | `unregistered`, `registering`, `registered`, `offline` or `destroyed`. After `destroy()` the state is `destroyed` and every method throws | | `identity` | The identity the current token was minted for. `undefined` until registered | | `number` | The number the identity is bound to. `undefined` until registered | | `calls` | Every call in progress | | `activeCall` | The call placed or answered last, until that call ends, or `null` | | `isBusy` | Whether `activeCall` is set. A pending incoming call does not make it true | | `audio` | The microphones and speakers. See [Devices](#devices) | | Method | Description | |--------|-------------| | `register()` | Fetches a token from `tokenProvider`, registers with it, and keeps it refreshed. Resolves once the client is `registered` | | `unregister()` | Stops receiving calls and leaves calls in progress alone | | `destroy()` | Ends every call and tears the client down for good | | `connect({ to })` | Calls a phone number in E.164 format or another user of your app by identity. See [Calls](#calls) | | `joinConference({ name })` | Joins one of your account's rooms by name | | Event | Fires | |-------|-------| | `registering` | `register()` started | | `registered` | The client is registered and ready for calls | | `unregistered` | The client went offline: `unregister()` was called, or `register()` failed. It fires before the teardown finishes, so await `unregister()` before registering again | | `offline` | The token could not be refreshed, with a `TokenExpiredError` as the reason. The client keeps trying | | `tokenWillExpire` | Before the token is refreshed, with `{ expiresAt }` | | `incomingCall` | A call arrived, with its `CallInvite`. See [Receiving Calls](#receiving-calls) | | `activeCallChanged` | `activeCall` was set or cleared, with the call or `null` | | `error` | Something failed outside a method call, such as a token refresh, with a `SentVoiceError` | ## Token Lifecycle [#token-lifecycle] `tokenProvider` is how the SDK gets every token. It must return the `token` that `POST /v3/voice/tokens` responded with, unchanged and fetched fresh each time, because the SDK calls it again before each token expires. The token is opaque: read the identity, number, and expiry from the minting response, not from the token. The SDK exchanges it with Sent for what it registers with, so nothing your backend or app handles belongs to the calling engine. - `register()` calls it and resolves once the client is `registered`. The client moves from `unregistered` to `registering` to `registered`, emitting each state as an event. - A token provider that throws or rejects, or a token exchange that cannot reach Sent or is rate limited, is retried after a short backoff, 2 more times by default (`registerRetries`); `register()` then rejects with a `NetworkError`. A value that is not a voice token, or a token Sent refuses, rejects with a `TokenInvalidError` at once. - The token is refreshed at 80% of its lifetime, or 30 seconds before it expires if that is earlier, but never before half of its lifetime has passed. `tokenWillExpire` fires first, then `tokenProvider` is called with the same retries. Nothing else changes for your app. - If the retries run out, the client emits `error` with the cause and `offline` with a `TokenExpiredError`, then tries again about every 30 seconds until it is `registered` again; calling `register()` tries at once. Calls in progress go on, but `connect()` and `joinConference()` throw a `NotRegisteredError` while the client is offline. - `unregister()` stops receiving calls and leaves calls in progress alone. `destroy()` ends every call and tears the client down for good. Tokens stay in memory and are redacted from log messages. ```ts import SentVoice from '@sentdm/voice-client'; const client = new SentVoice({ tokenProvider: async () => { const response = await fetch('/api/voice-token'); if (!response.ok) throw new Error(`Fetching the voice token failed with status ${response.status}`); return response.text(); }, }); client.on('registered', () => console.log('Ready for calls')); client.on('tokenWillExpire', ({ expiresAt }) => console.log('Refreshing, expires', new Date(expiresAt))); client.on('offline', (reason) => console.warn(`Offline (${reason.code}), trying again every 30 seconds`)); ``` ## Calls [#calls] `connect({ to })` calls a phone number in E.164 format, like `'+14155551234'`, or another user of your app by identity, like `'ben'`. `joinConference({ name })` joins one of your account's rooms, named with letters, digits, `-` and `_`, up to 27 characters. Either throws a `SentVoiceError` with code `INVALID_ADDRESS` when `to` or `name` does not fit, and one with code `CALL_IN_PROGRESS` while a call is in progress or an incoming call is still waiting for an answer. Both open the microphone, and reject with a `MediaPermissionError` when the user refuses. `to` says who the user wants to reach; your backend's answer decides what rings. A leg to a phone number, whether the answer connects the call to a number or a phone participant is added through the API, runs for at most what your account's balance affords at the destination's per-minute rate, capped at four hours. Legs to app users and rooms have no such limit because they cost nothing. A call that reaches the cap ends as `completed`. ```ts const call = await client.connect({ to: 'ben' }); call.on('ringing', () => console.log('Ringing')); call.on('connected', () => call.sendDigits('1')); call.on('muteChanged', (isMuted) => console.log(isMuted ? 'Muted' : 'Unmuted')); call.on('disconnected', ({ state, error }) => console.log(`The call ended as ${state}`, error?.code)); ``` A call you place moves through `initiated`, `ringing`, `answered` and `connected`; an incoming call starts at `ringing`. Either kind ends as `completed`, `failed`, `busy` or `noAnswer`, which `disconnected` reports. `client.activeCall` is the call placed or answered last, until that call ends, and `activeCallChanged` reports each change. `client.calls` lists every call in progress. | Property | Description | |----------|-------------| | `id` | The call id of the calling provider, for your logs. The Sent `call_` id is not observable in the browser; your backend sees it on the callback question and the webhooks | | `direction` | `inbound` or `outbound` | | `from`, `to` | `{ kind: 'user', identity }`, `{ kind: 'number', number }` or `{ kind: 'conference', name }` | | `state` | `initiated`, `ringing`, `answered`, `connected`, `reconnecting`, `completed`, `failed`, `busy` or `noAnswer` | | `isMuted` | Whether the microphone is muted | | `startedAt` | When the call connected, in epoch milliseconds. `undefined` until then | | Method | Description | |--------|-------------| | `hangup()` | Ends the call. Does nothing once the call has ended | | `mute(muted)` | Mutes or unmutes the microphone. Toggles when called without an argument | | `sendDigits(digits)` | Sends DTMF tones down the line | | `getStats()` | Reads the call's `jitter` and `rtt` in milliseconds and its `packetLoss` as a fraction between 0 and 1 | | Event | Fires | |-------|-------| | `ringing` | The other side is being rung. Calls you place only: an incoming call starts in `ringing`, so it never fires this event | | `answered` | The other side answered | | `connected` | Audio flows both ways | | `reconnecting`, `reconnected` | The connection dropped and came back. See [Call Quality and Reconnection](#call-quality-and-reconnection) | | `muteChanged` | `mute()` changed the microphone, with the new `isMuted` | | `qualityWarning` | A network metric crossed its threshold, with `{ metric, cleared }` | | `error` | The call failed, with a `SentVoiceError`. `disconnected` follows | | `disconnected` | The call ended, with `{ state, error }`. `state` is `completed`, `failed`, `busy` or `noAnswer` | The SDK plays the other party through an audio element it creates. Pass your own with the `audio: { element }` option. ## Receiving Calls [#receiving-calls] ```ts client.on('incomingCall', async (invite) => { console.log('Incoming call from', invite.from); invite.on('cancelled', () => console.log('The caller hung up')); // When the user answers const call = await invite.accept(); call.on('disconnected', ({ state }) => console.log(`The call ended as ${state}`)); // When the user declines instead // await invite.reject(); }); ``` The microphone opens when the call arrives, and `accept()` asks for permission again if that was refused, then resolves with the call. When the user refuses, it rejects with a `MediaPermissionError` and the invite stays pending, so the user can try again. `reject()` declines the call, and `cancelled` fires when the caller hangs up first. A call that arrives while another one is in progress still raises `incomingCall`; your handler decides whether to `accept()` it or `reject()` it. The call accepted last becomes `activeCall`. | `CallInvite` member | Description | |---------------------|-------------| | `from`, `to` | Who is calling and who they asked for, as addresses | | `state` | `pending`, `accepted`, `rejected` or `cancelled` | | `accept()` | Answers the call and resolves with the `Call` | | `reject()` | Declines the call | | `accepted` event | The invite was accepted, with the call | | `rejected` event | The invite was declined | | `cancelled` event | The caller hung up before an answer | ## Call Quality and Reconnection [#call-quality-and-reconnection] `qualityWarning` fires when a network metric of a connected call crosses its threshold, and again with `cleared: true` once it recovers. Stats are sampled every half second. | `metric` | Raised when | Cleared when | | ------------ | ------------------------------------------------------------------------- | ------------------------------ | | `jitter` | incoming audio jitter is over 30 ms in 3 of the last 4 samples | fewer than 3 of the last 4 are | | `packetLoss` | over 1% of the incoming audio packets are lost in 3 of the last 4 samples | fewer than 3 of the last 4 are | | `rtt` | the round-trip time is over 300 ms | it is 300 ms or less again | The `rtt` warning follows every sample, so it can go on and off while the round-trip time hovers around 300 ms. A warning still raised when the call ends is not cleared. ```ts call.on('qualityWarning', ({ metric, cleared }) => console.log(metric, cleared ? 'recovered' : 'poor')); call.on('reconnecting', () => console.log('Connection lost, reconnecting')); call.on('reconnected', () => console.log('Connection back')); ``` When the connection drops for 2 seconds, the call goes `reconnecting`, and `reconnected` fires when it comes back on the same network. A call cannot move to a new network: after a network switch its connection does not come back, and a call that has not reconnected within 5 minutes ends as `failed` with a `NetworkError`. ## Handling Errors [#handling-errors] Every error the SDK throws or emits at runtime is a `SentVoiceError` with a stable `code`, a `category` (`auth`, `media`, `signaling`, `network`, `validation` or `capability`) and whether it is `retriable`. The one exception is a programming error: using a React hook outside `SentVoiceProvider` throws a plain `Error`. Check for the subclasses with `instanceof`: ```ts import { MediaPermissionError, SentVoiceError } from '@sentdm/voice-client/errors'; try { await invite.accept(); } catch (error) { if (error instanceof MediaPermissionError) console.warn('Allow microphone access to answer calls'); else if (error instanceof SentVoiceError) console.error(error.code, error.message); } ``` | Error | `code` | `category` | When | | ---------------------------- | ------------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `TokenInvalidError` | `TOKEN_INVALID` | `auth` | `register()`: the token provider returned something that is not a voice token, or a token Sent refuses | | `TokenExpiredError` | `TOKEN_EXPIRED` | `auth` | the `offline` event: the token could not be refreshed | | `NotRegisteredError` | `NOT_REGISTERED` | `validation` | `connect()` or `joinConference()` while not registered; registering, calling or choosing a device after `destroy()` | | `MediaPermissionError` | `MEDIA_PERMISSION_DENIED` | `media` | `connect()`, `joinConference()` or `accept()`: the microphone could not be opened | | `CallFailedError` | `CALL_FAILED` | `signaling` | `accept()` on a call that ended before it was answered; a call that could not be set up, such as to an identity that is not registered, ends as `failed` with it | | `CallRejectedError` | `CALL_REJECTED` | `signaling` | not raised yet: a call the other side declines ends as `busy` | | `NetworkError` | `NETWORK` | `network` | `register()`, when the token provider or the token exchange keeps failing or the calling engine cannot be loaded; a call whose connection failed or was lost | | `CapabilityUnsupportedError` | `CAPABILITY_UNSUPPORTED` | `capability` | `setOutputDevice()` where the browser cannot choose the speaker; listing devices over plain HTTP | | `SentVoiceError` | `INVALID_ADDRESS` | `validation` | `connect()` or `joinConference()` with a `to` or `name` that does not fit | | `SentVoiceError` | `CALL_IN_PROGRESS` | `validation` | `connect()` or `joinConference()` while a call is in progress or an incoming call is waiting for an answer | | `SentVoiceError` | `UNKNOWN` | `signaling` | anything else, such as `register()` failing because notifications are blocked | Errors that happen outside a method call arrive as events: the client's `error` when a token refresh fails, and a call's `error`, followed by `disconnected` with `{ state: 'failed', error }`. The underlying engine error is not exposed on the error; the SDK reports it to Sent as telemetry. The error classes are exported from `@sentdm/voice-client/errors` and from the root entry point. ## Devices [#devices] ```ts const isHeadset = (device) => device.label.includes('Headset'); const microphone = (await client.audio.inputDevices()).find(isHeadset); if (microphone) await client.audio.setInputDevice(microphone.deviceId); const speaker = (await client.audio.outputDevices()).find(isHeadset); if (speaker) await client.audio.setOutputDevice(speaker.deviceId); client.audio.on('deviceChanged', () => console.log('A device was plugged in or out')); ``` - `inputDevices()` and `outputDevices()` list the microphones and speakers. Browsers leave out labels, and may list a single device, until the user has allowed microphone access in the page, which the first call asks for. - `setInputDevice()` switches the microphone of the call in progress and of later calls. While the device is missing, the default one is used. - `setOutputDevice()` plays calls through a speaker. It throws a `CapabilityUnsupportedError` in browsers that cannot choose the audio output. - Both work before `register()`, and take effect when it runs. To start with saved devices, pass `audio: { inputDeviceId, outputDeviceId }`. - `deviceChanged` fires when a device is plugged in or out. ## Ringtones [#ringtones] The SDK plays no ringtone or ringback. Play your own on `incomingCall` and when a placed call is `ringing`, and stop it when the call is answered or ends: ```ts const ringtone = new Audio('/sounds/ringtone.mp3'); ringtone.loop = true; const play = () => ringtone.play().catch(() => {}); const stop = () => { ringtone.pause(); ringtone.currentTime = 0; }; // Incoming: ring until the invite is settled client.on('incomingCall', (invite) => { play(); invite.on('accepted', stop).on('rejected', stop).on('cancelled', stop); }); // Outgoing: ringback until the call connects or ends const call = await client.connect({ to: '+14155551234' }); call.on('ringing', play).on('connected', stop).on('disconnected', stop); ``` ## React [#react] [`@sentdm/voice-client-react`](https://www.npmjs.com/package/@sentdm/voice-client-react) wraps one client in a provider, with hooks that re-render on its events. It supports React 18 and 19. Install it next to the client, which it declares as a peer dependency so that your app holds one client: ```bash npm install @sentdm/voice-client @sentdm/voice-client-react ``` ```tsx import { SentVoiceProvider, useActiveCall, useIncomingCall, useSentVoice } from '@sentdm/voice-client-react'; const getVoiceToken = () => fetch('/api/voice-token').then((response) => response.text()); export function App() { return ( ); } function Phone() { const { client, state, register } = useSentVoice(); const invite = useIncomingCall(); const { call, state: callState, isMuted, mute, hangup, duration } = useActiveCall(); if (state !== 'registered') return ; if (invite) { return (

); } if (call) { return (

{callState} for {duration} s

); } return ; } ``` - `SentVoiceProvider` takes every client option, plus `autoRegister` (default `true`), which registers as soon as the client exists. Registering needs the notification permission, which Firefox and Safari only ask for after a user gesture, so the example registers from a click. - The client is created after the provider mounts, so its children render first, on the server too, with `client` `null` and `state` `'unregistered'`. Unmounting destroys the client and ends its calls. - Props are read once, when the client is created: remount the provider with a new `key` to change them, for example for another user. `tokenProvider` is the exception, the latest one is always used. - `useSentVoice()` gives the client, its state, `register` and `unregister`. `useIncomingCall()` gives the newest invite still waiting for an answer, or `null`. `useActiveCall()` gives the active call with its state, `isMuted`, `mute`, `hangup`, `sendDigits` and `duration`, the seconds since it connected. `useAudioDevices()` gives the microphones and speakers as `inputs` and `outputs`, with `setInput` and `setOutput`. - The hooks throw when used outside a `SentVoiceProvider`. - The entry point is marked `'use client'` for the Next.js App Router. ## Telemetry [#telemetry] The SDK reports usage and call quality data to Sent, authenticated with the voice token: - the SDK version, and the browser, its major version, the operating system, its version and the device type, as read from the user agent (the user agent itself is not sent) - how long `register()` took, its attempts and, when it failed, its error; how long `unregister()` took - for each call: its id, direction and outcome, how long it took to connect and how long it lasted, and at its end the average round-trip time, jitter and packet loss of samples taken every 10 seconds - the errors the client and its calls report: code, category, whether retriable, the message, and the underlying engine error with its name, message, stack, and properties No audio, phone numbers or identities are added by the SDK. Batches go to `/v3/voice/telemetry` under `baseURL` (`https://api.sent.dm` by default) 3 seconds after the first event queued, so events that happen together share one request, and at once when a call ends, when the page is hidden and when the client is destroyed. A batch that fails, or that Sent refuses (for example with a 429 or a 5xx), is retried once, with the next batch or within 30 seconds, then dropped; telemetry never throws to your app and never delays a call. Turn it off with `telemetry: { disabled: true }`. ## Browser Realities [#browser-realities] - WebRTC requires a secure context: serve your app over HTTPS, or from `localhost` while developing. Over plain HTTP the browser hides the microphone and service worker APIs, so registering and calling fail. It is the first thing that breaks when you open the app from another device on your network. - A page refresh or tab close ends any live call: WebRTC media dies with the page, and there is no resuming a call across reloads. - Laptop sleep or a network switch does not unregister the client: incoming calls reach it through the browser's push service, which reconnects by itself, so the client stays `registered`, but calls that arrive while the device sleeps or is offline are missed. If a token refresh falls in that gap, the client goes `offline` and tries again about every 30 seconds until it is `registered` again (the state goes from `offline` to `registered`). - One `SentVoice` instance per tab. The same identity registered in several tabs or devices creates one registration per device. Every device rings, the first to answer takes the call, and the others see their invite cancelled. Tabs of one browser share a registration, so they all ring. - Tokens are per-registration; each tab runs its own `tokenProvider` calls. ## Migrate From `@sentdm/voice` [#migrate-from-sentdmvoice] `@sentdm/voice` 0.1.1 is deprecated on npm and stays installable. `@sentdm/voice-client` 0.2.0 has the same client, calls, events, and errors. Four things change: 1. Install `@sentdm/voice-client` instead of `@sentdm/voice`, and replace every `@sentdm/voice` import, including `@sentdm/voice/errors` and the `sw.js` copy, with `@sentdm/voice-client`. 2. Install `@sentdm/voice-client-react` for the React bindings, and import `SentVoiceProvider` and the hooks from it instead of `@sentdm/voice/react`. 3. `tokenProvider` must return the `token` from `POST /v3/voice/tokens` unchanged. The SDK exchanges it with Sent itself; a token minted any other way fails `register()` with a `TokenInvalidError`. 4. `telemetry.baseURL` is gone. Set `baseURL` on the client instead; `telemetry` keeps `disabled`. ## What the SDK Does Not Do [#what-the-sdk-does-not-do] - **Video.** Calls are audio only. - **SIP calling.** `connect()` takes a phone number or an identity; there is no SIP address kind. - **Hold.** There is no `hold()` on a call. Your callback can `park` a call; see [Voice Recipes](/start/guides/voice-recipes). - **Transfer and participants.** Adding, muting and removing participants stays on the REST API; see [Calls, Recordings, and Participants](/start/guides/managing-calls). - **Recording control.** Recording is started by your callback answer or by the REST API, never from the browser. - **Presence.** The SDK does not know which identities are online. Your backend does, and your callback answer uses that knowledge. - **Push to closed tabs.** Pushes only deliver calls to open pages; the service worker never wakes a closed tab. ## Source & Issues [#source--issues] - **Releases**: [GitHub Releases](https://github.com/sentdm/sent-dm-voice-typescript/releases) - **GitHub**: [`sentdm/sent-dm-voice-typescript`](https://github.com/sentdm/sent-dm-voice-typescript) - **NPM**: [`@sentdm/voice-client`](https://www.npmjs.com/package/@sentdm/voice-client) and [`@sentdm/voice-client-react`](https://www.npmjs.com/package/@sentdm/voice-client-react) - **Issues**: [Report a bug](https://github.com/sentdm/sent-dm-voice-typescript/issues) ## Getting Help [#getting-help] - **Documentation**: [API Reference](/reference/api) - **Troubleshooting**: [Common Issues](/sdks/troubleshooting) - **Support**: email [support@sent.dm](mailto:support@sent.dm) with your request ID --- # Voice SDK for iOS (/sdks/voice/ios.md) # Voice SDK for iOS [#voice-sdk-for-ios] [`sent-dm-voice-swift`](https://github.com/sentdm/sent-dm-voice-swift) lets an iOS app place Sent Voice calls: to a phone number, to another user of your app, or into a conference. Your backend mints a short-lived voice token for each user with the Sent API. The SDK registers the device with it, places calls, and reports how they go. What rings when a user calls is decided by your callback, as for every call; see [Answering Calls](/start/guides/answering-calls). This SDK places calls. Receiving calls on a phone is not part of it; the [browser SDK](/sdks/voice) receives calls. ## Installation [#installation] A Swift package for iOS 15 or later. In Xcode, choose File → Add Package Dependencies and enter the repository URL, or add it to `Package.swift`: ```swift dependencies: [ .package(url: "https://github.com/sentdm/sent-dm-voice-swift.git", from: "0.1.0"), ], ``` Add the `SentVoice` product to your app target. Calls use the microphone, so add `NSMicrophoneUsageDescription` to the app's `Info.plist`; iOS asks the user on the first call. ## Quick Start [#quick-start] ### Mint voice tokens on your backend [#mint-voice-tokens-on-your-backend] Mint tokens on your server with your Sent API key, never in the app, for the user who is signed in: ```ts // On your server, behind a route such as GET /api/voice-token const response = await fetch('https://api.sent.dm/v3/voice/tokens', { method: 'POST', headers: { 'x-api-key': process.env.SENT_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ identity: user.id }), }); const { data } = await response.json(); return data.token; ``` `identity` names the user in calls: letters, digits, `-` and `_`, up to 200 characters. The user is bound to your default voice number unless you pass `number`, one of the numbers you turned voice on for with `POST /v3/channels/voice`, and the token lasts `ttl` seconds (600 by default, at most 3600). Return the token as text from an endpoint of your own, such as `/api/voice-token`. The token is opaque: read the identity, number, and expiry from the minting response, not from the token. The token endpoint and the binding rules are covered in [Calls From Your App](/start/guides/in-app-calls). ### Register and call [#register-and-call] ```swift import SentVoice let client = SentVoice.client(options: SentVoiceOptions(tokenProvider: { let (data, _) = try await URLSession.shared.data(from: URL(string: "https://example.com/api/voice-token")!) return String(decoding: data, as: UTF8.self) })) try await client.register() let call = try await client.connect(to: "+14155551234") let listener = call.on { event in switch event { case .connected: print("Connected") case .disconnected(let state, _): print("The call ended as \(state)") default: break } } ``` Keep one client for the life of the app. `register()` fetches a token through `tokenProvider`, registers with it, and refreshes it before it expires. A listener stays until you call `cancel()` on the token `on` returns. ## Client Options [#client-options] `SentVoiceOptions` takes the following options. Only `tokenProvider` is required. | Option | Description | |--------|-------------| | `tokenProvider` | An async closure that returns a voice token from your backend, which mints it with `POST /v3/voice/tokens`. Called by `register()` and again before each token expires | | `registerRetries` | How many more times registering or refreshing the token is retried after a temporary failure, such as a network error. Default `3` | | `baseURL` | The Sent API origin the token exchange and telemetry use. Default `https://api.sent.dm` | | `telemetryDisabled` | Turns off the call quality and error reports the SDK sends to Sent. Default `false` | | `log` | A closure that receives the SDK's log lines with their level. Voice tokens never appear in them | ## Client [#client] The client holds one registration and the call that runs on it. | Property | Description | |----------|-------------| | `state` | `unregistered`, `registering`, `registered`, `offline` or `destroyed`. After `destroy()` the state is `destroyed` and every method throws | | `identity` | The identity the current token was minted for. `nil` until registered | | `number` | The number the identity is bound to. `nil` until registered | | `activeCall` | The call in progress, or `nil` | | Method | Description | |--------|-------------| | `register()` | Fetches a token from `tokenProvider`, registers with it, and keeps it refreshed. Returns once the client is `registered` | | `unregister()` | Drops the registration and leaves a call in progress alone | | `destroy()` | Ends the call and tears the client down for good | | `connect(to:)` | Calls a phone number in E.164 format or another user of your app by identity. See [Calls](#calls) | | `joinConference(name:)` | Joins one of your account's rooms by name | | `on(_:)` | Adds a listener for the events below and returns a token; `cancel()` on it removes the listener | | Event | Fires | |-------|-------| | `registering` | `register()` started | | `registered` | The client is registered and ready for calls | | `unregistered` | `unregister()` finished | | `activeCallChanged(Call?)` | A call was placed, or the call in progress ended | | `tokenWillExpire(expiresAt:)` | The token is about to expire and the next refresh is due | | `offline(SentVoiceError)` | The refresh retries ran out. The client tries again about every 30 seconds; `register()` tries at once | | `error(SentVoiceError)` | Something failed outside a method call, such as a refresh | ## Calls [#calls] `connect(to:)` and `joinConference(name:)` return a `Call` once the provider accepted it; the call then moves through `ringing`, `answered` and `connected` to `completed`, `failed`, `busy` or `no_answer`. One call at a time: a second `connect` while one is in progress throws `CALL_IN_PROGRESS`. | Property | Description | |----------|-------------| | `id`, `direction`, `from`, `to`, `startedAt` | What the call is | | `state` | The call's state, as above | | `isMuted` | Whether the microphone is muted | | `connectedTime`, `endedTime` | When the parties were joined, and when the call ended | | `error` | The error that ended the call, when one did | | Method | Description | |--------|-------------| | `hangup()` | Ends the call | | `mute(_:)` | Mutes or unmutes the microphone | | `sendDigits(_:)` | Sends DTMF digits, for example to a phone menu | | `on(_:)` | Adds a listener for the events below and returns a token | | Event | Fires | |-------|-------| | `ringing`, `answered`, `connected` | The call progressed | | `reconnecting`, `reconnected` | The media path dropped and came back | | `disconnected(state:error:)` | The call ended in `state`, with the error that ended it when there is one | | `muteChanged(Bool)` | `mute(_:)` took effect | | `qualityWarning(QualityWarning)` | The media quality degraded | | `error(SentVoiceError)` | Something failed on the call | ## Errors [#errors] Every failure is a `SentVoiceError` with a `code`, a `category`, whether it is `retriable`, and a `message` you can show. The codes are the same on every platform: | Code | Meaning | |------|---------| | `TOKEN_INVALID` | The value from `tokenProvider` is not a voice token, or Sent refused it | | `TOKEN_EXPIRED` | The token expired and could not be refreshed | | `NOT_REGISTERED` | A call was placed while the client was not `registered` | | `MEDIA_PERMISSION_DENIED` | The user refused the microphone | | `INVALID_ADDRESS` | `to` is neither an E.164 number nor an identity, or a room name is malformed | | `CALL_IN_PROGRESS` | A call was placed while one was in progress | | `CALL_REJECTED` | The other party, or your callback, declined the call | | `CALL_FAILED` | The call could not be placed or dropped | | `NETWORK` | Sent or the provider could not be reached. Retriable | | `CAPABILITY_UNSUPPORTED` | The device or the SDK version cannot do what was asked | | `UNKNOWN` | Anything else; `message` says what | ## Telemetry [#telemetry] The SDK reports call quality and errors to Sent so support can see what a user saw, batched and sent in the background. Set `telemetryDisabled` to turn it off. Nothing in the reports identifies the person beyond the identity your backend minted the token for. # Register 10DLC Campaigns via the API (/start/advanced/10dlc-campaigns-api.md) # Register 10DLC Campaigns via the API [#register-10dlc-campaigns-via-the-api] This guide shows you how to register and track 10DLC campaigns programmatically with the `/v3/profiles/{profileId}/campaigns` endpoints. Use it when you manage US SMS registration for many brands at once, the typical setup for agencies and resellers, or when you want campaign submission wired into your own onboarding flow instead of the dashboard. **These endpoints are deprecated.** A campaign is no longer a standalone collection with a lifecycle: it is a registration, singular per market, and it now travels in the `compliance.campaign` object of the market call. All four operations still behave exactly as before, so nothing has to change today. For new integrations: | This page | Use instead | | --- | --- | | `POST` / `PUT /v3/profiles/{profileId}/campaigns` | `compliance.campaign` on [`POST /v3/channels/sms`](/start/guides/managing-channels#sms-markets), or `PATCH /v3/channels/sms/{country}/{type}` to correct it | | `GET /v3/profiles/{profileId}/campaigns` | `GET /v3/channels/sms/{country}/{type}`, whose `compliance.campaign` and `compliance.requirements` say what is registered and what is still owed | | `DELETE /v3/profiles/{profileId}/campaigns/{campaignId}` | `"campaign": { "inherit": true }` to fall back to the organization's, or `"campaign": null` to say the same thing the short way | | `PATCH /v3/profiles/{profileId}` with `inherit_tcr_campaign: false` | Supply `compliance.campaign` fields on the market. Sending the data is what makes the campaign dedicated; there is no separate flag to turn off. | Start from [`GET /v3/compliance/requirements`](/start/guides/managing-channels#sms-markets), which returns the market's requirements and a ready-to-send body. It assumes you already understand 10DLC and have a registered brand. If you are new to 10DLC, or you want the dashboard flow, start with the [10DLC Registration Guide](/start/advanced/10dlc-registration). That guide also owns the content rules your campaign must satisfy: opt-in forms, autoresponses, and sample messages. This page covers only the API mechanics. ## Prerequisites [#prerequisites] - An organization with at least one [Sender Profile](/start/concepts/sender-profiles). The `{profileId}` in every campaign endpoint must be a profile that belongs to your organization. - A brand for the profile, either registered for the profile itself or inherited from the organization. Without one, campaign requests return `404 RESOURCE_009` ("Brand not found for this profile"). - Your organization API key, passed in the `x-api-key` header. ## Register a Campaign [#register-a-campaign] ### Give the Profile Its Own Campaign [#give-the-profile-its-own-campaign] A profile whose TCR campaign is inherited from the organization (`inherit_tcr_campaign: true`) has read-only campaigns; create and update requests return `400 VALIDATION_001`. To register a dedicated campaign for the profile, turn inheritance off first: ```bash curl -X PATCH "https://api.sent.dm/v3/profiles/$PROFILE_ID" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{"inherit_tcr_campaign": false}' ``` The brand can stay inherited: when `inherit_tcr_brand` is `true`, the campaign you create attaches to the organization's brand. This partial inheritance (shared brand, dedicated campaign) is a supported [sender profile TCR pattern](/start/concepts/sender-profiles#tcr-brand-and-campaign). ### Create the Campaign [#create-the-campaign] Send `POST /v3/profiles/{profileId}/campaigns` with at least one use case. Each use case carries 1 to 5 sample messages of up to 1,024 characters each. ```bash curl -X POST "https://api.sent.dm/v3/profiles/$PROFILE_ID/campaigns" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 10dlc-reg-$PROFILE_ID" \ -d '{ "campaign": { "name": "Customer Notifications", "description": "Appointment reminders and account notifications", "type": "App", "volume": "1500", "useCases": [ { "messagingUseCaseUs": "ACCOUNT_NOTIFICATION", "sampleMessages": [ "Hi {name}, your appointment is confirmed for {date} at {time}.", "Your order #{order_id} has been shipped. Track at {url}" ] } ], "messageFlow": "User signs up on website and opts in to receive SMS notifications", "privacyPolicyLink": "https://acmecorp.com/privacy", "termsAndConditionsLink": "https://acmecorp.com/terms", "optinMessage": "You have opted in to Acme Corp notifications. Reply STOP to opt out.", "optoutMessage": "You have been unsubscribed. Reply START to opt back in.", "helpMessage": "Reply STOP to unsubscribe or contact support@acmecorp.com", "optinKeywords": "YES, START, SUBSCRIBE", "optoutKeywords": "STOP, UNSUBSCRIBE, END", "helpKeywords": "HELP, INFO, SUPPORT" } }' ``` `name`, `description`, `type`, and `useCases` are always required. When the brand is a TCR application, the compliance fields are required too: `messageFlow`, `privacyPolicyLink`, `termsAndConditionsLink`, all three autoresponse messages, and all three keyword lists. Requests missing any of them return `400 VALIDATION_001` naming the missing field. Write these values to pass carrier review, not just validation; the [opt-in form requirements](/start/advanced/10dlc-registration#opt-in-form-requirements) and [autoresponse requirements](/start/advanced/10dlc-registration#autoresponse-requirements) list what reviewers reject. The `volume` field sets your expected daily messaging volume for this campaign as a numeric string (for example `"1500"` or `"10000"`). It is optional; if omitted on create, `volume` is `null` in the response and no explicit tier is declared to TCR. On update, omitting `volume` preserves the existing value. It drives two things when set: - **TCR tier**: values strictly below `2000` register the campaign at the low-volume tier (capped at 2,000 messages per day, lower monthly TCR fee); `2000` and above register as standard (higher throughput, higher fee). - **Fees**: the campaign's 10DLC fees are priced by its tier. The tier is fixed once the campaign is submitted to TCR (`submittedToTCR` is `true` or `tcrCampaignId` is set). After that, an update that moves `volume` across `2000` is refused with `409 CONFLICT_017`, and a change within the same tier is still accepted. Before submission you can change `volume` freely. Changing `volume` moves no money on its own. Sent passes `volume` to TCR as part of the campaign submission and surfaces it back in the response. Messaging volume is a per-campaign setting; it is not set on the brand. The `Idempotency-Key` header makes retries safe: the API caches the response for 24 hours per key per customer, so a retried request cannot create a duplicate campaign. Refer to [Idempotency](/reference/api/idempotency) for key rules. To validate a payload without registering anything, add `"sandbox": true` next to `"campaign"` in the request body. The API runs authentication and validation, then returns a simulated `201` with no side effects. See [Sandbox Mode](/reference/api/test-mode). ### Verify the Campaign Was Created [#verify-the-campaign-was-created] A successful create returns `201` with the campaign in `data`. Every new campaign starts in `SENT_CREATED` status with `submittedToTCR: false`: ```json { "success": true, "data": { "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "name": "Customer Notifications", "brandId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": "SENT_CREATED", "submittedToTCR": false, "tcrCampaignId": null, "volume": "1500", "useCases": [ { "messagingUseCaseUs": "ACCOUNT_NOTIFICATION", "sampleMessages": ["..."] } ] } } ``` (Response abbreviated.) Store `data.id`; you need it to update or delete the campaign later. To confirm the campaign from another process, list the profile's campaigns: ```bash curl "https://api.sent.dm/v3/profiles/$PROFILE_ID/campaigns" \ -H "x-api-key: $SENT_API_KEY" ``` For a profile with `inherit_tcr_campaign: true`, this returns the organization's inherited campaigns instead. ## Campaign Status Lifecycle [#campaign-status-lifecycle] Poll `GET /v3/profiles/{profileId}/campaigns` and read the `status` field to track each campaign: | Status | Meaning | What to do | |---|---|---| | `SENT_CREATED` | The campaign exists in Sent but TCR has not approved it. Every campaign starts here. | Wait for review and submission; see below. | | `ACTIVE` | TCR approved the campaign. Your US SMS traffic is registered. | Nothing; start sending. | | `EXPIRED` | TCR deactivated the campaign. Sent releases the campaign's dedicated number back to the pool. | Register a new campaign, or contact [support@sent.dm](mailto:support@sent.dm) to investigate. | ### While the Campaign Is in SENT_CREATED [#while-the-campaign-is-in-sent_created] `SENT_CREATED` covers two waiting stages, distinguishable by `submittedToTCR`: 1. **Not yet submitted** (`submittedToTCR: false`): the Sent compliance team reviews your campaign content before submitting it to TCR on your behalf, the same [review flow](/start/advanced/10dlc-registration#applying-through-sent) as dashboard submissions. 2. **Submitted, awaiting TCR** (`submittedToTCR: true`, `tcrCampaignId` set): TCR and the carriers are reviewing. Most submissions come back approved within 1 to 3 business days. When TCR reports a decision, Sent updates `status` automatically. If a campaign sits in `SENT_CREATED` well past that window: - Confirm every compliance field is filled in and meets the [opt-in form requirements](/start/advanced/10dlc-registration#opt-in-form-requirements); incomplete content stalls review. - Confirm the brand itself finished verification; campaigns cannot be approved under an unverified brand. - Contact [support@sent.dm](mailto:support@sent.dm) with the campaign `id`. If TCR rejected the campaign, the compliance team tells you exactly what to fix before resubmission. ## US Messaging Use Case Values [#us-messaging-use-case-values] `messagingUseCaseUs` accepts one of 13 values. Pick what matches your actual traffic; carriers flag mismatches between the registered use case and the messages you send. The [campaign type guidance](/start/advanced/10dlc-registration#choosing-the-right-campaign-type) explains how to choose. | Value | Typical traffic | |---|---| | `MARKETING` | Promotional offers, discounts, announcements | | `ACCOUNT_NOTIFICATION` | Password resets, balance alerts, appointment reminders | | `CUSTOMER_CARE` | Support conversations, ticket updates | | `FRAUD_ALERT` | Suspicious-activity notices | | `TWO_FA` | One-time passcodes, login verification | | `DELIVERY_NOTIFICATION` | Order shipped, out for delivery | | `SECURITY_ALERT` | Security incident notifications | | `M2M` | Machine-to-machine traffic | | `MIXED` | Multiple use cases under one campaign | | `HIGHER_EDUCATION` | Messaging from colleges and universities | | `POLLING_VOTING` | Polling and voting notifications | | `PUBLIC_SERVICE_ANNOUNCEMENT` | Public service announcements | | `LOW_VOLUME` | Mixed use cases, capped at 2,000 messages per day | The `LOW_VOLUME` use-case type and the `volume` field are independent. `LOW_VOLUME` declares what kind of traffic you send; `volume` declares your expected daily message count and determines the TCR fee tier. A campaign can use the `LOW_VOLUME` use-case type while setting `volume` to any value, and vice versa. ## Update or Delete a Campaign [#update-or-delete-a-campaign] To fix campaign content, for example after a rejection or to refresh sample messages, send the full campaign object to `PUT /v3/profiles/{profileId}/campaigns/{campaignId}`. The required fields match create: `name`, `description`, `type`, and `useCases`. The use cases you send replace the existing list; optional fields you omit keep their current values. If you are migrating from the old `expected_messaging_volume` field on the brand, set `volume` here instead. See the [July 2026 changelog](/reference/changelog#10dlc-messaging-volume-moved-to-campaign-breaking-change) for the full migration table. Once the campaign is submitted to TCR, `volume` can't cross the `2000` tier boundary: that update is refused with `409 CONFLICT_017`. ```bash curl -X PUT "https://api.sent.dm/v3/profiles/$PROFILE_ID/campaigns/$CAMPAIGN_ID" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "campaign": { "name": "Customer Notifications", "description": "Appointment reminders and account notifications", "type": "App", "volume": "1500", "useCases": [ { "messagingUseCaseUs": "ACCOUNT_NOTIFICATION", "sampleMessages": [ "Acme Corp: Your appointment is confirmed for {date} at {time}." ] } ] } }' ``` If the campaign was already submitted to TCR, Sent syncs the update to TCR. Check `tcrSyncError` in the response: `null` means the sync succeeded; otherwise it holds the TCR error message and the change is saved in Sent only. To remove a campaign, send `DELETE /v3/profiles/{profileId}/campaigns/{campaignId}`. A successful delete returns `204` with no body. Deleting a campaign is permanent. To change a campaign's content, update it instead of deleting and recreating it, so you keep its review progress. ## Bulk Registration for Agencies and Resellers [#bulk-registration-for-agencies-and-resellers] TCR ties each campaign to the business responsible for the messages, so every client needs its own registration; you cannot bundle clients under one campaign. The API pattern: 1. Map each client to a Sender Profile with a dedicated TCR campaign (and a dedicated or inherited brand, per client). The [multi-tenant patterns](/start/concepts/sender-profiles#architectural-patterns) page compares the options. 2. Enumerate profiles with `GET /v3/profiles` and create one campaign per profile, as shown earlier, collecting the client's compliance details in your own onboarding form. 3. Poll each profile's campaign list, or check it on demand, and surface `status` to the client until it reads `ACTIVE`. Two scoping notes for organization keys: - The campaign endpoints take the profile ID in the URL path, so you do not need the `x-profile-id` header here. Your organization API key can address every profile in the organization directly. - Where you do use `x-profile-id` (endpoints without a profile ID in the path, such as sending messages), only organization API keys may send it; profile-scoped keys receive `403`. Use a distinct `Idempotency-Key` per profile (for example, derived from your client ID) so a retried batch never double-registers a client. ## Troubleshooting [#troubleshooting] {/* vale Google.WordList = NO */} {/* "TCR application" is the regulatory submission and TCR's own vocabulary, not a software app. */} | Symptom | Likely cause | Fix | |---|---|---| | `400 VALIDATION_001`: "Cannot create campaigns when inherit_tcr_campaign=true" (or "These campaigns are read-only") | The profile inherits the organization's campaign | `PATCH /v3/profiles/{profileId}` with `{"inherit_tcr_campaign": false}` | | `400 VALIDATION_001`: "MessageFlow is required for TCR applications" (or similar) | The brand is a TCR application and a compliance field is missing | Include `messageFlow`, both policy links, and all autoresponse messages and keywords | | `404 RESOURCE_009`: "Brand not found for this profile" | No brand is registered for the profile or its organization | Register the brand first; see the [10DLC Registration Guide](/start/advanced/10dlc-registration) | | `404 RESOURCE_014`: "Profile not found" | `{profileId}` is not a child profile of your organization (passing your organization's own ID also fails) | Use a profile ID returned by `GET /v3/profiles` | | `404 RESOURCE_010`: "Campaign not found for this profile" | `{campaignId}` does not belong to this profile's brand | List the profile's campaigns and reuse the returned `id` | | `409 CONFLICT_017`: "This campaign is registered with TCR, so its volume can no longer move between low and high volume" | The update moves `volume` across `2000` on a campaign already submitted to TCR | Keep `volume` on the same side of `2000`, or register a new campaign at the other tier | | Campaign stays in `SENT_CREATED` | Review or TCR submission still pending | Work through the checks in [Campaign Status Lifecycle](#campaign-status-lifecycle) | {/* vale Google.WordList = YES */} Error codes and remediation for the whole API are in the [Error Catalog](/reference/api/error-catalog). ## Related Pages [#related-pages] - Endpoint reference: [create campaign](/reference/api/brands/SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsCreateBrandCampaignEndpoint), [list campaigns](/reference/api/brands/SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsGetBrandCampaignsEndpoint), [update campaign](/reference/api/brands/SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsUpdateBrandCampaignEndpoint), [delete campaign](/reference/api/brands/SentDmServicesEndpointsCustomerAPIv3BrandsCampaignsDeleteBrandCampaignEndpoint) - [10DLC Registration Guide](/start/advanced/10dlc-registration) for the registration concepts, dashboard flow, and content requirements - [Sender Profiles](/start/concepts/sender-profiles) for the inheritance model behind `inherit_tcr_brand` and `inherit_tcr_campaign` - [Idempotency](/reference/api/idempotency) and [Sandbox Mode](/reference/api/test-mode) for safe retries and dry runs # 10DLC Registration Guide (/start/advanced/10dlc-registration.md) # 10DLC Registration Guide [#10dlc-registration-guide] **TL;DR:** To send SMS to US numbers, you need to register your business and messaging use cases. Sent handles the submission on your behalf. You fill out the form in our platform, our compliance team reviews it, and we submit to TCR. Most approvals take 1–3 business days. This guide shows you how to register for 10DLC through the Sent dashboard: where to start, which campaign type to pick, and what to put in each part of the form so it passes review. If you are new to 10DLC, or you want to understand why US carriers require registration and how the review works, read [What is 10DLC?](/start/concepts/10dlc) first. To register many brands programmatically, see [Register 10DLC Campaigns via the API](/start/advanced/10dlc-campaigns-api). ![10DLC registration process overview](/10dlc-process.svg) ## Applying through Sent [#applying-through-sent] ### Fill out the form [#fill-out-the-form] In the Sent dashboard, go to **Compliance** and select **Apply** on the US 10DLC notice, or open the [10DLC registration form](https://app.sent.dm/dashboard/brand-registration) directly. Submit your business and campaign details; the form collects everything TCR requires, and the sections below cover what to enter in each part. ### Compliance review [#compliance-review] Our compliance team reviews your submission and gives you feedback to maximize your chances of approval before it reaches TCR. ### TCR submission [#tcr-submission] We submit your registration to TCR on your behalf. ### Approval tracking [#approval-tracking] We track the review and notify you when you're approved, or if anything needs fixing. Most submissions come back approved within **1–3 business days**. If your submission is rejected, the Sent compliance team reviews it and gives you specific steps for resubmission. All Sent customers (including those who haven't sent any messages yet) get compliance support throughout this process. --- ## Choosing the right campaign type [#choosing-the-right-campaign-type] Pick the use cases that reflect what you're actually sending. Don't try to game this: carriers flag mismatches between your registered use case and your actual messages. | Use case | When to use | |---|---| | Marketing | Promotional offers, discounts, announcements | | Customer care | Support conversations, ticket updates | | 2FA / OTP | One-time passcodes, login verification | | Account notifications | Password resets, balance alerts | | Appointment reminders | Booking confirmations, schedule changes | | Delivery notifications | Order shipped, out for delivery | | Fraud alerts | Suspicious activity notices | If you have multiple use cases, a **mixed-use campaign** covers them all under one brand. For smaller senders, **low-volume mixed** offers the same flexibility with a cap of 2,000 messages per day. This is usually what Sent recommends for growing businesses and startups. ### TCR fees [#tcr-fees] TCR charges pass-through fees for campaign registration. Sent waives the first 12 months of these fees. | Campaign type | TCR fee | |---|---| | Low-volume mixed | $1.50/month | | Standard / high-volume | $10.00/month | **These are TCR's fees, not Sent's.** Sent charges its own campaign fee on top of them, and the 12-month waiver covers only the TCR pass-through fees. Sent's fee depends on the volume tier you pick and is billed on its own schedule, which is not always monthly. You see the exact amount and billing period for your tier in the dashboard when you register the campaign, before you confirm. Check there rather than budgeting from this table. --- ## What goes into your submission [#what-goes-into-your-submission] ### Brand name [#brand-name] **Brand name matters.** This field should not be your official legal name. It should be how your customers actually know you. If your LLC is registered as "Kevin's Donuts LLC" but your website and receipts say "Kevin's Donuts," use the latter. That's what appears in messages to your customers and needs to match what they'd recognize. ### Campaign description [#campaign-description] Keep this short: one or two sentences covering who's sending, what they're sending, and why. ### Opt-in method [#opt-in-method] You need to document how you get consent from people before texting them. TCR calls this your **message flow**. Someone fills out a form on your site. You provide the URL and describe how they get there. The form itself has its own requirements (see below). Gathered over the phone or in person. Document the script used, where the contact info is published, and whether it's phone or in-person. Marketing use cases require double opt-in if consent is spoken. You publish a number and keyword, and subscribers text it to opt in. Best practice is to display the full disclaimer wherever you publish the number. A physical form collected during an in-person visit, with a hosted screenshot submitted as documentation. ### Opt-in form requirements [#opt-in-form-requirements] If your 10DLC keeps getting rejected, the form is usually why. Carriers are strict about explicit consent: missing even one element is enough to fail. If you're using a web or paper form, it needs **all of the following**, clearly visible before the user hits submit (not buried in fine print): - **Program name**: make it clear who is texting them and what the program is - **Message frequency**: something concrete, like "Max 4 msgs/month," not "frequency may vary" - **Cost warning**: "Msg & data rates may apply" - **Opt-out info**: "Reply STOP to opt out" or "Text STOP to cancel" - **Legal links**: direct links to your Privacy Policy and Terms of Service - **Full disclaimer** (or equivalent): > *You are opting in to receive [message types] from [Brand]. Msg and data rates may apply. Msg frequency may vary. Reply HELP for help or STOP to opt out. No mobile information will be sold or shared with third parties for promotional or marketing purposes.* - SMS consent is voluntary, distinct, and explicit, typically an unchecked optional checkbox - The checkbox **cannot be pre-checked** For marketing campaigns, the language should make clear the messages are promotional. For charity or political campaigns, note whether donations will be solicited. --- ## Autoresponse requirements [#autoresponse-requirements] Every 10DLC campaign needs three documented autoresponses. Each has required elements. Triggered by START or a related keyword. Must include: - Brand name - Reply HELP for help - Reply STOP to opt out - Msg and data rates may apply - Msg frequency may vary **Example:** ``` [Brand]: Welcome! Please reply HELP for help. Message frequency may vary. Msg & data rates may apply. Reply STOP to opt out. ``` Triggered by STOP or related keywords. Must include: - Brand name - Unsubscription confirmation - Notice that no more messages will be sent **Example:** ``` [Brand]: You have been unsubscribed and will not receive more messages. ``` Triggered by HELP or related keywords. Must include: - Brand name - An email, toll-free number, or URL where support can be reached **Example:** ``` [Brand]: Please contact us at [email / toll-free number / URL] for support. ``` --- ## Sample messages [#sample-messages] For each use case you select, submit at least one sample message. Mixed and marketing use cases require two. Every sample must include the brand name and look like a real message. | Use case | Example | |---|---| | Marketing | `[Brand]: Thanks for opting in! Use code DISCOUNT20 for 20% off through the end of the month.` | | Account notification | `[Brand]: Your password has been reset.` | | 2FA | `[Brand]: Your code is 123456.` | | Customer care | `[Brand]: Thanks for your message! We'll be right with you.` | | Delivery notification | `[Brand]: Your order has been delivered.` | | Fraud alert | `[Brand]: We noticed a suspicious transaction. Log in or call us to complete it.` | You can update sample messages later. What you **cannot** do later is send messages that fall outside your registered use cases. --- ## Agencies and resellers [#agencies-and-resellers] If you're sending on behalf of clients, each business needs its own campaign registration. You can't bundle clients under a single campaign: TCR ties campaigns to the business actually responsible for the messages. You can submit registrations manually for each client through the dashboard. If you're managing multiple brands, collect the required information within your platform and submit programmatically; [Register 10DLC Campaigns via the API](/start/advanced/10dlc-campaigns-api) covers the endpoints and bulk registration patterns. --- ## If you get stuck [#if-you-get-stuck] 10DLC registration is a one-time requirement for each brand you send from. If a form field is unclear or your submission is rejected and the resubmission steps don't resolve it, email [support@sent.dm](mailto:support@sent.dm); the support team typically responds within 1 business day. For errors that appear after approval, see [Compliance & 10DLC Issues](/troubleshooting/compliance). --- # Compliance & Regulations (/start/advanced/compliance-regulations.md) # Compliance & Regulations [#compliance--regulations] This page describes the compliance controls Sent enforces automatically at send time, the obligations that remain yours, and the primary messaging regulation for each region, with links to authoritative sources. For implementation code, see [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent). This page is an orientation, not legal advice. The linked regulation texts and regulator guidance govern; consult your legal counsel before launching campaigns in a new market. ## Enforced at Send Time [#enforced-at-send-time] Sent applies these controls to every outbound message. They run inside the message pipeline, after the API accepts the send with `202`; outcomes surface as message statuses and webhooks, never as synchronous HTTP errors. | Control | Behavior | Client-visible signal | |---------|----------|-----------------------| | Consent gate | Sends to opted-out or suppressed recipients are filtered before any provider call | `FILTERED` status, reason code `ERR_CONSENT_BLOCKED`, `message.filtered` webhook | | Opt-out keywords | An inbound opt-out keyword sets the contact's `opt_out` flag across all channels | `message.received` webhook, `opt_out` on the contact record | | Quiet hours | Sends inside a protected local-time window are held, then released automatically | `SCHEDULED` status, `message.scheduled` webhook | | RCS STOP chip | Every outbound RCS message carries a STOP suggested-reply chip | Visible on the delivered RCS message | ### Consent Gate [#consent-gate] Sent enforces a consent gate on every message. The gate runs inside the message pipeline, after the API accepts your send: if the recipient's contact has `opt_out = true`, or their phone is on your phone-channel suppression list, the message is finalized as `FILTERED` instead of being dispatched. No provider call is made and you are not charged. The block is recorded with reason code `ERR_CONSENT_BLOCKED` (see the [Error Catalog](/reference/api/error-catalog)); the client-visible signal is the `FILTERED` status. The gate is fully asynchronous. A `POST /v3/messages` batch is accepted with `202` like any other send, even when **every** recipient has opted out; there is no synchronous `BUSINESS_004` rejection. Each message is then finalized as `FILTERED` individually, so detect opt-out blocks from message statuses (`message.filtered` webhooks or `GET /v3/messages/{id}`), not from the HTTP response. Compliance auto-replies are exempt from the gate: the confirmations Sent sends in response to STOP, START, and HELP keywords are delivered even to opted-out contacts, because CTIA and TCPA guidance permits (and for STOP and HELP requires) that one reply. ### Opt-Out Keywords [#opt-out-keywords] Every account is seeded with the CTIA/TCPA-mandated default keywords. Matching is exact and case-insensitive: the entire trimmed message body must equal the keyword. | Action | Default keywords | Effect | |--------|------------------|--------| | Opt out | `STOP`, `CANCEL`, `UNSUBSCRIBE`, `QUIT`, `END` | Sets `opt_out = true` on the contact | | Opt in | `START`, `UNSTOP`, `SUBSCRIBE` | Sets `opt_out = false` on the contact | | Help | `HELP`, `INFO` | Triggers the configured HELP auto-reply | Opt-out is contact-level and channel-agnostic: a `STOP` received on any channel suppresses the contact on SMS, WhatsApp, and RCS alike. Custom keywords are configured in the dashboard under **Compliance → Opt-Out Keywords**. Keyword mechanics, auto-replies, and per-channel caveats are covered in [Two-Way Conversations](/start/guides/two-way-conversations). ### Quiet Hours [#quiet-hours] Quiet-hours rules are defined per destination country and can be scoped to specific channels and template categories. A send that lands inside a protected window is not failed: the message is held with status `SCHEDULED` and released automatically when the window opens. No action is required to release it. - The recipient's country and local time zones are derived from the phone number. - When a number spans multiple time zones, the message is held if any zone is inside a window and released only once the window has opened in all of them. - Held messages report status `SCHEDULED` on `GET /v3/messages/{id}` and fire a `message.scheduled` webhook. ### RCS STOP Chip [#rcs-stop-chip] Every outbound RCS message includes a `STOP` suggested-reply chip; when the template does not define one, Sent appends it automatically. Opt-out footer text is not required on RCS. A tap on the chip is processed through the same keyword pipeline as a typed `STOP`. ## Your Responsibilities [#your-responsibilities] Sent does not collect consent for you and does not know your marketing context. These obligations remain yours under every regulation listed below: - **Consent collection and records.** Obtain the legally required form of consent before the first message and keep proof. For US marketing texts this is prior express written consent. - **Sender registration.** US long-code traffic requires brand and campaign registration; see [10DLC Registration](/start/advanced/10dlc-registration). US toll-free numbers require toll-free verification before production traffic. - **Data-subject requests.** Deletion and access requests under GDPR, LGPD, and similar laws cover the contact data you store in Sent. To stop messaging someone, set `opt_out` with `PATCH /v3/contacts/{id}`, which keeps the consent record. `DELETE /v3/contacts/{id}` removes the contact itself and is the only API call that does, but it is deprecated: contact [support](mailto:support@sent.dm) before building an erasure path on it. - **Stricter send windows.** Some regimes and some US states restrict marketing hours more tightly than the platform's quiet-hours rules; apply your own send window where your legal review requires one. Implementation of all four (mirroring opt-outs, setting opt-out state through the API, and custom send windows) is covered in [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent). ## Regulations by Region [#regulations-by-region] The summaries below orient you; the linked source governs. | Region | Regulation | Core requirements | Authoritative source | |--------|------------|-------------------|----------------------| | United States | TCPA | Prior express written consent for marketing texts; telephone solicitations restricted to 8 AM–9 PM recipient local time | [47 CFR § 64.1200 (eCFR)](https://www.ecfr.gov/current/title-47/chapter-I/subchapter-B/part-64/subpart-L/section-64.1200) | | European Union | GDPR | Lawful basis for processing (typically consent for marketing); right to erasure; records of processing | [Regulation (EU) 2016/679 (EUR-Lex)](https://eur-lex.europa.eu/eli/reg/2016/679/oj) | | Canada | CASL | Express consent before sending; sender identification and an unsubscribe mechanism in every message | [Canada's Anti-Spam Legislation (ISED)](https://ised-isde.canada.ca/site/canada-anti-spam-legislation/en) | | United Kingdom | PECR | Opt-in consent for electronic direct marketing | [Guide to PECR (ICO)](https://ico.org.uk/for-organisations/direct-marketing-and-privacy-and-electronic-communications/guide-to-pecr/) | | Australia | Spam Act 2003 | Consent, sender identification, and a functional unsubscribe facility | [Spam Act 2003 (Federal Register of Legislation)](https://www.legislation.gov.au/C2004A01214/latest/text) | | Singapore | PDPA | Consent for marketing messages; Do Not Call Registry checks | [Personal Data Protection Act (PDPC)](https://www.pdpc.gov.sg/overview-of-pdpa/the-legislation/personal-data-protection-act) | | Brazil | LGPD | Legal basis for processing personal data; data-subject rights | [ANPD (national data protection authority)](https://www.gov.br/anpd/pt-br) | ## Related Pages [#related-pages] - [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent): mirroring opt-outs, API opt-out, custom send windows - [Two-Way Conversations](/start/guides/two-way-conversations): keyword matching, auto-replies, cross-channel opt-out - [Trust & Safety](/start/concepts/trust-and-safety): the full send-time policy pipeline - [10DLC Registration](/start/advanced/10dlc-registration): US sender registration # Advanced Guides Overview (/start/advanced.md) # Advanced Guides Overview [#advanced-guides-overview] Advanced guides for power users, platforms, and enterprises building mission-critical messaging systems. ## Topics [#topics] These guides assume familiarity with Sent fundamentals. If you're new, start with the [Quickstart](/start/quickstart) and [Core Concepts](/start/concepts). --- # API v2 to v3 Migration (/start/advanced/migration-v2-v3.md) # API v2 to v3 Migration [#api-v2-to-v3-migration] Migrate your integration from the legacy v2 API to the current v3 API. ## Key Differences [#key-differences] | Feature | v2 | v3 | |---------|-----|-----| | Base URL | `api.sent.dm/v2` | `api.sent.dm/v3` | | Auth Header | `x-sender-id` + `x-api-key` | `x-api-key` (or `Authorization: Bearer`) | | Request Body | `phoneNumber` or `contactId`, `templateId`, `templateVariables` | `to`, `template` (object with `id`/`name`/`parameters`), `channel` | | Response Format | Flat data | Envelope with `success`, `data`, `error`, `meta` | | Rate Limits | Varies | 10,000 req/min (standard), 10 req/min (sensitive) | | Sandbox Mode | Not available | `sandbox: true` | | Templates | Simple text | Structured components | | Contacts | Basic | Channel intelligence | ## Authentication Changes [#authentication-changes] ### v2 (Legacy) [#v2-legacy] ```http GET /v2/messages/{id} x-sender-id: your-sender-id x-api-key: your-api-key ``` ### v3 (Current) [#v3-current] ```http GET /v3/messages/{id} x-api-key: your-api-key ``` ## Request Format Changes [#request-format-changes] ### Sending Messages [#sending-messages] #### v2 (Legacy) [#v2-legacy-1] v2 sends to one recipient per request through separate endpoints. `POST /v2/messages/phone` is shown here; `POST /v2/messages/contact` takes `contactId` instead of `phoneNumber`: ```json { "phoneNumber": "+1234567890", "templateId": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "templateVariables": { "name": "John", "order_id": "12345" } } ``` #### v3 (Current) [#v3-current-1] ```json { "to": ["+1234567890"], "template": { "id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "name": "order_confirmation", "parameters": { "name": "John", "order_id": "12345" } }, "channel": ["sms"], "sandbox": false } ``` **Key Changes:** - Separate `/v2/messages/phone` and `/v2/messages/contact` endpoints → single `POST /v3/messages` - `phoneNumber` (single string) → `to` (array of recipients) - `templateId` → `template.id` (inside the `template` object) - `templateVariables` → `template.parameters` - Added `template.name` (optional) - Added `channel`: explicit per-request channel selection - Added `sandbox`: sandbox mode is new in v3; v2 has no equivalent ## Response Format Changes [#response-format-changes] ### v2 (Legacy) [#v2-legacy-2] `POST /v2/messages/phone` returns `202 Accepted` with a bare message ID: ```json { "messageId": "8ba7b830-9dad-11d1-80b4-00c04fd430c8" } ``` ### v3 (Current) [#v3-current-2] ```json { "success": true, "data": { "status": "QUEUED", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+1234567890", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_abc123", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` **Key Changes:** - Response is now wrapped in an envelope with `success`, `data`, `error`, `meta` - Bare `messageId` → one entry per recipient and channel in `data.recipients[]`, each with its own `message_id` - Added `meta.request_id` to quote in support tickets ## Error Format Changes [#error-format-changes] ### v2 (Legacy) [#v2-legacy-3] v2 returns RFC 9110 problem details with human-readable text only: ```json { "type": "https://www.rfc-editor.org/rfc/rfc9110#section-15.5.1", "title": "One or more validation errors occurred.", "status": 400, "errors": { "PhoneNumber": ["Phone number is required"] } } ``` ### v3 (Current) [#v3-current-3] ```json { "success": false, "status": 402, "error": { "code": "BUSINESS_003", "message": "Account balance is insufficient to send this message", "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_abc123", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` **Key Changes:** - Errors now use the same envelope as success responses (`success: false`, `error`, `meta`) instead of RFC 9110 problem details - Added machine-readable `error.code` values prefixed by category (for example, `BUSINESS_003`, `AUTH_001`, `VALIDATION_002`); match on the code instead of parsing message text - Added `doc_url` with link to error documentation ## Webhook Event Changes [#webhook-event-changes] ### v2 (Legacy) [#v2-legacy-4] Legacy webhooks delivered a flat body identified by a `type` field with the plural value `messages`: ```json { "type": "messages", "timestamp": "2025-01-15T08:30:15Z", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "recipient_phone_number": "+1234567890", "message_status": "DELIVERED", "channel": "sms" } ``` ### v3 (Current) [#v3-current-4] ```json { "field": "message", "event": "message.delivered", "timestamp": "2025-01-15T08:30:15Z", "payload": { "updated_at": "2025-01-15T08:30:15Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1234567890", "message_status": "DELIVERED", "channel": "sms" } } ``` **Key Changes:** - `type` renamed to `field`; its value changed from `messages` (plural) to `message` (singular) - Added `event`: granular sub-type (such as `message.delivered`, `message.failed`) - Added `payload` wrapper: event data is now nested under `payload` - `message_id`, `template_id`, `message_status`, and `channel` moved into `payload` - `recipient_phone_number` → `payload.outbound_number` - Added `payload.updated_at`, `payload.account_id`, and `payload.template_name` - Webhooks still subscribed to the legacy `messages` event type keep receiving all `message.*` events; see the [Events Reference](/start/webhooks/event-types) for the full catalog ## Endpoint Mapping [#endpoint-mapping] | v2 Endpoint | v3 Endpoint | Changes | |-------------|-------------|---------| | `POST /v2/messages/contact` | `POST /v3/messages` | Single send endpoint; new request/response format | | `POST /v2/messages/phone` | `POST /v3/messages` | Single send endpoint; new request/response format | | `GET /v2/messages/{id}` | `GET /v3/messages/{id}` | Response uses envelope format | | `GET /v2/contacts` | `GET /v3/contacts` | Response uses envelope format | | Not available in v2 | `POST /v3/contacts` | New in v3: create contacts through the API | | `POST /v2/templates` | `POST /v3/templates` | New template structure | ## Idempotency Changes [#idempotency-changes] ### v2 (Legacy) [#v2-legacy-5] v2 has no idempotency support: retrying a timed-out request can send the same message twice. ### v3 (Current) [#v3-current-5] ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: order_123_456" \ -d '{ "to": ["+1234567890"], "template": {"id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8"} }' ``` **Key Changes:** - Idempotency is new in v3: send an `Idempotency-Key` header on write requests to make retries safe - Keys are cached for 24 hours ## Migration Steps [#migration-steps] 1. **Update Base URL** - Change from `/v2` to `/v3` 2. **Update Authentication** - Remove the `x-sender-id` header. Keep `x-api-key`, or send the key as `Authorization: Bearer` instead 3. **Update Request Format** - Replace `phoneNumber`/`contactId` with the `to` array, `templateId` with `template.id`, and `templateVariables` with `template.parameters` 4. **Update Response Handling** - Handle the new envelope format with `success`, `data`, `error`, `meta` 5. **Update Error Handling** - Match on the new `error.code` values (for example, `BUSINESS_003`) instead of parsing error text 6. **Update Webhook Handlers** - Adjust for new nested event structure (`payload` wrapper added; use `payload.message_id` and `payload.message_status`) 7. **Add Idempotency** - Send an `Idempotency-Key` header on write requests (new in v3) 8. **Test in Sandbox Mode** - Validate all features with `sandbox: true` 9. **Deploy Gradually** - Use feature flags for rollout The v2 API is deprecated for new integrations but remains operational, and no sunset date has been announced. New capabilities such as sandbox mode, idempotency keys, and contact creation ship in v3 only, so plan your migration now rather than against a deadline. Watch the [API changelog](/reference/changelog) for version and deprecation announcements. --- # Multi-tenant architectures on Sent: profiles vs. accounts (/start/advanced/multi-tenant-architectures.md) # Multi-tenant architectures on Sent: profiles vs. accounts [#multi-tenant-architectures-on-sent-profiles-vs-accounts] This guide shows you how to choose and set up a tenant model for a platform or ISV that sends messages on behalf of multiple customers. Sent's primary multi-tenancy mechanism is [Sender Profiles](/start/concepts/sender-profiles): isolated messaging identities inside one organization, provisioned through the API. A single shared account and fully separate accounts remain workable alternatives at the two ends of the isolation spectrum, and both are covered below with their constraints. It assumes you can already [send messages](/start/guides/sending-messages). The profile-based setup additionally requires an **organization account** ([`GET /v3/me`](/reference/api/accounts/SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint) returns `"type": "organization"`) and an API key whose user has the `admin` role. See [roles and permissions](/reference/api/roles-and-permissions). ## Compare the three tenant models [#compare-the-three-tenant-models] | | Sender Profiles | One shared account | Separate accounts | | --- | --- | --- | --- | | **Isolation** | Contacts and templates are always dedicated per profile; the identity, campaign, and billing are inherited or dedicated | None (every tenant shares all resources) | Complete (nothing shared) | | **Tenant provisioning** | API: [`POST /v3/sender-profiles`](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesCreateSenderProfileEndpoint), one call | None needed | Manual: each tenant signs up for their own account, and the API has no account-creation endpoint | | **Billing** | Organization, dedicated, or dedicated with organization backing (`billing`) | One bill to you | Each tenant pays Sent directly | | **Credentials** | Per-profile API key, or one organization key scoped with `x-profile-id` | One API key | One API key per tenant, managed by you | | **Rate limit pool** | A separate pool per profile key; requests scoped via `x-profile-id` draw from the organization's pool | One pool shared by all tenants | A separate pool per account | To pick a model: - If you onboard tenants programmatically, or tenants need a dedicated US A2P (TCR) registration, a dedicated sender, or a WhatsApp presence of their own, use **Sender Profiles**. Isolated contact lists and templates come with the model rather than being a reason to choose it. - If every tenant sends the same kind of content under your platform's single brand and sender identity, a **shared account** is enough, provided you accept the shared rate limit pool and build tenant attribution yourself. - If tenants must own their Sent relationship end to end (their own login and billing relationship, no shared organization), use **separate accounts** and treat each one as an independent integration. ## Build on Sender Profiles [#build-on-sender-profiles] This is the recommended model: one organization, one profile per tenant. The full provisioning walkthrough with every field, status, and failure mode is [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api); the sequence below is the architecture-level view. ### Provision a profile per tenant [#provision-a-profile-per-tenant] One call. `name` and `short_name` are the only required fields; billing says who pays, and a `channels.sms` block says whether the tenant gets a dedicated sender: ```bash curl -X POST "https://api.sent.dm/v3/sender-profiles" \ -H "x-api-key: $ORG_API_KEY" \ -H "Idempotency-Key: create-profile-tenant-42" \ -H "Content-Type: application/json" \ -d '{ "name": "Tenant 42 Coffee Co", "short_name": "T42COFFEE", "description": "Sender profile for tenant 42", "billing": { "inherit": true } }' ``` `billing: {"inherit": true}` keeps charges on your platform's bill, and `{"inherit": false}` bills the tenant alone. Omit the block and the tenant pays first, with your organization covering what the tenant's balance can't. Contacts and templates stay isolated to the tenant either way — there is nothing to configure and no way for one tenant to see another's. There is no completion step and no callback to receive: the profile is usable as soon as it is created. With no sender of its own it reaches only the countries Sent runs a shared route for, and the US isn't one of them: SMS to US numbers needs a US `TEN_DLC` number on the profile. For a US `TEN_DLC` market, it runs on your 10DLC brand and campaign only if the request says so, with `"compliance": { "brand": { "inherit": true }, "campaign": { "inherit": true } }`; without `compliance` it has neither. Give it a dedicated sender, and register its compliance, with [`POST /v3/channels/sms`](/start/guides/managing-channels#sms-markets) when the tenant needs one. The response carries the profile's `api_key`, shown once and never returned again. ### Route each tenant's traffic [#route-each-tenants-traffic] Two options, usable side by side: - **Per-profile API keys**: store one key per tenant and instantiate the client with it. Each profile key gets a separate 10,000 requests-per-minute [rate limit pool](/reference/api/rate-limits): one tenant's burst cannot starve another's. - **One organization key + `x-profile-id`**: keep a single credential and scope each request to a profile by UUID. All scoped requests draw from the organization's rate limit pool. ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{"to": ["+15551234567"], "template": {"id": "tmpl_123"}}' ``` Only organization keys may send `x-profile-id`; profile keys are rejected with `403`, and a profile outside your organization returns `404`. Per-language client code for both patterns is in [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles). ### Attribute webhook events to tenants [#attribute-webhook-events-to-tenants] Select events under `sender_profile` on your organization's webhook, and Sent clones it onto every profile, including profiles you create later, so every tenant's events arrive at one endpoint. Each event names its profile in `payload.account_id`, so map that ID to the tenant. The receiver code is in [Track usage per profile in webhooks](/start/guides/integrating-sender-profiles#track-usage-per-profile-in-webhooks), and the clones are documented in [Sender Profile Events](/start/webhooks/event-types#sender-profile-events). Isolation is per resource, not all-or-nothing: contacts, templates, and the sender are always dedicated to the profile, while the brand, the campaign, and billing can be inherited from your organization. See the [governance model](/start/concepts/sender-profiles#resource-governance-model) for what each resource does. ## Alternative: one shared account [#alternative-one-shared-account] If all tenants message under your platform's brand, with the same sender identity, the same templates, and no per-tenant compliance registration, you can run everything through a single account. The send request has no tenant or metadata field, so tenant attribution is entirely your app's job. Record the mapping when you send, using the `message_id` values the API returns: ```typescript const response = await client.messages.send({ to: recipients, template: { id: templateId } }); // The request body carries no tenant identifier — persist the mapping yourself await db.messages.insertMany( response.data.recipients.map((r) => ({ sentMessageId: r.message_id, to: r.to, tenantId: tenant.id })) ); ``` Webhook handlers then look up the tenant by `payload.message_id`. Every tenant shares your account, so `payload.account_id` is the same for all of them and can't tell them apart. That field is what the [per-profile attribution pattern](/start/guides/integrating-sender-profiles#track-usage-per-profile-in-webhooks) keys on instead. Constraints to plan for: - All tenants share one 10,000 requests-per-minute pool. The ceiling is high enough that a single tenant is unlikely to starve the others, but one runaway tenant can still consume it. Enforce per-tenant quotas in your own app. See [How to handle Sent API rate limits](/start/guides/handling-rate-limits). - Every tenant sends from the same numbers, templates, and TCR registration; a compliance problem caused by one tenant affects all of them. - If you later need isolation, you can move a tenant onto a Sender Profile without leaving your organization. That migration path is the main argument for starting with profiles even when sharing would work today. ## Alternative: separate accounts per tenant [#alternative-separate-accounts-per-tenant] If each tenant must be Sent's customer of record (their own login, billing, and compliance standing, and no shared organization), give each tenant a separate account. There is no API for creating accounts, so each tenant signs up through the dashboard themselves; your platform stores their API key and treats each account as an independent integration: ```typescript // One secrets-manager entry per tenant; a leaked key exposes one tenant, not all const client = new SentDm({ apiKey: await secrets.get(`sent-api-key-${tenant.id}`) }); ``` Each account has its own rate limit pool and its own bill. The costs are operational: onboarding cannot be automated, nothing (templates, contacts, registration) can be shared, and there is no organization-level view across tenants. Before choosing this model, check whether a Sender Profile with dedicated billing and a dedicated sender already gives the tenant what they actually need (direct billing and full data isolation) without giving up API provisioning. ## Verify your setup [#verify-your-setup] - Send a test message as one tenant and confirm the `202` response, then confirm its delivery events resolve to that tenant. With their profile key or `x-profile-id` scope, `payload.account_id` is the tenant's profile. With an account key, look the `message_id` values up in the mapping you stored when sending. - For profile-based setups, list templates with tenant A's key and confirm you see only that profile's templates, never tenant B's. - For shared-account setups, confirm your per-tenant quota enforcement triggers before the account-wide limit does: a tenant at its quota should be throttled by your app, not by a `429` that affects every tenant. ## Related pages [#related-pages] - [Sender Profiles](/start/concepts/sender-profiles): the inheritance and governance model behind profile-based multi-tenancy - [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api): the full provisioning walkthrough - [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles): per-tenant sending and webhook attribution in eight languages - [Creating a Sender Profile](/start/guides/creating-a-sender-profile): the dashboard flow - [Rate Limits](/reference/api/rate-limits): pool scoping rules for accounts, profiles, and `x-profile-id` # Performance optimization: high throughput on the Sent API (/start/advanced/performance-optimization.md) # Performance optimization: high throughput on the Sent API [#performance-optimization-high-throughput-on-the-sent-api] This guide shows you how to get maximum throughput from a Sent integration: work within the documented rate limits, use batching to raise your effective ceiling, stop spending requests on avoidable reads and polling, and structure sustained volume around a queue. It assumes you can already [send messages](/start/guides/sending-messages). ## Stay under the rate limits [#stay-under-the-rate-limits] All throughput planning starts from two numbers, both applied per customer account: | Tier | Limit | Window | Applies to | | --- | --- | --- | --- | | Standard | 10,000 requests per minute | Sliding 60-second window | All endpoints, including `POST /v3/messages` | | Sensitive | 10 requests per minute | Fixed 60-second window | `POST /v3/webhooks/{id}/rotate-secret` and `POST /v3/webhooks/{id}/test` only | Three properties of the limits shape everything else in this guide: - **The pool is shared per account.** Every API key on the account draws from the same 10,000 requests per minute, and requests scoped to a profile with the `x-profile-id` header count against the organization's pool. Budget the limit across your workers rather than letting each one assume it has 10,000. - **There is no quota readout on successful responses.** The `X-RateLimit-*` headers and `Retry-After` appear only on `429` responses, so treat each `429` as your pressure signal: honor `Retry-After` before retrying, and count `429`s in your metrics. - **Failed validation still costs budget.** Requests rejected with `400` or `422` count toward the limit (only `401`/`403` authentication rejections do not), so an oversized or malformed batch consumes a request without sending anything. Refer to the [Rate Limits reference](/reference/api/rate-limits) for the per-endpoint table and the `429` response format, and to [How to handle Sent API rate limits](/start/guides/handling-rate-limits) for ready-made backoff, monitoring, and throttling implementations in TypeScript, Python, and Go. ## Batch recipients to raise the ceiling [#batch-recipients-to-raise-the-ceiling] Limits count **per request, not per recipient**, and a single `POST /v3/messages` accepts up to **1,000 recipients**. That makes batching the most effective optimization available: 10,000 requests per minute at 1,000 recipients each is a ceiling of 10 million accepted messages per minute from one account, a thousand times what per-recipient requests would allow. Chunk larger lists into slices of 1,000 (a request with more recipients fails validation with `400` and still counts against the limit), and give each batch a deterministic idempotency key so retries cannot double-send: ```typescript const BATCH_SIZE = 1000; // API maximum per request for (let i = 0; i < recipients.length; i += BATCH_SIZE) { await client.messages.send( { to: recipients.slice(i, i + BATCH_SIZE), template: { id: templateId } }, { idempotencyKey: `campaign_${campaignId}_batch_${i / BATCH_SIZE}` } ); } ``` At 1,000 recipients per request the rate limit stops being the binding constraint for most campaigns – a million-recipient list is 1,000 requests, a tenth of one minute's budget. The full campaign pattern, covering pacing, partial-failure handling, and reconciling accepted messages against webhook events, is in [Batch Operations](/start/guides/batch-operations). ## Reuse one client instance [#reuse-one-client-instance] Create the SDK client once, at startup or in your dependency container, and share it across requests and jobs. A shared client keeps HTTP connections alive and pooled, so high-volume sending does not pay a TLS handshake per request: ```typescript import SentDm from '@sentdm/sentdm'; // Create once at startup — not inside a request handler or per job export const sent = new SentDm({ apiKey: process.env.SENT_API_KEY }); ``` ## Cut requests with caching and webhooks [#cut-requests-with-caching-and-webhooks] The cheapest request is the one you never send, and every read you avoid is latency and infrastructure you don't pay for: - **Cache repeated reads.** Contact and template lookups (`GET /v3/contacts/{id}`, `GET /v3/templates/{id}`) that your send path repeats are cache candidates. Use a short TTL and remember that message and contact state changes server-side, so expire entries when webhook events tell you the underlying data moved. A worked caching example is in [the rate limits guide](/start/guides/handling-rate-limits#cache-responses-and-pace-batch-work). - **Never poll for delivery status.** Polling `GET /v3/messages/{id}` for every message in a campaign consumes the same pool your sends need. Subscribe to the [webhook events](/start/webhooks/event-types) `message.delivered`, `message.failed`, `message.filtered`, and `message.blocked` instead: delivery outcomes arrive as they happen and cost you zero requests. See [Message status tracking](/start/guides/message-status-tracking). ## Queue sends for sustained volume [#queue-sends-for-sustained-volume] For continuous high volume, as opposed to one-off campaigns, run sends through a persistent job queue (BullMQ, Sidekiq, Celery, or similar). The queue mechanics belong to your infrastructure; the Sent-specific requirements are: - One job per batch of up to 1,000 recipients, so each job makes exactly one `POST /v3/messages` call. - Worker concurrency capped so combined throughput stays under 10,000 requests per minute. - An idempotency key per job, so queue retries replay the original response instead of double-sending. See [How to retry Sent API requests safely](/start/guides/retrying-requests-safely). - The `message_id` values from each `202` response persisted, so webhook events can be matched back to jobs. The worked version of this pattern, including queue-depth monitoring, is in [Batch Operations](/start/guides/batch-operations#queue-based-processing). A `202` response means the batch was accepted, not delivered. Individual messages can still end `FAILED`, `FILTERED`, or `BLOCKED` asynchronously. Reconcile accepted IDs against webhook events rather than treating the `202` as delivery confirmation. ## Verify your throughput [#verify-your-throughput] Your integration is performing correctly when: - A campaign of *N* recipients completes in roughly *N* / 1,000 requests. If your request count is near *N*, you are not batching. - Steady-state traffic produces no `429` responses, and your metrics would show a spike if it started to. - Delivery outcomes arrive through webhooks, and your request log shows no per-message status polling. If you hit sustained `429`s after batching, caching, and pacing, your legitimate volume exceeds the account limit. Contact [support@sent.dm](mailto:support@sent.dm) about an increase, as described in [the Rate Limits reference](/reference/api/rate-limits#increasing-rate-limits). ## Related pages [#related-pages] - [Rate Limits](/reference/api/rate-limits): limit values, window semantics, headers, and the `429` body - [How to handle Sent API rate limits](/start/guides/handling-rate-limits): backoff, monitoring, and throttling implementations - [Batch Operations](/start/guides/batch-operations): campaign loops, bulk imports, and queue-based processing - [How to retry Sent API requests safely](/start/guides/retrying-requests-safely): idempotency keys for retried mutations # Create and activate Sender Profiles via the API (/start/advanced/sender-profiles-api.md) # Create and activate Sender Profiles via the API [#create-and-activate-sender-profiles-via-the-api] This guide shows you how to provision a [Sender Profile](/start/concepts/sender-profiles) through the API: create it, decide which resources are dedicated to it and which are inherited, give it a sender, and read what its compliance still owes. It is written for platforms and resellers that onboard tenants programmatically; for the dashboard flow, see [Creating a Sender Profile](/start/guides/creating-a-sender-profile), and for choosing between shared and per-tenant architectures, see [Multi-Tenant Architectures](/start/advanced/multi-tenant-architectures). This guide covers `/v3/sender-profiles`. The older `/v3/profiles` endpoints, including the two-step create-then-complete flow with a webhook callback, are **deprecated**. They still behave exactly as before, so nothing has to change today. See [Migrating from `/v3/profiles`](#migrating-from-v3profiles) at the end of this page. Before you start, you need: - An **organization account**. Call [`GET /v3/me`](/reference/api/accounts/SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint): the response `type` must be `organization`. - An organization API key whose user has the **`admin` role** in the organization. See [roles and permissions](/reference/api/roles-and-permissions) for how roles are granted. All requests authenticate with the `x-api-key` header. ## The minimum request [#the-minimum-request] A profile needs a name and a short name. Its inbox and opt-out list come from your organization. Its brand and campaign are your organization's only where `compliance` says `{ "inherit": true }`: a profile created without `compliance` has neither. Billing defaults to the profile's own balance, with your organization covering what the profile's balance can't: ```bash curl -X POST "https://api.sent.dm/v3/sender-profiles" \ -H "x-api-key: $ORG_API_KEY" \ -H "Idempotency-Key: create-profile-tenant-42" \ -H "Content-Type: application/json" \ -d '{ "name": "Tenant 42 Coffee Co", "short_name": "T42COFFEE" }' ``` | Field | Rule | | --- | --- | | `name` | Required. Up to 200 characters. | | `short_name` | Required. This is the SMS sender id, so it must be 3–11 characters of letters, numbers, and spaces, with at least one letter. | | `description` | Optional. | | `notifications` | Optional. Who receives email notifications about the profile, such as template review decisions, 10DLC registration updates, and an SMS sender going live, being removed, or being declined: `ORGANIZATION` (the organization's email, the default), `SENDER_PROFILE` (the contact email on the profile's brand), or `ORGANIZATION_AND_SENDER_PROFILE`. If the profile's brand has no contact email, notifications go to the organization. Reads always include it, as `ORGANIZATION` for a profile that never set it. | The response carries the profile, its `id`, and its `api_key`. **The key is shown once, by create, and is never returned again.** Store it before you discard the response. Reads never include it. The status code tells you whether anything is still in flight: | Code | Meaning | | --- | --- | | `201` | The profile is complete on return, because nothing needed registering. | | `202` | The profile was accepted and something is provisioning. Read its channels for the per-capability status. | Neither is an error, and neither needs a callback: there is no completion step to run and nothing to wait for before the profile is usable. ## Dedicated, inherited, or absent [#dedicated-inherited-or-absent] Every capability is one of three things, and there is no flag per state: | You want | Send | | --- | --- | | Dedicated to the profile | The capability's fields | | Inherited from the organization | `{ "inherit": true }`, with nothing else | | Neither | Omit the block entirely | There is no `"inherit": false` that also carries no data: a second way to say the same thing would let a request contradict itself. Billing is the one exception, described below. Inheriting needs no id, because a customer has exactly one brand. **Inheriting is opt-in.** The brand and campaign are a US `TEN_DLC` registration, so inheriting them only matters for a `TEN_DLC` market. A profile uses the organization's registration only when the request says `{ "inherit": true }`. Create stores that choice even without a `TEN_DLC` market, and it applies when the profile adds one later. Send both halves to run on the organization's registration: ```json { "compliance": { "brand": { "inherit": true }, "campaign": { "inherit": true } } } ``` - `"brand": { "inherit": true }` on its own inherits the brand only. The campaign is then the profile's own, so a `TEN_DLC` market asks for every campaign field. - A request can't inherit the campaign while giving the profile a brand of its own, or `"brand": { "inherit": false }`: that's a `400` on `compliance.campaign`. A campaign is filed against a brand, and your organization's campaign is filed against your organization's brand. Inherit both, own both, or inherit the brand and own the campaign. - On a `TEN_DLC` market, inheriting a brand or campaign your organization doesn't have yet is a `400`. Register the organization's brand or create its campaign first, or supply the profile's own. ### Brand and campaign [#brand-and-campaign] The brand and the campaign can each be inherited, but not in every combination: | `compliance` | Result | | --- | --- | | `"brand": { "inherit": true }` | The profile runs on the organization's brand. Its campaign stays its own. | | `"campaign": { "inherit": true }`, with `brand` omitted or `{ "inherit": true }` | The profile runs on the organization's campaign and on its brand. A campaign is filed against a brand, so inheriting the campaign inherits the brand with it. | | `"campaign": { "inherit": true }` with the brand's own fields, or with `"brand": { "inherit": false }` | `400` on `compliance.campaign`. An inherited campaign can't sit under a brand of the profile's own. | On a market that registers with a regime, such as US `TEN_DLC`, the organization must already have what the profile inherits. Inheriting a brand or campaign the organization doesn't have is a `400` naming `compliance.brand` or `compliance.campaign`. The organization's campaign only has to exist, not be approved: a profile inheriting a campaign still in review gets its number when the campaign is approved. **A sender is the exception.** A brand and a campaign can be inherited; a number cannot. A profile either has a dedicated sender, through `channels.sms`, or it has none and reaches only the countries Sent runs a shared route for. The US has none: without a `TEN_DLC` number of its own, a profile's SMS to US numbers ends as `FAILED` with reason code `DELIVERY_003`. ### Billing [#billing] ```json { "billing": { "inherit": true } } ``` | Send | Who pays | | --- | --- | | Omit `billing` | The profile pays first, and your organization covers what the profile's balance can't | | `{ "inherit": false }` or `{}` | The profile only | | `{ "inherit": true }` | Your organization | Reads report the default as `{ "inherit": false }`, the same as a profile that pays alone. To tell the two apart, read `settings.billing_model` from [`GET /v3/account`](/reference/api/accounts/SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint) as the profile, or `profiles[].settings.billing_model` as the organization. It reports `profile`, `organization`, or `profile_and_organization`. ## Giving the profile a sender [#giving-the-profile-a-sender] ### Ask the market what it wants [#ask-the-market-what-it-wants] Call [`GET /v3/compliance/requirements`](/reference/api/compliance/SentDmServicesEndpointsCustomerAPIv3ComplianceGetComplianceRequirementsEndpoint) **first**. It returns what the market demands and `setup[]`, the calls that satisfy it, each with a body you can copy and send as it stands: ```bash curl "https://api.sent.dm/v3/compliance/requirements?channel=sms&country=US&type=TEN_DLC" \ -H "x-api-key: $ORG_API_KEY" ``` `channel` defaults to `sms`, which is the only channel answered today; `whatsapp` and `rcs` return `501` until their requirements are declared. Requirements vary enormously by market: US `TEN_DLC` registers a brand and a campaign with The Campaign Registry and asks for a substantial set of values, while an alphanumeric sender needs supporting documents in one country and nothing at all in another. The response gives you `requirements[]` — each entry keyed as you write it, such as `brand.legal_name` or `campaign.message_flow` — plus `sender_id_pattern` for the values the market accepts, and `setup[]`. There is always exactly one setup step, `POST /v3/channels/sms`, because the identity travels in that call's body rather than needing a separate call. Anything that cannot be a JSON value, such as an uploaded document, is listed under `attachments` instead of in the body template. This is the same declaration that validates the calls themselves, so it cannot drift from what the API accepts. ### Add the market [#add-the-market] You can name the profile's first market at create time: ```bash curl -X POST "https://api.sent.dm/v3/sender-profiles" \ -H "x-api-key: $ORG_API_KEY" \ -H "Idempotency-Key: create-profile-tenant-42" \ -H "Content-Type: application/json" \ -d '{ "name": "Tenant 42 Coffee Co", "short_name": "T42COFFEE", "billing": { "inherit": true }, "channels": { "sms": { "country": "US", "number_type": "TEN_DLC" } }, "compliance": { "brand": { "inherit": true }, "campaign": { "inherit": true } } }' ``` Or add it afterwards, and add every market after the first, with [`POST /v3/channels/sms`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddSmsChannelEndpoint) and the `x-profile-id` header. Create takes one market; the sub-resource takes the rest. See [Managing channels](/start/guides/managing-channels) for that call in full. | Field | Rule | | --- | --- | | `channels.sms.country` | Required when `channels.sms` is present. ISO 3166-1 alpha-2, for example `US`. | | `channels.sms.number_type` | Required when `channels.sms` is present. `LOCAL`, `MOBILE`, `TEN_DLC`, `TOLL_FREE`, `SHORT_CODE`, or `ALPHANUMERIC`. `10DLC` is accepted as a synonym of `TEN_DLC`. Availability varies by country. | | `channels.sms.sender_value` | Only for the types where you choose the sender rather than the carrier assigning it — an alphanumeric sender id, a short code, or a number you already own. **Required** when `number_type` is `ALPHANUMERIC`; leaving it out is a `400`. Omit it for carrier-assigned types and one is provisioned. | | `channels.sms.area_codes` | Optional, `LOCAL` or `TEN_DLC` only. The area codes to take the number from, in your order of preference, for example `["415", "628"]`: one to 50 entries, each listed once. Each code is tried in turn and is honored exactly: you get a number in one of the codes you named or none yet, never a neighboring code. Omit it for a number anywhere in the country. | | `channels.sms.numbers` | Optional, `LOCAL` or `TEN_DLC` only, and not together with `area_codes`. Several numbers in one request, one entry per area code: `[{ "area_code": "212", "quantity": 2 }, { "area_code": "415" }, { "quantity": 1 }]` asks for two numbers in 212, one in 415, and one in any area code. `quantity` defaults to 1; an entry without `area_code` means any area code, and only one entry may leave it out. Omit `numbers` for one number. At most 49 numbers in total, and on `TEN_DLC` the limit counts every number on the campaign. Not available when the profile inherits the organization's campaign. US `TEN_DLC` numbers are assigned when the campaign is approved, not at request time. | `compliance.brand` is **required** when `number_type` is `TEN_DLC`, either as `{ "inherit": true }` or as the identity's fields. A 10DLC registration attaches to an identity, and no later call can supply it, so a request without one is a `400` rather than a market left with something outstanding. An empty `brand` object, or `{ "inherit": false }` on its own, names no identity either and is refused the same way. The OpenAPI document marks only `country` as required inside `channels.sms`. The validator also requires `number_type`. ### Read where the sender stands [#read-where-the-sender-stands] `GET /v3/sender-profiles/{id}` reports every market the profile sends in, each with its own status and outstanding compliance: ```bash curl "https://api.sent.dm/v3/sender-profiles/$PROFILE_ID" \ -H "x-api-key: $ORG_API_KEY" ``` The document mirrors the create request, with three differences that follow from a read not being a request: - **`channels.sms` is a list.** Create takes the one market a profile starts in; a profile can go on to send in several. - **`brand` comes back in full, with `inherit` saying whose it is.** On a request, `{ "inherit": true }` carries no data because there is nothing to send; here it carries the data, because the point of a read is to say what the profile actually sends under. - **There is no `campaigns` array.** A campaign is only ever a registration, so what a read can usefully say is whether anything is still owed for it — reported per market, in `channels.sms[].compliance.requirements`. A profile on the organization's campaign is asked for none of the campaign fields, so an empty `requirements` is how an inherited campaign reads. Status lives on the channel, never on the profile or the brand. A profile live in one country and mid-registration in another reports exactly that: | Status | Meaning | | --- | --- | | `PROVISIONING` | Sent is arranging the sender; nothing is required from you | | `ACTION_NEEDED` | Something is owed: read `compliance.requirements` for the keys, or a resubmission has been asked of you. Send it with `PATCH /v3/channels/sms/{country}/{type}` | | `PENDING_REVIEW` | With a carrier or registry (filed, or assembled and queued for Sent to file), and their answer is what moves it | | `ACTIVE` | The market can send | An empty `requirements` means that market is satisfied. Anything listed is what to supply, keyed as you write it. Every channel that is not `ACTIVE` also carries `reason_code` and `reason`, which say what it's waiting on; see [`reason_code` and `reason`](/start/guides/managing-channels#reason_code-and-reason). A profile belonging to another organization reads as `404` rather than `403`: saying which of the two it is would confirm the id exists. ### Correct what compliance holds [#correct-what-compliance-holds] `PATCH /v3/channels/sms/{country}/{type}` writes what a market declares, and answers with the market as stored — the same shape `GET` on that path returns, so what comes back can be sent back: ```bash curl -X PATCH "https://api.sent.dm/v3/channels/sms/us/ten_dlc" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{ "compliance": { "brand": { "tax_id": "12-3456789" } } }' ``` The write is partial at every level: an omitted key is left alone, and an explicit `null` clears it. Those are different requests, so `{}` changes nothing and is refused rather than silently accepted. Correcting one field does not blank the others. A `requirements` key is the path into the body that clears it. Nothing here creates a second anything — one identity and one campaign per market — so a write is an upsert and a replayed request lands on the row it already wrote. The same call clears everything else an `ACTION_NEEDED` market can ask for: documents, sent as `multipart/form-data` files named after their key, in any market; a registration sent back for correction; and `numbers`, the list the market asks for. See [Correct what it holds](/start/guides/managing-channels#correct-what-it-holds) for each. ### Operate as the profile [#operate-as-the-profile] To call any `/v3` endpoint as the profile, add the `x-profile-id` header to a request made with your organization API key: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{ "to": ["+15551234567"], "template": {"id": "tmpl_123"} }' ``` The request executes as the profile and the response echoes the scope in an `X-Profile-Id` header. Only organization API keys can use `x-profile-id`; profile-scoped keys are rejected with `403`, and a profile id outside your organization returns `404`. If you would rather hand tenants their own credentials than proxy through your organization key, use the `api_key` that create returned. See [API credentials and isolation](/start/concepts/sender-profiles#api-credentials-and-isolation). ## Listing, updating, and deleting [#listing-updating-and-deleting] **List** with `GET /v3/sender-profiles`, newest first. `page` and `page_size` are both required. Each entry is the same document a single read returns, with one difference: **listed markets carry no `compliance`**. Working out what a market owes means a catalog lookup and a document read per market, and doing that for every profile on a page would turn one request into dozens to answer a question you did not ask. Read a single profile for that. `compliance` being **absent** is not the same as it being **empty**. Absent means it was not worked out here; empty means the market owes nothing. **Update** with `PATCH /v3/sender-profiles/{id}`, which changes `name`, `short_name`, `description`, and `notifications`, and only those. A profile's identity, its markets, and its compliance each have a separate sub-resource, because each has its own validation and external consequences: a brand change may need re-registering, a market change provisions a sender. Omitting a field leaves it alone and sending `null` clears it, so `{}` is refused rather than returning a `200` and an unchanged profile. `name`, `short_name`, and `notifications` cannot be cleared. **Delete** with `DELETE /v3/sender-profiles/{id}`, which returns `204`. The delete is soft: the profile stops being usable and stops appearing in reads, and its message history is kept, because deleting a profile must not delete the record of what it sent. Anything the profile still held goes with it: a phone number returns to our inventory and can be given to whoever asks next, and a dedicated WhatsApp account is deregistered from Meta. A profile that only inherits holds nothing dedicated, so it releases nothing. A released number does not stay reserved for you, and getting the same number back afterwards is not something we can promise. ## Migrating from `/v3/profiles` [#migrating-from-v3profiles] The `/v3/profiles` endpoints and the profile-campaign endpoints under them are deprecated. They still work, so nothing breaks today, but new integrations should use `/v3/sender-profiles`. | Old | New | | --- | --- | | `POST /v3/profiles` then `POST /v3/profiles/{profileId}/complete` with a `webHookUrl` | `POST /v3/sender-profiles`: one call, no completion step and no callback to receive | | `POST /v3/profiles/{profileId}/campaigns` | `compliance.campaign` on the market call, per market | | `brand` object on create | `compliance.brand`, alongside the campaign it is filed against | | `GET /v3/profiles/{profileId}` for a single flattened `status` | `GET /v3/sender-profiles/{id}`, with a status per channel and per market | Six fields on the old endpoints are now **accepted and ignored**, and are worth checking for in existing code because a request carrying them still succeeds: | Field | Behaviour now | | --- | --- | | `inherit_contacts`, `inherit_templates` | Accepted and ignored. Contact and template inheritance between profiles is gone: a profile sees only its own records, while the organization sees those of every profile beneath it. Every profile reads back `false`. | | `allow_contact_sharing`, `allow_template_sharing` | Accepted and ignored, reading back `false`, for the same reason. | | `sending_phone_number_profile_id`, `sending_whatsapp_number_profile_id` | Accepted and ignored. A profile can no longer be pointed at another profile's number; give it a dedicated sender with `channels.sms` instead. Both read back `null` on `/v3/profiles` responses. Where the field is populated on another read, such as [`GET /v3/me`](/reference/api/accounts/SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint), it reports which account holds the number in inventory. It is never a sender you can choose. | These were bound rather than removed so an SDK that assigns them keeps compiling. Nothing is refused, because a `400` would break an integration that is otherwise working. Even so, a caller that reads back what it wrote can see it did not take. ## Troubleshooting [#troubleshooting] {/* vale Google.WordList = NO */} {/* vale Vale.Terms = NO */} {/* "admin access" and "channels.sms.number_type" appear inside verbatim API error strings and must match the API byte for byte. */} | Symptom | Likely cause | Fix | | --- | --- | --- | | `400` "short_name is required" | `short_name` was omitted | Send `short_name` as well as `name` | | `400` "short_name must be 3–11 characters…" | The sender id is malformed | Use 3–11 characters of letters, numbers, and spaces with at least one letter | | `400` "compliance.brand is required when channels.sms.number_type is TEN_DLC" | A 10DLC market with no identity to file against | Send `compliance.brand` as `{"inherit": true}` or with the identity's fields | | `400` "compliance.brand must be \{ "inherit": true \} or the identity's own fields when channels.sms.number_type is TEN_DLC" | `compliance.brand` sent as `{}` or as `{"inherit": false}` alone | Send `{"inherit": true}` or the identity's fields | | `400` "compliance.campaign can only be inherited together with the brand…" | `campaign` inherited while `brand` carries its own fields or `inherit: false` | Inherit both, or supply a campaign of the profile's own | | `400` "Your organization has no brand to inherit…" or "Your organization has no campaign to inherit…" | The profile inherits a brand or campaign the organization hasn't registered | Register the organization's brand or campaign first, or supply the profile's own | | `400` "channels.sms.number_type is required" | `channels.sms` supplied with only a country | Add `number_type` | | `502` on create | Meta couldn't be reached to verify `channels.whatsapp` | Nothing was created. Send the request again | | `400` on `PATCH` with an empty body | `{}` is refused rather than treated as a no-op | Send the field you meant to change, or `null` to clear it | | `403` "You do not have admin access to this organization" | Your API key's user lacks the `admin` role | Ask the organization owner to grant it (see [roles and permissions](/reference/api/roles-and-permissions)) | | `403` "Profile API keys cannot use x-profile-id" | Scoping header sent with a profile-scoped key | Use an organization API key, or drop the header | | `404` on a profile you believe exists | The profile belongs to another organization | Confirm the id; a foreign id is `404` by design | | `501` from the requirements endpoint | `channel=whatsapp` or `channel=rcs` | Only `sms` is answered today | | A write to `sending_phone_number_profile_id` reads back `null` | The field is reported, not set | Give the profile a dedicated sender with `channels.sms` | {/* vale Vale.Terms = YES */} {/* vale Google.WordList = YES */} ## Related pages [#related-pages] - [Sender Profiles](/start/concepts/sender-profiles) - which resources are dedicated and which are inherited - [Managing channels](/start/guides/managing-channels) - adding SMS markets, WhatsApp, and RCS to a profile - [Creating a Sender Profile](/start/guides/creating-a-sender-profile) - the dashboard flow - [Multi-Tenant Architectures](/start/advanced/multi-tenant-architectures) - choosing shared versus per-tenant setups - [10DLC Registration](/start/advanced/10dlc-registration) - registering for US SMS - Refer to the [create](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesCreateSenderProfileEndpoint), [list](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesGetSenderProfilesEndpoint), [read](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesGetSenderProfileEndpoint), [update](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesPatchSenderProfileEndpoint), and [delete](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesDeleteSenderProfileEndpoint) Sender Profile references for every field and response # What is 10DLC? (/start/concepts/10dlc.md) # What is 10DLC? [#what-is-10dlc] 10DLC stands for 10-Digit Long Code. It is the US registration system for A2P (Application-to-Person) SMS: messages sent by software to people, as opposed to two people texting each other. If your business sends texts to US phone numbers, 10DLC applies to you. This page explains why the system exists, how a registration is reviewed, and where Sent fits in, so the requirements in the [10DLC Registration Guide](/start/advanced/10dlc-registration) read as a coherent system rather than a list of arbitrary rules. ## Why carriers built a registration system [#why-carriers-built-a-registration-system] For years, businesses could send SMS from regular 10-digit numbers with no registration required. Carriers (AT&T, Verizon, T-Mobile) couldn't tell a legitimate business from a bot farm, so in 2019 they built a gating system: unregistered A2P traffic is filtered or throttled, and registered traffic is treated as legitimate. Registration happens through **TCR (The Campaign Registry)**, which acts as the central record-keeper for all 10DLC submissions. You tell TCR who you are and what you're sending. In return, carriers treat your messages as legitimate traffic. The distinction TCR polices is A2P versus P2P (Person-to-Person): a person texting a friend needs no registration, while software texting customers does, even at a small volume of appointment reminders. Virtually all messages sent through a platform like Sent are A2P. TCR plays the same role for US SMS that Meta's Business Verification plays for WhatsApp: an identity layer that lets the network attach a reputation to a sender. The difference is that 10DLC is carrier-imposed and US-specific, while WhatsApp's rules are global. ## Brands and campaigns: the two halves of a registration [#brands-and-campaigns-the-two-halves-of-a-registration] Every 10DLC submission has two parts, reviewed very differently. A **brand** is your business identity: legal name, address, tax ID. TCR verifies your business is real using the information you provide. This review is algorithmic, fast, and mostly a lookup against existing business registration data. A **campaign** describes the messages themselves: the type of messages you're sending, who's receiving them, how they opted in, and sample examples. Unlike brand verification, a campaign is **manually reviewed by a human**, which is where things get inconsistent. The same campaign description can pass or fail depending on who reviews it, and rejection error codes (805, 806, 851) give you a category of problem rather than specific guidance on what to fix. This split explains most of the friction in the process. The brand check rarely fails for a real business, but campaign review is subjective, so the documented content rules (opt-in forms, autoresponses, sample messages) exist to remove any grounds a reviewer might have for rejection. ## Volume tiers and trust [#volume-tiers-and-trust] Campaigns are tiered by declared volume. Below 2,000 messages per day, a campaign qualifies as **low volume**, with lower registration fees and fewer declared use cases (up to 5, rather than 11 for a standard campaign); past that threshold it registers as standard (high volume). TCR also assigns each brand a trust score, and carriers use it to set throughput limits: a better-established brand can send faster. Some senders register the cheapest tier or a convenient use case and plan to correct it later. This is usually counterproductive: carriers compare your registered use case against your actual traffic, and mismatches lead to filtering or campaign suspension. Registering what you actually send is the reliable path. ## Where Sent fits [#where-sent-fits] Sent sits between you and TCR. You fill out one form in the Sent dashboard (or submit via the API), and the Sent compliance team reviews your submission before it reaches TCR. Because campaign review is the subjective, human part, this pre-review catches the problems that commonly cause rejections. Sent then submits the registration on your behalf, tracks the review, and notifies you when you're approved or when something needs fixing. You never interact with TCR directly, but the registration is still legally yours: TCR ties each campaign to the business responsible for the messages, which is why agencies and resellers must register each client separately rather than bundling them under one campaign. ## Where to go from here [#where-to-go-from-here] Now that you understand what 10DLC registration involves, you can act on it: - [10DLC Registration Guide](/start/advanced/10dlc-registration): register your brand and campaign through the Sent dashboard - [Register 10DLC Campaigns via the API](/start/advanced/10dlc-campaigns-api): programmatic registration for agencies and resellers - [Compliance & Regulations](/start/advanced/compliance-regulations): what Sent enforces at send time, and per-region regulations beyond the US - [Compliance & 10DLC Issues](/troubleshooting/compliance): fixes when 10DLC errors block your sending # API Authentication (/start/concepts/api-authentication.md) # API Authentication [#api-authentication] Every request to the Sent API v3 carries exactly one credential: an API key, sent in the `x-api-key` header or as a Bearer token in the `Authorization` header. There is no OAuth handshake, no token refresh, and no session. This page explains why authentication works this way, what the design trades away, and what it asks of you in return. ## One key, resolved on every request [#one-key-resolved-on-every-request] When a request arrives, the API looks up the presented key, resolves it to your customer account, and attaches that identity to the request. Nothing persists between calls: each request is authenticated independently, and the server keeps no session on your behalf. That is why the API has no login step: the key is the entire credential on every call. The header you choose does not change the model. `x-api-key` and `Authorization: Bearer` carry the same key to the same lookup, and `x-api-key` wins if a request sends both. The Bearer form exists for clients that can only attach OAuth2 or Bearer credentials to a request. This model has a name in HTTP security: the key is a *bearer credential*. Whoever presents it is treated as the account. Most of the security guidance around Sent API keys follows from that single property. ## Why a header, not a URL or body [#why-a-header-not-a-url-or-body] A credential can travel in three places in an HTTP request: the query string, the body, or a header. Query strings are the worst home for a secret, because they are routinely written to server access logs, proxy logs, and browser history, so a credential in a URL leaks by default. The request body is safer, but it ties authentication to methods that have bodies, leaving `GET` requests with nowhere to put the credential. A header is the remaining channel: it is uniform across HTTP methods and conventionally excluded from logs. The same reasoning leads most API-key platforms to the same design. A header is plaintext inside the connection, so its confidentiality rests entirely on TLS. This is why the API is served over HTTPS, and why a key should never travel over an unencrypted channel. ## Why not OAuth [#why-not-oauth] OAuth exists to solve delegation: a third-party app acting on a user's behalf without ever seeing the user's password. Calls to the Sent API are not delegated (your backend acts on your own account), so an OAuth flow would add token issuance, expiry, and refresh without adding a security boundary. {/* "disable" is the product term here: the dashboard exposes a disable action for keys, distinct from delete. */} {/* vale Google.WordList = NO */} Some platforms use OAuth client-credentials even for first-party, server-to-server APIs, because short-lived tokens bound how long a leaked credential remains useful. That is a reasonable approach, but it means every integration must implement token acquisition and refresh before it can make its first call. Sent chooses the other side of that trade: a static key makes the first request a one-liner, and containment comes from revocation and rotation. You can disable or delete any key in the dashboard, and it stops working immediately. {/* vale Google.WordList = YES */} ## What the trade-off asks of you [#what-the-trade-off-asks-of-you] Because the key is a static bearer credential, the burden the design places on you is key handling. Each of the standard practices exists for a specific reason: - **Environment variables instead of source code**, because repository history is effectively permanent: a key committed once remains recoverable even after you delete it. - **Server-side use only**, because anything delivered to a browser or bundled into a mobile app is public; a key there is equivalent to publishing it. - **One key per environment**, because separate keys contain the blast radius of a leak and let you rotate development credentials without touching production. - **Periodic rotation**, because rotation bounds the useful lifetime of a key that leaked without your knowledge. All four practices answer the same underlying fact: possession of the key is authorization. The how-to guide [Creating and managing API keys](/start/guides/api-keys) turns them into concrete steps. ## Guarding against brute force [#guarding-against-brute-force] A single static credential invites guessing, so the API tracks consecutive failed attempts per presented credential and temporarily locks a credential after repeated failures, with lockout periods that escalate from 1 minute up to 60 minutes. The lockout is keyed to the credential itself rather than to the caller's IP address. This is deliberate: many tenants can sit behind one shared ingress or proxy and therefore share an IP, so an IP-keyed lockout would let one misconfigured client (or a scanner probing random keys) lock out every valid tenant behind the same address. Scoping the lockout to the guessed credential means a valid key is never collateral damage. ## Where to act on this [#where-to-act-on-this] - [Creating and managing API keys](/start/guides/api-keys): create, store, verify, and rotate keys. - [Authentication reference](/reference/api/authentication): the exact header, response headers, and AUTH error codes. - [Per-request authentication pattern](/build/authentication): the integration blueprint for multi-tenant apps where each customer supplies their own key. # Channels (/start/concepts/channels.md) # Channels [#channels] A channel is a delivery path for a message: SMS, MMS, RCS, or WhatsApp. Most messaging platforms expose each of these as a separate API, which makes the channel the developer's problem, because every send starts with a decision about how the message should travel. Sent inverts that: the channel is a routing decision the platform makes per message and per recipient, behind a single send call. This page explains why Sent built the model that way, what each channel contributes, and which factors drive routing. ## Intent-Based Messaging [#intent-based-messaging] When each channel is its own API, channel management leaks into your app code: separate integrations, separate content formats, and hand-written fallback logic. Sent replaces channel selection with **intent-based messaging**. You state what to send and to whom, and the platform works out the delivery path: ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); await client.messages.send({ to: ['+14155551234'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { name: 'John Doe' }, }, }); ``` This call omits the `channel` field, so Sent chooses the route. That is the default behavior, equivalent to `channel: ["sent"]`. Sent discovers the channels available to each recipient, selects a route, and adapts the content format to the channel it selects. The same call can therefore produce a WhatsApp delivery for one recipient and an SMS delivery for another, without any branching in your code. When a specific channel matters (a compliance requirement, for example), the `channel` field pins the route. [Channel Selection Strategies](/start/guides/sending-messages#channel-selection-strategies) covers the request syntax and its trade-offs. ## Channels [#channels-1] Sent supports four channels, each playing a distinct role: - **SMS: The universal foundation.** SMS works on every mobile device with cellular connectivity, rides carrier infrastructure, and defines the baseline capabilities every template must support. It's also the final fallback when richer channels can't deliver. A US 10DLC or local number also reaches the six US territories, such as Puerto Rico and the US Virgin Islands; see [Channel Routing](/reference/channel-routing#how-auto-detect-resolves-a-channel). - **MMS: Carrier media messaging.** MMS travels the same carrier infrastructure as SMS, using the same number and registration, and adds one attachment per message: an image, video, document, or contact card. It's available in the US, Canada, Puerto Rico, and Australia, and requires per-account consent. See [Sending MMS](/start/guides/mms) for the full guide. - **RCS: The carrier-native rich layer.** RCS adds interactive suggestion chips and a branded, verified sender over carrier networks, natively in Google Messages on Android, with no separate app install. It bridges the gap between SMS reach and WhatsApp interactivity for Android users. - **WhatsApp: The rich engagement layer.** WhatsApp delivers media, buttons, and branded business profiles, supports conversation-based interactions, and reports read receipts. The layering is the point: SMS guarantees reach, MMS adds media over the same carrier path, RCS and WhatsApp add interactivity and branding where the recipient's device and registration allow it, and routing decides, per message, which layer applies. ## One Template, Every Channel [#one-template-every-channel] Because every message starts from a [template](/start/concepts/templates), content adapts to the capabilities of whichever channel ends up carrying it: - **Universal compatibility**: every template starts from content that works on SMS, the most constrained channel, so every message is deliverable everywhere. - **Automatic enrichment**: delivered over WhatsApp, the same template gains interactive buttons, media headers, and branded formatting. - **Graceful degradation**: complex WhatsApp templates simplify for SMS delivery, preserving the essential information. The same template renders differently on each channel: | Message Type | SMS | RCS | WhatsApp | |--------------|-----|-----|----------| | **Authentication** | "Your verification code is 123456" | Branded text from your verified sender with a "Got it" suggestion chip | Rich template with branding, verification code, security tips, and interactive "Got it" button | | **Order Update** | "Order #12345 shipped. Track: [link]" | Branded text with a "Track Order" suggestion chip | Rich card with product image, detailed status, tracking button, and customer service contact | MMS is absent from the table because it adds no formatting of its own. It renders a subject line, text, and one attachment. The text comes from the template's `mms` body, falling back to the shared `multiChannel` body and then the `sms` body, as RCS does. The subject and template media exist only on an `mms` body. MMS is used only when the message carries an attachment, from the template's `mms` body or the send's `media_urls`. ## Channel Discovery [#channel-discovery] Channel availability is a property of each recipient, not of your account. When Sent first encounters a phone number, it establishes which channels can reach it: carrier and number-type data determine SMS and RCS deliverability, and Sent checks WhatsApp registration status separately. Providers also report what each channel supports (media, templates, inbound messages), so routing knows whether a channel is reachable and what it can carry. Sent stores the result on the contact as its available channels and default channel, and the result can change over time. A recipient who registers for WhatsApp after months of SMS-only delivery can start receiving WhatsApp messages without any change to your code. ## Your Side of the Channel [#your-side-of-the-channel] Channel discovery answers what can reach a recipient. The other half is what you can send from, and that has a lifecycle: a market has to be registered, an account has to be connected, an agent has to be approved. Sent models this as one channel per thing that can send, readable at `GET /v3/channels`: every market you send SMS in, your WhatsApp account, and your RCS agent. **A market is a country plus a sender type**: `US` and `TEN_DLC`, `GB` and `ALPHANUMERIC`. The pair identifies it everywhere, because requirements attach to the pair rather than to the country: what a US 10DLC sender must register bears no resemblance to what an alphanumeric sender in the United Kingdom must. **Status lives on the channel, never on your account or your brand.** An identity has no lifecycle; what has one is the registration of a sender in a market and the approval of a channel. So a sender live in one country and mid-registration in another reports exactly that, rather than one flattened answer that is true of neither: | Status | Meaning | | --- | --- | | `PROVISIONING` | Sent is arranging the sender | | `ACTION_NEEDED` | Something is owed, or a resubmission has been asked of you | | `PENDING_REVIEW` | With a carrier or registry, whose answer is what moves it | | `ACTIVE` | The channel can send | A channel that is not `ACTIVE` also says why, as a stable `reason_code` (`CHANNEL_001` to `CHANNEL_011`) and a `reason` sentence. Branch on the code; show the sentence. Each market also reports what it still owes, as a list of keys you write back with the market's `PATCH`. An empty list means that market is satisfied. [Managing channels](/start/guides/managing-channels) covers reading and changing all of this; `GET /v3/compliance/requirements` describes what any given market demands before you add it. ## Routing Factors [#routing-factors] When more than one channel can reach a recipient, the router weighs a small set of factors: - **Region**: country-specific regulation and carrier policy constrain which routes Sent can use. - **Content**: media and interactive elements route to channels that support them; plain text can travel on any channel. - **Cost**: among viable routes, the router prefers the cheaper one, based on regional pricing, provider rates, and conversation-window rules. - **Fallback**: when the selected channel can't deliver, the router retries on the next viable channel, ending at SMS. Fallback applies only to [automatic selection](/start/guides/sending-messages#automatic-selection-default). A request that pins the `channel` field is a broadcast instruction, not a fallback order: each listed channel produces its own message, and a pinned channel that can't deliver fails rather than falling back. ## Content Adaptation Mechanics [#content-adaptation-mechanics] Adaptation happens at send time, per route: - **Character limits**: rich templates compress to fit SMS constraints while preserving the essential information and the call to action. - **Media**: images and videos become descriptive text with links on SMS and RCS; MMS and WhatsApp carry the media itself, with no text fallback. - **Interactive elements**: buttons and quick replies become text alternatives with URL links on SMS, and they remain fully interactive on RCS and WhatsApp. ## What Each Channel Brings [#what-each-channel-brings] ### RCS [#rcs] **Carrier-native delivery**: RCS messages travel over carrier networks directly into Google Messages, the default Android messaging app, so recipients install nothing. **Branded sender**: unlike SMS, which shows a phone number, RCS messages display your company logo, name, and a verified checkmark. **No number provisioning**: RCS does not use phone numbers. Each business operates an "RCS Agent" (a branded sender identity), so you don't need short codes or carrier number registration like SMS requires. **Suggestion chips**: RCS messages sent through Sent include suggestion chips: quick reply, open URL, and dial number buttons displayed below the message. Sent maps up to four template buttons to chips per message. Suggestion chips aren't available on SMS. **Rich cards and carousels (roadmap)**: rich cards (title, description, image or video, and action buttons) and carousel cards (scrollable sets of rich cards) are part of the RCS standard but aren't yet available through Sent. RCS messages currently render as text plus suggestion chips. **Read receipts**: like WhatsApp, RCS delivers read receipts when the recipient opens the message. SMS has no equivalent. **Built-in STOP chip**: every RCS message automatically includes a STOP button for compliance, so you don't need to add opt-out footer text. A tap on the chip arrives as an ordinary inbound STOP message and opts the contact out, exactly as texting STOP does on SMS. [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent) shows how to mirror those opt-outs into your own systems, and the [events reference](/start/webhooks/event-types) documents the inbound webhook payload. **Automatic fallback**: when RCS can't reach a recipient (unsupported device or carrier), automatic channel selection falls back to SMS. **Agent registration**: RCS sends from a branded RCS Agent (display name, logo, brand color) rather than a phone number. You register the agent yourself, in the dashboard or through the API; Sent reviews it and the carriers vet it, and you can send RCS once the agent is launched. See [Enable RCS](/start/quickstart/channel-setup#enable-rcs) for the steps. ### WhatsApp [#whatsapp] **Managed template approval**: Sent submits new templates to Meta and tracks their approval status, so you never work in Meta's platform directly. **Business verification**: WhatsApp Business accounts display verification badges and professional profiles, which recipients trust more readily than SMS from an unknown number. ### SMS [#sms] **Carrier network integration**: SMS routing is aggregator- and carrier-agnostic. Sent validates phone numbers in real time, assesses SMS capability, and routes through carrier networks without depending on a single provider. **Regulatory compliance**: Sent handles regional SMS requirements, carrier filtering, spam prevention, and opt-out management automatically for each country. **Predictable economics**: a straightforward per-message pricing model keeps cost calculation and customer billing transparent. ## Further Reading [#further-reading] The channel model means fallback logic, regional preferences, and platform-specific formats live in the platform rather than in your code. To act on it: - [Sending Messages](/start/guides/sending-messages): send over specific channels, broadcast to several, or send free-form text. - [Sending MMS](/start/guides/mms): attach media over the carrier path, and the size limits and routing rules that apply. - [Managing channels](/start/guides/managing-channels): add SMS markets, connect WhatsApp, request an RCS agent, and clear what compliance owes. - [Channel Setup](/start/quickstart/channel-setup): activate SMS, WhatsApp, and RCS on your account. - [Voice](/start/guides/managing-channels#voice): turn phone calls on for a number and point it at your callback URL. Voice is per number and is not a message channel. - [Unified Messaging Intelligence](/start/concepts/unified-messaging): the broader intent-based delivery model that channel routing sits inside. # Contacts (/start/concepts/contacts.md) # Contacts [#contacts] A contact in Sent is a validated communication endpoint: a phone number enriched with the channel information the platform needs to reach its owner. Rather than forcing developers to manage the complexity of different messaging channels, contacts provide a unified abstraction that handles channel validation, metadata, and routing automatically. ## Contacts Architecture [#contacts-architecture] The Sent Contacts Architecture is designed to be intelligent and flexible, while allowing you to have full control over the messaging experience. ### Channel-Agnostic Abstraction [#channel-agnostic-abstraction] Traditional messaging platforms require developers to understand and integrate with separate APIs for SMS, WhatsApp, and other channels. This leads to several problems such as integration complexity, validation overhead, routing decisions, and fallback handling, all of which need to be implemented manually. Sent solves these problems by providing a **channel-agnostic abstraction**. When you send a message to a contact, the platform handles all channel-specific complexity behind a unified interface. ### The Contact as a Validated Communication Endpoint [#the-contact-as-a-validated-communication-endpoint] A contact in Sent is fundamentally different from a simple phone number or user record. It represents: **A validated, intelligent communication endpoint** that: - Knows which messaging channels can successfully reach the recipient - Understands the optimal channel for delivery based on regional preferences and availability - Maintains channel-specific formatting and validation rules - Provides automatic fallback routing when primary channels fail This abstraction allows developers to focus on their app logic rather than the intricacies of multi-channel messaging infrastructure. ### Channel Availability and Routing [#channel-availability-and-routing] A contact records which channels can currently reach its phone number. SMS, WhatsApp, and RCS are all live channels in Sent, and a contact carries a per-channel availability record for each. When you send without pinning a channel, routing selects among the contact's available channels per recipient at send time. There is no fixed channel preference order: the winning route depends on the routing rules configured for your account and the recipient, and the remaining candidates are kept as fallbacks. The factors the router weighs are summarized in [Routing Factors](/start/concepts/channels#routing-factors); [Unified Messaging Intelligence](/start/concepts/unified-messaging#the-decision-engine) explains the decision engine, and the [channel routing reference](/reference/channel-routing) specifies the exact matching and ordering rules. ### Persistent State [#persistent-state] Contacts maintain persistent state that benefits future interactions: - **Channel availability** is cached and periodically refreshed - **Routing decisions** improve based on delivery history - **Validation status** prevents repeated failed delivery attempts This persistence means that applications naturally become more efficient over time without additional developer effort. ### Phone Number Normalization [#phone-number-normalization] Contacts handle the complexity of phone number formatting across different contexts: - **E.164 format**: International standard for programmatic use - **International format**: Human-readable international representation - **National format**: Localized formatting for user interfaces - **RFC format**: Standardized format for system integration This multi-format support ensures that contacts work correctly regardless of how phone numbers are provided or displayed in your app. ### Customer Scoping and Isolation [#customer-scoping-and-isolation] Contacts are scoped to individual customers, providing: - **Access control**: Customers can only access their own contacts - **Billing isolation**: Message costs are attributed correctly - **Data privacy**: Contact information remains segregated between customers This architecture supports multi-tenant applications while maintaining security and billing accuracy. ### Channel-Specific Metadata [#channel-specific-metadata] While contacts abstract channel complexity, they also preserve channel-specific information when needed: - **WhatsApp profile status**: Whether a number has an active WhatsApp Business API registration - **SMS carrier information**: Network-specific delivery capabilities - **Regional restrictions**: Compliance and availability constraints by geography This metadata enables advanced applications to make informed decisions while still benefiting from the unified API approach. ## Contact Intelligence [#contact-intelligence] ### Automatic Contact Creation [#automatic-contact-creation] Contacts follow a **lazy creation** pattern that reduces integration friction. This approach means developers never need to pre-register contacts. The system creates and optimizes them automatically during the first messaging interaction. Here's how it works: to +1234567890]) Validate[System validates
phone number across
all channels] Create[Contact created with
channel availability
metadata] Route[Message routed to
optimal channel] Persist[Contact persists for
future optimized messaging] Start --> Validate Validate --> Create Create --> Route Route --> Persist style Start fill:#4F46E5,stroke:#4338CA,color:#fff style Validate fill:#8B5CF6,stroke:#7C3AED,color:#fff style Create fill:#10B981,stroke:#059669,color:#fff style Route fill:#F59E0B,stroke:#D97706,color:#fff style Persist fill:#06B6D4,stroke:#0891B2,color:#fff `} width={600} /> ### Real-Time Channel Validation [#real-time-channel-validation] When a contact is created, and again as messages are sent to it, Sent validates the phone number against the supported channels: - **SMS availability**: verified through carrier network validation - **WhatsApp registration**: checked against the WhatsApp Business API - **RCS capability**: checked against the recipient device's RCS support, with the result cached for reuse This validation ensures that every contact represents a **deliverable endpoint**, reducing bounce rates and failed message attempts. ### Contact Enrichment Over Time [#contact-enrichment-over-time] Contacts become more intelligent through usage: - **Delivery success patterns** inform future routing decisions - **Channel preferences** are learned from recipient engagement - **Validation status** is periodically refreshed to maintain accuracy This creates a feedback loop where messaging performance improves automatically as the system learns more about each contact. ## Contacts for Developers [#contacts-for-developers] Sent supports two primary patterns for working with contacts. Both patterns use the same underlying intelligence but offer different levels of control and visibility. **Direct phone messaging** (automatic contact creation): - Send immediately to any phone number - Contact created and optimized transparently - Ideal for one-off or ad-hoc messaging **Explicit contact management**: - Retrieve and work with contact objects - Access channel availability metadata - Suitable for applications that need contact state awareness [Managing Contacts](/start/guides/managing-contacts) covers both patterns in practice. **When building with Sent's contact system, developers should shift their mental model to a contact-based approach** Avoid the traditional approach of branching on channel in your own code: ```javascript if (user.hasWhatsApp) { sendWhatsApp(message, user.phone); } else { sendSMS(message, user.phone); } ``` Prefer the contact-based approach, where the platform picks the channel: ```javascript sendMessage(message, contact); ``` --- # Core Concepts Overview (/start/concepts.md) # Core Concepts Overview [#core-concepts-overview] Before you start building with Sent, it's important to understand the fundamental concepts that make up the Sent messaging platform. This section will help you build a mental model of how Sent works and why it's designed the way it is. ## Learning Path [#learning-path] ### Platform Overview [#platform-overview] Start here to understand the high-level architecture and how Sent fits into your application stack. [Read more →](/start/concepts/platform-overview) **You'll learn:** - The components of Sent's architecture - How messages flow through the system - Key benefits for developers and businesses ### Unified Messaging [#unified-messaging] Understand the philosophy behind intent-based messaging and how it differs from traditional channel-specific approaches. [Read more →](/start/concepts/unified-messaging) **You'll learn:** - Imperative vs declarative messaging - How the decision engine works - Automatic fallback and retry logic ### Channels [#channels] Learn about the intelligent abstraction layer that handles SMS, WhatsApp, RCS, and future messaging channels. [Read more →](/start/concepts/channels) **You'll learn:** - How channel selection works - How one template adapts to each channel - Real-time availability detection ### Contacts [#contacts] Understand how Sent's contact system provides intelligent, channel-agnostic communication endpoints. [Read more →](/start/concepts/contacts) **You'll learn:** - Contact lifecycle and validation - Routing decision engine - Phone number normalization ### Templates [#templates] Learn about the foundation of unified messaging and how templates adapt across channels. [Read more →](/start/concepts/templates) **You'll learn:** - Template anatomy and components - Dynamic content handling - Content adaptation mechanics ## Concept Map [#concept-map] } /> } /> } /> } /> } /> } /> } /> } /> ## Key Principles [#key-principles] ### 1. Intent Over Implementation [#1-intent-over-implementation] Sent focuses on *what* you want to achieve (send a notification) rather than *how* (SMS vs WhatsApp vs RCS). This abstraction allows the platform to optimize delivery without your intervention. ### 2. Richer Where the Channel Allows [#2-richer-where-the-channel-allows] Every message works on the most constrained channel, SMS, and picks up media, buttons, and branding automatically when it routes to a richer channel. ### 3. Intelligence Through Data [#3-intelligence-through-data] Delivery outcomes feed back into routing: delivery patterns and success rates inform the routing rules that decide how future messages are sent. ### 4. Developer Experience First [#4-developer-experience-first] Complexity is absorbed by the platform, not pushed to developers. You shouldn't need telecom expertise to send messages reliably. ## How These Concepts Work Together [#how-these-concepts-work-together] ``` Your Application ↓ [Intent] → "Send order confirmation to customer" ↓ [Contact] → Intelligent endpoint with channel info ↓ [Template] → Channel-agnostic message definition ↓ [Decision Engine] → Optimal channel selection ↓ [Channel] → SMS, WhatsApp, RCS, etc. ↓ Delivery with automatic fallback ``` **Ready to build?** Once you understand these concepts, move on to the [Quickstart](/start/quickstart) to send your first message, or dive into the [Implementation Guides](/start/guides) for detailed how-tos. ## Common Questions [#common-questions] **Do you need to understand all these concepts before using Sent?** No. You can start sending messages with just the [Quickstart](/start/quickstart). These concepts help you build more effectively and troubleshoot issues. **Which concept should you learn first?** Start with [Platform Overview](/start/concepts/platform-overview) for the big picture, then [Unified Messaging](/start/concepts/unified-messaging) to understand the core philosophy. **How do concepts relate to the API?** Concepts map directly to API resources: - Contacts → `/v3/contacts` - Templates → `/v3/templates` - Messages → `/v3/messages` --- # Platform Overview (/start/concepts/platform-overview.md) # Platform Overview [#platform-overview] Sent is an intelligent messaging platform that simplifies omnichannel communication through a unified API. By abstracting the complexity of multiple messaging channels, Sent enables developers to focus on building great user experiences while Sent handles delivery optimization, routing, and reliability. ## How Sent Works [#how-sent-works] Sent acts as an intelligent middleware layer between your app and various messaging channel providers (SMS, WhatsApp, RCS, etc.). When you send a message through Sent's API, the platform automatically determines the optimal delivery path based on multiple factors including cost, speed, delivery success rates, and recipient preferences. |Single API Request| API API -->|Message Payload| Intelligence Intelligence -->|Enriched Context| Router Router -->|Optimal Route| SMS Router -->|Optimal Route| WA Router -->|Optimal Route| RCS SMS -.->|Delivery Status| Storage WA -.->|Delivery Status| Storage RCS -.->|Delivery Status| Storage Storage -->|Webhooks & Analytics| App style App fill:#4F46E5,stroke:#4338CA,color:#fff style Intelligence fill:#10B981,stroke:#059669,color:#fff style Router fill:#F59E0B,stroke:#D97706,color:#fff style Storage fill:#8B5CF6,stroke:#7C3AED,color:#fff `} width={900} /> ## Core Architecture Components [#core-architecture-components] ### Unified API Layer [#unified-api-layer] Your single integration point for all messaging channels. Send messages across SMS, WhatsApp, RCS, and more through one consistent API interface. No need to manage multiple provider integrations or handle different authentication schemes. **Key Features:** - Single authentication mechanism across all channels - Consistent request/response format - Built-in rate limiting and retry logic ### Message Delivery Intelligence [#message-delivery-intelligence] Sent's intelligent routing engine makes real-time decisions about how to deliver your messages. Each decision weighs: - **Cost Efficiency**: Automatically selects the most cost-effective channel - **Success Rate**: Uses historical data to predict and optimize delivery - **Geographic Optimization**: Considers recipient location and local channel preferences ### Smart Routing & Failover [#smart-routing--failover] When a message cannot be delivered through the primary channel, Sent automatically attempts delivery through fallback channels without any additional code on your end. **Routing Considerations:** - Recipient channel availability (WhatsApp installed, RCS-capable device/carrier, internet connected, etc.) - Message content: text, media, or interactive components such as RCS suggestion chips and rich cards - Regulatory compliance and regional restrictions ### Real-Time Analytics & Webhooks [#real-time-analytics--webhooks] Track every message through its entire lifecycle with detailed analytics and real-time webhook notifications. - Delivery confirmations - Read receipts (WhatsApp and RCS; not available on SMS) - Bounce and failure reasons - Aggregate performance metrics ## Sent for Developers [#sent-for-developers] - **Faster Time to Market**: One integration instead of managing multiple provider SDKs - **Simplified Maintenance**: No need to update code when switching or adding providers - **Better Error Handling**: Unified error codes and automatic retry logic - **Sandbox Testing**: A sandbox mode for every channel ## Sent for Businesses [#sent-for-businesses] - **Cost Optimization**: Automatic routing to most cost-effective channels - **Higher Delivery Rates**: Intelligent failover and channel selection - **Global Reach**: Support for regional providers and compliance - **Scalability**: Infrastructure that grows with your message volume --- # Sender Profiles (/start/concepts/sender-profiles.md) # Sender Profiles: Multi-Tenant Resource Governance [#sender-profiles-multi-tenant-resource-governance] Sender Profiles provide an architectural abstraction that enables true multi-tenancy within a single Sent organization. Rather than creating separate accounts for each business unit, brand, or customer, Sender Profiles isolate messaging identities and their data, while letting billing and compliance stay with the organization. A profile is a customer of yours: it sends under its own identity or yours, and your customers never see Sent. This page explains why the model is built this way and what each choice trades off; the hands-on work lives in [Creating a Sender Profile](/start/guides/creating-a-sender-profile) and [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles). ## The Sender Profile Abstraction [#the-sender-profile-abstraction] Traditional approaches to multi-tenant messaging force a binary choice: completely separate accounts with full isolation (and operational overhead), or a shared account with no isolation (and security risks). Sub-accounts in traditional CPaaS platforms mostly reproduce the first option, because every resource of the sub-account is isolated whether that serves you or not. Sender Profiles instead let the expensive resources (the legal identity, the registration, the payment method) stay with the organization, while each tenant's data stays isolated. ### The Inheritance Architecture [#the-inheritance-architecture] Sender Profiles implement a resource model with three levels: - **Organization level**: the root entity that owns billing, compliance, and the identity a registration is filed against. Organizations serve as the administrative boundary and cost center. - **Sender Profile level**: individual messaging identities that can inherit compliance and billing from the organization. Each profile has its own API credentials, sending identity, and configuration. - **Resource level**: each capability is one of three things: dedicated to the profile, inherited from the organization, or absent. Resolution flows downward: when a profile inherits a resource, requests made as that profile transparently use the organization's copy; when the resource is dedicated, the profile's copy is used and the organization's is invisible to it. **Contacts and templates are not inheritable, and never shared between profiles.** A profile sees only its own contacts and templates, while the organization sees those of every profile beneath it. The four flags that used to govern this — `inherit_contacts`, `inherit_templates`, `allow_contact_sharing`, and `allow_template_sharing` — are now accepted and ignored on `/v3/profiles`, and every profile reads them back as `false`. See [Migrating from `/v3/profiles`](/start/advanced/sender-profiles-api#migrating-from-v3profiles). **A sender is never inherited either.** A brand and a campaign can be; a number cannot. A profile either has a dedicated sender or it has none, and without one it reaches only the countries Sent runs a shared route for. The US is not one of them: a profile with no US `TEN_DLC` number can't send SMS to US numbers, and such a send ends as `FAILED` with reason code `DELIVERY_003`. This model enables use cases like agencies managing multiple client brands, franchises with centralized billing but local operations, or platforms offering white-labeled messaging. ### Resource Governance Model [#resource-governance-model] Each resource type implements a specific governance pattern: | Resource | Pattern | Use Case | |----------|---------------------|----------| | **Billing** | Organization, Dedicated, or Dedicated with organization backing (the default) | Centralized cost control vs. separate invoicing | | **SMS sender** | Dedicated per profile, or none | A dedicated number per tenant vs. the shared routes, where the destination country has one (the US doesn't) | | **WhatsApp Business Account** | Dedicated per profile, or none | Sharing an account would share its inbox and throughput, so it is not offered | | **RCS Agent** | Dedicated per profile | Each Sender Profile can have its own branded RCS sender identity (logo, verified name) | | **Contacts** | Always dedicated | A profile sees only its own contacts; the organization sees every profile's | | **Templates** | Always dedicated | The same | | **TCR Brand/Campaign** | Full/Partial/Dedicated | Unified compliance vs. separate brand registration | ## Resource Configuration Patterns [#resource-configuration-patterns] ### Billing Inheritance [#billing-inheritance] Billing governance offers three modes, expressed on the API as one `billing` block: - **Inherited** (`{"inherit": true}`): all charges flow to the organization's payment methods. Ideal for centralized cost management and single-invoice accounting. - **Dedicated** (`{"inherit": false}`): the profile pays alone. Useful when clients or business units need direct billing. - **Dedicated with organization backing** (omit the block): the profile pays first, and the organization's balance covers what the profile's can't. This is the default. Useful when tenants pay directly but you guarantee their usage. Reads report the default as `{"inherit": false}`; `settings.billing_model` on `GET /v3/account` tells it apart from dedicated billing. Inherited billing is the better default for most organizations, since a single invoice and payment method keeps accounting simple; dedicated billing earns its overhead only when a client genuinely needs to be the payer of record. ### Contacts and Templates [#contacts-and-templates] Contacts and templates are always dedicated to the profile that created them. There is no inheritance and no sharing between profiles: a profile sees only its own records, and no request parameter can reach across that boundary. Reads widen upward rather than downward. The organization sees every contact and template across its profiles, which is what makes centralized support and auditing possible without giving one tenant sight of another. This replaces an earlier model where contacts and templates could be inherited from the organization and shared between profiles. The columns behind it are gone, so a tenant's customer data can no longer become visible to a sibling tenant by configuration. ### RCS Agent (Branded Sender) [#rcs-agent-branded-sender] RCS uses a branded sender identity (called an RCS Agent) instead of a phone number. Each Sender Profile can have its own dedicated RCS Agent with a custom logo, verified business name, and brand color displayed in the recipient's Google Messages inbox. Register a Sender Profile's RCS Agent from the **RCS** tab on the Channels page while that profile is selected, or through the API by sending `x-profile-id` with an organization key. Sent reviews the registration and the carriers vet it before the agent can send. See [Enable RCS](/start/quickstart/channel-setup#enable-rcs). ### TCR Brand and Campaign [#tcr-brand-and-campaign] For US SMS compliance, TCR registration offers flexible inheritance: - **Fully Inherited**: use the organization's brand and campaign - **Partially Inherited**: inherit the organization's brand but register a dedicated campaign for the profile - **Dedicated**: complete separate TCR registration for this profile On the API, both halves live in the `compliance` object of the market they register: `compliance.brand` and `compliance.campaign`, each carrying `inherit` to say whose it is. Inheriting is opt-in: a profile created without `compliance` has neither a brand nor a campaign. Inheriting the campaign inherits the brand too, and a profile with a brand of its own can't inherit the campaign. See [Managing channels](/start/guides/managing-channels). The reason partial inheritance exists is that [TCR itself splits registration in two](/start/concepts/10dlc): a brand establishes the business identity behind the messages, while a campaign describes a specific use case being sent. Many multi-tenant setups share one legal entity but send a different use case per tenant, so inheriting the organization's brand while registering a dedicated campaign per profile mirrors how TCR divides responsibility. When tenants are distinct legal entities, dedicated registration is the only honest representation: TCR ties each campaign to the business responsible for the messages, which is why agencies and resellers register each client separately rather than bundling them under one campaign. ## API Credentials and Isolation [#api-credentials-and-isolation] Each Sender Profile has unique API credentials. The key is returned once, by create, and never again. The API key presented on a request determines which profile's resources the request uses: templates, contacts, numbers, WhatsApp Business Account, and TCR settings all resolve through the profile the key belongs to. No request parameter can reach across a profile boundary. Organization-level API keys are the one deliberate exception: they can act on behalf of a child profile by naming it explicitly (the `x-profile-id` request header), which platforms use to keep a single credential while still routing traffic per tenant. Both approaches, per-profile keys and organization-key scoping, are shown with code in [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles); the scoping rules and error behavior are documented in [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api). ## Architectural Patterns [#architectural-patterns] ### Pattern 1: Agency Model [#pattern-1-agency-model] Centralized billing with dedicated WhatsApp Business Account per client: - **Billing**: Inherited (agency pays) - **WhatsApp Business Account**: Dedicated per profile (client branding) - **TCR brand**: Inherited, with a dedicated campaign per client - **Contacts and templates**: Dedicated per client; the agency still sees all of them from the organization ### Pattern 2: Franchise Model [#pattern-2-franchise-model] Shared resources with local brand presence: - **Billing**: Inherited (franchisor manages) - **WhatsApp Business Account**: Dedicated per location (local phone numbers) - **TCR brand and campaign**: Both inherited (one legal entity, one programme) - **Contacts and templates**: Dedicated per location, with the franchisor seeing all of them ### Pattern 3: Platform/ISV Model [#pattern-3-platformisv-model] Full tenant isolation: - **Billing**: Dedicated (tenants pay directly) - **WhatsApp Business Account**: Dedicated per tenant - **TCR brand and campaign**: Both dedicated, since tenants are distinct legal entities - **Contacts and templates**: Dedicated, as always The three patterns are points on one spectrum, and what varies between them is billing and compliance rather than data: customer data is isolated in all three. Choose by asking who pays, who the recipients believe they are hearing from, and who answers to regulators; the pattern falls out of those three answers rather than from the industry label. ## Where to Go from Here [#where-to-go-from-here] Now that you understand the governance model, you can act on it: - [Creating a Sender Profile](/start/guides/creating-a-sender-profile) walks through the dashboard wizard - [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles) covers per-profile API keys, customer mapping, and webhook attribution - [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api) automates profile provisioning for tenant onboarding - [Managing channels](/start/guides/managing-channels) covers giving a profile a sender and clearing its compliance - [Multi-Tenant Architectures](/start/advanced/multi-tenant-architectures) compares account-level alternatives to the profile model - [Roles and Permissions](/reference/api/roles-and-permissions) documents who can manage profiles within an organization # SMS Encoding & Message Length (/start/concepts/sms-encoding-and-length.md) # SMS Encoding & Message Length [#sms-encoding--message-length] An SMS is not a free-form text field with a simple character cap. The number of characters that fit in a single message, and how many billable messages a longer text becomes, depends on **which characters you use**. This is a property of the SMS standard itself, not of Sent, and understanding it is the difference between a predictable one-part message and one that silently becomes three. This page explains the mechanics. For how it maps to segment counts, billing, and practical tips on Sent (including a live calculator), see [SMS Length, Segments & Cost](/start/guides/sms-length-and-cost). ## Two encodings [#two-encodings] Every SMS is encoded one of two ways, decided automatically by the characters in the message body. ### GSM-7 (the default) [#gsm-7-the-default] Standard SMS uses **GSM-7**, a 7-bit alphabet defined by the GSM 03.38 standard. It covers everything most Latin-script messages need: - Upper- and lower-case A–Z and the digits 0–9 - Common punctuation and symbols - A set of accented and non-English Latin characters (`à é ù ì ò Ç Ø Å Δ Φ Ñ Ä Ö Ü §` and more) A message that uses only GSM-7 characters fits **160 characters** in a single SMS. ### The GSM-7 extension table [#the-gsm-7-extension-table] A small set of characters are technically part of GSM-7 but live in an *extension table*. They're sent as an escape character followed by the character itself, so each one **counts as two characters**: ```text \ | ^ € { } [ ] ~ ``` (Plus one non-printable entry, the form-feed control character, for ten in total.) A message like `Balance: {amount}` looks like 17 characters, but `{` and `}` are extension characters that each count as two, so it actually costs 19. It's still a GSM-7 message. A character that *isn't* in GSM-7 at all, such as an arrow (`→`), an emoji, or a curly quote, is a different matter, and brings you to the second encoding. ### Unicode (UCS-2) [#unicode-ucs-2] The moment a message contains **one single character** outside the GSM-7 set, the entire message switches to **Unicode (UCS-2)**, a 16-bit encoding. This includes: {/* The emoji in this list are the subject matter: they are the examples of characters that force UCS-2. */} {/* vale Sent.Emoji = NO */} - Emoji and other non-GSM symbols (😀, ✅, →, ™) - Non-Latin scripts (Arabic, Chinese, Japanese, Korean, Cyrillic, Greek, Hebrew, Thai, …) - Many "smart" typographic characters that word processors and phones insert automatically: curly quotes (`" "`), en/em dashes (`– —`), and the ellipsis (`…`) {/* vale Sent.Emoji = YES */} A Unicode message fits only **70 characters** in a single SMS. **One emoji re-encodes the whole message.** Unicode applies to the entire body, not just the non-GSM character. Adding a single 😀 to a 100-character message doesn't add one character. It changes the encoding, dropping your limit from 160 to 70 and turning a one-part message into a two-part one. The most common accidental trigger is a curly quote or an em dash pasted in from another app. ## Single message limits [#single-message-limits] | Encoding | Triggered by | Single-message limit | |---|---|---| | **GSM-7** | Latin text within the GSM 03.38 set | **160** characters | | **UCS-2 (Unicode)** | any emoji, non-Latin script, or non-GSM symbol | **70** characters | ## Longer messages: concatenation [#longer-messages-concatenation] When a message exceeds the single-message limit, it isn't rejected. Instead, it's split into multiple **segments** that the recipient's phone stitches back together into one message. This is called **concatenation**. Concatenation isn't free of overhead. Each segment carries a small **User Data Header (UDH)** that tells the receiving phone how many parts there are and in what order to reassemble them. That header consumes space that would otherwise hold message content, so **the per-segment limit is lower than the single-message limit**: | Encoding | Single message | Per segment when concatenated | |---|---|---| | **GSM-7** | 160 | **153** | | **UCS-2 (Unicode)** | 70 | **67** | So a 161-character GSM-7 message doesn't split into 160 + 1. It splits into two segments of up to 153 characters each. A 300-character GSM-7 message is 2 segments; a 459-character one (3 × 153) is exactly 3, and a single character more tips it into a fourth. **A GSM-7 extension character can't be split across a segment boundary.** Because characters like `{` or `€` are a two-character escape sequence, if one would land on the boundary between segments it's pushed wholesale into the next segment. In rare cases this means a message sits one character below a limit yet still rolls to an extra segment. ## Template body limit [#template-body-limit] Separately from these SMS-standard limits, Sent enforces a 1,024-character limit on stored template bodies at save time. This is a platform validation rule that applies regardless of encoding, documented with its counting semantics in the [template definition reference](/reference/api/template-definition#content-rules-and-limits). ## Why it matters [#why-it-matters] Three consequences follow directly from these mechanics, and each is covered in the [companion guide](/start/guides/sms-length-and-cost): - **Cost.** Each segment is a separately billed SMS. A message you think of as "one text" can bill as three. - **Predictability.** A template that's comfortably within 160 characters in English can exceed 70 once translated into a non-Latin script, or once a variable expands. - **Deliverability.** More segments mean more parts that must arrive and reassemble correctly; not every network handles long concatenated messages identically. ## Related [#related] --- # Templates (/start/concepts/templates.md) # Templates [#templates] A template in Sent is a reusable, channel-agnostic message definition. It describes what a message says (its text, variables, media, and buttons) once, and the platform adapts that definition to the formatting rules, limits, and approval processes of each channel it is delivered on. Rather than forcing developers to manage channel-specific message formats, templates provide a unified abstraction that automatically adapts to the capabilities and requirements of each messaging platform. ## The Template Abstraction [#the-template-abstraction] Before template systems, messaging applications faced significant architectural challenges. Developers had to manage the complexity of different messaging channels, each with their own formatting rules, character limits, and approval processes. Templates abstract away the complexity of different messaging channels, providing a unified interface for content creation and management. ### Channel-Agnostic Messaging [#channel-agnostic-messaging] Templates introduce a **channel-agnostic message definition layer** that describes communication intent and structure without being bound to specific [channel](/start/concepts/channels) implementations: - **Unified Definition Model**: A single template definition automatically generates appropriate content for all supported channels, eliminating the need for channel-specific message creation. - **Rich Content That Degrades Cleanly**: Templates support rich content (media, interactive buttons, structured layouts) that gracefully degrades to simpler formats on channels with limited capabilities. - **Regulatory Compliance**: Templates manage complex approval workflows required by different channels, including WhatsApp (via Meta) and RCS (via your RCS Sender Profile; see [Sender Profiles](/start/concepts/sender-profiles)), without developer intervention. - **Per-Channel Overrides**: Templates support an `rcs` channel override in the body, letting you define separate rich content (rich card layout, carousel, suggestion chips) for RCS while the same template falls back to plain text on SMS. This means a single template ID covers all channels without duplicate templates. ## Template Anatomy [#template-anatomy] Templates use a **declarative content model** with four primary components, each supporting [dynamic content](#dynamic-content): - **Body (required)**: The core message content that every channel must support, including text with embedded variables, links, and media references. On SMS, body length determines how many billable segments the rendered message becomes. See [SMS Encoding & Message Length](/start/concepts/sms-encoding-and-length). - **Header (optional)**: An introduction that can include text or media, adapting to each channel's capabilities. Headers render natively on WhatsApp and are prepended to the message text on RCS; SMS delivers body content only, so headers are omitted there. - **Footer (optional)**: Additional context such as disclaimers or contact information, appended or integrated based on channel formatting capabilities. - **Buttons (optional)**: Interactive elements including quick replies, URL buttons, and custom actions that channels implement according to their interaction models. ### Dynamic Content [#dynamic-content] Templates implement an **entity system** that handles dynamic content insertion with two primary types: - **Dynamic variables** - **Text variables**: Dynamic placeholders carrying a `variableType` of `text`, `link`, `image`, or `file`, plus a sample value used for previews and channel review. Values are substituted as strings, so formatting a number or a date is your app's job before it passes the value in. - **Media variables**: Image, video, and document references with automatic optimization, CDN delivery, and format adaptation that ensures rich content is delivered appropriately across channels. - **Dynamic links** - URL references with built-in optimization including automatic shortening, click tracking, and channel-appropriate formatting that adapts to channel constraints. ### Content Adaptation Mechanics [#content-adaptation-mechanics] The template system processes content through sophisticated adaptation: **Structural Transformation**: Templates define ideal message structure that automatically transforms to match each channel's capabilities: full structure for WhatsApp, body-only text for SMS. **Variable Substitution**: Type-aware rendering ensures variables display appropriately for each channel while maintaining business meaning and context. **Interactive Element Conversion**: Buttons render as interactive buttons on WhatsApp and as suggestion chips on RCS (the first four). SMS delivers body content only, so buttons are not delivered there. Essential links belong in the body. ### A Worked Example [#a-worked-example] Consider a shipping notification defined once, with two text variables and a dynamic link in the body, plus a URL button labeled "Track your order": ```text Hi {{0:variable}}, your order {{1:variable}} has shipped. Track it here: {{2:link}} ``` In the template definition, placeholder `0` is declared as a text variable named `customerName` and placeholder `1` as one named `orderNumber`, each with a sample value used for previews and channel approval; placeholder `2` is a link entity carrying the tracking URL. When your app sends the template with `parameters: { "customerName": "Maria", "orderNumber": "#4321" }`, the one definition renders differently per channel: - **On WhatsApp**: "Hi Maria, your order #4321 has shipped. Track it here: …" arrives as a structured template message with the link in the body and a tappable **Track your order** button beneath it. - **On SMS**: the same body arrives as a plain text message. The link in the body still reaches the recipient, but the button is not delivered, because SMS carries body content only. The business meaning is identical on both channels; only the packaging changes, and none of the adaptation logic lives in your app. ## Template Lifecycle [#template-lifecycle] Templates implement a **managed lifecycle** that handles complexity and compliance automatically: 1. **Draft state**: New templates begin in draft state, allowing experimentation without impacting production messaging or triggering external approval processes. 2. **Validation and processing**: When published, templates undergo automatic validation, entity processing, and format optimization before becoming available for message sending. 3. **Approval integration**: For channels requiring approval (WhatsApp via Meta, RCS via your RCS Sender Profile), the system automatically submits templates and tracks approval status, managing complex interaction with external platform APIs. ## Templates for Developers [#templates-for-developers] Applications should adopt a **template-first approach** by implementing template-driven messaging architectures. Your app should: - **Treat templates as contracts**: Templates define the interface between app logic and message delivery, creating a stable contract that isolates business logic from messaging platform complexity. - **Provide dynamic variables**: Applications provide data to templates rather than constructing messages directly, enabling consistent formatting and automated optimization. - **Implement channel-agnostic operations**: Messaging code references template IDs and provides variable data, while the platform handles channel selection, formatting, and delivery optimization. This allows you to send messages to WhatsApp, SMS, RCS, and other channels with the same codebase. **Success with templates requires adopting specific thinking patterns:** - **Think Intent, Not Channels**: Focus on communication purpose rather than technical delivery methods. - **Design Rich, Degrade Gracefully**: Create rich experiences knowing that automatic adaptation ensures broad compatibility. - **Trust Template Intelligence**: Allow the platform to handle compliance, optimization, and adaptation rather than implementing custom logic. To put this model to work, [Working with Templates](/start/guides/working-with-templates) is the practical starting point for building and approving templates, and the [template definition reference](/reference/api/template-definition) documents every field, limit, and status of the definition JSON. For how routing chooses the channel a template renders on, see [Unified Messaging Intelligence](/start/concepts/unified-messaging). --- # Trust & Safety (/start/concepts/trust-and-safety.md) # Trust & Safety [#trust--safety] Every message you send through Sent passes through a multi-layer protection pipeline before it is dispatched to any carrier or provider. This pipeline exists to protect your recipients, your account, and the platform from spam, fraud, and abuse. None of this requires any configuration on your part. The protections operate automatically on every send request. ## What the pipeline checks [#what-the-pipeline-checks] Each message is evaluated against a series of independent checks, in order. Apart from account standing, which is enforced when the request arrives, the checks run inside the message pipeline, after the API has accepted your send with `202 Accepted`. A message that fails a check is finalized with a terminal status and reason instead of being dispatched. No provider is contacted, and no charges are incurred. - **Account standing**: Accounts under review or suspension cannot send messages until the issue is resolved. - **Recipient opt-out**: Contacts who have opted out of receiving messages are automatically respected. Sends to opted-out recipients are filtered before dispatch. - **Geographic restrictions**: Sending to certain destinations is restricted based on carrier fraud patterns and regulatory requirements. Your account is provisioned for the countries you declared during onboarding. - **Onboarding compliance**: Accounts that have not yet completed compliance review are subject to sending limits. Completing verification removes these limits. - **Template approval**: Only approved templates may be used for sending. Templates must pass provider review (WhatsApp / TCR) and any applicable platform review before they become active. - **Sender health**: WhatsApp isn't used for a send when Meta reports that your WhatsApp Business Account or its number can't send messages. A send pinned to WhatsApp fails, and an automatically routed one tries its other channels. Meta business verification isn't part of this check, and a Meta lookup that fails briefly doesn't block anything. - **Balance**: A positive account balance is required before any message is dispatched. If the balance is exhausted, the API still accepts the send and each message is finalized as `BLOCKED` instead of being dispatched. New sends go through once you top up. - **Risk screening**: New accounts undergo an automated risk and compliance assessment during onboarding to identify prohibited industries and high-risk patterns before messages are sent at scale. {/* TODO(verify): the generated v3 OpenAPI spec still declares a synchronous 402 on POST /v3/messages, but sent-dm-services commit 549a6939e moved the balance gate async (202 + BLOCKED). This page documents the code behavior; re-check when engineering settles the Swagger metadata (escalations 2026-07-25, item 1). */} ## How this affects your integration [#how-this-affects-your-integration] Under normal operating conditions (verified account, positive balance, approved templates, opted-in recipients), you will never encounter these checks. They are invisible. Only request-shape and account-standing problems are rejected synchronously: an unknown template returns `404`, invalid template variables return `400`, and send requests from a suspended account are rejected with `403` and code `BUSINESS_014`. Everything else is decided inside the pipeline after the API accepts the send. A message stopped by a check is finalized with a terminal status and a specific reason code rather than a generic failure. The status appears on `GET /v3/messages/{id}`, its activities, and `message.filtered` / `message.blocked` webhooks: | Check | Final status | Reason code | |-------|--------------|-------------| | Recipient opt-out or suppression list | `FILTERED` | `ERR_CONSENT_BLOCKED` | | Routing rules, including geographic restrictions | `FILTERED` | `ERR_ROUTE_DENIED` | | Insufficient balance | `BLOCKED` | `ERR_INSUFFICIENT_BALANCE` | | Onboarding sending limit reached (KYC stage) | `BLOCKED` | `ERR_KYC_COMPLETED_QUOTA_EXCEEDED` | | Onboarding sending limit reached (channel-setup stage) | `BLOCKED` | `ERR_CHANNEL_SETUP_COMPLETED_QUOTA_EXCEEDED` | | Template not approved for sending | `BLOCKED` | `ERR_TEMPLATE_NOT_APPROVED_FOR_SENDING` | | Light-onboarding template not published | `FAILED` | `ERR_LOB_TEMPLATE_NOT_PUBLISHED` | | Light-onboarding template daily cap reached | `FAILED` | `ERR_LOB_TEMPLATE_DAILY_CAP_REACHED` | | WhatsApp sender health (Meta reports the account can't send) | `FAILED` | `ERR_WABA_DEGRADED` | `FILTERED` and `BLOCKED` are policy decisions, not delivery failures, and both are excluded from your deliverability rate. Resending without resolving the underlying issue produces the same outcome. See the [Error Catalog](/reference/api/error-catalog) for full remediation steps. ## Opt-out handling [#opt-out-handling] Sent automatically enforces recipient opt-outs. When a contact replies with a recognized opt-out keyword (such as STOP or UNSUBSCRIBE), their record is updated immediately and all future sends to that number are blocked. You can also manage opt-out status programmatically through the Contacts API. An attempt to send to an opted-out contact is still accepted by the API; the message is then finalized as `FILTERED` before any provider is contacted. The contact's preference is always respected. ## Geographic availability [#geographic-availability] Your account is provisioned for specific destination countries based on the information you provide during onboarding. Sending to destinations outside your approved list is blocked to protect against carrier fraud patterns that disproportionately affect certain routes. If your business legitimately needs to reach a destination that is currently unavailable on your account, contact [support@sent.dm](mailto:support@sent.dm). ## Completing verification [#completing-verification] Accounts that have not yet completed compliance review can send messages up to a limited threshold. Once that threshold is reached, further messages are finalized as `BLOCKED` and your account team will be notified to assist you in completing the process. To ensure uninterrupted sending, complete KYC verification, channel setup, and template approval before going live. The [account setup guide](/start/quickstart/account-setup) walks through each step. ## Getting help [#getting-help] If you encounter a protection-layer error that you believe is incorrect, or if your account has been suspended in error, contact [support@sent.dm](mailto:support@sent.dm) with your request ID. Include the full error response. The request ID in the response body allows the support team to trace the exact check that triggered. --- # Unified Messaging Intelligence (/start/concepts/unified-messaging.md) # Unified Messaging Intelligence [#unified-messaging-intelligence] Most messaging platforms expose separate APIs for SMS, WhatsApp, RCS, and other channels. That means developers end up writing routing code, handling edge cases, and debugging delivery problems across multiple providers. Sent takes a different approach: instead of giving you channel-specific APIs, Sent gives you a single interface that understands your intent (what you want to send, to whom, and why) and figures out the best way to deliver it. ## The Intelligent Architecture [#the-intelligent-architecture] When you integrate directly with channel APIs, you run into the same problems every time: - **Integration Sprawl**: Each channel has different auth, payload formats, error codes, and quirks. - **Business Logic Scattered Everywhere**: Your app logic gets littered with “if WhatsApp, do this; if SMS, do that; if RCS, do something else,” making the code harder to maintain. - **You Own the Routing Logic**: You’re responsible for retries, fallbacks, and figuring out what channels are available for a given phone number as well as which channel is fastest, cheapest, and most reliable. Sent flips that around: you implement messaging into your app once, and the platform handles channel selection, routing, retries, and compliance. ### Imperative vs. Declarative Messaging [#imperative-vs-declarative-messaging] The two integration styles differ in where the routing knowledge lives. Imperative code encodes channel decisions in your app; declarative code states the intent and leaves the decision to the platform: **Imperative messaging**: ```javascript if (user.hasWhatsApp && templateApproved) { await whatsappAPI.send(whatsappTemplate, user.whatsappId); } else if (user.hasSMS) { await smsAPI.send(smsMessage, user.phoneNumber); } ``` **Declarative messaging with Sent**: ```javascript await sent.sendMessage({ phoneNumber: "+1234567890", templateId: "order_confirmation", templateVariables: { orderId: "12345", total: "$99.99" } }); ``` The imperative version already contains two channel checks and no fallback handling; every new channel, region, or compliance rule adds another branch. The declarative version stays the same size as those concerns grow, because they are absorbed by the platform. The [Sending Messages guide](/start/guides/sending-messages) shows the declarative call in full, including how to pin a channel explicitly when you need to. Messaging complexity shouldn’t live in your codebase. Sent centralizes it as infrastructure: - **Absorbed Complexity**: Multi-channel routing, compliance, and optimization handled once, not by every app. - **Centralized Expertise**: Sent maintains the industry rules, carrier quirks, and provider integrations. - **Faster Innovation**: New features and integrations roll out at the platform level. **Sent chooses the channel, adapts content, handles fallbacks.** This way you can focus on your business logic instead of channel quirks. ## The Decision Engine [#the-decision-engine] ### Real-Time Routing [#real-time-routing] Every message you send through Sent is resolved by a routing engine at send time, after the API has accepted the request. For each recipient, the engine weighs: * **The requested channel**: a pinned channel (`sms`, `whatsapp`, `rcs`) restricts routing to that channel; the default auto-detect channel lets the engine choose. * **Routing rules**: rules matched on the recipient (country, number prefix, carrier, number type), the sender, the template, and the channel. Account-scoped rules take precedence over global ones, and more specific matches over less specific ones. * **Channel capability**: whether the recipient is registered on WhatsApp, whether the device supports RCS, and whether the template is approved on each candidate channel. * **Compliance gates**: recipient consent and account preconditions are checked before any route is attempted. The matching rules form an ordered candidate list: the first candidate wins and the message dispatches on it, while the remaining candidates are held as fallback routes. There is no fixed channel preference order: the winner depends on which routes exist for your account and the recipient. The factors that decide among viable channels are summarized in [Routing Factors](/start/concepts/channels#routing-factors), and the exact matching and ordering rules are specified in the [channel routing reference](/reference/channel-routing). ### Fallback [#fallback] When a route fails, Sent walks the fallback candidates that routing already resolved instead of giving up on the message: the message?} Delivered([✓ Message delivered]) MoreCandidates{Rule allows fallback and
candidates remain?} Next[Attempt next
candidate route] DlrFailed{Delivery
failed later?} Overcomable{Failure a different route
might overcome?} Reroute[Re-enter routing,
excluding attempted routes] Stop[Report failure via
webhook and API] Start --> Submitted Submitted -->|No| MoreCandidates MoreCandidates -->|Yes| Next Next --> Submitted MoreCandidates -->|No| Stop Submitted -->|Yes| DlrFailed DlrFailed -->|No| Delivered DlrFailed -->|Yes| Overcomable Overcomable -->|Yes| Reroute Reroute --> Start Overcomable -->|No| Stop style Start fill:#4F46E5,stroke:#4338CA,color:#fff style Delivered fill:#10B981,stroke:#059669,color:#fff style Stop fill:#EF4444,stroke:#DC2626,color:#fff style Overcomable fill:#F59E0B,stroke:#D97706,color:#fff style Next fill:#8B5CF6,stroke:#7C3AED,color:#fff style Reroute fill:#06B6D4,stroke:#0891B2,color:#fff `} width={800} /> **How the fallback path behaves:** * **Failed submission to a provider** → the next candidate route is attempted, when the matched rule allows fallback. That next route may be the same channel through a different provider, or a different channel on auto-detect sends. * **Accepted, then reported as failed** → the message re-enters routing only when the failure is one a different route might overcome, such as a provider outage, timeout, or a WhatsApp recipient-side failure (the path behind WhatsApp-to-SMS fallback). Routes already attempted are excluded, and a message attempts at most 3 distinct routes. * **Permanent failures** (invalid number, opted-out recipient) → the send stops and the terminal status is reported. Consent is re-checked on every reroute, so an opted-out recipient never receives a fallback attempt. Each attempt and the terminal outcome surface as status webhooks. See [Message Status Tracking](/start/guides/message-status-tracking) for observing this lifecycle from your app. ### Multi-Provider Orchestration [#multi-provider-orchestration] Sent plugs into multiple carriers and APIs, normalizing the differences: - **Provider Abstraction**: One interface to SMS providers, WhatsApp Business API, RCS providers, and others. - **Health Monitoring**: Real-time checks on provider reliability and limits. - **Load Balancing**: Spreads traffic across providers for cost, capacity, and performance. ### Regulatory Compliance [#regulatory-compliance] **Built-In Regulatory Compliance Logic**: - **Global Rules**: Sent tracks country-specific restrictions and applies them at send time. - **Consent Enforcement**: Opt-ins/outs applied consistently across all channels. - **Content Validation**: Automatic checks against carrier and platform rules. **Template Approvals (WhatsApp)**: - **Submission Automation**: Templates formatted and submitted through each channel's approval flow automatically: Meta for WhatsApp, carrier verification for RCS. - **Status Tracking**: Approval state synced back into your system. - **Retry Logic**: Failed approvals reworked and resubmitted. Compliance is baked into the platform. No chasing new regulations or patching code every time rules change. ### Always Learning [#always-learning] The routing engine learns from real delivery data: * **Pattern recognition** → what works best by region, channel, time * **Anomaly detection** → auto-adapts to outages and disruptions * **Route tuning** → balances cost, reliability, and engagement ### Network Effects [#network-effects] Because all apps share the same intelligence layer, everyone benefits: * **Shared learnings** → improve delivery everywhere * **Regional insights** → drive smarter defaults * **Carrier relationships** → are used at platform scale ## Template-Driven Intelligence [#template-driven-intelligence] ### Templates as Config, Not Hardcoded Messages [#templates-as-config-not-hardcoded-messages] Templates let you describe intent (“confirm order,” “welcome user”) without worrying about formatting differences between SMS, WhatsApp, and RCS. Sent adapts them automatically. For RCS, templates can include an `rcs` channel override that defines rich card layouts, suggestion chips, and carousel cards, while the same template ID delivers plain text on SMS: * **Built-in compliance** (WhatsApp approval, SMS opt-in, regional rules) * **Rich formats where the channel supports them** (plain text everywhere else) How this adaptation works is the subject of the [Templates concept page](/start/concepts/templates); [Working with Templates](/start/guides/working-with-templates) shows how to build and publish one. ### Variables for Dynamic Content [#variables-for-dynamic-content] * **Type-safe**: Variables know their types and adapt across channels * **Context-preserving**: Business meaning stays intact while formatting adjusts * **Fallback values**: Missing/invalid variables degrade gracefully ## Built for Change [#built-for-change] Messaging isn’t static. New channels, new compliance rules, new algorithms. Sent’s architecture is designed to absorb this without you rewriting your code: * **Plug-in new channels** without changing your app * **Routing algorithms auto-upgrade** as Sent improves them * **Compliance handled at the platform level**, so you stay safe without extra work Sent’s unified messaging intelligence removes multi-channel complexity from your codebase by abstracting away provider APIs and routing logic. You express intent, Sent handles delivery. As channels, carriers, and provider APIs change, Sent absorbs the change, so your app doesn’t need constant rewrites. The trade-off is the one you accept with any managed abstraction, whether a payments API or a container orchestrator: you give up direct control over per-channel mechanics in exchange for one consistent interface that hides provider complexity. For most applications that trade is worth making, because routing rules, compliance requirements, and provider integrations change faster than product code should. When you do need direct control, you can pin a channel explicitly in the send request. The value here isn’t just integration simplicity. Routing rules, provider health handling, and compliance gates are maintained at the platform level, so each application benefits from work no single app team would build on its own. --- # Answering Calls (/start/guides/answering-calls.md) # Answering Calls [#answering-calls] Every call on one of your voice numbers is decided by your own backend. When a call starts, Sent POSTs a question to the number's callback URL and follows the answer: ring an app user, dial a number, play a menu, hold, or hang up. This guide covers the loop, how to verify that a question came from Sent, the deadline your endpoint has to meet, and how to test the URL before a real call reaches it. ## Prerequisites [#prerequisites] Phone calls must be enabled for your account. This is set by Sent: contact [support@sent.dm](mailto:support@sent.dm) to request it. You also need: - A number with calls turned on and a callback URL stored on it. See [Voice](/start/guides/managing-channels#voice) in the channels guide. A number bound to a [voice agent](/start/guides/voice-agents) isn't asked: the agent takes calls to it, and only calls your app places from the number reach the callback. - A public HTTPS URL for that callback (HTTP is accepted too, but use HTTPS). Sent only calls URLs that resolve to a public address, so a tunnel is needed even on one laptop. - A webhook subscribed to `call` events, so you learn when a call is answered, ends, or has a recording ready. See the [`call` events](/start/webhooks/event-types#call). ## How a Call Is Answered [#how-a-call-is-answered] Sent asks, your backend answers, and the call does what the answer says. There are two questions. 1. **`call.request`** when a call starts: someone dialed your number, or a user of your app placed a call. Your answer decides where the call goes. 2. **`call.input`** when a caller presses keys on a menu you played. Your answer decides what happens next, which is how menus chain. A `call.request` for a call placed from your app to a phone number looks like this: ```json { "type": "call.request", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:00+00:00", "direction": "outbound", "from": { "kind": "user", "identity": "agent-42" }, "to": { "kind": "number", "number": "+14155551234" } } ``` `callId` is Sent's id for the call. It is the same id on every later question, on every `call.*` webhook, and on `GET /v3/voice/calls/{id}`. `number` is your voice number that owns the call: the dialed number for an inbound call, the caller's bound number for a call placed from your app, or your default number for app calls when the caller has none bound. An answer carries optional instructions, which run in order, and exactly one action, which decides where the call goes. The shortest valid answer rings an app user: ```json { "action": { "action": "connectToUser", "identity": "ben", "record": false } } ``` Answer with HTTP `200` and a JSON body. The [Voice Callback Contract](/reference/api/voice-callback) lists every question field, every action, every instruction, and the rules each one is checked against. Three casings meet here. The question and answer use `camelCase` (`callId`, `dialTimeoutSeconds`). The REST API and the `call.*` webhooks use `snake_case` (`call_id`, `duration_seconds`). A handler that reads `call_id` off a question gets nothing. ## Verify the Signature [#verify-the-signature] Every question is signed, the same way your webhooks are. Verify it before you act on the question. | Header | What it carries | | --- | --- | | `X-Webhook-ID` | The id of the voice number's callback configuration. Not the number, and not one of your webhook ids | | `X-Webhook-Timestamp` | Unix seconds at which this attempt was signed | | `X-Webhook-Signature` | `v1,` followed by the Base64 HMAC-SHA256 of `{id}.{timestamp}.{rawBody}` | | `X-Request-Id` | Sent's id for this request, for support | | `X-Sent-Retry` | `1` on the one retry Sent makes, absent on the first attempt | | `User-Agent` | `SentDM-Voice/1.0` | The key is the number's `callback_secret`, returned once by `POST /v3/channels/voice` and again by `POST /v3/channels/voice/{number}/rotate-secret`. Strip the `whsec_` prefix and Base64-decode the rest to get the raw key bytes. Each voice number has its own secret, so pick the one for the number named in the question's `number` field. The scheme is the one your webhooks already use, described in [Webhook Security](/start/webhooks/signature-verification). Sign over the raw body exactly as it arrived. Parsing and re-serializing the JSON changes the bytes and the check fails. Reject a timestamp more than 5 minutes away from your clock, which stops a captured question from being replayed later. Answer `401` to a question that does not verify: Sent treats a 4xx as your refusal of the call and does not retry. ```typescript import express from 'express'; import { createHmac, timingSafeEqual } from 'node:crypto'; const TOLERANCE_SECONDS = 300; function verifySentSignature(headers, rawBody, secret) { const id = headers['x-webhook-id']; const timestamp = headers['x-webhook-timestamp']; const signature = headers['x-webhook-signature']; if (!id || !timestamp || !signature) return false; const skew = Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)); if (!Number.isFinite(skew) || skew > TOLERANCE_SECONDS) return false; const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const expected = createHmac('sha256', key).update(`${id}.${timestamp}.${rawBody}`).digest(); return signature .split(/\s+/) .filter((part) => part.startsWith('v1,')) .some((part) => { const provided = Buffer.from(part.slice(3), 'base64'); return provided.length === expected.length && timingSafeEqual(provided, expected); }); } const app = express(); // Raw body: the signature covers the bytes as sent, so do not use express.json() on this route app.post('/voice/callback', express.raw({ type: 'application/json' }), (req, res) => { const rawBody = req.body.toString('utf8'); const question = JSON.parse(rawBody); const secret = secretForNumber(question.number); // the callback secret of that voice number if (!verifySentSignature(req.headers, rawBody, secret)) { return res.status(401).json({ error: 'Invalid signature' }); } res.json({ action: { action: 'connectToUser', identity: 'agent-42' } }); }); ``` ```python import base64, hashlib, hmac, time from flask import Flask, request, jsonify TOLERANCE_SECONDS = 300 def verify_sent_signature(headers, raw_body: bytes, secret: str) -> bool: webhook_id = headers.get("X-Webhook-ID") timestamp = headers.get("X-Webhook-Timestamp") signature = headers.get("X-Webhook-Signature") if not webhook_id or not timestamp or not signature: return False try: skew = abs(int(time.time()) - int(timestamp)) except ValueError: return False if skew > TOLERANCE_SECONDS: return False key = base64.b64decode(secret.removeprefix("whsec_")) signed = f"{webhook_id}.{timestamp}.".encode() + raw_body expected = hmac.new(key, signed, hashlib.sha256).digest() for part in signature.split(): if not part.startswith("v1,"): continue try: provided = base64.b64decode(part[3:]) except ValueError: continue if hmac.compare_digest(provided, expected): return True return False app = Flask(__name__) @app.post("/voice/callback") def voice_callback(): raw_body = request.get_data() # the bytes as sent, before any parsing question = request.get_json(force=True) secret = secret_for_number(question["number"]) # the callback secret of that voice number if not verify_sent_signature(request.headers, raw_body, secret): return jsonify(error="Invalid signature"), 401 return jsonify(action={"action": "connectToUser", "identity": "agent-42"}) ``` ```go package main import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/json" "io" "math" "net/http" "strconv" "strings" "time" ) const toleranceSeconds = 300 func verifySentSignature(h http.Header, rawBody []byte, secret string) bool { id := h.Get("X-Webhook-ID") timestamp := h.Get("X-Webhook-Timestamp") signature := h.Get("X-Webhook-Signature") if id == "" || timestamp == "" || signature == "" { return false } ts, err := strconv.ParseInt(timestamp, 10, 64) if err != nil || math.Abs(float64(time.Now().Unix()-ts)) > toleranceSeconds { return false } key, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(secret, "whsec_")) if err != nil { return false } mac := hmac.New(sha256.New, key) mac.Write([]byte(id + "." + timestamp + ".")) mac.Write(rawBody) expected := mac.Sum(nil) for _, part := range strings.Fields(signature) { if !strings.HasPrefix(part, "v1,") { continue } provided, err := base64.StdEncoding.DecodeString(part[3:]) if err == nil && hmac.Equal(provided, expected) { return true } } return false } func voiceCallback(w http.ResponseWriter, r *http.Request) { rawBody, _ := io.ReadAll(r.Body) // the bytes as sent, before any parsing var question struct { Number string `json:"number"` } _ = json.Unmarshal(rawBody, &question) secret := secretForNumber(question.Number) // the callback secret of that voice number if !verifySentSignature(r.Header, rawBody, secret) { http.Error(w, `{"error":"Invalid signature"}`, http.StatusUnauthorized) return } w.Header().Set("Content-Type", "application/json") w.Write([]byte(`{"action":{"action":"connectToUser","identity":"agent-42"}}`)) } ``` ```csharp using System.Security.Cryptography; using System.Text; using System.Text.Json; const int ToleranceSeconds = 300; static bool VerifySentSignature(IHeaderDictionary headers, string rawBody, string secret) { string? id = headers["X-Webhook-ID"]; string? timestamp = headers["X-Webhook-Timestamp"]; string? signature = headers["X-Webhook-Signature"]; if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(timestamp) || string.IsNullOrEmpty(signature)) return false; if (!long.TryParse(timestamp, out var ts) || Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) > ToleranceSeconds) return false; var key = Convert.FromBase64String(secret.StartsWith("whsec_") ? secret["whsec_".Length..] : secret); var expected = HMACSHA256.HashData(key, Encoding.UTF8.GetBytes($"{id}.{timestamp}.{rawBody}")); foreach (var part in signature.Split(' ', StringSplitOptions.RemoveEmptyEntries)) { if (!part.StartsWith("v1,")) continue; byte[] provided; try { provided = Convert.FromBase64String(part[3..]); } catch (FormatException) { continue; } if (CryptographicOperations.FixedTimeEquals(provided, expected)) return true; } return false; } app.MapPost("/voice/callback", async (HttpRequest request) => { using var reader = new StreamReader(request.Body); var rawBody = await reader.ReadToEndAsync(); // the body as sent, before any parsing var number = JsonDocument.Parse(rawBody).RootElement.GetProperty("number").GetString(); var secret = SecretForNumber(number); // the callback secret of that voice number if (!VerifySentSignature(request.Headers, rawBody, secret)) return Results.Json(new { error = "Invalid signature" }, statusCode: 401); return Results.Json(new { action = new { action = "connectToUser", identity = "agent-42" } }); }); ``` ```php TOLERANCE_SECONDS) { return false; } $encoded = str_starts_with($secret, 'whsec_') ? substr($secret, 6) : $secret; $key = base64_decode($encoded, true); if ($key === false) { return false; } $expected = hash_hmac('sha256', "$id.$timestamp.$rawBody", $key, true); foreach (preg_split('/\s+/', $signature) as $part) { if (!str_starts_with($part, 'v1,')) { continue; } $provided = base64_decode(substr($part, 3), true); if ($provided !== false && hash_equals($expected, $provided)) { return true; } } return false; } $rawBody = file_get_contents('php://input'); // the body as sent, before any parsing $question = json_decode($rawBody, true); $secret = secretForNumber($question['number']); // the callback secret of that voice number $headers = [ 'X-Webhook-ID' => $_SERVER['HTTP_X_WEBHOOK_ID'] ?? '', 'X-Webhook-Timestamp' => $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? '', 'X-Webhook-Signature' => $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '', ]; if (!verifySentSignature($headers, $rawBody, $secret)) { http_response_code(401); echo json_encode(['error' => 'Invalid signature']); exit; } header('Content-Type: application/json'); echo json_encode(['action' => ['action' => 'connectToUser', 'identity' => 'agent-42']]); ``` The signature header can carry more than one `v1,` value separated by spaces, which is why each snippet checks every part. Sent sends one today. ## Deadlines and Retries [#deadlines-and-retries] A caller is waiting while your endpoint decides, so the deadline is short. | Limit | Value | | --- | --- | | Time per attempt, including DNS, connecting, and reading the body | 2.5 seconds | | Attempts to the same URL | 2 | | Largest response body | 64 KiB | A failed attempt is anything other than a `2xx` with a body Sent can read as an answer: a timeout, a connection failure, a `3xx` (redirects are not followed), a `5xx`, a body over 64 KiB, a callback URL Sent will not call, or an answer that fails validation. Sent asks once and retries once, with `X-Sent-Retry: 1`, unless the first attempt answered with a `4xx`. A `4xx` is your refusal of the call and is not retried. The retry carries the same `callId`, so a handler that saw the first attempt can answer the same way again. The outcome is whatever the last attempt produced, and the two attempts need not fail the same way. A first attempt with an unreadable body followed by a second that times out ends as `callback_timeout`; a first attempt that times out followed by a `4xx` ends as `rejected`. Do no network calls inside the handler. Decide from what you already know: who is online, which department a number belongs to, what the caller pressed. The example app keeps its routing rules in memory for this reason, and anything slower than the deadline, such as looking a caller up in a remote CRM, belongs in a cache your handler reads rather than a call it makes. ## What Happens When Your Callback Fails [#what-happens-when-your-callback-fails] What a failure does to the call depends on which question it was. - **On `call.request`** the call has not been answered yet, so it fails. The call ends with `status` `FAILED` and you receive `call.failed` with a `reason` taken from the last attempt: `callback_timeout` when it timed out, could not connect, was answered with a `3xx` or a `5xx`, returned a body over 64 KiB, or the URL was one Sent will not call; `invalid_answer` when it returned a `2xx` with a body that was not an answer Sent could use; `rejected` when it returned a `4xx`. A `callback_timeout` is not always a slow server: check the response size and that the URL answers directly, without a redirect. - **On `call.input`** the call was already answered by the menu, so it is hung up instead. It ends with `status` `COMPLETED`, is billed for the time it ran, and you receive `call.completed`. The same holds for a `4xx` or a `reject` action on a `call.input`. Some calls are refused before any question is asked. A call placed from your app is hung up when your balance is at or below zero (`insufficient_balance`), whoever it is to: a phone number, another app user, or a room. A call placed from your app to a phone number in a country Sent does not allow calls to is hung up too (`destination_blocked`). Inbound calls to your numbers are not checked for balance before the question; a phone leg your answer adds to one is. A call to a number that has no callback URL stored is hung up as well (`callback_not_configured`). A call placed from your app on such a number is not: it connects straight to the phone number, app user, or room it dialed. Each arrives as `call.failed` with that reason, after a `call.initiated`: that event is sent when the call arrives, before these checks run, so it does not mean your callback was asked. The full list is in [Call Failure Reasons](/reference/api/error-catalog#call-failure-reasons). ## Keep State With Cookies [#keep-state-with-cookies] Your backend does not have to remember anything between questions. A `setCookie` instruction stores a value against the call, and every later `call.input` for that call carries the whole set under `cookies`. A later value replaces an earlier one under the same key, and the cookies live as long as the call does. An answer that plays a menu and remembers which step the caller is on: ```json { "instructions": [ { "instruction": "setCookie", "key": "step", "value": "account-number" } ], "action": { "action": "playMenu", "prompt": { "text": "Enter your four digit account number" }, "maxDigits": 4, "timeoutSeconds": 8 } } ``` The keypress comes back with everything stored so far: ```json { "type": "call.input", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:07+00:00", "digits": "1", "cookies": { "step": "greeted", "department": "sales" } } ``` `digits` is an empty string when the menu timed out without input. `cookies` is absent when nothing was stored yet. ## Test Before the First Call [#test-before-the-first-call] `POST /v3/channels/voice/{number}/test` sends a synthetic `call.request` to the number's callback URL, signed with that number's real secret, and reports what came back. No call is placed, nothing is billed, and nothing is stored. The question carries `"test": true`, which a real call never does, so a backend can treat a question without the field as a live call. The number goes in the path with its plus sign URL-encoded as `%2B`. ```bash curl -X POST "https://api.sent.dm/v3/channels/voice/%2B12025550123/test" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' ``` The verdict is `outcome`: `ok` when your endpoint answered 2xx with a valid answer, otherwise `timeout`, `connection_failed`, `http_error`, or `invalid_answer`. The response also shows the exact headers and body your endpoint received, so you can compare them against what it verified, and your answer as Sent read it, with a missing caller id filled in and numbers normalized. ```json { "success": true, "data": { "outcome": "ok", "call_id": "call_9f2ab000-0000-4000-8000-000000000001", "request": { "url": "https://example.com/voice", "headers": { "User-Agent": "SentDM-Voice/1.0", "X-Webhook-ID": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "X-Webhook-Timestamp": "1784721600", "X-Webhook-Signature": "v1,xJ/WfHm26o0BBWZ/SIDmZio7C3BbqlcbxvO/QIZpjUA=", "X-Request-Id": "req_7X9zKp2jDw" }, "body": "{\"type\":\"call.request\",\"version\":\"1\",\"callId\":\"call_9f2ab000-0000-4000-8000-000000000001\",\"number\":\"+12025550123\",\"timestamp\":\"2026-07-22T12:00:00+00:00\",\"test\":true,\"direction\":\"outbound\",\"from\":{\"kind\":\"user\",\"identity\":\"test-user\"},\"to\":{\"kind\":\"number\",\"number\":\"+12025550142\"}}" }, "response": { "status_code": 200, "body": "{ \"action\": { \"action\": \"connectToUser\", \"identity\": \"agent-42\" } }" }, "answer": { "action": { "action": "connectToUser", "identity": "agent-42", "record": false } }, "error": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` The `X-Webhook-Signature` value in this example is illustrative and does not verify against the body shown. A real response carries the signature computed over the exact body that was sent. When the outcome is not `ok`, `error` says what went wrong: a machine-readable `reason` such as `timeout`, `http_error`, `malformed_json`, `missing_action`, or `unknown_action`, the dotted `path` of the answer field at fault when one field is to blame, and a `message` saying what to fix. `call_id` exists nowhere else and cannot be looked up. A wrong secret shows up here as your endpoint answering `401` and the outcome `http_error`. Fix the secret your handler uses, not the signature check, and run the test again before taking a real call. ## Next Steps [#next-steps] # Creating and Managing API Keys (/start/guides/api-keys.md) # Creating and Managing API Keys [#creating-and-managing-api-keys] This guide shows you how to create a Sent API key, store it securely, verify that it authenticates, and rotate or revoke it. It assumes you have a Sent account with the Owner, Admin, or Developer role; these roles can open the API Keys page. ## Create an API key [#create-an-api-key] 1. In the [Sent Dashboard](https://app.sent.dm), open **Development → API Keys** in the sidebar, or go directly to the [API Keys page](https://app.sent.dm/dashboard/api-keys). 2. Select **Add API Key**. 3. Name the key after where it will be used (for example, `production-backend`), then select **Create Key**. The key appears in the table with its value masked. Use the copy control on the key value to copy the full key. If you deploy to more than one environment, create a separate key for each (development, staging, production). All keys share the same UUID format; separate keys let you rotate or revoke one environment without touching the others. The page header also displays the ID of your current selection, labeled **Organization ID** or **Profile ID**. It is not a credential: v3 requests authenticate with the API key alone, and you pass this ID only as the `x-profile-id` header when an organization key sends on behalf of a profile, or as `x-sender-id` on legacy v1/v2 endpoints. ## Store the key securely [#store-the-key-securely] Keep the key out of source code. Load it from an environment variable: ```bash # .env — add this file to .gitignore SENT_API_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` - Never commit keys to version control; a key in repository history stays exposed even after you delete it from the working tree. - Never ship a key to a browser or mobile app. Call the API from your backend only. - If each of your customers has their own Sent account and supplies their own key, build a per-request client instead of reading one key from the environment. See the integration blueprint's [per-request authentication pattern](/build/authentication). ## Verify the key authenticates [#verify-the-key-authenticates] Call the account endpoint with the new key: ```bash curl https://api.sent.dm/v3/me \ -H "x-api-key: $SENT_API_KEY" ``` A `200` response with your account profile confirms the key works. If you get a `401` with error code `AUTH_002`: {/* vale Google.WordList = NO */} {/* "Disabled" is the key state the dashboard shows in the Status column, not a generic verb. */} - Confirm you copied the full key and the header value is not empty (`echo $SENT_API_KEY`). - Check the key's **Status** in the API Keys table; a disabled key is rejected. - Confirm you are using the key for the intended environment. {/* vale Google.WordList = YES */} If you retry a failing key repeatedly, 10 consecutive failures temporarily lock that credential and the API returns `429`. Wait for the `Retry-After` period, then retry with a valid key. See the [Authentication reference](/reference/api/authentication) for the exact error responses. ## Rotate a key [#rotate-a-key] To rotate without downtime: {/* vale Google.WordList = NO */} {/* "Disable" is the action Sent labels in the dashboard Actions column, not a generic verb. */} 1. Create a replacement key as described in [Create an API key](#create-an-api-key). 2. Update `SENT_API_KEY` in your environment or secrets manager and redeploy. 3. Verify the new key with the `/v3/me` call from the previous section. 4. In the API Keys table, disable or delete the old key from the **Actions** column. {/* vale Google.WordList = YES */} If a key is compromised, invert the order: delete the compromised key immediately, then deploy the replacement. Requests fail with `401` until the new key is live, which is preferable to leaving a leaked key active. ## Related pages [#related-pages] - [Authentication reference](/reference/api/authentication): the `x-api-key` and `Authorization: Bearer` headers, response headers, and AUTH error codes. - [API authentication](/start/concepts/api-authentication): why Sent authenticates with a single header-based key. - [Rate limits](/reference/api/rate-limits): per-account request limits. # Batch Operations (/start/guides/batch-operations.md) # Batch Operations [#batch-operations] This guide shows you how to send high-volume campaigns and import contacts in bulk while staying inside Sent's API limits. ## Overview [#overview] When dealing with large volumes: - **Batch message sending** - Send to up to 1000 recipients in one request - **Bulk contact import** - Import thousands of contacts efficiently - **Rate limit management** - Stay within API limits - **Queue-based processing** - Process large jobs asynchronously ### Large-Scale Sending Flow [#large-scale-sending-flow] 5000 contacts] --> B{Batch Processor} B -->|Batch 1| C[Send 1000 recipients] B -->|Batch 2| D[Send 1000 recipients] B -->|Batch 3| E[Send 1000 recipients] B -->|...| F[Send remaining] C --> G[Rate Limit Check] D --> G E --> G F --> G G -->|Under limit| H[Process Batch] G -->|At limit| I[Wait/Retry] I --> G H --> J[Collect Results] J --> K[Webhook Updates] style A fill:#e1f5fe style K fill:#e8f5e8 `} /> ## Batch Message Sending [#batch-message-sending] ### Multiple Recipients [#multiple-recipients] Send the same message to up to 1000 recipients in one request: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": [ "+1234567890", "+1987654321", "+1555555555" ], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "announcement": "New feature launched!" } }, "channel": ["sms", "whatsapp", "rcs"] }' ``` ```typescript const response = await client.messages.send({ to: [ '+1234567890', '+1987654321', '+1555555555' // Up to 1000 recipients ], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { announcement: 'New feature launched!' } } }); // Track individual message IDs const messageIds = response.data.recipients.map(r => r.message_id); console.log(`Sent ${messageIds.length} messages`); ``` ```python response = client.messages.send( to=[ "+1234567890", "+1987654321", "+1555555555" # Up to 1000 recipients ], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "announcement": "New feature launched!" } } ) message_ids = [r.message_id for r in response.data.recipients] print(f"Sent {len(message_ids)} messages") ``` ```go response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{ "+1234567890", "+1987654321", "+1555555555", // Up to 1000 recipients }, Channel: []string{"sms", "whatsapp", "rcs"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Parameters: map[string]interface{}{ "announcement": "New feature launched!", }, }, }) // Track individual message IDs messageIDs := make([]string, len(response.Data.Recipients)) for i, r := range response.Data.Recipients { messageIDs[i] = r.MessageID } fmt.Printf("Sent %d messages\n", len(messageIDs)) ``` ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addTo("+1987654321") .addTo("+1555555555") .addChannel("sms") .addChannel("whatsapp") .addChannel("rcs") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("announcement", JsonValue.from("New feature launched!")) .build()) .build()) .build(); var response = client.messages().send(params); // Track individual message IDs List messageIds = response.data().recipients().stream() .map(r -> r.messageId()) .toList(); System.out.println("Sent " + messageIds.size() + " messages"); ``` ```csharp MessageSendParams parameters = new() { To = new List { "+1234567890", "+1987654321", "+1555555555" // Up to 1000 recipients }, Channels = new List { "sms", "whatsapp", "rcs" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Parameters = new Dictionary { { "announcement", "New feature launched!" } } } }; var response = await client.Messages.Send(parameters); // Track individual message IDs var messageIds = response.Data.Recipients.Select(r => r.MessageId).ToList(); Console.WriteLine($"Sent {messageIds.Count} messages"); ``` ```php $result = $client->messages->send( to: [ '+1234567890', '+1987654321', '+1555555555' // Up to 1000 recipients ], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'parameters' => [ 'announcement' => 'New feature launched!' ] ], channels: ['sms', 'whatsapp', 'rcs'] ); // Track individual message IDs $message_ids = array_map(fn($r) => $r->message_id, $result->data->recipients); echo "Sent " . count($message_ids) . " messages\n"; ``` ```ruby result = sent_dm.messages.send_( to: [ "+1234567890", "+1987654321", "+1555555555" # Up to 1000 recipients ], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", parameters: { announcement: "New feature launched!" } }, channels: ["sms", "whatsapp", "rcs"] ) # Track individual message IDs message_ids = result.data.recipients.map(&:message_id) puts "Sent #{message_ids.length} messages" ``` ### Batch Response [#batch-response] ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "product_announcement", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+1234567890", "channel": "sms" }, { "message_id": "8ba7b831-9dad-11d1-80b4-00c04fd430c8", "to": "+1987654321", "channel": "whatsapp" }, { "message_id": "8ba7b832-9dad-11d1-80b4-00c04fd430c8", "to": "+1555555555", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_batch_001", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` Batch requests count against rate limits per request (not per recipient). Each `POST /v3/messages` call counts as one request toward the 10,000 req/min limit, regardless of how many recipients are included. ## Large-Scale Sending (10,000+ Recipients) [#large-scale-sending-10000-recipients] For campaigns with tens of thousands of recipients, process the list in slices of 1000 with a delay between batches: ```typescript // batchProcessor.ts const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); async function sendCampaign(recipients: string[], templateId: string) { const BATCH_SIZE = 1000; // Maximum recipients per request const DELAY_BETWEEN_BATCHES = 1000; // 1 second const results = { sent: 0, failed: 0, messageIds: [] }; // Process in batches for (let i = 0; i < recipients.length; i += BATCH_SIZE) { const batch = recipients.slice(i, i + BATCH_SIZE); try { const response = await client.messages.send({ to: batch, template: { id: templateId } }); // The 202 response confirms acceptance; track delivery via webhooks results.sent += response.data.recipients.length; results.messageIds.push(...response.data.recipients.map(r => r.message_id)); console.log(`Batch ${i / BATCH_SIZE + 1} complete: ${batch.length} messages`); // Rate limiting delay (except for last batch) if (i + BATCH_SIZE < recipients.length) { await sleep(DELAY_BETWEEN_BATCHES); } } catch (error) { console.error(`Batch ${i / BATCH_SIZE + 1} failed:`, error); results.failed += batch.length; } } return results; } // Usage const recipients = await getAllCustomerPhoneNumbers(); // 5000 numbers const results = await sendCampaign(recipients, '7ba7b820-9dad-11d1-80b4-00c04fd430c8'); console.log(`Campaign complete: ${results.sent} sent, ${results.failed} failed`); ``` ## Bulk Contact Import [#bulk-contact-import] ### CSV Import [#csv-import] Format your CSV file: ```csv phone_number +1234567890 +1987654321 +1555555555 ``` Import script: ```typescript import { parse } from 'csv-parse'; import fs from 'fs'; const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); async function importContacts(csvPath: string) { const parser = fs.createReadStream(csvPath).pipe(parse({ columns: true, skip_empty_lines: true })); const results = { created: 0, failed: 0, errors: [] }; const BATCH_SIZE = 50; let batch = []; for await (const record of parser) { batch.push({ phoneNumber: record.phone_number }); if (batch.length >= BATCH_SIZE) { const result = await processBatch(batch); results.created += result.created; results.failed += result.failed; results.errors.push(...result.errors); batch = []; // Rate limit protection await sleep(100); } } // Process remaining if (batch.length > 0) { const result = await processBatch(batch); results.created += result.created; results.failed += result.failed; } return results; } async function processBatch(batch: any[]) { const results = { created: 0, failed: 0, errors: [] }; await Promise.all(batch.map(async (contact) => { try { await client.contacts.create(contact); results.created++; } catch (error) { results.failed++; results.errors.push({ contact, error: error.message }); } })); return results; } ``` ## Rate Limit Management [#rate-limit-management] ### Understanding Limits [#understanding-limits] | Endpoint | Limit | Window | |----------|-------|--------| | `POST /v3/messages` | 10,000 requests | 1 minute | | `POST /v3/contacts` | 10,000 requests | 1 minute | | `GET /v3/*` | 10,000 requests | 1 minute | Limits count per request, not per recipient, and all API keys on an account share one pool. A stricter tier of 10 requests per minute applies only to two sensitive endpoints, `POST /v3/webhooks/{id}/rotate-secret` and `POST /v3/webhooks/{id}/test`, neither of which is involved in batch sending. Refer to the [Rate Limits reference](/reference/api/rate-limits) for the full per-endpoint table and rate limit headers. ### Staying Under the Limit [#staying-under-the-limit] Space your batch requests so total throughput stays below 10,000 requests per minute. The one-second delay between batches in the [Large-Scale Sending](#large-scale-sending-10000-recipients) loop keeps you at 60 requests per minute, well inside the limit – it paces the send, it isn't needed to satisfy the limit. If you need finer-grained control, refer to the [Rate Limits reference](/reference/api/rate-limits#implement-request-throttling) for ready-made throttle and backoff implementations in TypeScript, Python, and Go. ### Handling Rate Limit Errors [#handling-rate-limit-errors] If a request returns `429`, honor the `Retry-After` header before retrying: ```typescript const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); async function sendWithBackoff(phoneNumber: string, templateId: string, maxRetries = 3) { for (let attempt = 0; attempt <= maxRetries; attempt++) { try { return await client.messages.send({ to: [phoneNumber], template: { id: templateId } }); } catch (error) { if (error.status === 429) { // Get retry-after header or use exponential backoff const retryAfter = error.headers['retry-after'] || Math.pow(2, attempt); console.log(`Rate limited. Waiting ${retryAfter} seconds...`); await sleep(retryAfter * 1000); continue; } throw error; } } throw new Error('Max retries exceeded'); } ``` ## Queue-Based Processing [#queue-based-processing] For sustained high volume, run sends through a persistent job queue (for example BullMQ, Sidekiq, or Celery) instead of a single in-process loop. The queue and worker mechanics belong to your infrastructure; the Sent-specific requirements are: - **One job per batch** - Group up to 1000 recipients per job so each job makes a single `POST /v3/messages` call. - **Bounded concurrency** - Cap workers so combined throughput stays under 10,000 requests per minute. - **Idempotent jobs** - Set an idempotency key per job so queue retries don't double-send; see [Retry Safely with Idempotency Keys](#retry-safely-with-idempotency-keys). - **Persist message IDs** - Store the `message_id` values from each `202` response so webhook events can be matched back to jobs. - **Watch queue depth** - Alert when jobs accumulate faster than workers drain them. Reuse a single SDK client instance across jobs so HTTP connections are pooled. ## Monitoring Bulk Operations [#monitoring-bulk-operations] Log progress per batch from the counts in each `202` response, as the [Large-Scale Sending](#large-scale-sending-10000-recipients) loop does. For delivery outcomes, subscribe to the webhook events `message.delivered`, `message.failed`, `message.filtered`, and `message.blocked` instead of polling `GET /v3/messages/{id}` for every message; see [Status Tracking](/start/guides/message-status-tracking). ## Best Practices [#best-practices] ### Handle Partial Failures [#handle-partial-failures] A `202` response confirms acceptance, not delivery. Validation is all-or-nothing (a `400` rejects the whole request), so every recipient in an accepted batch gets a `message_id`, but individual messages can still end `FAILED`, `FILTERED` (recipient opted out), or `BLOCKED` (insufficient balance) asynchronously. Persist the accepted IDs and reconcile them against webhook events: ```typescript const recipients = ['+14155551234', '+14155555678']; const response = await client.messages.send({ to: recipients, template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } }); // Persist each accepted message so your webhook handler can mark it // DELIVERED, FAILED, FILTERED, or BLOCKED as events arrive const accepted = response.data.recipients.map((r) => ({ messageId: r.message_id, to: r.to, status: 'PENDING' })); console.log(`Accepted ${accepted.length} messages`); ``` ### Retry Safely with Idempotency Keys [#retry-safely-with-idempotency-keys] Give every batch a deterministic idempotency key so a retried request (after a timeout, `429`, or worker crash) replays the original response instead of double-sending: ```typescript const recipients = ['+14155551234', '+14155555678']; const campaignId = 'spring_launch'; const batchNumber = 1; const response = await client.messages.send( { to: recipients, template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } }, { idempotencyKey: `campaign_${campaignId}_${batchNumber}` } ); ``` Refer to the [Idempotency reference](/reference/api/idempotency) for key format and replay behavior. ### Start Small [#start-small] Before launching a full campaign, run the batch pipeline against a small slice, for example `sendCampaign(recipients.slice(0, 10), templateId)`, and confirm delivery through webhooks before committing the full list. --- # Cancelling Scheduled Messages (/start/guides/cancelling-messages.md) # Cancelling Scheduled Messages [#cancelling-scheduled-messages] `POST /v3/messages/{id}/cancel` calls off a message you scheduled with `scheduled_at`, as long as it is still being held. The message moves to `CANCELLED`, which is terminal, and it is never sent. Cancelling is the counterpart to [scheduling](/start/guides/scheduled-messages). It is free: nothing was charged for the hold in the first place. For the generated schema and the interactive request builder, see [Cancel a scheduled message](/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesCancelMessageV3Endpoint) in the API reference. ## What Can Be Cancelled [#what-can-be-cancelled] Only a message whose current status is `SCHEDULED`. That covers both ways a message is held: one you scheduled with `scheduled_at`, and one the recipient's quiet hours deferred. | Message status | Cancellable? | Notes | |----------------|--------------|-------| | `SCHEDULED` | Yes | Held for a `scheduled_at` instant or a quiet-hours window | | `CANCELLED` | Yes, as a repeat | Returns `200` with the same body and fires no second webhook | | `QUEUED`, `PROCESSED`, `ROUTED`, `SENT` | No | Already released and in flight | | `DELIVERED`, `READ`, `FAILED`, `FILTERED`, `BLOCKED` | No | Finished | Everything in the third and fourth rows returns `409` with error code `BUSINESS_006`. The release sweeper checks for due messages every 30 seconds, so a cancellation sent within about a minute of the scheduled instant can lose that race and be refused with `409`. Cancel with time to spare. ## Lifecycle [#lifecycle] API accepts request"] -->|consumer parks row| S["**SCHEDULED**
Held until scheduled_at"] S -->|POST /cancel| X["**CANCELLED**
Terminal, never sent"] S -->|release tick| R["**ROUTED**
Carrier assigned"] R --> B["**SENT**
Dispatched to provider"] B --> C["**DELIVERED**
To device"] style A fill:#e1f5fe style S fill:#e8eaf6 style R fill:#e8eaf6 style B fill:#f3e5f5 style C fill:#e8f5e8 style X fill:#ffebee `} darkTextAlways /> Once the release sweeper has claimed the message, the send is in flight and the cancellation is refused. The two paths are mutually exclusive: a message is either cancelled or released, never both. ## Making a Request [#making-a-request] The request body is empty. The message to cancel is identified by the `id` path parameter. ```bash curl -X POST "https://api.sent.dm/v3/messages/8ba7b830-9dad-11d1-80b4-00c04fd430c8/cancel" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" ``` ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); const response = await client.messages.cancel('8ba7b830-9dad-11d1-80b4-00c04fd430c8'); console.log(response.data.status); // "CANCELLED" console.log(response.data.scheduled_at); // the send time that was called off ``` ```python import os from sentdm import SentDm client = SentDm(api_key=os.environ.get("SENT_API_KEY")) response = client.messages.cancel("8ba7b830-9dad-11d1-80b4-00c04fd430c8") print(response.data.status) # "CANCELLED" print(response.data.scheduled_at) # the send time that was called off ``` ```go package main import ( "context" "fmt" "os" sentdm "github.com/sentdm/sentdm-go" ) func main() { client := sentdm.NewClient(os.Getenv("SENT_API_KEY")) response, err := client.Messages.Cancel(context.Background(), "8ba7b830-9dad-11d1-80b4-00c04fd430c8") if err != nil { panic(err) } fmt.Println(response.Data.Status) // "CANCELLED" fmt.Println(response.Data.ScheduledAt) // the send time that was called off } ``` ```java import com.sentdm.SentDm; import com.sentdm.models.MessageResponse; public class CancelExample { public static void main(String[] args) { SentDm client = new SentDm(System.getenv("SENT_API_KEY")); MessageResponse response = client.messages().cancel("8ba7b830-9dad-11d1-80b4-00c04fd430c8"); System.out.println(response.getData().getStatus()); // "CANCELLED" System.out.println(response.getData().getScheduledAt()); // the send time that was called off } } ``` ```csharp using SentDm; var client = new SentDmClient(Environment.GetEnvironmentVariable("SENT_API_KEY")); var response = await client.Messages.CancelAsync("8ba7b830-9dad-11d1-80b4-00c04fd430c8"); Console.WriteLine(response.Data.Status); // "CANCELLED" Console.WriteLine(response.Data.ScheduledAt); // the send time that was called off ``` ```php messages->cancel('8ba7b830-9dad-11d1-80b4-00c04fd430c8'); echo $response->data->status; // "CANCELLED" echo $response->data->scheduled_at; // the send time that was called off ``` ```ruby require 'sentdm' client = SentDm::Client.new(api_key: ENV['SENT_API_KEY']) response = client.messages.cancel('8ba7b830-9dad-11d1-80b4-00c04fd430c8') puts response.data.status # "CANCELLED" puts response.data.scheduled_at # the send time that was called off ``` ### Response [#response] A `200 OK` response means the message is cancelled and will not be sent. The body is the message itself, in the same shape `GET /v3/messages/{id}` returns, plus `scheduled_at`: ```json { "success": true, "data": { "id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "customer_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "contact_id": "5ba7b800-9dad-11d1-80b4-00c04fd430c8", "phone": "+14155551234", "phone_international": "+1 415-555-1234", "region_code": "US", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "channel": "sms", "status": "CANCELLED", "scheduled_at": "2026-10-01T07:00:00Z", "direction": "OUTBOUND", "created_at": "2026-09-30T11:59:00Z", "events": [ { "status": "QUEUED", "timestamp": "2026-09-30T11:59:00Z" }, { "status": "SCHEDULED", "description": "Send scheduled by the customer for a later time. Scheduled to send at 2026-10-01 07:00:00Z.", "scheduled_at": "2026-10-01T07:00:00Z", "timestamp": "2026-09-30T11:59:02Z" } ] }, "error": null, "meta": { "request_id": "req_9Y0aLq3kEx", "timestamp": "2026-09-30T12:04:11Z", "version": "v3" } } ``` Two fields are worth reading carefully: - **`status`** is read off the row the cancellation just wrote, so it is the outcome rather than a prediction. Branch on it. - **`events`** is the message timeline as it stood immediately before the cancellation. The `CANCELLED` entry is written asynchronously and lands a moment later, so it is not in this body. `GET /v3/messages/{id}` is cached briefly, so an immediate re-fetch can still show the pre-cancellation timeline; re-fetch after a few seconds if you need the entry itself. `scheduled_at` is the instant the message was being held for, in UTC: the time it would have gone out. It survives the cancellation, so `GET /v3/messages/{id}` and `GET /v3/messages/{id}/activities` keep reporting it afterwards. ## One Message Per Call [#one-message-per-call] A cancellation names one message. A send to several recipients, or on several channels, becomes one message per recipient per channel, each with its own ID, so cancel the ones you want stopped: ```bash for id in "$MESSAGE_ID_1" "$MESSAGE_ID_2"; do curl -X POST "https://api.sent.dm/v3/messages/$id/cancel" \ -H "x-api-key: $SENT_API_KEY" done ``` There is no bulk form and no batch identifier on the send response. Record the `message_id` of each recipient from the [send response](/start/guides/scheduled-messages#response) if you expect to cancel the send later. ## Repeating a Cancellation [#repeating-a-cancellation] Cancelling a message that is already `CANCELLED` returns `200` with the same body. It is not a `409`: you asked for the message not to be sent, and it will not be sent. The repeat changes nothing. It writes no second status, fires no second `message.cancelled` webhook, and adds no second entry to the activity timeline. Only the first call that found the message `SCHEDULED` published anything. ## The `message.cancelled` Webhook [#the-messagecancelled-webhook] A cancellation fires `message.cancelled` exactly once, on the first call that took effect. | Payload field | Value on `message.cancelled` | |---------------|------------------------------| | `message_status` | `CANCELLED` | | `scheduled_at` | The release instant that was called off, in UTC. The same value `message.scheduled` carried for this message | | `body` | `null`. A cancelled send never resolved a channel, so there is no rendered copy to publish | | `schedule_reason` | Omitted. It explains why the message was held, which is a property of the hold rather than of the cancellation | | `reason_code`, `reason` | Omitted. Sent has nothing to explain about a send you stopped yourself | Everything else is the shape every message status event carries. See [Outbound message event fields](/start/webhooks/event-types#message). `scheduled_at` is the field to key on: a consumer that recorded a future send when `message.scheduled` arrived has what it needs to un-record it. Webhook delivery is neither ordered nor guaranteed, so a consumer that missed `message.scheduled` still learns from the cancellation alone that there is no future send to wait for. `message.cancelled` is a new sub-type. If you subscribe to the `message` parent event, you receive it without any change. If you subscribe with `event_filters`, add `cancelled` to the `message` list to receive it. ## The Activity Timeline [#the-activity-timeline] `GET /v3/messages/{id}/activities` gains a `CANCELLED` entry carrying the same `scheduled_at`: ```json { "status": "CANCELLED", "description": "Send cancelled by the customer before release. It was scheduled to send at 2026-10-01 07:00:00Z.", "scheduled_at": "2026-10-01T07:00:00Z", "timestamp": "2026-09-30T12:04:12Z" } ``` The entry is written asynchronously, so it appears within a second or two of the `200` rather than in the cancellation response itself. ## Billing [#billing] Cancelling is free, and nothing had been charged for the message in the first place. A scheduled message is priced and billed at release, not when you schedule it, so a message cancelled while held costs nothing. A cancelled message is also excluded from your deliverability rate in both the numerator and the denominator. It was never a send attempt. ## A Cancelled Message Is Final [#a-cancelled-message-is-final] `CANCELLED` is terminal. The message is never released, never routed, and never dispatched. To send after cancelling, create a new message with `POST /v3/messages`. ## Idempotency [#idempotency] The `Idempotency-Key` header is honored. Retrying a cancellation with the same key replays the original `200` response rather than re-executing the call. A retry sent while the first request is still in flight is answered with `409 CONFLICT_001`; retry it once the original completes. See [Idempotency](/reference/api/idempotency#concurrent-requests). Idempotency is a convenience here rather than a safeguard. A repeated cancellation without a key is already harmless: it answers `200` and publishes nothing a second time. ## Rate Limiting [#rate-limiting] This endpoint is not in the Sensitive tier: a cancellation bills nothing and reduces spend. The general v3 limits apply. See [Rate limits](/reference/api/rate-limits). ## Sandbox [#sandbox] This endpoint supports [sandbox mode](/reference/api/test-mode). Send `{"sandbox": true}` as the body and the API validates and authenticates the request, then returns a simulated `200` reporting `CANCELLED` without reading or writing anything. No message is cancelled, no webhook is delivered. ## Error Reference [#error-reference] | HTTP status | Error code | Cause | |-------------|------------|-------| | `400` | `VALIDATION_001` | The message ID is not a valid UUID. The error details are keyed on `id` | | `401` | `AUTH_002` | No API key was sent, or its value is not a recognized key. `AUTH_001` appears only for a request that is unauthenticated for another reason | | `404` | `RESOURCE_003` | No such message for this account | | `409` | `BUSINESS_006` | The message is not `SCHEDULED`, so there is nothing to cancel | | `409` | `CONFLICT_001` | A request with the same `Idempotency-Key` is still being processed. Retry with the same key once it completes to receive its cached response | | `429` | `BUSINESS_002` | Rate limit exceeded | | `500` | `INTERNAL_001` | Unexpected error | The `409` body carries this message: > Only a scheduled message can be cancelled. This message has already been released for sending, is in flight, or has finished. It is a state conflict, not a transient one: retrying returns the same `409`, because a message that has left `SCHEDULED` never returns to it. Read the current status with `GET /v3/messages/{id}` to see where the message went. A message ID that belongs to another account returns `404`, not `403`, so the response does not reveal whether the ID exists. ## Next Steps [#next-steps] # Connect a WhatsApp Business Account (WABA) to Sent (/start/guides/connect-whatsapp.md) # Connect a WhatsApp Business Account (WABA) to Sent [#connect-a-whatsapp-business-account-waba-to-sent] This guide shows you how to connect a WhatsApp Business Account (WABA) to Sent and confirm that the channel can send. It assumes you administer a Meta Business Account and that your Sent account has cleared [KYC review](/start/quickstart/account-setup). If you are working through initial setup of all three channels, this step sits inside [Channel Setup](/start/quickstart/channel-setup) alongside your SMS number, RCS, and billing. ## Before you start [#before-you-start] Confirm all four requirements. The flow fails at a different stage for each one you skip. - **A verified Meta Business Account.** Meta's business verification is separate from Sent's KYC review, and both must pass before Meta lets you share a WABA with a partner. - **A Facebook personal account with administrator access** to that Meta Business Account. Meta blocks the authorization step for non-administrators. - **A phone number that is not linked to another WhatsApp Business Account.** A number can belong to one WABA at a time, including numbers registered with the WhatsApp Business app. - **A Sent account with KYC approved.** Sent locks channel configuration until compliance review clears. For the long form of each requirement, see [Prerequisites for WhatsApp setup](/troubleshooting/whatsapp-setup#prerequisites-for-whatsapp-setup). **Open the WhatsApp connection flow** If your account is still in onboarding, open the [Sent dashboard](https://app.sent.dm/dashboard), select **Continue Channel Setup**, and advance to the WhatsApp step of the wizard. If your account is already onboarded, open [Channels](https://app.sent.dm/dashboard/channels), switch to the **WhatsApp** tab, and select **Connect Account** under Account Management. The same dialog reads **Switch Account** when a WABA is already connected. **Authorize Sent from the Meta window** Select **Log in with Meta**. Sent opens Meta's signup window, where you log in with your Facebook account, pick an existing WhatsApp Business Account or create one, and grant Sent permission to manage messages on it. The button stays inactive until Meta's script finishes loading, and the authorization window is a pop-up. Ad blockers and privacy extensions are the most common cause of a failed authorization: they block Meta's script, so the button never activates or the pop-up never opens. Use a browser profile without extensions, or an incognito window, and allow pop-ups from `sent.dm` and `facebook.com`. Chrome is the most reliable choice, because Safari's tracking prevention interferes with Meta's login flow. **Choose the sending number** After authorization, Sent reads the numbers on the WABA and asks which one sends your WhatsApp messages. Which options appear depends on what the WABA and your Sent account already hold: | Option | When it appears | What it does | | :--- | :--- | :--- | | **Existing Numbers** | The WABA already has numbers registered | Sends from a number already on the WABA | | **New Number** | Your Sent account has a number that is not yet on the WABA | Registers your Sent number with the WABA | | **Use your own phone number** | Onboarding wizard, when neither your Sent account nor the WABA has a number | Registers a number you enter. Meta sends it a verification code, which can take a few minutes to arrive | | **Get a provisioned number** | Channels dialog, when neither your Sent account nor the WABA has a number | Allocates a number from Sent and registers it with the WABA | If your Sent number is already registered on the WABA, the dialog selects it for you. To keep one identity across SMS, WhatsApp, and RCS, send from the number you already use for SMS: recipients see it on every channel. A US SMS number you hold from Sent is pre-verified with Meta in the background once it is on your campaign, and signup offers it first. A pre-verified number needs no verification code. If code verification does not complete, select **Verify Later**. The number is attached and the connection saves, but WhatsApp sending stays unavailable until the number reaches `Connected`. A WABA holds a limited number of phone numbers. When it is full, the dialog says so, and you have to remove a number from the WABA before adding another. **Save the connection** Select **Continue**. Sent stores the WABA ID, business name, business owner, and access token against your account, then subscribes the WABA to Meta's webhook notifications so sent, delivered, and read updates reach your account. A success message names the business you connected. Switching an existing connection to a *different* WABA prompts you to move templates. **Confirm** resubmits your templates to the new WABA; **Delete** removes them. Resubmitted templates go through Meta approval again, so time a switch away from a running campaign. **Verify the channel is live** In the dashboard, [Channels](https://app.sent.dm/dashboard/channels) → **WhatsApp** now shows the Facebook Business Owner, WhatsApp Business Name, Phone Number, and Business ID. Two indicators tell you whether the channel can actually send: - **Phone number status**, next to the number. `Connected` means the number is registered and ready. `Pending` means registration has not finished. `Flagged`, `Restricted`, `Banned`, `Disconnected`, and `Offline` each carry an explanation in the dashboard. - **Messaging status**, which appears only when something is wrong. `limited` or `blocked` lists the issues Meta reports, each with its suggested fix, and links to the WABA in Meta Business Manager. From the API, `GET /v3/me` reports the same connection: ```bash curl "https://api.sent.dm/v3/me" \ -H "x-api-key: $SENT_API_KEY" ``` A connected channel returns `configured: true` with the number and business name: ```json { "success": true, "data": { "channels": { "whatsapp": { "configured": true, "phone_number": "+14155550100", "business_name": "Acme Corporation" } } } } ``` Refer to the [get account reference](/reference/api/accounts/SentDmServicesEndpointsCustomerAPIv3AccountGetAccountEndpoint) for the rest of the response. ## Disconnect a WhatsApp Business Account [#disconnect-a-whatsapp-business-account] Open [Channels](https://app.sent.dm/dashboard/channels), switch to the **WhatsApp** tab, and select **Disconnect** next to **Switch Account**. The button appears for organizations and Sender Profiles alike once an account is connected. - **WhatsApp falls back to SMS, if you can send SMS.** After the disconnect, WhatsApp messages go out on SMS until you connect an account again. Without an SMS sender for the recipient's country, they fail with [`DELIVERY_003`](/reference/api/error-catalog#message-outcome-codes) instead, so add an SMS market first if the number you are disconnecting is your only one. The dashboard shows the fields as `Not configured` and the button reads **Connect Account**. - **Your own number stays yours.** Sent leaves a number you brought untouched at Meta. - **A number provided by Sent has to leave the WABA first.** Meta offers no way for Sent to remove it, so deregister and delete it from your account in WhatsApp Manager, then disconnect again. Until then the disconnect is refused with a message saying so, and nothing changes. - **A number provided by Sent is then released**, unless it is also your SMS number, in which case you keep it for SMS. - **Other accounts on the same WABA keep working.** If another Sent account is connected to the same WhatsApp Business Account or Meta business, disconnecting yours does not revoke its access. - **Partner solutions:** disconnecting an organization that owns a partner solution also disconnects the Sender Profiles attached through it. A Sender Profile whose account came through a partner solution cannot be disconnected on its own. ## Connect a WABA to a Sender Profile [#connect-a-waba-to-a-sender-profile] A Sender Profile's WhatsApp account is dedicated to it, or it has none. The organization's account is never inherited, because sharing one means sharing its inbox and its throughput, which makes two senders indistinguishable to a recipient. Until a profile has an account of its own, its WhatsApp messages don't go out from your organization's account. Connect an account that your organization already holds through a [Multi-Partner Solution](/start/guides/whatsapp-partner-solution) with [`POST /v3/channels/whatsapp`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddWhatsappChannelEndpoint): ```bash curl -X POST "https://api.sent.dm/v3/channels/whatsapp" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{ "waba_id": "123456789012345", "phone_number_id": "987654321098765" }' ``` **Two fields, because everything else is derived.** - `waba_id` is required. You hold one shared account per client, and nothing else can say which of them this is. - `phone_number_id` is optional. It names the account's number, which assigns it to the profile as the number it sends from. Omit it to connect the account now and settle the number later: the channel reads as `ACTION_NEEDED` with `reason_code` `CHANNEL_007`, because naming the number is yours to do. Until a number is named, the profile's WhatsApp messages fail rather than going out from your organization's account. - `access_token`, `solution_id`, and `owner_business_id` are **not accepted**. The first two are Meta's answer about which partnership the account arrived through, and the token is minted per client business and rotates roughly every sixty days. A value you sent would be stale before it was useful. All three are resolved from your organization. The same resolution runs behind `channels.whatsapp` on `POST /v3/sender-profiles`, so connecting at create time and connecting afterwards fill the same fields. The response returns **the account**, not every channel you have. The older route (a `whatsapp_business_account` object with an `access_token` on `POST /v3/profiles`) still works, but `/v3/profiles` is deprecated. See [Migrating from `/v3/profiles`](/start/advanced/sender-profiles-api#migrating-from-v3profiles). The [Sender Profiles API guide](/start/advanced/sender-profiles-api) covers provisioning end to end, and [Managing channels](/start/guides/managing-channels) covers reading channel status. ## Before your first WhatsApp message [#before-your-first-whatsapp-message] - **Send from an approved template.** WhatsApp requires an approved template for business-initiated messages. [Create a template in the dashboard](/start/guides/create-a-template), then send it with [your first message](/start/quickstart/first-message). - **Expect your preview templates to disappear.** Completing WABA setup removes the light-onboarding sample templates, which were never submitted to Meta, and submits your auto-reply templates to the new WABA for approval. - **Watch the onboarding send cap.** Accounts that have finished channel setup but not the remaining compliance steps hit a stage send limit, after which messages are blocked with `ERR_CHANNEL_SETUP_COMPLETED_QUOTA_EXCEEDED`. See [Trust & Safety](/start/concepts/trust-and-safety#how-this-affects-your-integration). ## If a stage fails [#if-a-stage-fails] | Symptom | Stage | Where to fix it | | :--- | :--- | :--- | | **Log in with Meta** stays greyed out, or no Meta window opens | Authorize | [Browser extensions block the Meta script](/troubleshooting/whatsapp-setup#log-in-with-meta-button-is-greyed-out-or-pop-up-does-not-open) | | "The information could not be verified" after you authorize | Authorize | [Meta business verification and browser fixes](/troubleshooting/whatsapp-setup#the-information-could-not-be-verified-connection-error) | | Meta reports that your account lacks permission | Authorize | [Missing administrator permissions](/troubleshooting/whatsapp-setup#missing-administrator-permissions-for-waba-connection) | | "This phone number is already used and linked to a WhatsApp account" | Choose a number | [Release the number from its current WABA](/troubleshooting/whatsapp-setup#this-phone-number-is-already-used-and-linked-to-a-whatsapp-account) | | Meta sends a verification code to a number you cannot access | Choose a number | [Verification on Sent-provisioned numbers](/troubleshooting/whatsapp-setup#meta-verification-code-sent-to-sent-provisioned-number) | | Your country or number is no longer offered | Choose a number | [Country or number became unavailable](/troubleshooting/whatsapp-setup#country-or-number-became-unavailable-after-registration) | | Messages fail after the channel connects | Sending | [WhatsApp delivery failures by error code](/troubleshooting/whatsapp-delivery-errors) | ## Related [#related] - [WhatsApp onboarding troubleshooting](/troubleshooting/whatsapp-setup): every known Meta-side connection failure and its resolution. - [Channels](/start/concepts/channels): how Sent picks between SMS, RCS, and WhatsApp per message. - [Channel Setup](/start/quickstart/channel-setup): the surrounding onboarding steps, including your SMS number, RCS, and billing. - [WhatsApp template issues](/troubleshooting/template-issues): template creation, approval, and rejection on a connected WABA. # Create a Template in the Dashboard (/start/guides/create-a-template.md) # Create a Template in the Dashboard [#create-a-template-in-the-dashboard] This guide shows you how to build a custom message template in the Sent dashboard and submit it for review. It assumes your account has completed [account setup](/start/quickstart/account-setup), because template creation requires a fully onboarded account. If you have never created a template, start with the [first template quickstart](/start/quickstart/first-template); for background on how templates adapt content per channel, see [how templates work](/start/concepts/templates). **Open the template builder** In the dashboard, open [Templates](https://app.sent.dm/dashboard/templates) and create a new template. The builder shows a live per-channel preview as you edit. **Add a header (optional)** Headers appear on WhatsApp and RCS only: WhatsApp renders a native header, RCS prepends the text to the message body. A header holds up to 60 characters and at most 1 dynamic variable. Text headers cannot contain emojis, newlines, or formatting markup (`*`, `_`, `~`).
**Write the body** The body is the only required component and the only one that reaches SMS as well as WhatsApp and RCS. It holds up to 1024 characters (an RCS-specific body holds up to 3072). To personalize it, click **Insert dynamic variable** or **Insert dynamic link**. Variables render as yellow boxes and links as light-blue boxes. | Dynamic Variable Type | Description | | :--- | :--- | | Text | Plain text content that can be personalized | | Link | Dynamic URLs for tracking or personalization | | Image/Media | Images or media files (WhatsApp only) | | File | Document files (WhatsApp only) | Give every variable a descriptive name (`customerName`, `orderNumber`) and a realistic sample value: reviewers see the sample when they evaluate the template. If you want different wording per channel, the definition lets you replace the multi-channel body with an `sms` + `whatsapp` pair (both are required, and neither can be combined with the multi-channel body), and an `rcs` body can be added on top of either arrangement. Refer to the [body object reference](/reference/api/template-definition#body-object) for the exact rule. **SMS message length depends on encoding.** A plain-text (GSM-7) SMS fits 160 characters; a message containing any emoji or non-Latin character encodes as Unicode and fits only 70. Longer bodies are split into billed segments (153 or 67 characters each). Remember that a variable can push a template over a limit at send time. See [SMS Encoding & Message Length](/start/concepts/sms-encoding-and-length) for the full rules and [SMS Length, Segments & Cost](/start/guides/sms-length-and-cost) for a live calculator.
**Add a footer (optional)** Footers appear on WhatsApp and RCS only: WhatsApp renders a native footer, RCS appends the text to the message body. A footer holds up to 60 characters and cannot contain variables, emojis, newlines, or formatting markup.
**Add buttons (optional)** Buttons appear on WhatsApp and RCS: WhatsApp renders interactive buttons, RCS shows the first four as suggestion chips. Click **Add button** and pick a type. A template holds up to 10 buttons, and button labels hold up to 25 characters. | Button Type | Quantity allowed | Description | | :--- | :--- | :--- | | Custom Buttons | Up to 10 | Custom quick replies and preconfigured responses | | Visit Website Buttons | Up to 2 | Static URLs, or dynamic URLs with exactly one variable at the end | | Phone Number Button | Up to 1 | One-tap calling with country code and phone number | | Copy Offer Button | Up to 1 | One-tap copying for OTP or offer codes | Place the most important action first: on RCS only the first four buttons render, so order decides what users see.
**Set the category and language** Both fields are detected automatically from the template content; override them manually if the detection is wrong. Choose the category (MARKETING, UTILITY, or AUTHENTICATION) that matches the message's real intent. Meta re-categorizes mismatched WhatsApp templates during review, so an honest category speeds approval. **Review the JSON** Click **View JSON** to see the template's definition: the same JSON you send in the `definition` field when you [create a template via the API](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesCreateTemplateEndpoint) with `POST /v3/templates`. Refer to the [template definition reference](/reference/api/template-definition) for every field and limit. **Save as draft or submit for review** To keep editing and testing, click **Save as Draft**. Drafts cannot be sent on any channel. To start approval, click **Submit for Review**: Meta reviews WhatsApp templates (typically 24–48 hours); when no WhatsApp Business Account is connected, Sent's compliance team reviews the template per channel. See [how template approval works](/start/guides/working-with-templates#how-template-approval-works). If you create templates via the API instead, the same choice is the `submit_for_review` field on `POST /v3/templates`: it defaults to `false` (saved as a draft), and `true` submits the template for review immediately after creation. **Verify and copy the template ID** The new template appears in your [templates list](https://app.sent.dm/dashboard/templates) with status `DRAFT` if saved, or `PENDING` while review is in progress. Copy its template ID; you pass it as the template `id` when [sending messages](/start/guides/sending-messages). Store it in your own database; it is the stable key for this template across all channels. To track approval automatically, subscribe to `templates` [webhook events](/start/webhooks/event-types); each event carries the template ID, channel, and new status.
## Troubleshooting [#troubleshooting] | Symptom | Likely cause | Fix | | :--- | :--- | :--- | | The builder rejects the body | A content rule failed: bodies cannot start or end with a newline, place variables back-to-back, or contain more than two consecutive line breaks | Adjust the text; the full rules are in the [content rules reference](/reference/api/template-definition#content-rules-and-limits) | | Save fails with "placeholder with an unsupported type" | A `{{index:type}}` placeholder in the body or header uses an unrecognized type (for example, `{{0:message}}`) | Change the type to `variable`, `link`, or `media` and update the matching entry in the `variables` array | | Template stuck in `PENDING` | Meta review is still in progress (typically 24–48 hours) | See [template troubleshooting](/troubleshooting/template-issues) | | Template `REJECTED` | The reviewer declined the content | Revise the template and resubmit; the `templates` webhook event carries the rejection reason in its `reason` field | ## Related [#related] - Refer to the [template definition reference](/reference/api/template-definition) for a full list of fields, limits, and statuses. - [Sending Messages](/start/guides/sending-messages): send with your approved template. - [Working with Templates](/start/guides/working-with-templates): overview of all template documentation. # Creating a Sender Profile (/start/guides/creating-a-sender-profile.md) # Creating a Sender Profile [#creating-a-sender-profile] This guide shows you how to create a Sender Profile in the Sent dashboard and confirm it is ready to send. It assumes your account belongs to an organization and holds the **ADMIN** role; only organization administrators can view and manage Sender Profiles. For what Sender Profiles are and which resources a profile can inherit, see [Sender Profiles](/start/concepts/sender-profiles). To provision profiles programmatically instead, see [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api). ## Create the profile [#create-the-profile] The wizard asks only for what the profile needs: the channels you pick decide which of the later steps appear. Your brand, campaign, and billing choices map directly to the [resource configuration patterns](/start/concepts/sender-profiles#resource-configuration-patterns); you can edit a profile later from the Profiles page if a decision changes. ### Open the Profiles page [#open-the-profiles-page] In the dashboard, go to **Profiles** and select **+ Create Sender Profile**. ### Enter basic information [#enter-basic-information] Give the profile a display name and a short name. Both are required; the description is optional. The short name is 3 to 11 characters (letters, numbers, and spaces, with at least one letter) and is used as the sender ID for SMS, so pick the name recipients should see. The same step sets how the profile relates to the organization: - **Brand**: **Inherit the organization's** brand, or **Create a dedicated one**. Inheriting is unavailable until the organization has a brand of its own. - **Campaign**: **Inherit the organization's** 10DLC campaign, or **Create a dedicated one**. A profile with a dedicated brand always has a dedicated campaign. - **Billing**: **Inherit organization billing**, **Dedicated profile billing** (the profile has its own payment methods and invoices), or **Mixed** (inherit the organization's billing now, with the ability to switch the profile to its own later). - **Notifications**: who receives the profile's notifications, by email: the **Organization**, the **Sender Profile**, or **Organization and Sender Profile**. The default is **Organization**. The trade-offs between inheriting and dedicating a brand and campaign are covered in [TCR brand and campaign inheritance](/start/concepts/sender-profiles#tcr-brand-and-campaign). ### Review billing [#review-billing] Confirm the billing details for the type you chose. With dedicated or mixed billing, enter the profile's billing details and add at least one payment method for the profile; the wizard doesn't continue without one. ### Review the brand [#review-the-brand] The brand the profile sends under. An inherited brand is shown read-only; a dedicated brand asks for the business details: business and legal name, contact name, email, phone, and role, website, country of registration, business type, and tax ID. ### Choose channels [#choose-channels] Select the channels the profile sends on: **WhatsApp**, **SMS**, and **RCS**. Each choice adds the steps it needs: - **WhatsApp** adds the WhatsApp Business connection step. - **SMS** adds the number type step and the registration that type requires. To register the profile's RCS Agent, see [Enable RCS](/start/quickstart/channel-setup#enable-rcs). ### Connect WhatsApp Business [#connect-whatsapp-business] Shown when the profile sends on WhatsApp. Select **Log in with Meta** and connect an existing or a new WhatsApp Business account. ### Choose the number type [#choose-the-number-type] Shown when the profile sends SMS. Pick one or both: - **10DLC**: a dedicated US 10-digit number for two-way messaging. Requires 10DLC registration first. - **Alphasender**: your brand name as the sender, one-way. Each type opens its own registration step, so a profile that picks both walks through each. ### Register for 10DLC [#register-for-10dlc] Shown when you picked 10DLC. With an inherited brand and campaign, the step shows the organization's 10DLC brand and campaigns. With a dedicated campaign or brand, register them here. US 10DLC registration adds review time before US sending starts; see [10DLC Registration](/start/advanced/10dlc-registration) for the process and timelines. To register a brand and campaign through the API instead, send them in the `compliance` object of the market call; see [Managing channels](/start/guides/managing-channels#sms-markets). ### Register the alphasender [#register-the-alphasender] Shown when you picked Alphasender. Some countries require the sender name to be registered before you can use it. Choose the countries to register in; each one shows its status: **Requested**, **Provisioning**, or **Active**. ### Verify the profile is ready [#verify-the-profile-is-ready] The final step finishes setup in the background and shows **You're all set** when it completes; select the button to return to the Profiles page. Confirm the new profile card shows the **COMPLETED** status, the **Profile ID** value, and the phone number or WhatsApp account attached to each channel. ## Switch between profiles [#switch-between-profiles] To work inside a specific profile (its templates, contacts, API keys, and settings), open the context switcher at the top of the sidebar and select the profile. Selecting **Organization** returns you to the organization-level view. ## Troubleshooting [#troubleshooting] | Symptom | Likely cause | Fix | | --- | --- | --- | | "Admin Access Required" on the Profiles page | Your user is not an ADMIN of the organization | Ask an organization administrator to create the profile or change your role | | Setup does not complete after several retries | Background provisioning failed | Try again shortly; if it keeps failing, contact support | | A channel shows "Not configured" on the profile card | No number or WhatsApp account attached for that channel | Edit the profile and complete the corresponding wizard step | ## Related [#related] - [Sender Profiles](/start/concepts/sender-profiles) explains the resource model behind each wizard step - [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles) covers sending with profile API keys - [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api) automates this flow for tenant onboarding # Error Handling (/start/guides/error-handling.md) # Error Handling [#error-handling] This guide shows you how to build resilient messaging integrations with error classification, retries, fallbacks, and safe re-sends. ## Overview [#overview] When sending messages, errors can occur at multiple levels: - **API errors** - Invalid requests, authentication failures - **Network errors** - Connection timeouts, DNS failures - **Provider errors** - Carrier issues, rate limiting - **Business errors** - Insufficient balance, template not approved This guide covers patterns for handling each type of error. ## Error Types [#error-types] ### API Errors (4xx) [#api-errors-4xx] Client-side errors indicate a problem with the request. Fix the request instead of retrying: | Status | Example Code | Meaning | Action | |--------|--------------|---------|--------| | 400 | `VALIDATION_001` | Request validation failed | Fix the request body; check `error.details` | | 401 | `AUTH_002` | Invalid or missing API key | Verify the API key; don't retry | | 404 | `RESOURCE_001` | Resource not found | Verify IDs | | 409 | `CONFLICT_001` | Concurrent idempotent request in progress | Wait for the original request to complete | | 429 | `BUSINESS_002` | Rate limit exceeded | Implement backoff and respect `Retry-After` | These are the statuses the retry logic in this guide branches on. For every code with causes and remediation steps, see the [Error Catalog](/reference/api/error-catalog); for limit values, see [Rate Limits](/reference/api/rate-limits). ### Server Errors (5xx) [#server-errors-5xx] Temporary server-side errors - safe to retry: | Status | Meaning | Action | |--------|---------|--------| | 500 | Internal server error | Retry with backoff | | 502 | Bad gateway | Retry with backoff | | 503 | Service unavailable | Retry with backoff | | 504 | Gateway timeout | Retry with backoff | ### Business Logic Errors [#business-logic-errors] Application-level errors requiring business decisions: | Error Code | Meaning | Action | |------------|---------|--------| | `BUSINESS_003` | Insufficient account balance | Alert billing, queue for later | | `BUSINESS_005` | Template not approved | Wait or use SMS fallback | | `BUSINESS_007` | Channel not available for this contact | Switch channel or use fallback | | `VALIDATION_002` | Invalid phone number format | Validate input, notify user | | `ERR_CONSENT_BLOCKED` | Recipient opted out: the message is finalized as `FILTERED` (asynchronous, surfaces on `message.filtered`) | Suppress the contact and skip further sends until renewed consent | `POST /v3/messages` accepts sends with `202` and applies business rules asynchronously, so opt-out, balance, and template-approval outcomes arrive as message statuses and webhooks rather than HTTP errors. The [Error Catalog](/reference/api/error-catalog) lists every business logic code with remediation steps. ## Basic Error Handling [#basic-error-handling] ### Try-Catch Pattern [#try-catch-pattern] ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); async function sendMessage(phoneNumber: string, templateId: string, channels?: string[]) { try { const response = await client.messages.send({ to: [phoneNumber], template: { id: templateId }, // Omit channel for automatic selection; pass e.g. ['sms'] to pin the channel ...(channels ? { channel: channels } : {}) }); return { success: true, messageId: response.data.recipients[0].message_id }; } catch (error) { if (error instanceof SentDm.APIError) { return handleApiError(error); } // Network or other errors return { success: false, error: 'Network error', retryable: true }; } } function handleApiError(error: SentDm.APIError) { switch (error.status) { case 429: return { success: false, error: 'Rate limited', retryable: true, delay: 60000 }; case 401: return { success: false, error: 'Invalid API key', retryable: false }; case 400: return { success: false, error: error.message, retryable: false }; default: return { success: false, error: error.message, retryable: error.status >= 500 }; } } ``` ```python import sent_dm from sent_dm import SentDm client = SentDm() def send_message(phone_number: str, template_id: str): try: response = client.messages.send( to=[phone_number], template={"id": template_id} ) return {"success": True, "message_id": response.data.recipients[0].message_id} except sent_dm.RateLimitError as e: return {"success": False, "error": "Rate limited", "retryable": True, "delay": 60} except sent_dm.AuthenticationError as e: return {"success": False, "error": "Invalid API key", "retryable": False} except sent_dm.BadRequestError as e: return {"success": False, "error": str(e), "retryable": False} except sent_dm.APIStatusError as e: return {"success": False, "error": str(e), "retryable": e.status_code >= 500} except sent_dm.APIConnectionError as e: return {"success": False, "error": "Network error", "retryable": True} ``` ```go func sendMessage(phoneNumber, templateId string) (*SendResult, error) { client := sentdm.NewClient() response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{phoneNumber}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String(templateId), }, }) if err != nil { if apiErr, ok := err.(*sentdm.APIError); ok { return nil, handleAPIError(apiErr) } // Network or other errors return &SendResult{Retryable: true, Error: err}, nil } return &SendResult{Success: true, MessageID: response.Data.Recipients[0].MessageID}, nil } func handleAPIError(err *sentdm.APIError) error { switch err.StatusCode { case 429: return fmt.Errorf("rate limited, retry after %d seconds", err.RetryAfter) case 401: return fmt.Errorf("invalid API key") case 400: return fmt.Errorf("bad request: %s", err.Message) default: if err.StatusCode >= 500 { return fmt.Errorf("server error: %s (retryable)", err.Message) } return fmt.Errorf("API error: %s", err.Message) } } ``` ```java public SendResult sendMessage(String phoneNumber, String templateId) { try { MessageSendParams params = MessageSendParams.builder() .addTo(phoneNumber) .template(MessageSendParams.Template.builder() .id(templateId) .build()) .build(); var response = client.messages().send(params); return new SendResult(true, response.data().recipients().get(0).messageId(), null); } catch (RateLimitException e) { return new SendResult(false, null, "Rate limited, retry after " + e.getRetryAfter()); } catch (AuthenticationException e) { return new SendResult(false, null, "Invalid API key"); } catch (BadRequestException e) { return new SendResult(false, null, e.getMessage()); } catch (APIException e) { boolean retryable = e.getStatusCode() >= 500; return new SendResult(false, null, e.getMessage() + (retryable ? " (retryable)" : "")); } } ``` ```csharp public async Task SendMessageAsync(string phoneNumber, string templateId) { try { var parameters = new MessageSendParams { To = new List { phoneNumber }, Template = new MessageSendParamsTemplate { Id = templateId } }; var response = await client.Messages.Send(parameters); return new SendResult(true, response.Data.Recipients[0].MessageId, null); } catch (RateLimitException ex) { return new SendResult(false, null, $"Rate limited, retry after {ex.RetryAfter}"); } catch (AuthenticationException ex) { return new SendResult(false, null, "Invalid API key"); } catch (BadRequestException ex) { return new SendResult(false, null, ex.Message); } catch (APIException ex) when (ex.StatusCode >= 500) { return new SendResult(false, null, $"{ex.Message} (retryable)"); } catch (APIException ex) { return new SendResult(false, null, ex.Message); } } ``` ```php function sendMessage($phoneNumber, $templateId) { try { $result = $this->client->messages->send( to: [$phoneNumber], template: ['id' => $templateId] ); return ['success' => true, 'message_id' => $result->data->recipients[0]->message_id]; } catch (RateLimitException $e) { return ['success' => false, 'error' => 'Rate limited', 'retryable' => true]; } catch (AuthenticationException $e) { return ['success' => false, 'error' => 'Invalid API key', 'retryable' => false]; } catch (BadRequestException $e) { return ['success' => false, 'error' => $e->getMessage(), 'retryable' => false]; } catch (APIException $e) { $retryable = $e->getCode() >= 500; return ['success' => false, 'error' => $e->getMessage(), 'retryable' => $retryable]; } } ``` ```ruby def send_message(phone_number, template_id) result = sent_dm.messages.send_( to: [phone_number], template: { id: template_id } ) { success: true, message_id: result.data.recipients[0].message_id } rescue Sentdm::RateLimitError => e { success: false, error: 'Rate limited', retryable: true } rescue Sentdm::AuthenticationError => e { success: false, error: 'Invalid API key', retryable: false } rescue Sentdm::BadRequestError => e { success: false, error: e.message, retryable: false } rescue Sentdm::APIError => e retryable = e.code >= 500 { success: false, error: e.message, retryable: retryable } end ``` The remaining examples in this guide build on the TypeScript `sendMessage` helper from [Try-Catch Pattern](#try-catch-pattern). ## Retry Strategies [#retry-strategies] ### Exponential Backoff [#exponential-backoff] Increase wait time between retries to avoid overwhelming the API: ```typescript async function sendWithRetry( phoneNumber: string, templateId: string, maxRetries: number = 3 ): Promise { for (let attempt = 0; attempt <= maxRetries; attempt++) { const result = await sendMessage(phoneNumber, templateId); if (result.success || !result.retryable) { return result; } if (attempt < maxRetries) { // Exponential backoff: 1s, 2s, 4s const delay = Math.pow(2, attempt) * 1000; console.log(`Retry ${attempt + 1}/${maxRetries} after ${delay}ms`); await sleep(delay); } } return { success: false, error: 'Max retries exceeded' }; } ``` ### Jitter [#jitter] Add randomness to prevent thundering herd: ```typescript function sleepWithJitter(baseDelay: number): Promise { const jitter = Math.random() * 1000; // 0-1000ms random return sleep(baseDelay + jitter); } // Usage const delay = Math.pow(2, attempt) * 1000; await sleepWithJitter(delay); ``` ### Circuit Breaker Pattern [#circuit-breaker-pattern] Retries handle brief errors; a circuit breaker handles sustained outages by failing fast instead of piling retries onto an API that is already struggling. The pattern itself is generic. Use a maintained circuit-breaker library for your platform rather than implementing the state machine yourself. Two rules matter when you wrap Sent calls: - Trip the breaker only on retryable failures: network errors and `5xx` responses. A `4xx` response means your request needs fixing, and a `429` needs backoff (see [Exponential Backoff](#exponential-backoff)), not an open circuit. - Wrap the `sendMessage` helper (or your equivalent) so queued sends fail fast while the circuit is open, then re-enter your retry flow when the probe request succeeds. ## Idempotency [#idempotency] Prevent duplicate messages when retrying: ```typescript async function sendMessageIdempotent( phoneNumber: string, templateId: string, idempotencyKey: string ) { try { return await client.messages.send({ to: [phoneNumber], template: { id: templateId } }, { headers: { 'Idempotency-Key': idempotencyKey } }); } catch (error) { if (error.code === 'CONFLICT_001') { // Duplicate request - message already sent with this key console.log('Message already sent with this idempotency key'); return { success: true, duplicate: true }; } throw error; } } // Generate idempotency key from business context const idempotencyKey = `order_confirmation_${orderId}_${userId}`; await sendMessageIdempotent(phoneNumber, templateId, idempotencyKey); ``` ## Fallback Strategies [#fallback-strategies] ### Channel Fallback [#channel-fallback] If you want Sent to handle fallback for you, omit the `channel` field: automatic selection is the only mode with cross-channel fallback, and it routes each message over another channel when the preferred one can't deliver. Refer to [Channel Selection Strategies](/start/guides/sending-messages#channel-selection-strategies) for how selection works. An explicit `channel` value pins the send and disables fallback. Because `POST /v3/messages` returns `202` before delivery, a pinned send that can't deliver fails asynchronously: the failure arrives as a [`message.failed` webhook event](/start/webhooks/event-types), not as an error response. To fall back manually, re-send on the other channel from your webhook handler: ```typescript // At send time: pin to WhatsApp and store the context keyed by message ID const result = await sendMessage(phoneNumber, templateId, ['whatsapp']); if (result.success) { await pendingSends.set(result.messageId, { phoneNumber, templateId }); } // In your webhook handler: re-send over SMS when the WhatsApp message fails async function handleFailedEvent(event) { if (event.event === 'message.failed' && event.payload.channel === 'whatsapp') { const context = await pendingSends.get(event.payload.message_id); if (context) { console.log('WhatsApp delivery failed, falling back to SMS'); await sendMessage(context.phoneNumber, context.templateId, ['sms']); await pendingSends.delete(event.payload.message_id); } } } ``` ### Queue for Later [#queue-for-later] `POST /v3/messages` accepts sends with `202` even when your balance is too low. Each affected message then finalizes as `BLOCKED` and fires a [`message.blocked` webhook event](/start/webhooks/event-types) instead of returning a synchronous error, and blocked messages are not re-sent automatically after a top-up. Handle the event by queuing a re-send and alerting your billing owner, reusing the `pendingSends` store from the fallback example: ```typescript async function handleBlockedEvent(event) { if (event.event === 'message.blocked') { // Account-level gate (for example, insufficient balance); message not dispatched const context = await pendingSends.get(event.payload.message_id); if (context) { await retryQueue.add(context); await pendingSends.delete(event.payload.message_id); } await alertBillingTeam('Messages blocked - check account balance'); } } // After topping up, re-send queued messages as new requests for (const context of await retryQueue.drain()) { await sendMessage(context.phoneNumber, context.templateId); } ``` ## Monitoring and Alerting [#monitoring-and-alerting] ### Error Metrics [#error-metrics] Track error rates to detect issues: ```typescript // Increment counters errorCounter.labels({ type: 'rate_limited' }).inc(); errorCounter.labels({ type: 'network' }).inc(); // Alert on high error rates if (errorRate > 0.1) { // 10% error rate await sendAlert('High message send error rate', { errorRate }); } ``` ### Structured Logging [#structured-logging] Log errors with context for debugging: ```typescript logger.error('Message send failed', { error: error.message, errorCode: error.code, phoneNumber: maskPhone(phoneNumber), templateId, attempt: attemptNumber, retryable: isRetryable(error) }); ``` ## Best Practices [#best-practices] ### 1. Distinguish Retryable vs Non-Retryable [#1-distinguish-retryable-vs-non-retryable] ```typescript function isRetryable(error: APIError): boolean { // Never retry auth errors if (error.status === 401) { return false; } // Never retry payment / balance errors (legacy v2 send endpoints only; // v3 sends surface balance problems asynchronously as BLOCKED) if (error.status === 402) { return false; } // Don't retry validation errors if (error.status === 400 || error.status === 422) { return false; } // Retry server errors and rate limits return error.status >= 500 || error.status === 429; } ``` ### 2. Set Maximum Retry Limits [#2-set-maximum-retry-limits] Prevent infinite loops: ```typescript const MAX_RETRIES = 3; const MAX_DELAY = 30000; // 30 seconds const delay = Math.min(Math.pow(2, attempt) * 1000, MAX_DELAY); ``` ### 3. Fail Fast for User-Facing Errors [#3-fail-fast-for-user-facing-errors] Don't retry if user needs to fix something: ```typescript if (error.code === 'VALIDATION_002') { // Show error to user immediately return { success: false, userError: 'Please enter a valid phone number' }; } ``` ### 4. Use Dead Letter Queues [#4-use-dead-letter-queues] For messages that ultimately fail: ```typescript async function processMessage(message: Message) { const result = await sendWithRetry(message); if (!result.success) { // Move to dead letter queue for manual review await deadLetterQueue.add({ originalMessage: message, error: result.error, attempts: result.attempts, failedAt: new Date() }); } } ``` ## Testing Error Handling [#testing-error-handling] To exercise each error path without sending real messages: - **Success path**: add `sandbox: true` to the request body. The API authenticates and validates the request, then returns `202` with `status: "QUEUED"` and generated message IDs. Nothing is sent or charged. See [Sandbox Mode](/reference/api/test-mode). - **Validation errors**: request validation runs even with `sandbox: true`, so a malformed request (for example, a phone number that isn't E.164) returns a real `400` your handler can be tested against. - **Provider and rate-limit errors**: sandbox mode does not simulate `429`, `5xx`, or delivery failures. Unit-test your retry and fallback branches by mocking the SDK client to throw those errors, as shown in [Testing & Debugging](/start/guides/testing-debugging). - **Webhook-driven paths**: trigger your `message.failed` and `message.blocked` handlers with the [webhook test endpoint](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksTestWebhookEndpoint), which sends a test event to your registered URL. For failure injection beyond unit tests (dropped connections, dependency outages), apply standard chaos-engineering practice at your infrastructure layer. It requires no Sent-specific setup. --- # How to handle Sent API errors (/start/guides/handling-api-errors.md) # How to handle Sent API errors [#how-to-handle-sent-api-errors] This guide shows you how to handle Sent API v3 errors in your client code: detect failures, branch on error codes, capture request IDs for support, prevent avoidable errors, and test your handling without side effects. It assumes you can already authenticate and send requests to the API; if not, start with the [API reference overview](/reference/api). Every error uses the same JSON envelope with a machine-readable `code`. The [Error Handling reference](/reference/api/errors) documents the envelope and HTTP status codes; the [Error Catalog](/reference/api/error-catalog) enumerates every code. ## Check the success flag on every response [#check-the-success-flag-on-every-response] The envelope's `success` boolean is the reliable failure signal. Check it before reading `data`: ```typescript const response = await fetch('/v3/messages', { ... }); const data: ApiResponse = await response.json(); if (!data.success) { // Handle error console.error(`Error ${data.error?.code}: ${data.error?.message}`); return; } // Process successful response console.log(data.data); ``` ```python import requests response = requests.post('/v3/messages', ...) data = response.json() if not data['success']: # Handle error print(f"Error {data['error']['code']}: {data['error']['message']}") return # Process successful response print(data['data']) ``` ```go resp, err := http.Post("/v3/messages", "application/json", body) if err != nil { log.Fatal(err) } defer resp.Body.Close() var data ApiResponse[Message] if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { log.Fatal(err) } if !data.Success { // Handle error log.Printf("Error %s: %s\n", data.Error.Code, data.Error.Message) return } // Process successful response log.Println(data.Data) ``` ## Branch on error codes, not messages [#branch-on-error-codes-not-messages] Error messages can change; codes are stable. Branch on `error.code` and give each class of failure its own recovery path: ```typescript switch (data.error?.code) { case 'AUTH_001': case 'AUTH_002': // Redirect to login or refresh API key break; case 'RESOURCE_001': // Prompt user to create the resource break; case 'BUSINESS_002': // Implement retry with backoff const retryAfter = response.headers.get('Retry-After'); await sleep(parseInt(retryAfter || '60') * 1000); break; default: // Log unexpected error console.error('Unexpected error:', data.error); } ``` ```python error_code = data['error']['code'] if error_code in ('AUTH_001', 'AUTH_002'): # Redirect to login or refresh API key pass elif error_code == 'RESOURCE_001': # Prompt user to create the resource pass elif error_code == 'BUSINESS_002': # Implement retry with backoff retry_after = int(response.headers.get('Retry-After', 60)) time.sleep(retry_after) else: # Log unexpected error print('Unexpected error:', data['error']) ``` ```go switch data.Error.Code { case "AUTH_001", "AUTH_002": // Redirect to login or refresh API key case "RESOURCE_001": // Prompt user to create the resource case "BUSINESS_002": // Implement retry with backoff retryAfter := resp.Header.Get("Retry-After") seconds, _ := strconv.Atoi(retryAfter) if seconds == 0 { seconds = 60 } time.Sleep(time.Duration(seconds) * time.Second) default: // Log unexpected error log.Printf("Unexpected error: %+v\n", data.Error) } ``` If you retry on `BUSINESS_002` (rate limit) or 5xx errors, use exponential backoff. See [How to handle Sent API rate limits](/start/guides/handling-rate-limits) for a complete implementation. ## Log request IDs for support [#log-request-ids-for-support] Every response includes `meta.request_id`. Log it with each failure, and include it when contacting [support@sent.dm](mailto:support@sent.dm). The ID lets support trace the exact request: ```typescript console.error(`Request ID: ${data.meta.request_id}`); // Provide this to support@sent.dm when reporting issues ``` ```python print(f"Request ID: {data['meta']['request_id']}") # Provide this to support@sent.dm when reporting issues ``` ```go log.Printf("Request ID: %s\n", data.Meta.RequestID) // Provide this to support@sent.dm when reporting issues ``` ## Make retries safe with idempotency keys [#make-retries-safe-with-idempotency-keys] If your error handling retries mutations (`POST`, `PUT`, `PATCH`), send an `Idempotency-Key` header so a retry after a timeout or 5xx error cannot perform the operation twice: ```http POST /v3/messages x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Idempotency-Key: send-msg-order-8412 Content-Type: application/json ``` Derive the key from a business identifier for the operation (an order ID, a client-generated request ID) and reuse the same key on every retry attempt. [How to retry Sent API requests safely](/start/guides/retrying-requests-safely) covers key derivation and retry loops in full. ## Validate inputs before sending [#validate-inputs-before-sending] Prevent the most common `VALIDATION_*` errors client-side. Phone numbers must be in E.164 format: ```typescript // Validate phone number format function isValidE164(phone: string): boolean { return /^\+[1-9]\d{1,14}$/.test(phone); } if (!isValidE164(phoneNumber)) { throw new Error('Phone number must be in E.164 format'); } ``` ```python import re # Validate phone number format def is_valid_e164(phone: str) -> bool: return bool(re.match(r'^\+[1-9]\d{1,14}$', phone)) if not is_valid_e164(phone_number): raise ValueError('Phone number must be in E.164 format') ``` ```go import "regexp" // Validate phone number format func isValidE164(phone string) bool { matched, _ := regexp.MatchString(`^\+[1-9]\d{1,14}$`, phone) return matched } if !isValidE164(phoneNumber) { log.Fatal("Phone number must be in E.164 format") } ``` When the server rejects input, read the `error.details` object. It carries field-level messages you can surface directly to users. ## Test your error handling with sandbox mode [#test-your-error-handling-with-sandbox-mode] To exercise your error paths without sending real messages, add `sandbox: true` to any mutation request. Validation still runs, so invalid input returns real validation errors with no side effects: ```bash curl -X POST https://api.sent.dm/v3/messages \ -H "x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "sandbox": true, "to": ["invalid"], "template": {"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"} }' ``` This returns a `VALIDATION_*` error envelope without attempting to send a message. Refer to the [Sandbox Mode reference](/reference/api/test-mode) for the full contract. ## Verify your handling [#verify-your-handling] You have working error handling when: - A request with an invalid phone number surfaces the field-level message from `error.details` instead of a generic failure. - A `429` response triggers a delayed retry rather than an immediate one. - Failed requests appear in your logs with `error.code` and `meta.request_id`. ## Related [#related] - Refer to the [Error Handling reference](/reference/api/errors) for the envelope format, HTTP status codes, and common codes. - The [Error Catalog](/reference/api/error-catalog) lists every error code with causes and remediation. - [How to retry Sent API requests safely](/start/guides/retrying-requests-safely) - [How to handle Sent API rate limits](/start/guides/handling-rate-limits) # How to handle Sent API rate limits (/start/guides/handling-rate-limits.md) # How to handle Sent API rate limits [#how-to-handle-sent-api-rate-limits] This guide shows you how to keep an integration running smoothly under the Sent API v3 rate limits: recover from `429` responses, watch for limit pressure, and shape your own traffic so batch jobs and bursts stay under the account limit. It assumes you can already send authenticated requests; for the limit values and window semantics, see the [Rate Limits reference](/reference/api/rate-limits). Rate limits apply per customer account (10,000 requests per minute for standard endpoints), so every strategy below operates at the account level, not per API key. ## Back off and retry on 429 [#back-off-and-retry-on-429] When a request returns `429 Too Many Requests`, wait the number of seconds in the `Retry-After` header before retrying. Fall back to exponential backoff if the header is absent: ```typescript async function makeRequestWithRetry( url: string, options: RequestInit, maxRetries = 3 ): Promise { for (let attempt = 0; attempt <= maxRetries; attempt++) { const response = await fetch(url, options); if (response.status !== 429) { return response; } if (attempt === maxRetries) { throw new Error('Max retries exceeded'); } // Get retry delay from header or use exponential backoff const retryAfter = response.headers.get('Retry-After'); const delay = retryAfter ? parseInt(retryAfter) * 1000 : Math.pow(2, attempt) * 1000; console.log(`Rate limited. Retrying after ${delay}ms...`); await sleep(delay); } throw new Error('Unreachable'); } function sleep(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } ``` ```python import time import requests from typing import Optional def make_request_with_retry( method: str, url: str, headers: dict, json_data: Optional[dict] = None, max_retries: int = 3 ) -> requests.Response: """Make request with exponential backoff on 429.""" for attempt in range(max_retries + 1): response = requests.request( method, url, headers=headers, json=json_data ) if response.status_code != 429: return response if attempt == max_retries: raise Exception('Max retries exceeded') # Get retry delay from header or use exponential backoff retry_after = response.headers.get('Retry-After') delay = int(retry_after) if retry_after else (2 ** attempt) print(f'Rate limited. Retrying after {delay}s...') time.sleep(delay) raise Exception('Unreachable') ``` ```go package main import ( "fmt" "math" "net/http" "strconv" "time" ) func makeRequestWithRetry( req *http.Request, maxRetries int, ) (*http.Response, error) { client := &http.Client{} for attempt := 0; attempt <= maxRetries; attempt++ { resp, err := client.Do(req) if err != nil { return nil, err } if resp.StatusCode != 429 { return resp, nil } if attempt == maxRetries { return nil, fmt.Errorf("max retries exceeded") } // Get retry delay from header or use exponential backoff retryAfter := resp.Header.Get("Retry-After") delay := math.Pow(2, float64(attempt)) if retryAfter != "" { if seconds, err := strconv.Atoi(retryAfter); err == nil { delay = float64(seconds) } } fmt.Printf("Rate limited. Retrying after %.0fs...\n", delay) time.Sleep(time.Duration(delay) * time.Second) } return nil, fmt.Errorf("unreachable") } ``` If the retried request is a mutation (`POST`, `PUT`, `PATCH`), send an `Idempotency-Key` so the retry can't duplicate the operation. See [How to retry Sent API requests safely](/start/guides/retrying-requests-safely). ## Monitor 429 responses as a pressure signal [#monitor-429-responses-as-a-pressure-signal] The API sends the `X-RateLimit-*` headers only on `429` responses, so there is no per-request quota readout to poll. Treat each `429` as the signal instead: count them in your metrics and alert when they occur, using the headers on the rejection to log when capacity returns: ```typescript async function makeRequest(url: string, options: RequestInit): Promise { const response = await fetch(url, options); if (response.status === 429) { const limit = response.headers.get('X-RateLimit-Limit'); const reset = response.headers.get('X-RateLimit-Reset'); console.warn( `Rate limited: limit ${limit}/min, window resets at ${new Date(parseInt(reset!) * 1000)}` ); // Send to your monitoring system // metrics.increment('api.rate_limited', { limit }); } return response; } ``` ```python import time import requests def make_request(url: str, headers: dict) -> requests.Response: """Make request and track 429 responses for monitoring.""" response = requests.get(url, headers=headers) if response.status_code == 429: limit = response.headers.get('X-RateLimit-Limit') reset = response.headers.get('X-RateLimit-Reset') reset_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(reset))) print(f'WARNING: rate limited: limit {limit}/min, window resets at {reset_time}') # Send to your monitoring system (Datadog, Prometheus, etc) # statsd.increment('api.rate_limited') return response ``` ```go package main import ( "fmt" "net/http" "strconv" "time" ) func makeRequest(req *http.Request) (*http.Response, error) { client := &http.Client{} resp, err := client.Do(req) if err != nil { return nil, err } if resp.StatusCode == 429 { limit := resp.Header.Get("X-RateLimit-Limit") resetUnix, _ := strconv.ParseInt(resp.Header.Get("X-RateLimit-Reset"), 10, 64) resetTime := time.Unix(resetUnix, 0) fmt.Printf("WARNING: rate limited: limit %s/min, window resets at %s\n", limit, resetTime) // Send to your monitoring system // statsd.Increment("api.rate_limited") } return resp, nil } ``` A sustained 429 rate means your steady-state traffic exceeds the account limit. Throttle client-side (next section) or contact [support@sent.dm](mailto:support@sent.dm) about a higher limit. ## Throttle requests client-side [#throttle-requests-client-side] To avoid hitting the limit at all, space out requests at the source. Most integrations never need this – at 1,000 recipients per `POST /v3/messages` the standard limit accepts 10 million messages a minute. Reach for a throttle when a fan-out job can burst past 10,000 requests in a minute. Pacing at 150 requests per second keeps you at 9,000 requests per minute, under the 10,000/minute standard limit: ```typescript class RateLimiter { private minInterval: number; private lastRequestTime: number = 0; constructor(requestsPerSecond: number) { this.minInterval = 1000 / requestsPerSecond; } async throttle(): Promise { const now = Date.now(); const timeSinceLastRequest = now - this.lastRequestTime; if (timeSinceLastRequest < this.minInterval) { const delay = this.minInterval - timeSinceLastRequest; await sleep(delay); } this.lastRequestTime = Date.now(); } } function sleep(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } // Use: limit to 150 requests per second (9,000/min, under the 10,000 limit) const limiter = new RateLimiter(150); async function makeThrottledRequest(url: string, options: RequestInit): Promise { await limiter.throttle(); return fetch(url, options); } ``` ```python import time import requests from typing import Optional class RateLimiter: """Simple rate limiter that enforces a minimum interval between requests.""" def __init__(self, requests_per_second: float): self.min_interval = 1.0 / requests_per_second self.last_request_time: Optional[float] = None def throttle(self): """Wait if necessary to maintain rate limit.""" if self.last_request_time is None: self.last_request_time = time.time() return now = time.time() time_since_last = now - self.last_request_time if time_since_last < self.min_interval: delay = self.min_interval - time_since_last time.sleep(delay) self.last_request_time = time.time() # Use: limit to 150 requests per second (9,000/min, under the 10,000 limit) limiter = RateLimiter(150) def make_throttled_request(url: str, headers: dict) -> requests.Response: limiter.throttle() return requests.get(url, headers=headers) ``` ```go package main import ( "net/http" "sync" "time" ) type RateLimiter struct { minInterval time.Duration lastRequestTime time.Time mu sync.Mutex } func NewRateLimiter(requestsPerSecond float64) *RateLimiter { return &RateLimiter{ minInterval: time.Duration(float64(time.Second) / requestsPerSecond), } } func (r *RateLimiter) Throttle() { r.mu.Lock() defer r.mu.Unlock() if r.lastRequestTime.IsZero() { r.lastRequestTime = time.Now() return } timeSinceLast := time.Since(r.lastRequestTime) if timeSinceLast < r.minInterval { time.Sleep(r.minInterval - timeSinceLast) } r.lastRequestTime = time.Now() } // Use: limit to 150 requests per second (9,000/min, under the 10,000 limit) var limiter = NewRateLimiter(150) func makeThrottledRequest(req *http.Request) (*http.Response, error) { limiter.Throttle() client := &http.Client{} return client.Do(req) } ``` If several workers share one account, budget the limit across them: for example, four workers at 40 requests per minute each. Every API key on the account draws from the same pool. ## Cache responses and pace batch work [#cache-responses-and-pace-batch-work] Two ways to reduce the requests you send in the first place: cache reads you would otherwise repeat, and process bulk workloads in paced batches instead of all at once. ```typescript // ❌ Inefficient: unpaced individual requests (100 API calls at once) for (const contact of contacts) { await createContact(contact); } // ✅ Efficient: cache repeated reads, process writes in paced batches class CachedContactClient { private cache = new Map(); async getContact(id: string): Promise { // Return cached result if available if (this.cache.has(id)) { return this.cache.get(id)!; } const contact = await fetchContact(id); this.cache.set(id, contact); return contact; } async batchProcessContacts( contacts: Contact[], batchSize: number = 10 ): Promise { // Process in batches with rate limiting for (let i = 0; i < contacts.length; i += batchSize) { const batch = contacts.slice(i, i + batchSize); // Process batch concurrently await Promise.all( batch.map(contact => this.processContact(contact)) ); // Wait between batches if (i + batchSize < contacts.length) { await sleep(1000); } } } private async processContact(contact: Contact): Promise { // Implementation } } function sleep(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } ``` ```python from typing import Dict, List import time import requests # ❌ Inefficient: unpaced individual requests (100 API calls at once) # for contact in contacts: # create_contact(contact) # ✅ Efficient: cache repeated reads, process writes in paced batches class CachedContactClient: def __init__(self, api_key: str): self.api_key = api_key self.cache: Dict[str, dict] = {} def get_contact(self, contact_id: str) -> dict: """Get contact with caching.""" # Return cached result if available if contact_id in self.cache: return self.cache[contact_id] response = requests.get( f'https://api.sent.dm/v3/contacts/{contact_id}', headers={'x-api-key': self.api_key} ) contact = response.json()['data'] self.cache[contact_id] = contact return contact def batch_process_contacts( self, contacts: List[dict], batch_size: int = 10 ): """Process contacts in batches with rate limiting.""" for i in range(0, len(contacts), batch_size): batch = contacts[i:i + batch_size] # Process batch for contact in batch: self.process_contact(contact) # Wait between batches (except after last batch) if i + batch_size < len(contacts): time.sleep(1) def process_contact(self, contact: dict): """Process a single contact.""" # Implementation pass ``` ```go package main import ( "sync" "time" ) // ❌ Inefficient: unpaced individual requests (100 API calls at once) // for _, contact := range contacts { // createContact(contact) // } // ✅ Efficient: cache repeated reads, process writes in paced batches type CachedContactClient struct { apiKey string cache map[string]Contact mu sync.RWMutex } func NewCachedContactClient(apiKey string) *CachedContactClient { return &CachedContactClient{ apiKey: apiKey, cache: make(map[string]Contact), } } func (c *CachedContactClient) GetContact(id string) (Contact, error) { // Return cached result if available c.mu.RLock() if contact, ok := c.cache[id]; ok { c.mu.RUnlock() return contact, nil } c.mu.RUnlock() // Fetch and cache contact, err := fetchContact(id, c.apiKey) if err != nil { return Contact{}, err } c.mu.Lock() c.cache[id] = contact c.mu.Unlock() return contact, nil } func (c *CachedContactClient) BatchProcessContacts( contacts []Contact, batchSize int, ) error { if batchSize == 0 { batchSize = 10 } for i := 0; i < len(contacts); i += batchSize { end := i + batchSize if end > len(contacts) { end = len(contacts) } batch := contacts[i:end] // Process batch concurrently var wg sync.WaitGroup for _, contact := range batch { wg.Add(1) go func(c Contact) { defer wg.Done() processContact(c) }(contact) } wg.Wait() // Wait between batches if end < len(contacts) { time.Sleep(time.Second) } } return nil } func processContact(contact Contact) error { // Implementation return nil } type Contact struct { ID string PhoneNumber string } func fetchContact(id, apiKey string) (Contact, error) { // Implementation return Contact{}, nil } ``` A single `POST /v3/messages` request accepts multiple recipients, so sending to a list is one request, not one per recipient. For high-volume sending patterns, see the [Batch Operations guide](/start/guides/batch-operations). If you cache responses, remember that message and contact state changes server-side. Prefer [webhooks](/start/webhooks/getting-started) over polling for status updates, and expire cached reads accordingly. ## Verify your handling [#verify-your-handling] You have working rate-limit handling when: - A `429` response results in a delayed retry that succeeds, not a failed operation. - Your metrics show 429 counts, and a sustained increase triggers an alert. - Batch jobs complete without producing 429 bursts, because throttling and pacing keep steady-state traffic under 10,000 requests per minute. ## Related [#related] - Refer to the [Rate Limits reference](/reference/api/rate-limits) for limit values, window semantics, and the 429 response format. - [How to retry Sent API requests safely](/start/guides/retrying-requests-safely) - [How to handle Sent API errors](/start/guides/handling-api-errors) # Calls From Your App (/start/guides/in-app-calls.md) # Calls From Your App [#calls-from-your-app] A user of your web app can place and receive phone calls as one of your numbers. Your backend mints a short-lived voice token for the signed-in user, the browser registers with it through the [`@sentdm/voice-client`](https://www.npmjs.com/package/@sentdm/voice-client) SDK, and every call the user places or receives is decided by your callback, the same way an inbound call to your number is. ## Prerequisites [#prerequisites] Phone calls must be enabled for your account. This is set by Sent: contact [support@sent.dm](mailto:support@sent.dm) to request it. You also need: - At least one number with phone calls turned on. See [Voice](/start/guides/managing-channels#voice) in the channels guide. - A callback URL that answers Sent's questions about each call, if you want to decide what rings. See [Answering Calls](/start/guides/answering-calls). Without one, a call placed from your app connects straight to the phone number, app user, or room it dialed, and calls to the number are declined. - A web app served over HTTPS, or from `localhost` while developing. The browser hides the microphone and service worker APIs over plain HTTP. ## How It Fits Together [#how-it-fits-together] 1. Your backend calls `POST /v3/voice/tokens` with the user's identity and returns the token to the browser. 2. The browser registers with `@sentdm/voice-client`, which fetches tokens through a `tokenProvider` function you give it, exchanges each one with Sent for what it registers with, and refreshes them before they expire. 3. When the user places a call, Sent asks your callback what to do with it. `to` in the app says who the user wants to reach. Your answer decides what rings. 4. Incoming calls reach the browser as push messages, through a service worker your app serves. The API key stays on your server. The browser only ever holds a voice token, which is bound to one identity and expires on its own. The token is opaque, and nothing from the calling engine passes through your backend or your app. ## Mint a Voice Token [#mint-a-voice-token] Mint tokens on your backend, for the user who is signed in: ```bash curl -X POST "https://api.sent.dm/v3/voice/tokens" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "identity": "agent-42", "number": "+12025550123", "ttl": 600 }' ``` | Field | Description | |-------|-------------| | `identity` | Your identifier for the app user, for example an agent id. Letters, digits, `-`, and `_` only, up to 200 characters. Required | | `number` | One of your voice numbers, in E.164 format. Calls this identity places go out from it, and your callback sees it as `number` on every question about them. Omit it to use your default line for app calls | | `ttl` | Token lifetime in seconds. Defaults to 600 and cannot exceed 3600 | The response carries the token and what it was bound to: ```json { "success": true, "data": { "token": "vt_eyJ2IjoxLCJzdWIiOiJhZ2VudC00MiJ9.signature", "identity": "agent-42", "number": "+12025550123", "expires_at": "2026-07-22T12:34:56+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-22T12:24:56+00:00", "version": "v3" } } ``` Hand `token` to the browser unchanged, and read `identity`, `number`, and `expires_at` from the response rather than from the token. Minting again for the same identity binds it to the number given in that request, so an identity can move between numbers. | Status | Code | When | |--------|------|------| | 400 | `VALIDATION_011` | `identity` is missing or has characters outside letters, digits, `-` and `_`, or is longer than 200 characters | | 400 | `BUSINESS_024` | `number` is not one of your voice-enabled numbers | | 400 | `VALIDATION_001` | `ttl` is outside 1 to 3600 | | 403 | `BUSINESS_023` | Your account has no active voice number, so there is no line to place calls from | Never call the token endpoint from the browser. It authenticates with your API key, which must not leave your server. Expose an endpoint of your own, such as `/api/voice-token`, that checks the user's session and returns the token as text. ## Register the Browser [#register-the-browser] Install the SDK and serve the service worker it ships, which is how incoming calls reach the page: ```bash npm install @sentdm/voice-client cp node_modules/@sentdm/voice-client/sw.js public/sw.js ``` Create one client per tab with a `tokenProvider` that fetches a fresh token from your backend, then register: ```ts import SentVoice from '@sentdm/voice-client'; const client = new SentVoice({ tokenProvider: () => fetch('/api/voice-token').then((response) => response.text()), }); // From a click handler: the browser asks for the notification permission here await client.register(); const call = await client.connect({ to: '+14155551234' }); call.on('connected', () => console.log('Connected')); call.on('disconnected', ({ state }) => console.log(`The call ended as ${state}`)); ``` The first `register()` asks the user to allow notifications, which the browser needs to deliver incoming calls. Firefox and Safari only show that prompt after a user gesture, so call it from a click handler. `tokenProvider` is how the SDK gets every token, and must return the `token` from the minting response unchanged. It is called by `register()` and again before each token expires: at 80% of the token's lifetime, or 30 seconds before it expires if that is earlier. `tokenWillExpire` fires first. A provider that throws is retried after a short backoff. If the retries run out, the client emits `offline` and tries again about every 30 seconds until it is registered again; calls in progress go on, and `connect()` throws `NotRegisteredError` until then. ```ts client.on('registered', () => console.log('Ready for calls')); client.on('tokenWillExpire', ({ expiresAt }) => console.log('Refreshing, expires', new Date(expiresAt))); client.on('offline', (reason) => console.warn(`Offline (${reason.code}), trying again every 30 seconds`)); ``` Every method, event and error is documented on the [Voice SDK](/sdks/voice) page. ## Place and Receive Calls [#place-and-receive-calls] `connect({ to })` calls a phone number in E.164 format or another user of your app by identity. `joinConference({ name })` joins one of your account's rooms. Either way, `to` says who the user wants; your callback's answer decides what rings. ```ts const call = await client.connect({ to: 'ben' }); call.on('ringing', () => console.log('Ringing')); call.on('connected', () => call.sendDigits('1')); call.on('disconnected', ({ state, error }) => console.log(`The call ended as ${state}`, error?.code)); ``` Incoming calls arrive as an invite the user can accept or decline: ```ts client.on('incomingCall', async (invite) => { console.log('Incoming call from', invite.from); invite.on('cancelled', () => console.log('The caller hung up')); // When the user answers const call = await invite.accept(); call.on('disconnected', ({ state }) => console.log(`The call ended as ${state}`)); // When the user declines instead // await invite.reject(); }); ``` A leg to a phone number costs money and runs for at most what your account's balance affords at the destination's per-minute rate, capped at four hours. Legs between app users and legs into a room cost nothing and have no such limit. Every call, app to app included, is a record under `GET /v3/voice/calls` and reports through the `call` webhooks. ## Route by Department [#route-by-department] Bind identities to numbers when you mint tokens. Mint a sales agent's token with `number` set to the sales line and a support agent's token with the support line. Calls each agent places go out from that number, and every question your callback receives about those calls carries it as `number`. ```bash curl -X POST "https://api.sent.dm/v3/voice/tokens" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "identity": "sales-agent-7", "number": "+12125550100" }' ``` An inbound call to the sales line carries the same `number`, so one callback can serve every department by branching on it: ring an agent of that department who is online, dial a fallback phone number when nobody is, and answer `reject` with `busy` when there is no fallback. The [Department Routing](/start/guides/voice-recipes#department-routing) recipe shows the answers. ## Next Steps [#next-steps] # Implementation Guides (/start/guides.md) # Implementation Guides [#implementation-guides] Practical, step-by-step guides for implementing common messaging patterns with Sent. ## Guide Categories [#guide-categories] ### Core Messaging [#core-messaging] } /> } /> } /> } /> } /> ### Advanced Patterns [#advanced-patterns] } /> } /> } /> ### Voice [#voice] } /> } /> } /> } /> } /> } /> ## Quick Reference [#quick-reference] | Task | Guide | API Endpoint | |------|-------|--------------| | Send a message | [Sending Messages](/start/guides/sending-messages) | `POST /v3/messages` | | Track delivery | [Status Tracking](/start/guides/message-status-tracking) | Webhooks / `GET /v3/messages/{id}` | | Create contacts | [Managing Contacts](/start/guides/managing-contacts) | `POST /v3/contacts` | | Create templates | [Working with Templates](/start/guides/working-with-templates) | `POST /v3/templates` | | Handle errors | [Error Handling](/start/guides/error-handling) | - | **New to Sent?** Start with the [Quickstart](/start/quickstart) to send your first message, then return here for detailed implementation guidance. ## Getting Help [#getting-help] - [Troubleshooting Guide](/start/reference-guides/troubleshooting) - Common issues and solutions - [Error Catalog](/reference/api/error-catalog) - Complete error code reference - [Support](/start/reference-guides/support) - Contact the support team --- # Integrating Sender Profiles into Your Application (/start/guides/integrating-sender-profiles.md) # Integrating Sender Profiles into Your Application [#integrating-sender-profiles-into-your-application] This guide shows you how to route messaging traffic through Sender Profiles in your own app: send with a profile's API key, map customers to profiles in a multi-tenant platform, and attribute webhook events to the right profile. It assumes your organization already has at least one profile ([create one in the dashboard](/start/guides/creating-a-sender-profile) or [via the API](/start/advanced/sender-profiles-api)) and that you can already [send messages](/start/guides/sending-messages). For the inheritance model behind profiles, see [Sender Profiles](/start/concepts/sender-profiles). ## Send with a profile's API key [#send-with-a-profiles-api-key] Each Sender Profile has its own API credentials. The API key you authenticate with determines which profile's resources (templates, contacts, numbers, and compliance settings) the request uses, so sending as a profile is just sending with that profile's key: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $PROFILE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": {"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8"} }' ``` ```typescript import SentDm from '@sentdm/sentdm'; // Uses profile-specific API key const client = new SentDm({ apiKey: process.env.PROFILE_API_KEY }); await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } }); ``` ```python from sent_dm import SentDm client = SentDm(api_key=os.environ['PROFILE_API_KEY']) client.messages.send( to=["+1234567890"], template={"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8"} ) ``` ```go package main import ( "context" "os" "github.com/sentdm/sent-dm-go" "github.com/sentdm/sent-dm-go/option" ) func main() { client := sentdm.NewClient( option.WithAPIKey(os.Getenv("PROFILE_API_KEY")), ) client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), }, }) } ``` ```java SentDmClient client = SentDmOkHttpClient.builder() .apiKey(System.getenv("PROFILE_API_KEY")) .build(); client.messages().send(MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .build()) .build()); ``` ```csharp SentDmClient client = new(apiKey: Environment.GetEnvironmentVariable("PROFILE_API_KEY")); await client.Messages.Send(new MessageSendParams { To = new List { "+1234567890" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }); ``` ```php use SentDM\Client; $client = new Client($_ENV['PROFILE_API_KEY']); $client->messages->send( to: ['+1234567890'], template: ['id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8'] ); ``` ```ruby require "sentdm" client = Sentdm::Client.new(api_key: ENV["PROFILE_API_KEY"]) client.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } ) ``` If you prefer to keep a single credential instead of one key per profile, send with your organization API key and scope each request with the `x-profile-id` header (a profile UUID belonging to your organization). Only organization keys can use this header; profile-scoped keys are rejected with `403`. The [Sender Profiles API guide](/start/advanced/sender-profiles-api#operate-as-the-profile) covers this pattern in detail. ## Map each customer to a profile [#map-each-customer-to-a-profile] For platforms serving multiple customers, store the profile-to-customer mapping in your own database and resolve the credentials per request: ```typescript async function sendOnBehalfOfCustomer(customerId: string, message: MessageRequest) { const profile = await db.senderProfiles.findByCustomer(customerId); const client = new SentDm({ apiKey: profile.apiKey }); return client.messages.send({ to: message.recipients, template: { id: message.templateId }, variables: message.variables }); } ``` ```python def send_on_behalf_of_customer(customer_id: str, message: dict): profile = db.sender_profiles.find_by_customer(customer_id) client = SentDm(api_key=profile.api_key) return client.messages.send( to=message["recipients"], template={"id": message["template_id"]}, variables=message["variables"] ) ``` ```go func sendOnBehalfOfCustomer(customerID string, msg MessageRequest) (*sentdm.MessageResponse, error) { profile, _ := db.SenderProfiles.FindByCustomer(customerID) client := sentdm.NewClient(option.WithAPIKey(profile.APIKey)) return client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: msg.Recipients, Template: sentdm.MessageSendParamsTemplate{ID: &msg.TemplateID}, }) } ``` ```java public MessageResponse sendOnBehalfOfCustomer(String customerId, MessageRequest message) { SenderProfile profile = db.senderProfiles().findByCustomer(customerId); SentDmClient client = SentDmOkHttpClient.builder() .apiKey(profile.getApiKey()) .build(); return client.messages().send(MessageSendParams.builder() .addTo(message.getRecipients().get(0)) .template(MessageSendParams.Template.builder() .id(message.getTemplateId()) .build()) .build()); } ``` ```csharp public async Task SendOnBehalfOfCustomer(string customerId, MessageRequest message) { var profile = await db.SenderProfiles.FindByCustomerAsync(customerId); var client = new SentDmClient(apiKey: profile.ApiKey); return await client.Messages.Send(new MessageSendParams { To = message.Recipients, Template = new MessageSendParamsTemplate { Id = message.TemplateId }, Variables = message.Variables }); } ``` ```php function sendOnBehalfOfCustomer(string $customerId, array $message): array { $profile = $this->db->senderProfiles->findByCustomer($customerId); $client = new Client($profile->apiKey); return $client->messages->send( to: $message['recipients'], template: ['id' => $message['template_id']], variables: $message['variables'] ?? [] ); } ``` ```ruby def send_on_behalf_of_customer(customer_id, message) profile = db.sender_profiles.find_by_customer(customer_id) client = Sentdm::Client.new(api_key: profile.api_key) client.messages.send_( to: message[:recipients], template: { id: message[:template_id] }, variables: message[:variables] ) end ``` ## Track usage per profile in webhooks [#track-usage-per-profile-in-webhooks] Every event names its account in `payload.account_id`: the Sender Profile for events its clones deliver, and your organization for your own events. Map that ID to your tenant, rather than storing each `message_id` and looking the message up when its event arrives. The samples skip your organization's own sends by comparing with its ID, `ORGANIZATION_ID`. Receive every profile's events at one endpoint by selecting them under `sender_profile` on your organization's webhook. Sent clones the webhook onto each profile, including profiles you create later, so onboarding a tenant needs no webhook change. See [Sender Profile Events](/start/webhooks/event-types#sender-profile-events) for the request. ```typescript app.post('/webhooks/sent', async (req, res) => { res.sendStatus(200); const { field, payload } = req.body; if (field === 'message' && payload.message_status === 'SENT') { // Your organization's own sends carry its ID const senderProfileId = payload.account_id; if (senderProfileId !== ORGANIZATION_ID) { await analytics.track('message_sent', { senderProfileId, messageId: payload.message_id, channel: payload.channel, outboundNumber: payload.outbound_number, timestamp: new Date() }); } } }); ``` ```python @app.post("/webhooks/sent") async def webhook(request: Request): data = await request.json() p = data.get("payload", {}) if data.get("field") == "message" and p.get("message_status") == "SENT": # Your organization's own sends carry its ID sender_profile_id = p["account_id"] if sender_profile_id != ORGANIZATION_ID: analytics.track("message_sent", { "sender_profile_id": sender_profile_id, "message_id": p["message_id"], "channel": p["channel"], "outbound_number": p["outbound_number"], "timestamp": datetime.now().isoformat() }) return {"status": "ok"} ``` ```go func webhookHandler(w http.ResponseWriter, r *http.Request) { var event struct { Field string `json:"field"` Payload struct { AccountID string `json:"account_id"` MessageID string `json:"message_id"` MessageStatus string `json:"message_status"` Channel string `json:"channel"` OutboundNumber string `json:"outbound_number"` } `json:"payload"` } json.NewDecoder(r.Body).Decode(&event) w.WriteHeader(http.StatusOK) if event.Field == "message" && event.Payload.MessageStatus == "SENT" { // Your organization's own sends carry its ID if event.Payload.AccountID != organizationID { analytics.Track("message_sent", map[string]interface{}{ "sender_profile_id": event.Payload.AccountID, "message_id": event.Payload.MessageID, "channel": event.Payload.Channel, "outbound_number": event.Payload.OutboundNumber, }) } } } ``` ```java @PostMapping("/webhooks/sent") public ResponseEntity webhook(@RequestBody WebhookEvent event) { if ("message".equals(event.getField()) && "SENT".equals(event.getPayload().getMessageStatus())) { // Your organization's own sends carry its ID String senderProfileId = event.getPayload().getAccountId(); if (!ORGANIZATION_ID.equals(senderProfileId)) { analytics.track("message_sent", Map.of( "sender_profile_id", senderProfileId, "message_id", event.getPayload().getMessageId(), "channel", event.getPayload().getChannel(), "outbound_number", event.getPayload().getOutboundNumber() )); } } return ResponseEntity.ok().build(); } ``` ```csharp [ApiController] [Route("webhooks")] public class WebhookController : ControllerBase { [HttpPost("sent")] public async Task Webhook([FromBody] WebhookEvent evt) { if (evt.Field == "message" && evt.Payload.MessageStatus == "SENT") { // Your organization's own sends carry its ID var senderProfileId = evt.Payload.AccountId; if (senderProfileId != OrganizationId) { await analytics.TrackAsync("message_sent", new { sender_profile_id = senderProfileId, message_id = evt.Payload.MessageId, channel = evt.Payload.Channel, outbound_number = evt.Payload.OutboundNumber }); } } return Ok(); } } ``` ```php #[Post('/webhooks/sent')] public function webhook(Request $request): JsonResponse { $data = $request->getPayload()->all(); $p = $data['payload'] ?? []; if (($data['field'] ?? '') === 'message' && ($p['message_status'] ?? '') === 'SENT') { // Your organization's own sends carry its ID $senderProfileId = $p['account_id'] ?? null; if ($senderProfileId !== self::ORGANIZATION_ID) { $this->analytics->track('message_sent', [ 'sender_profile_id' => $senderProfileId, 'message_id' => $p['message_id'], 'channel' => $p['channel'], 'outbound_number' => $p['outbound_number'], ]); } } return new JsonResponse(['status' => 'ok']); } ``` ```ruby post '/webhooks/sent' do request.body.rewind data = JSON.parse(request.body.read) p = data['payload'] || {} if data['field'] == 'message' && p['message_status'] == 'SENT' # Your organization's own sends carry its ID sender_profile_id = p['account_id'] if sender_profile_id != ORGANIZATION_ID analytics.track('message_sent', { sender_profile_id: sender_profile_id, message_id: p['message_id'], channel: p['channel'], outbound_number: p['outbound_number'] }) end end { status: 'ok' }.to_json end ``` ## Secure multi-tenant credentials [#secure-multi-tenant-credentials] - Store each profile's API key in a separate secrets-management entry so one leaked key exposes one tenant, not all of them. - [Verify webhook signatures](/start/webhooks/signature-verification) before trusting any event. - Apply per-profile rate limiting in your own app so one tenant cannot consume another tenant's throughput. ## Verify the integration [#verify-the-integration] Send a test message with one profile's key, then confirm its delivery events carry that profile's ID in `payload.account_id`. If no events arrive at your endpoint, check that your organization's webhook selects them under `sender_profile`, and that the profile hasn't deleted its clone. ## Related [#related] - [Sender Profiles](/start/concepts/sender-profiles) explains inheritance, sharing, and isolation - [Creating a Sender Profile](/start/guides/creating-a-sender-profile) walks through the dashboard wizard - [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api) automates tenant onboarding - [Multi-Tenant Architectures](/start/advanced/multi-tenant-architectures) compares shared and per-tenant setups - Refer to the [messages API reference](/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesSendMessageV3Endpoint) for the full list of send options # Calls, Recordings, and Participants (/start/guides/managing-calls.md) # Calls, Recordings, and Participants [#calls-recordings-and-participants] Every call Sent handles for you is a record under `/v3/voice/calls`. This guide covers reading that record, ending a live call, recording it, and managing the participants of a call your callback connected to a conference room. ## Prerequisites [#prerequisites] - A call id. It arrives as `callId` on the `call.request` question your callback receives, and as `call_id` on every `call.*` webhook. See [Answering Calls](/start/guides/answering-calls). - A number with phone calls turned on, with a callback URL that answers. See [Managing channels](/start/guides/managing-channels#voice). All requests authenticate with the `x-api-key` header. Call ids look like `call_9f2ab000-0000-4000-8000-000000000001`; anything else is refused with `400`. ## The Call Record [#the-call-record] [`GET /v3/voice/calls/{id}`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallEndpoint) returns one of your calls, with a timeline of when it entered each status: ```bash curl "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001" \ -H "x-api-key: $SENT_API_KEY" ``` ```json { "success": true, "data": { "id": "call_9f2ab000-0000-4000-8000-000000000001", "mode": "inapp", "agent_id": null, "direction": "outbound", "from": { "kind": "user", "value": "agent-42" }, "to": { "kind": "number", "value": "+12025550142" }, "number": "+12025550123", "status": "COMPLETED", "failure_reason": null, "started_at": "2026-07-22T12:00:00+00:00", "answered_at": "2026-07-22T12:00:05+00:00", "ended_at": "2026-07-22T12:00:47+00:00", "duration_seconds": 42, "price": 0.02, "connected_number": null, "caller_id_used": "+12025550123", "legs": [ { "direction": "outbound", "number": "+12025550142", "billed_minutes": 1, "cost": 0.02, "currency": "USD" } ], "recording_available": false, "timeline": [ { "status": "INITIATED", "timestamp": "2026-07-22T12:00:00+00:00" }, { "status": "ANSWERED", "timestamp": "2026-07-22T12:00:05+00:00" }, { "status": "COMPLETED", "timestamp": "2026-07-22T12:00:47+00:00" } ] }, "error": null } ``` | Field | Description | | --- | --- | | `id` | The call id. The same one the `call.request` question and every `call.*` webhook carry | | `mode` | `inapp` for a call your callback URL decides, `agent` for a call one of your [voice agents](/start/guides/voice-agents) answered | | `agent_id` | The voice agent that answered the call, such as `agent_9f2ab000-0000-4000-8000-000000000001`. Null on an `inapp` call | | `direction` | `outbound` for a call placed from your app, `inbound` for a call to one of your numbers | | `from`, `to` | Who placed the call and who it was for. `kind` is `user`, `number`, `conference` or `anonymous`; `value` is the app user's identity, the phone number in E.164 format, or the room name. `value` is null when the kind is `anonymous` | | `number` | Your number that owns the call: the dialed number for an inbound call, the caller's bound number for a call placed from your app | | `status` | `INITIATED`, `RINGING`, `ANSWERED`, `COMPLETED`, `FAILED`, `NO_ANSWER` or `REJECTED`. Upper case, like a message status | | `failure_reason` | Why the call did not complete. Null while the call is live, when it completed, and when it failed without a recorded reason. See [Call Failure Reasons](/reference/api/error-catalog#call-failure-reasons) | | `started_at` | When the call was placed (UTC) | | `answered_at` | When the call was answered (UTC). Null until then, and always null for a call between two of your app users | | `ended_at` | When the call ended (UTC). Null while the call is live | | `duration_seconds` | Billable duration in seconds. Null while the call is live | | `price` | What the call cost, the sum of its `legs`. Null until it has been priced. Only completed calls are charged | | `connected_number` | The number a forwarded or fallback call was connected to, in E.164 format: the number your answer dialled with `connectToNumber`, or a voice agent's `fallback`. Null on every other call | | `caller_id_used` | The caller id shown on the leg Sent dialled, in E.164 format. Null when Sent dialled no leg | | `legs` | The legs the call was billed for, each with `direction` (`inbound` or `outbound`), `number`, `billed_minutes`, `cost` and `currency`. A forwarded or fallback call is one record with two billed legs, the caller's leg to your number and the leg to `connected_number`, both over the same minutes. Every other call has one | | `recording_available` | True once a recording of the call is available | | `timeline` | When the call entered each status, oldest first. Only returned when reading one call | [`GET /v3/voice/calls`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallsEndpoint) lists your calls, most recent first, in pages of `page_size` (default 20, at most 100) starting at `page` 1. Filter with `direction`, `status`, `number` (one of your voice numbers), `mode` (`inapp` or `agent`), `agent_id` (the voice agent that answered) and the time the call started: `from` and `to`, both inclusive, as ISO 8601. ```bash curl "https://api.sent.dm/v3/voice/calls?direction=inbound&status=completed&from=2026-07-22T00:00:00Z" \ -H "x-api-key: $SENT_API_KEY" ``` Filters match any case, so `status=completed` and `status=COMPLETED` are the same filter. Use the `call.*` webhooks for live updates; the list is for looking calls up afterwards. In the [dashboard](https://app.sent.dm/dashboard/activities), calls are listed on the Activities page with the channel filter set to **Voice**. The default view lists messages only. ## Hang Up a Call [#hang-up-a-call] [`POST /v3/voice/calls/{id}/hangup`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsHangupCallEndpoint) ends one of your live calls: ```bash curl -X POST "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001/hangup" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' ``` The response is `204`. The call then ends the way any other call does, once the disconnect is reported. An answered call ends `COMPLETED` and you receive `call.completed`. A call that was still ringing ends `NO_ANSWER`, `REJECTED` or `FAILED`, as the disconnect reports it, and you receive `call.failed`. | Response | Meaning | | --- | --- | | `409` `CONFLICT_008` | The call has already ended | | `409` `CONFLICT_011` | The call has no phone leg, such as a call between two of your app users. The app ends that call itself | | `409` `CONFLICT_015` | One of your voice agents answers the call. The agent ends it with its `hangup` tool | ## Record a Call [#record-a-call] A recording starts in one of three ways: - `record: true` on a `connectToNumber` or `connectToConference` answer. Recording starts the moment the legs join. - A `startRecording` instruction in an answer, before the action runs. - [`POST /v3/voice/calls/{id}/recordings`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsRecordCallEndpoint) with `action` `start`, mid-call. ```bash curl -X POST "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001/recordings" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "action": "start" }' ``` Stop the same way with `action` `stop`, or with a `stopRecording` instruction in a later answer. Either stops a recording started by any of the three. The response is `204`. Each start is a recording of its own. Once the call was recorded and the recording has landed, `call.recording_ready` is sent once per recording, naming it in `recording_id`. Until then, and for a call that was never recorded, the recordings list is empty. [`GET /v3/voice/calls/{id}/recordings`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallRecordingsEndpoint) returns every recording of the call, oldest first, each with a link: ```bash curl "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001/recordings" \ -H "x-api-key: $SENT_API_KEY" ``` ```json { "success": true, "data": { "recordings": [ { "recording_id": "7c1d2e3f-4a5b-4c6d-8e9f-0a1b2c3d4e5f", "download_url": "https://recordings.example.com/9f2ab000-0000-4000-8000-000000000001/7c1d2e3f4a5b4c6d8e9f0a1b2c3d4e5f.mp3?X-Amz-Expires=3600&X-Amz-Signature=...", "url_expires_at": "2026-07-22T13:00:00+00:00" } ] }, "error": null } ``` | Field | Description | | --- | --- | | `recording_id` | The recording's id, the one its `call.recording_ready` webhook announced it under | | `download_url` | A pre-signed link that downloads the recording as an MP3 file | | `url_expires_at` | When the link stops working (UTC). Request the recordings again for a fresh link | Anyone holding `download_url` can download the recording until the link expires. Treat it like the recording itself: fetch it from your backend, and never hand it to a browser you do not control. | Response | Meaning | | --- | --- | | `403` `BUSINESS_026` | Call recording is not available. Applies to `stop` as well, because nothing could be recording | | `409` `CONFLICT_008` | The call has already ended | | `409` `CONFLICT_011` | The call has no phone leg, such as a call between two of your app users, which cannot be recorded | | `409` `CONFLICT_015` | One of your voice agents answers the call, which cannot be recorded through this endpoint | A `connectToUser` answer accepts `record: true` but never honours it: a call connected to an app user cannot be recorded. The call connects without the recording. Stops in the same answer still run, because a recording started earlier in the call may still be running. ## Conference Participants [#conference-participants] Only a live call your answer connected to a conference room takes participants. A live call connected to a user or a number answers `409` `CONFLICT_009`, and so does a call a voice agent answers; a call that has ended answers `409` `CONFLICT_008`. [`POST /v3/voice/calls/{id}/participants`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsAddCallParticipantEndpoint) dials one of your app users or a phone number into the room: ```bash curl -X POST "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001/participants" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": { "kind": "number", "value": "+14155551234" }, "caller_id": "+12025550123" }' ``` | Field | Description | | --- | --- | | `to.kind` | `user` for one of your app users, `number` for a phone number | | `to.value` | The app user's identity, or the phone number in E.164 format | | `caller_id` | The number shown to a phone participant as the caller, in E.164 format. Must be one of your numbers. The call's owning number when omitted | The response is `202` with the participant's own call record. `from.kind` is `conference`, because the room called them: ```json { "success": true, "data": { "id": "call_9f2ab000-0000-4000-8000-000000000002", "mode": "inapp", "agent_id": null, "direction": "outbound", "from": { "kind": "conference", "value": "daily-standup" }, "to": { "kind": "number", "value": "+14155551234" }, "number": "+12025550123", "status": "INITIATED", "failure_reason": null, "started_at": "2026-07-22T12:00:00+00:00", "answered_at": null, "ended_at": null, "duration_seconds": null, "price": null, "recording_available": false, "timeline": null }, "error": null } ``` A participant is a call of their own. It has its own id, can be read with `GET /v3/voice/calls/{id}` and hung up, and is billed and reported through `call.completed` and `call.failed` like any other call. Every participant needs a positive balance on the account. A phone participant also needs a destination you may call and a caller id you own: | Response | Meaning | | --- | --- | | `400` `BUSINESS_011` | Calls to the destination country are not allowed | | `400` `BUSINESS_022` | `caller_id` is not one of your numbers | | `400` `BUSINESS_025` | The participant could not be dialed. Retry, and contact support with the request ID if it repeats | | `402` `BUSINESS_003` | Insufficient balance. Checked for every participant, app users included | | `409` `CONFLICT_008` | The call has ended | | `409` `CONFLICT_009` | The call is live but not in a conference | The room is recorded on the call as Sent reads your answer. A participant added right after the answer can briefly see `409` `CONFLICT_009` while that write lands. Retry for a few seconds before treating it as final. [`GET /v3/voice/calls/{id}/participants`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsGetCallParticipantsEndpoint) lists who is in the room, the call itself included: ```json { "success": true, "data": [ { "id": "call_9f2ab000-0000-4000-8000-000000000001", "kind": "user", "value": "agent-42", "muted": false, "duration_seconds": 184 }, { "id": "call_9f2ab000-0000-4000-8000-000000000002", "kind": "number", "value": "+14155551234", "muted": true, "duration_seconds": 96 } ], "error": null } ``` | Field | Description | | --- | --- | | `id` | The participant's own call id. What the mute and remove endpoints take, and what `GET /v3/voice/calls/{id}` accepts | | `kind` | `user` for one of your app users, `number` for a phone number, `anonymous` for a caller who withheld their number | | `value` | The app user's identity or the phone number in E.164 format. Null when the kind is `anonymous` | | `muted` | True while the room mutes this participant | | `duration_seconds` | How long the participant has been connected to the room, in seconds | The list is empty once everyone has left. [`PATCH /v3/voice/calls/{id}/participants/{participantId}`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsPatchCallParticipantEndpoint) mutes or unmutes one participant. `muted` is required: `true` silences them, `false` lets them be heard again. Muting a participant who is already muted succeeds, as does unmuting one who is not. The response is `204`. ```bash curl -X PATCH "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001/participants/call_9f2ab000-0000-4000-8000-000000000002" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "muted": true }' ``` [`DELETE /v3/voice/calls/{id}/participants/{participantId}`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsRemoveCallParticipantEndpoint) removes one participant. Their leg ends and is reported through `call.completed`; everyone else stays connected. [`DELETE /v3/voice/calls/{id}/participants`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsRemoveCallParticipantsEndpoint) removes every participant, the call itself included. Every leg ends and is reported through `call.completed`. A room that is already empty answers `204` as well. Both answer `404` `RESOURCE_017` for a participant who is not in this call's room, `409` `CONFLICT_008` for a call that has ended, and `409` `CONFLICT_009` for a live call that is not in a conference. ## What a Call Costs [#what-a-call-costs] `price` is on the call record and on `call.completed`. On the webhook it is omitted until billing has recorded the charge, so read the call again later if you need it. Only completed calls are charged. A forwarded or fallback call is one record with two billed legs, the caller's and the one to `connected_number`, over the same minutes: `legs` on the call record shows each leg with its cost, and `price` is their sum. A leg to a phone number costs money for as long as it runs. It is told up front how long your balance affords at the destination's per-minute rate, and ends as completed when it reaches that cap. Legs to app users and conference rooms are free and have no such limit. ## Next Steps [#next-steps] # Managing channels (/start/guides/managing-channels.md) # Managing channels [#managing-channels] A channel is where a sender can actually send: a market you send SMS in, your WhatsApp account, your RCS agent, a number you take phone calls on. This guide covers reading them, adding them, and clearing what their compliance still owes. For why Sent routes three channels behind one send call, see [Channels](/start/concepts/channels). All requests authenticate with the `x-api-key` header. Send `x-profile-id` with an organization key to read or change one of your [Sender Profiles](/start/concepts/sender-profiles) instead of the calling account. Only organization API keys may send `x-profile-id`; a profile-scoped key is rejected with `403`, and a profile outside your organization returns `404`. A profile key is already scoped to its own profile, so it reads and changes that profile's channels with no header at all. ## Status lives on the channel [#status-lives-on-the-channel] An identity has no lifecycle. What has one is the registration of a sender in a market and the approval of a channel, so a sender live in one country and mid-registration in another reports exactly that, rather than one flattened answer. | Status | Meaning | Who is holding it | | --- | --- | --- | | `PROVISIONING` | Sent is arranging the sender | Sent (nothing is required from you yet) | | `ACTION_NEEDED` | Something is owed or was rejected | You: read `compliance.requirements` for the keys, or a resubmission has been asked | | `PENDING_REVIEW` | Filed with a regulator or carrier | The Campaign Registry or a carrier (nothing either side can hurry) | | `ACTIVE` | The sender is live and can carry traffic | N/A | | `INACTIVE` | Had a working sender and no longer does | Sent (the number was released or the campaign it carried lapsed) | ### What each status means in practice [#what-each-status-means-in-practice] **`PROVISIONING`** covers two distinct situations that `reason_code` distinguishes: - No registration has started yet. Sent is setting the market up and nothing is required from you (`CHANNEL_011`). - The carriers have elected the campaign and Sent is acquiring a phone number (`CHANNEL_010`). Requesting specific area codes can extend this window. **`ACTION_NEEDED`** means something you supplied was rejected or something still owed was not sent: - One or more compliance fields or documents are outstanding. The response names them (up to three, then a count). Send them with `PATCH /v3/channels/sms/{country}/{type}`: fields as JSON, documents as `multipart/form-data` files named after their key. - Your registration came back from review and must be corrected. Sent emails what needs changing; send the corrected `compliance.brand` or `compliance.campaign` values with the same `PATCH` and Sent reviews the registration again. Whatever an `ACTION_NEEDED` market is waiting on, the `PATCH` on its own path is where you send it. See [Correct what it holds](#correct-what-it-holds). **`PENDING_REVIEW`** means the registration is with a regulator or carrier. For a `TEN_DLC` market, this state begins as soon as a brand row is stored and continues until the carriers elect the campaign. Nothing either side can do speeds this up. **`ACTIVE`** means the sender is live. Requirements still outstanding against the registration (a field update or resubmission) are communicated separately and do not stop the market from sending. A market with several numbers reports its healthiest one: `ACTIVE` as soon as any number can send, otherwise `PROVISIONING`, otherwise `INACTIVE`. Its `sender_value` is its first live number, and each entry in `numbers` carries that number's own status: `ACTIVE` once it can send, `PROVISIONING` while it is still to be assigned, and `INACTIVE` once it could send and no longer can. **`INACTIVE`** means the market had a working sender and lost it. Sends in this market will fail. Subscribe to `channel.deactivated` to be told the moment it happens; the event carries the reason. When Sent removes an approved sender outright, for example at your request, the event is `channel.removed` instead. ### `reason_code` and `reason` [#reason_code-and-reason] Every SMS market, the WhatsApp account, and the RCS agent that is not `ACTIVE` carries `reason_code` and `reason` alongside `status`, on `GET /v3/channels`, the single-market reads, and Sender Profiles. SMS markets also carry them on the [`channel` webhook](/start/webhooks/event-types#channel), which WhatsApp and RCS don't publish yet. On reads, an `ACTIVE` channel carries neither; the webhook can still carry `reason` for an `ACTIVE` market when the event brought its own explanation. - **`reason_code`** is a stable code to branch on, from `CHANNEL_001` to `CHANNEL_011`. It is decided by the same logic as `status`, so the two never disagree. - **`reason`** is a sentence for a person that names who is holding the channel and what, if anything, you need to do. Its wording may improve, so don't parse it. ```json { "status": "PENDING_REVIEW", "reason_code": "CHANNEL_009", "reason": "Your registration is awaiting submission to or review by The Campaign Registry. Nothing is needed from you." } ``` | Status | `reason_code` | Meaning | | --- | --- | --- | | `ACTION_NEEDED` | `CHANNEL_001` | Information or documents are outstanding or were rejected. On an SMS market, `reason` names them | | `ACTION_NEEDED` | `CHANNEL_002` | The registration came back from review and must be corrected | | `ACTION_NEEDED` | `CHANNEL_003` to `CHANNEL_005` | The RCS registration was rejected, the channel was suspended, or setup failed | | `ACTION_NEEDED` | `CHANNEL_006`, `CHANNEL_007` | No WhatsApp Business Account is connected, or it has no phone number | | `INACTIVE` | `CHANNEL_008` | The sender was lost: the number was released or its campaign lapsed | | `PENDING_REVIEW` | `CHANNEL_009` | With the registry or the carriers | | `PROVISIONING` | `CHANNEL_010`, `CHANNEL_011` | Approved and acquiring a number, or being set up | On reads, `reason` is specific to the market: it names the outstanding fields and, when they can all be sent as JSON, the `PATCH` path to send them to. A read that doesn't check a market's requirements says so in `reason` and points to `GET /v3/channels/sms/{country}/{type}`, which does. The response to adding a market carries the general sentence for its status. The full list, with what to do for each, is in the [Error Catalog](/reference/api/error-catalog#channel-status-reasons). `reason` replaces the `note` field, which is no longer returned. If you read `note`, read `reason` instead, and branch on `reason_code` rather than on either sentence. ## Read every channel at once [#read-every-channel-at-once] [`GET /v3/channels`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsGetChannelsEndpoint) returns every market you send SMS in, your WhatsApp account, your RCS agent, and the numbers you take phone calls on, each with its status: ```bash curl "https://api.sent.dm/v3/channels" \ -H "x-api-key: $SENT_API_KEY" ``` `sms` is a list with one entry per market. Each entry carries a `compliance` object naming the country and sender type it answers for. An empty `requirements` means that market is satisfied; anything listed is what to supply. The entries under `sms` are the same ones [`GET /v3/channels/sms`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsMarketGetSmsMarketsEndpoint) returns, in the same shape a single-market read returns, so a list, a member read, and the all-channels read cannot describe a market differently. `voice` lists the numbers you take phone calls on, in the shape [`GET /v3/channels/voice`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsGetVoiceChannelsEndpoint) returns. See [Voice](#voice). ## SMS markets [#sms-markets] A market is a country plus a sender type. The pair identifies it everywhere: in the list, in the path, and in the compliance it owes. Sender types are `LOCAL`, `MOBILE`, `TEN_DLC`, `TOLL_FREE`, `SHORT_CODE`, and `ALPHANUMERIC`. `10DLC` is accepted as a synonym of `TEN_DLC`, and availability varies by country. In a path the type is matched ignoring case, so `/v3/channels/sms/us/ten_dlc` and `/v3/channels/sms/US/TEN_DLC` are the same market. ### Ask what the market wants [#ask-what-the-market-wants] Call [`GET /v3/compliance/requirements`](/reference/api/compliance/SentDmServicesEndpointsCustomerAPIv3ComplianceGetComplianceRequirementsEndpoint) **before you add a market**. It returns what that market demands, and `setup[]`: the calls that satisfy it, each with a body you can copy and send as it stands: ```bash curl "https://api.sent.dm/v3/compliance/requirements?channel=sms&country=US&type=TEN_DLC" \ -H "x-api-key: $SENT_API_KEY" ``` | Field | What it carries | | --- | --- | | `required` | Whether this market demands anything at all | | `sender_id_pattern` | The values the market accepts as a sender id, where you choose it | | `requirements[]` | One entry per value the market asks for, keyed as you write it (`brand.legal_name`, `campaign.message_flow`), with its type, format, options, minimum length, and item shape | | `setup[]` | The ordered calls that satisfy the requirements, with a body template and any `attachments` | There is always exactly one setup step, `POST /v3/channels/sms`, because the identity travels in that call's body rather than needing a separate call. Anything that cannot be a JSON value, such as an uploaded document, is listed under `attachments` instead of in the body template. Requirements vary enormously. US `TEN_DLC` registers a brand and a campaign with The Campaign Registry and asks for a substantial set of values; an alphanumeric sender pre-registers with supporting documents in one country and needs nothing at all in another. This is the same declaration that validates the calls themselves, so it cannot drift from what the API accepts. `channel` defaults to `sms`, which is the only channel answered today. `whatsapp` and `rcs` return `501` until their requirements are declared. They are refused rather than answered with an empty requirement set, because empty would say the channel demands nothing, and both demand plenty: WhatsApp a business verification and a display-name review, RCS a carrier approval. ### Add the market [#add-the-market] [`POST /v3/channels/sms`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddSmsChannelEndpoint) gives the sender a market, whether it is the first one or the fifth: ```bash curl -X POST "https://api.sent.dm/v3/channels/sms" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Idempotency-Key: add-us-tendlc-tenant-42" \ -H "Content-Type: application/json" \ -d '{ "country": "US", "number_type": "TEN_DLC", "compliance": { "brand": { "legal_name": "Tenant 42 Coffee Company LLC", "business_name": "Tenant 42 Coffee Co", "tax_id": "12-3456789", "tax_id_type": "us_ein", "entity_type": "PRIVATE_PROFIT", "street": "123 Main Street", "city": "New York", "state": "NY", "postal_code": "10001", "country": "US", "contact_name": "Jane Doe", "contact_email": "jane@tenant42.example.com", "contact_phone": "+12125550123" }, "campaign": { "description": "Order and delivery updates for coffee subscriptions", "message_flow": "Customers opt in at checkout on tenant42.example.com by ticking a box that is unchecked by default. Consent is not a condition of purchase.", "use_cases": [ { "use_case": "DELIVERY_NOTIFICATION", "sample_messages": ["Tenant 42 Coffee: your order #1234 ships today. Reply STOP to opt out."] } ], "opt_in_keywords": "START,YES", "opt_out_keywords": "STOP", "help_keywords": "HELP", "opt_in_message": "Tenant 42 Coffee: you are subscribed to order updates. Reply STOP to opt out, HELP for help.", "opt_out_message": "Tenant 42 Coffee: you will receive no further messages.", "help_message": "Tenant 42 Coffee: for help, email support@tenant42.example.com. Reply STOP to opt out.", "privacy_policy_link": "https://tenant42.example.com/privacy", "terms_and_conditions_link": "https://tenant42.example.com/terms" } } }' ``` **Everything the regime wants arrives in `compliance`**, as two declared objects: `brand`, the identity the registration is filed against, and `campaign`, with the use case, the consent narrative, the volume, the sample messages, and the keywords. There is nothing to set up first, and nothing is submitted by this call: the rows are what a submission is later assembled from, and filing happens externally. Send `{ "inherit": true }` to run on your organization's registration instead. Inheriting the campaign inherits the brand too, so a request that sends `"campaign": { "inherit": true }` with a `brand` of the profile's own is a `400`. `"brand": { "inherit": true }` on its own inherits the brand only, and the campaign is then the profile's own: ```json { "country": "US", "number_type": "TEN_DLC", "compliance": { "brand": { "inherit": true }, "campaign": { "inherit": true } } } ``` - **Inheriting the brand inherits the brand alone.** The campaign stays the profile's own, so send its fields as well. - **Your organization must have a campaign to inherit.** If it has none, the request is a `400` on `compliance.campaign` saying the organization has no campaign to inherit. - **A profile created without `compliance` inherits nothing.** This call is how it starts running on the organization's registration. Only a profile with no brand or campaign of its own is moved this way, so a request about one new market doesn't reroute the markets a profile already sends in. A `TEN_DLC` market registers with a regime, and whichever half of that registration is yours (not inherited from your organization) must be complete when you add the market. The call checks both `brand` and `campaign`: - If you supply a dedicated `brand`, every field the regime requires must be present, either in this request or already stored from a previous call. - If you supply a dedicated `campaign`, the same applies: `description`, `message_flow`, `use_cases`, the keyword and message fields, and the policy links must all be present. - A half you run by inheritance (`"inherit": true`) is not asked for anything. A missing field on a half you own is a `400` that names each path (for example `compliance.campaign.message_flow`), not a `202` for a market that could never be submitted to TCR. A field you stored on an earlier call counts as supplied: you do not need to repeat it. Send only what is genuinely new. A few field rules worth knowing before you fill the template in: - `campaign.message_flow` is the consent narrative in prose. Under 40 characters is refused, and carriers reject vague descriptions: say where opt-in happens, that the box is unchecked by default, and that consent is not a condition of purchase. - `campaign.use_cases` takes one to five entries, each with one to five sample messages. `MIXED` and `LOW_VOLUME` are refused as use cases: `campaign.volume` decides those. Omitting `volume` registers the campaign at the higher-fee standard tier. - `sender_value` is only for the types where you choose the sender rather than the carrier assigning it (an alphanumeric sender id, a short code, or a number you already own). It is **required** when `number_type` is `ALPHANUMERIC`: leaving it out is a `400`. Omit it for carrier-assigned types and one is provisioned. - `area_codes` picks where a `LOCAL` or `TEN_DLC` number comes from: one to 50 area codes in your order of preference, for example `["415", "628"]`, each listed once. Each code is tried in turn and honored exactly: you get a number in a code you named or none yet, never a neighboring code. Omit it for a number anywhere in the country. - `numbers` asks for several `LOCAL` or `TEN_DLC` numbers in one call, one entry per area code: `[{ "area_code": "212", "quantity": 2 }, { "area_code": "415" }, { "quantity": 1 }]` is two numbers in 212, one in 415, and one in any area code. `quantity` defaults to 1, and only one entry may leave out `area_code`. It can't be combined with `area_codes`, and it isn't available when the profile inherits the organization's campaign. On a `LOCAL` market you already hold, it adds the numbers to that market. A market holds at most 49 numbers. On a US `TEN_DLC` market the limit is the campaign's and counts every number on it, including the one each Sender Profile sharing your organization's campaign receives. A request that would go over it is a `400` on `numbers` that states the limit. US `TEN_DLC` numbers are assigned when the campaign is approved, not at request time. **A market that pre-registers its sender needs its documents in this same call.** When the market's `setup[]` step lists `attachments`, send the request as `multipart/form-data` instead of JSON: each request field is its own form field, and each file is a part named after the requirement key it satisfies: ```bash curl -X POST "https://api.sent.dm/v3/channels/sms" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -F "country=$COUNTRY" \ -F "number_type=ALPHANUMERIC" \ -F "sender_value=ExmplRetail" \ -F "senderid_registration_requirements=@sender-id-registration.pdf" ``` A required document that isn't attached, or a file that is rejected, is a `422` naming each key (for example `compliance.senderid_registration_requirements`). Nothing is added: the market is refused before it is provisioned, so fix the files and send the whole request again. A JSON body for such a market is refused the same way, because it cannot carry the files. ### Read one market [#read-one-market] [`GET /v3/channels/sms/{country}/{type}`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsMarketGetSmsMarketEndpoint) reads one market: its sender, where that sender stands, and everything its compliance holds: ```bash curl "https://api.sent.dm/v3/channels/sms/us/ten_dlc" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" ``` A market that registers with a compliance regime reports `brand` and `campaign`, each carrying `inherit` to say whether it is yours or your organization's. A market that registers with nobody has neither, so **both keys are absent rather than null**. Absent says this market does not ask; null would say it asks and you supplied nothing. It reports `documents` instead. `requirements` lists what is still owed, keyed as you write it. `GET /v3/compliance/requirements` says what a market demands of anybody; this says what you gave it. ### Correct what it holds [#correct-what-it-holds] [`PATCH /v3/channels/sms/{country}/{type}`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsMarketPatchSmsMarketEndpoint) supplies whatever a market is waiting on, in any market you hold: | Outstanding | Send | | --- | --- | | A `brand` or `campaign` value (US `TEN_DLC`) | `compliance`, as below | | A document, in any market | A `multipart/form-data` file named after the document's key | | A registration sent back for correction | The corrected `compliance.brand` or `compliance.campaign` values, or both | | Different numbers (`LOCAL` or `TEN_DLC`) | `numbers`, the full list the market asks for from now on | For a US `TEN_DLC` market, it takes the `compliance` object from the read straight back: ```bash curl -X PATCH "https://api.sent.dm/v3/channels/sms/us/ten_dlc" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{ "compliance": { "brand": { "contact_phone": "+12125550123" } } }' ``` **Partial at every level.** An omitted key is left alone; an explicit `null` clears it. Those are different requests, so `{}` changes nothing and is refused rather than silently accepted, and correcting one field does not blank the others. A `requirements` key is the path into the body that clears it. | Body | Effect | | --- | --- | | `"brand": { … }` | Supplies or corrects a dedicated identity for this sender | | `"brand": { "inherit": true }` | Runs on your organization's identity, giving up the dedicated one | | `"brand": null` | The same thing, said the short way | | `"campaign": { … }` | Supplies or corrects a dedicated campaign for this sender | | `"campaign": { "inherit": true }` | Runs on your organization's campaign | | Key omitted | Left exactly as it is | Nothing here creates a second anything (one identity and one campaign per market), so a write is an upsert and a replayed request lands on the row it already wrote. There is no sub-resource for either half: both are singletons of the market, so both are written here. `compliance` only applies to a market that registers with a regime. Every other market has no `brand` or `campaign`, so `compliance` there is a `400`: its compliance is documents. **A filed identity is `409`, unless it was sent back for correction.** Once the brand is filed, changing it locally would leave it out of step with the filed copy, so `compliance.brand` is refused. The campaign is not frozen: omit `brand` and the same body is accepted. When the market reports `ACTION_NEEDED` because the registration came back from review, the identity is accepted too, and the correction sends the registration back to Sent for review. **Documents** travel as `multipart/form-data`, each file in a part named after the compliance key it satisfies (the key `requirements` names). `compliance` and `numbers` can ride in the same form as text parts holding their JSON: ```bash curl -X PATCH "https://api.sent.dm/v3/channels/sms/xk/alphanumeric" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -F "business_registration=@./business-registration.pdf" ``` A file whose name matches no document the market asks for is a `400` that lists the keys that would. A file the upload rules refuse (empty, too large, or an unsupported type) is a `422`. If a file fails to store, the call is a `500` and nothing else in the request is applied. **Numbers** take the same list as `POST /v3/channels/sms`, and **replace** what the market asks for: send the full list you want, not a difference. ```json { "numbers": [ { "area_code": "205", "quantity": 2 }, { "area_code": "334", "quantity": 1 } ] } ``` - Numbers already assigned stay. A list that leaves one of them out is a `400`, because this call never releases a number. - A `LOCAL` market claims the new numbers from inventory straight away. Whatever inventory can't cover stays pending. - A `TEN_DLC` market records the numbers on its campaign and assigns them once the campaign is approved, or on the next acquisition cycle if it already is. It needs a campaign of the profile's own: an inherited one is a `400`, and so is a market with no campaign of its own yet unless `compliance.campaign` comes in the same request. - `numbers` can't be cleared: `"numbers": null` is a `400`. The response is the market as stored, in the same shape `GET` returns, so what comes back can be sent back. ## WhatsApp [#whatsapp] [`POST /v3/channels/whatsapp`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddWhatsappChannelEndpoint) connects a WhatsApp Business Account that your organization already holds through a [Multi-Partner Solution](/start/guides/whatsapp-partner-solution). It takes two fields, `waba_id` and an optional `phone_number_id`; the solution, the owning business portfolio, and the access token are all resolved from your organization rather than accepted from you. See [Connect a WhatsApp Business Account](/start/guides/connect-whatsapp#connect-a-waba-to-a-sender-profile) for that call in full, including why the token is not a field. WhatsApp reports `ACTION_NEEDED` while there is something for you to do: no business account is connected (`CHANNEL_006`), or the connected account has no phone number registered (`CHANNEL_007`). Both used to report `PROVISIONING`. A profile with no WhatsApp channel at all reads `whatsapp: null`. The call is a `400` when `waba_id` is missing, the call isn't scoped to a profile with `x-profile-id`, the account isn't one your organization can reach, Meta won't issue a token for it, or another profile already uses the number. ## RCS [#rcs] [`POST /v3/channels/rcs`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddRcsChannelEndpoint) asks for an RCS agent and records the order form the carriers vet it against. It always returns `202`: an agent is approved by the carriers, not by this call, and nothing here can make that happen sooner. Three fields are required, because US carriers refuse a submission without them: | Field | Why | | --- | --- | | `brand_name` | The brand this agent presents. Not taken from `compliance.brand`: a business may present a different brand on RCS than the one its 10DLC registration is filed against, and the carriers vet this one. | | `privacy_policy_url` | Fetched over the public internet at review time, so it must be an absolute `http(s)` URL. One behind a login passes this call and fails the review. | | `terms_and_conditions_url` | The same. | Everything else is optional here and can follow as the submission is assembled: `display_name`, `description`, `agent_use_case`, `brand_color`, the contact details, `official_address`, the consent narrative, and the start, help, and stop messages. Two fields cannot be changed casually. `hosting_region` is `us` or `eu`, defaults to `us`, and **cannot be changed once the agent is approved**. `billing_category` is `CONVERSATIONAL`, `SINGLE_MESSAGE`, or `BASIC_MESSAGE`, and defaults to `CONVERSATIONAL`. ## Voice [#voice] Voice is per number the way SMS is per market: each number you hold can carry phone calls on its own, with its own callback URL, where Sent asks what to do with every call on it. Nothing registers, so a number carries calls as soon as it is turned on. One of your voice numbers is the default line for calls placed from your app. A number can be bound to one of your voice agents instead of, or as well as, a callback URL, and the agent then answers calls to it. See [Voice agents](/start/guides/voice-agents). Phone calls must be enabled for your account first. This is set by Sent: contact [support@sent.dm](mailto:support@sent.dm) to request it. What your callback URL is asked, and how to answer, is in [Answering Calls](/start/guides/answering-calls). ### Turn calls on for a number [#turn-calls-on-for-a-number] [`POST /v3/channels/voice`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddVoiceChannelEndpoint) adds voice to a number you hold, or gives you a new one: ```bash curl -X POST "https://api.sent.dm/v3/channels/voice" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "number": "+12125550100", "callback_url": "https://example.com/voice" }' ``` | Field | What it does | | --- | --- | | `number` | One of your numbers, in E.164 format. Leave the field out to be given a new US number instead. Sending it empty is refused rather than read as a request for a new number | | `area_code` | The US area code a new number should be in, such as `212`. Only for a request that leaves `number` out; sending both is refused. Omit it too and the number comes from anywhere in the country | | `callback_url` | Where Sent asks what to do with each call on this number: an absolute HTTP or HTTPS URL on a public host. Required unless `agent_id` is sent | | `agent_id` | One of your voice agents, such as `agent_9f2ab000-0000-4000-8000-000000000001`, which answers calls to the number. Send it instead of `callback_url`, or with it. The agent wins over the callback URL for calls to the number, and calls your app places from the number still follow the callback. The provider applies the move on its own clock: `routes_to` reads `agent_pending` until it has recorded it, and calls follow within about an hour. See [Bind a number to the agent](/start/guides/voice-agents#bind-a-number-to-the-agent) | | `default_for_app_calls` | Make this the line calls placed from your app use when a voice token names no number. Omit it and your first voice number takes that role; a later one leaves it where it is | The response is the number as stored plus `callback_secret`, the `whsec_` secret every question to the callback URL is signed with. It is shown here and by the rotate endpoint, nowhere else, so store it now. ```json { "success": true, "data": { "callback_secret": "whsec_MWYyZDFlMmU2N2RmNmI3YThmNTZhODFiYzJlNGQzYjI=", "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "callback", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-07-22T12:00:00+00:00" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` A number you turned off earlier is turned back on. The same number with a different `callback_url` has its URL replaced and keeps its secret. With `sandbox: true` the request is validated and a simulated number reported with `202`; nothing is written and no number is bought. | Status | Meaning | | --- | --- | | `201` | Voice is on for the number. Store `callback_secret` | | `202` | Sandbox: what would have been written | | `400` | `number` is not a phone number or not one of yours (`BUSINESS_022`), `number` and `area_code` were both sent, `callback_url` is not a public HTTP or HTTPS URL, neither `callback_url` nor `agent_id` was sent, or `agent_id` is not an agent id | | `404` | `agent_id` is not one of your voice agents (`RESOURCE_013`). Refused before any number is obtained | | `409` | Another account already carries calls on this number (`RESOURCE_007`), or no number is available in the area code asked for (`BUSINESS_028`) | | `502` | The number could not be set up to receive calls, or could not be moved to your agent; nothing was written, repeat the request (`BUSINESS_027`) | ### Read a voice number [#read-a-voice-number] [`GET /v3/channels/voice`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsGetVoiceChannelsEndpoint) lists every number you turned calls on for, active or inactive, oldest first. [`GET /v3/channels/voice/{number}`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsGetVoiceChannelEndpoint) reads one. The number goes in the path in E.164 format with the plus sign URL-encoded as `%2B`. The signing secret is never on a read. ```bash curl "https://api.sent.dm/v3/channels/voice/%2B12125550100" \ -H "x-api-key: $SENT_API_KEY" ``` ```json { "success": true, "data": { "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": null, "routes_to": "callback", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-07-22T12:00:00+00:00" }, "meta": { "request_id": "req_8H3jNq5sWx", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` | Field | What it carries | | --- | --- | | `number` | The number, in E.164 format | | `status` | `ACTIVE` while the number carries calls, `INACTIVE` once it was turned off. Nothing provisions, so there is no `PROVISIONING` here | | `default_for_app_calls` | Whether this is the line calls placed from your app use when a voice token names no number. Exactly one active voice number carries it while you have any | | `callback_url` | Where Sent asks what to do with each call on this number | | `agent_id` | The voice agent calls to this number go to. Null when no agent answers the number | | `routes_to` | Who answers calls to the number: `agent`, the agent in `agent_id`. `agent_pending`, that agent once the provider has finished moving the number; a read settles it to `agent` once the move is recorded, and calls follow within about an hour. `callback`, your `callback_url`. `none`, nobody, so calls to the number are declined | A number you never turned voice on for answers `404` (`RESOURCE_013`). ### Change a voice number [#change-a-voice-number] [`PATCH /v3/channels/voice/{number}`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsPatchVoiceChannelEndpoint) changes one voice number and answers with the number as stored, the same shape the read returns, so what comes back can be sent back: ```bash curl -X PATCH "https://api.sent.dm/v3/channels/voice/%2B12125550100" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "callback_url": "https://example.com/voice-v2" }' ``` | Body | Effect | | --- | --- | | `"status": "ACTIVE"` | Turns calls on again for a number you turned off. The callback URL and the secret it had are kept | | `"status": "INACTIVE"` | Turns calls off. The callback URL and the secret stay on the number | | `"default_for_app_calls": true` | Makes this the line calls placed from your app use | | `"callback_url": "https://..."` | Replaces where Sent asks what to do with each call. The secret and the status are kept | | `"agent_id": "agent_..."` | One of your voice agents answers calls to the number from now on. It wins over `callback_url` for calls to the number, and calls your app places from it still follow the callback. `routes_to` reads `agent_pending` while the carrier is still moving the number, and calls follow the change within about an hour | | `"agent_id": null` | Unbinds the agent, so `callback_url` answers calls to the number again. Calls follow the change within about an hour | | key omitted | Left exactly as it is | `status` is matched ignoring case, and any combination is accepted. `agent_id` is applied first, so a refusal to move the number to or from the agent leaves everything as it was. A body that names none of them is refused with `400`. A number can be on without a callback URL, for example one added from the dashboard without one. It is `ACTIVE` and can be your default line like any other. Calls placed from your app on it connect straight to the phone number, app user, or room they dial. Calls to the number are declined with `callback_not_configured`, because there is nobody to ask who should answer. Send a `callback_url` to start answering them, or bind a voice agent with `agent_id`. What it refuses: | Request | Answer | | --- | --- | | `default_for_app_calls: false` | `400`. An account with active voice numbers always has exactly one default, so the default moves by giving it to another number | | `status: "INACTIVE"` on the default line while other voice numbers are active | `409` (`CONFLICT_007`). Move the default first. Turning off your last voice number is allowed; that turns phone calls off | | `default_for_app_calls: true` on an inactive number | `400`. Send `status: "ACTIVE"` in the same call | | A number you never turned voice on for | `404`. Add it with `POST /v3/channels/voice` | | An `agent_id` that is not one of your voice agents | `404` (`RESOURCE_013`) | | The number could not be moved to or from the agent | `502` (`BUSINESS_027`). Nothing was written, repeat the request | With `sandbox: true` nothing is written: the request is validated against the stored number and the number is reported with `200` as it would read after the change. ### Rotate the secret [#rotate-the-secret] [`POST /v3/channels/voice/{number}/rotate-secret`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsRotateVoiceSecretEndpoint) generates a new signing secret for the questions sent to this number's callback URL and returns it. The previous secret stops signing the moment the response is returned, so update your backend before the next call reaches it. ```bash curl -X POST "https://api.sent.dm/v3/channels/voice/%2B12125550100/rotate-secret" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' ``` ```json { "success": true, "data": { "callback_secret": "whsec_MWYyZDFlMmU2N2RmNmI3YThmNTZhODFiYzJlNGQzYjI=" }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-07-22T12:00:00+00:00", "version": "v3" } } ``` With `sandbox: true` a secret is generated and returned with `202`, and nothing is written. A number that never had voice turned on answers `400` (`BUSINESS_024`). ### Test the callback URL [#test-the-callback-url] [`POST /v3/channels/voice/{number}/test`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsTestVoiceCallbackEndpoint) sends a synthetic `call.request` question, flagged `"test": true` and signed with the number's real secret, to its callback URL and reports what came back. No call is placed, nothing is billed, and nothing is stored. It makes one attempt with the same deadline as a live call, and no retry. ```bash curl -X POST "https://api.sent.dm/v3/channels/voice/%2B12125550100/test" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' ``` `outcome` is `ok` when your endpoint answered `2xx` with a valid answer, otherwise `timeout`, `connection_failed`, `http_error` or `invalid_answer`. The response carries the exact request your endpoint received, headers and body, what it answered, your answer as Sent read it, and for a bad answer the `reason`, the `path` of the field at fault and what to fix. Run it before the first call, and again after every change to your callback. The full walk-through, with a response, is in [Test Before the First Call](/start/guides/answering-calls#test-before-the-first-call). With `sandbox: true` nothing is sent: the verdict comes back `ok` with `202`. An account with no active voice number answers `403` (`BUSINESS_023`). ## Troubleshooting [#troubleshooting] | Symptom | Likely cause | Fix | | --- | --- | --- | | `400` "compliance.brand is required…" on adding a `TEN_DLC` market | No identity stored and none sent | Send `compliance.brand` as `{"inherit": true}` or with the identity's fields | | `400` listing `compliance.campaign.*` fields on adding a `TEN_DLC` market | Dedicated campaign is incomplete: one or more required fields are missing from what you sent and what you already hold | Supply the missing fields in this request, or switch to `"campaign": {"inherit": true}` to run on your organization's campaign | | `400` on `PATCH` with an empty body | `{}` is refused rather than treated as a no-op | Send the field you meant to change, or `null` to clear it | | `400` on `PATCH` sending `compliance` | The market registers with no regime, so it has no `brand` or `campaign` | Send its documents as multipart files named after their key | | `400` on `PATCH` naming the expected keys | A file's part name matches no document the market asks for | Rename the part to one of the listed keys | | `400` "asks for no documents" on `PATCH` | Files sent to a market that requires none | Remove the files | | `422` on `PATCH` with files | The upload rules refused a file: empty, too large, or an unsupported type | Fix the file and send the request again | | `400` on `numbers` | The list leaves out a number already assigned, the campaign is inherited, the market has no campaign of its own yet, or `numbers` is `null` | Include every assigned number, send `compliance.campaign` in the same request, or give the profile its own campaign first | | `409` on `PATCH` "This account holds more than one campaign…" | The account has several campaigns, and this call writes one | Contact [support@sent.dm](mailto:support@sent.dm) to change a multi-campaign registration | | `400` "compliance.campaign can only be inherited together with the brand…" | The request sends `campaign` as `{"inherit": true}` with a brand of the profile's own | Send `compliance.brand` as `{"inherit": true}`, or supply a campaign of the profile's own | | `400` "Your organization has no campaign to inherit…" | `campaign` is `{"inherit": true}` but the organization has no campaign | Create your organization's campaign first, or supply the profile's own | | `409` on `PATCH` sending `compliance.brand` | The identity is filed and no correction was asked for | Omit `brand`; to change a filed identity, contact [support@sent.dm](mailto:support@sent.dm) | | `400` on `campaign.message_flow` | Under 40 characters | Describe where opt-in happens, the unchecked box, and that consent is not a condition of purchase | | `400` on `campaign.use_cases` | `MIXED` or `LOW_VOLUME` used as a use case | Remove them and set `campaign.volume`, which decides how the campaign registers | | `404` on a market you believe exists | The country and type pair does not name a market this sender has | List with `GET /v3/channels/sms` first | | `409` on add or patch | A replay of a request already in flight, or a conflicting concurrent write | Reuse the same `Idempotency-Key` and read the market back | | `501` from the requirements endpoint | `channel=whatsapp` or `channel=rcs` | Only `sms` is answered today | | `400` `BUSINESS_022` on `POST /v3/channels/voice` | The number is not one you hold | List your numbers with `GET /v3/channels`, or leave `number` out to be given one | | `409` `CONFLICT_007` on `PATCH /v3/channels/voice/{number}` | Turning off the default line while other voice numbers are active | Give `default_for_app_calls: true` to another number first | | Test outcome `http_error` with status `401` | Your endpoint verified the question with the wrong secret | Use the `callback_secret` of the number that received the question; rotate it if it was lost | | Market stuck at `PROVISIONING` | Sent is arranging the sender | Nothing is owed by you; `ACTION_NEEDED` is the status that asks for something. A `TEN_DLC` market reads `PENDING_REVIEW` once its brand is stored, so `PROVISIONING` there means a number has been assigned but is not active yet | ## Related pages [#related-pages] - [Channels](/start/concepts/channels) - why one send call routes three channels - [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api) - provisioning a profile and its first market - [Connect a WhatsApp Business Account](/start/guides/connect-whatsapp) - the Meta authorization flow - [10DLC Registration](/start/advanced/10dlc-registration) - what The Campaign Registry asks for and why - [Compliance and regulations](/start/advanced/compliance-regulations) - what Sent enforces and what stays yours - [Answering Calls](/start/guides/answering-calls) - what your callback URL is asked and how to answer - [Calls From Your App](/start/guides/in-app-calls) - voice tokens and the browser SDK # Managing Contacts (/start/guides/managing-contacts.md) # Managing Contacts [#managing-contacts] This guide shows you how to handle the contact tasks that come up in a real integration: importing your user base, honoring opt-outs, and controlling which channel reaches each contact. It assumes you have an [API key](/start/guides/api-keys) and can already [send messages](/start/guides/sending-messages). A contact is a validated phone number record that Sent creates and maintains for every number you message. It stores the normalized number, the channels that can reach it (`available_channels`), the channel Sent prefers (`default_channel`), and the opt-out flag (`opt_out`). Sending to a phone number creates or updates its contact automatically and routes the message over the best channel, so you manage contacts directly only for the tasks below. For the routing architecture behind this, see [Contacts concepts](/start/concepts/contacts). ## Import your user base [#import-your-user-base] Store each user's phone number in your own database. The phone number (not the Sent contact ID) is what you pass to the messages API; Sent keys the contact record to the number and keeps it updated: ```typescript // Store the E.164 phone number on your user record const user = await db.users.create({ email: 'jane@example.com', phoneNumber: '+1234567890' }); // Send directly to the phone number — Sent creates or // updates the contact automatically await client.messages.send({ to: [user.phoneNumber], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } }); ``` If your users first hear from you in a campaign, this automatic creation is all you need: the first message to a new number creates its contact. For importing thousands of contacts at once, see the [Batch Operations](/start/guides/batch-operations) guide. ### Pre-create contacts [#pre-create-contacts] To run validation and channel detection before your first campaign, create each contact explicitly: ```bash curl -X POST "https://api.sent.dm/v3/contacts" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "phone_number": "+1234567890" }' ``` ```typescript const contact = await client.contacts.create({ phoneNumber: '+1234567890' }); console.log(`Contact created: ${contact.data.id}`); ``` ```python contact = client.contacts.create( phone_number="+1234567890" ) print(f"Contact created: {contact.data.id}") ``` ```go contact, err := client.Contacts.Create(context.Background(), sentdm.ContactCreateParams{ PhoneNumber: sentdm.String("+1234567890"), }) fmt.Println("Contact created:", contact.Data.ID) ``` ```java ContactCreateParams params = ContactCreateParams.builder() .phoneNumber("+1234567890") .build(); var contact = client.contacts().create(params); System.out.println("Contact created: " + contact.data().id()); ``` ```csharp ContactCreateParams parameters = new() { PhoneNumber = "+1234567890" }; var contact = await client.Contacts.Create(parameters); Console.WriteLine($"Contact created: {contact.Data.Id}"); ``` ```php $contact = $client->contacts->create( phoneNumber: '+1234567890' ); echo "Contact created: " . $contact->data->id . "\n"; ``` ```ruby contact = sent_dm.contacts.create( phone_number: "+1234567890" ) puts "Contact created: #{contact.data.id}" ``` If the number already has a contact, the API returns `409` with error code `RESOURCE_007`. Treat it as already imported and continue. ### Handle invalid numbers [#handle-invalid-numbers] Numbers Sent cannot parse are rejected with `400` and error code `VALIDATION_002`. Surface the error to the user instead of retrying: ```typescript try { const contact = await client.contacts.create({ phoneNumber: 'invalid-number' }); } catch (error) { if (error.code === 'VALIDATION_002') { // Prompt user to correct their number showValidationError('Please enter a valid phone number'); } } ``` Always include the country code. Sent normalizes any parseable format to E.164: | Input Format | Normalized (E.164) | Display Format | |--------------|-------------------|----------------| | +1 234-567-8900 | +12345678900 | +1 234-567-8900 | | (234) 567-8900 | +12345678900 | +1 234-567-8900 | | 234-567-8900 | +12345678900 | +1 234-567-8900 | Numbers without country codes are rejected or may be misrouted. ### Verify the import [#verify-the-import] Filter the contact list by phone number (URL-encode `+` as `%2B`) and confirm the record exists with its detected channels: ```bash curl "https://api.sent.dm/v3/contacts?page=1&page_size=100&phone=%2B1234567890" \ -H "x-api-key: $SENT_API_KEY" ``` ## Honor opt-outs [#honor-opt-outs] The contact's `opt_out` flag is the consent record Sent checks on every send. It is per contact, not per channel: setting it suppresses SMS, WhatsApp, and RCS alike. Sent sets the flag automatically when a contact texts an opt-out keyword such as `STOP`. Set it yourself when a user revokes consent on any other surface (a preference center, a support ticket, an email unsubscribe): ```bash curl -X PATCH "https://api.sent.dm/v3/contacts/6ba7b810-9dad-11d1-80b4-00c04fd430c8" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{"opt_out": true}' ``` Send `{"opt_out": false}` to restore consent, and only when you hold the contact's documented consent. The API does not check how the opt-out was created. You do not need a pre-send check of your own: a send to an opted-out contact is still accepted with `202`, then finalized as `FILTERED`, and a `message.filtered` webhook fires. For the full workflow (mirroring keyword opt-outs into your database and detecting consent-blocked sends), see [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent). ## Control channel routing [#control-channel-routing] By default, Sent picks each recipient's channel automatically. Two contact fields drive the decision: - `available_channels`: the channels that can reach the number, detected by Sent (for example `"sms,whatsapp"`). - `default_channel`: the channel Sent prefers for this contact. Sent adjusts it based on delivery results, and you can set it yourself. If a contact should receive messages on a specific channel by default, update `default_channel` (accepts `sms`, `whatsapp`, or `rcs`): ```bash curl -X PATCH "https://api.sent.dm/v3/contacts/6ba7b810-9dad-11d1-80b4-00c04fd430c8" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "default_channel": "whatsapp" }' ``` ```typescript const updated = await client.contacts.update('6ba7b810-9dad-11d1-80b4-00c04fd430c8', { defaultChannel: 'whatsapp' }); ``` ```python updated = client.contacts.update( "6ba7b810-9dad-11d1-80b4-00c04fd430c8", default_channel="whatsapp" ) ``` ```go updated, err := client.Contacts.Update(context.Background(), "6ba7b810-9dad-11d1-80b4-00c04fd430c8", sentdm.ContactUpdateParams{ DefaultChannel: sentdm.String("whatsapp"), }) ``` ```java ContactUpdateParams params = ContactUpdateParams.builder() .defaultChannel("whatsapp") .build(); var updated = client.contacts().update("6ba7b810-9dad-11d1-80b4-00c04fd430c8", params); ``` ```csharp ContactUpdateParams parameters = new() { DefaultChannel = "whatsapp" }; var updated = await client.Contacts.Update("6ba7b810-9dad-11d1-80b4-00c04fd430c8", parameters); ``` ```php $updated = $client->contacts->update( "6ba7b810-9dad-11d1-80b4-00c04fd430c8", defaultChannel: 'whatsapp' ); ``` ```ruby updated = sent_dm.contacts.update( "6ba7b810-9dad-11d1-80b4-00c04fd430c8", default_channel: "whatsapp" ) ``` Before switching a contact's default, confirm the target channel can reach them: ```typescript const contact = await client.contacts.get(contactId); // Check available channels before switching the default if (!contact.data.availableChannels.includes('whatsapp')) { console.log('WhatsApp not available for this contact — keep SMS'); } ``` The update response echoes the contact, so `default_channel` in the response confirms the change took effect. To pin a single send to a channel regardless of the contact's default, or to broadcast on several channels at once, set the `channel` field on the message itself. Refer to [Channel Selection Strategies](/start/guides/sending-messages#channel-selection-strategies) for how pinning disables cross-channel fallback. ## Find and inspect contacts [#find-and-inspect-contacts] Look up contacts when you reconcile your database with Sent or debug routing. `GET /v3/contacts` requires `page` and `page_size`, and supports `search`, `phone`, and `channel` filters. `search` matches a phone number by its digits, so E.164, digits only, dashes, or spaces and brackets all find the same contact, and part of a number matches too: ```bash # List with pagination curl "https://api.sent.dm/v3/contacts?page=1&page_size=100" \ -H "x-api-key: $SENT_API_KEY" # Search contacts (URL-encode + as %2B) curl "https://api.sent.dm/v3/contacts?page=1&page_size=100&search=%2B1234" \ -H "x-api-key: $SENT_API_KEY" ``` ```typescript // List all contacts const contacts = await client.contacts.list({ page: 1, page_size: 100 }); // Search contacts const searchResults = await client.contacts.list({ search: '+1234' }); // Iterate through all pages for (const contact of contacts.data) { console.log(`${contact.phoneNumber} - ${contact.availableChannels}`); } ``` ```python # List all contacts contacts = client.contacts.list(page=1, page_size=100) # Search contacts search_results = client.contacts.list(search="+1234") # Iterate through results for contact in contacts.data: print(f"{contact.phone_number} - {contact.available_channels}") ``` ```go // List all contacts contacts, err := client.Contacts.List(context.Background(), sentdm.ContactListParams{ Page: sentdm.Int(1), PageSize: sentdm.Int(100), }) // Search contacts searchResults, err := client.Contacts.List(context.Background(), sentdm.ContactListParams{ Search: sentdm.String("+1234"), }) // Iterate through results for _, contact := range contacts.Data { fmt.Printf("%s - %s\n", contact.PhoneNumber, contact.AvailableChannels) } ``` ```java // List all contacts ContactListParams params = ContactListParams.builder() .page(1) .pageSize(100) .build(); var contacts = client.contacts().list(params); // Search contacts var searchResults = client.contacts().list(ContactListParams.builder() .search("+1234") .build()); // Iterate through results for (var contact : contacts.data()) { System.out.println(contact.phoneNumber() + " - " + contact.availableChannels()); } ``` ```csharp // List all contacts ContactListParams parameters = new() { Page = 1, PageSize = 100 }; var contacts = await client.Contacts.List(parameters); // Search contacts var searchResults = await client.Contacts.List(new ContactListParams { Search = "+1234" }); // Iterate through results foreach (var contact in contacts.Data) { Console.WriteLine($"{contact.PhoneNumber} - {contact.AvailableChannels}"); } ``` ```php // List all contacts $contacts = $client->contacts->list(page: 1, pageSize: 100); // Search contacts $searchResults = $client->contacts->list(search: '+1234'); // Iterate through results foreach ($contacts->data as $contact) { echo "{$contact->phone_number} - {$contact->available_channels}\n"; } ``` ```ruby # List all contacts contacts = sent_dm.contacts.list(page: 1, page_size: 100) # Search contacts search_results = sent_dm.contacts.list(search: "+1234") # Iterate through results contacts.data.each do |contact| puts "#{contact.phone_number} - #{contact.available_channels}" end ``` Each contact carries the fields the tasks in this guide depend on: ```json { "success": true, "data": { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "phone_number": "+1234567890", "format_e164": "+1234567890", "format_international": "+1 234-567-890", "format_national": "(234) 567-890", "format_rfc": "tel:+1-234-567-890", "country_code": "1", "region_code": "US", "available_channels": "sms,whatsapp", "default_channel": "whatsapp", "opt_out": false, "is_inherited": false, "created_at": "2025-01-01T12:00:00Z", "updated_at": "2025-01-15T08:30:00Z" }, "error": null, "meta": { "request_id": "req_contact_001", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` To fetch one contact by ID, call `GET /v3/contacts/{id}`. Refer to the [get contact reference](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsGetContactByIdEndpoint) for the response contract. `is_inherited` is **always `false`**. Contacts are never inherited or shared between Sender Profiles: a profile sees only its own contacts, and the organization sees those of every profile beneath it. The field stays on the wire so existing clients keep deserializing; do not branch on it. ## Stop messaging a contact [#stop-messaging-a-contact] To stop every send to someone, opt them out. It is the same outcome deleting a contact was mostly used for, and it keeps the record of who they were and that they asked: ```bash curl -X PATCH "https://api.sent.dm/v3/contacts/6ba7b810-9dad-11d1-80b4-00c04fd430c8" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{"opt_out": true}' ``` Opt-out is per contact, not per channel: one flag stops SMS, WhatsApp, and RCS together. Sends to an opted-out contact are still accepted with `202` and then finalized as `FILTERED` with reason code `ERR_CONSENT_BLOCKED`, so treat a `message.filtered` webhook as the expected outcome rather than an error. See [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent) for the full consent workflow. `DELETE /v3/contacts/{id}` is **deprecated** and will be removed in a future release. It still behaves exactly as before, so nothing breaks today, but new integrations should opt contacts out instead. A delete discards the consent history along with the contact — which is the part you need if anyone later asks why you stopped messaging someone, or why you started again. If your workflow genuinely requires the record to be removed — a data-subject erasure request, for instance — the delete is still the only API call that does that. Contact [support](mailto:support@sent.dm) before building on it, so your erasure path does not disappear with the endpoint. ## Contacts API reference [#contacts-api-reference] This guide covers only what these tasks need. For the full contract of every endpoint (parameters, response fields, and error codes), refer to the Contacts API reference: - [Create a contact](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsCreateContactEndpoint) - [List contacts](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsGetContactsEndpoint) - [Get a contact by ID](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsGetContactByIdEndpoint) - [Update a contact](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsUpdateContactEndpoint) - also where `opt_out` is set - [Delete a contact](/reference/api/contacts/SentDmServicesEndpointsCustomerAPIv3ContactsDeleteContactEndpoint) - deprecated ## Next steps [#next-steps] - [Sending Messages](/start/guides/sending-messages): template sends, free-form text, and channel selection - [Batch Operations](/start/guides/batch-operations): import contacts in bulk - [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent): mirror opt-outs into your database and detect consent-blocked sends - [Contacts concepts](/start/concepts/contacts): the architecture behind channel detection and routing # Message Best Practices (/start/guides/message-best-practices.md) # Message Best Practices [#message-best-practices] This guide shows you how to harden your send path for production: store per-recipient message IDs, make critical sends idempotent, apply RCS-specific send rules, and estimate spend before a bulk send. It assumes you already [send messages](/start/guides/sending-messages) through an SDK or the REST API. Adjacent production concerns each have a dedicated guide: [Error Handling](/start/guides/error-handling), [Message Status Tracking](/start/guides/message-status-tracking), and [Testing & Debugging](/start/guides/testing-debugging). The sections below link to them where they fit into the send path. ## Store Message IDs [#store-message-ids] Every send returns one recipient entry per (recipient, channel) pair. Store each `message_id`, because webhook status events and `GET /v3/messages/{id}` lookups key on it: ```typescript // Store in your database - one entry per (recipient, channel) pair const recipients = response.data.recipients; for (const r of recipients) { await db.messages.create({ sentMessageId: r.message_id, recipient: r.to, channel: r.channel, templateId: response.data.template_id, templateName: response.data.template_name, status: response.data.status }); } ``` ```python # Store in your database - one entry per (recipient, channel) pair for r in response.data.recipients: db.messages.create({ "sent_message_id": r.message_id, "recipient": r.to, "channel": r.channel, "template_id": response.data.template_id, "template_name": response.data.template_name, "status": response.data.status }) ``` ```go // Store in your database - one entry per (recipient, channel) pair for _, r := range response.Data.Recipients { db.Messages.Create(MessageRecord{ SentMessageID: r.MessageID, Recipient: r.To, Channel: r.Channel, TemplateID: response.Data.TemplateID, TemplateName: response.Data.TemplateName, Status: response.Data.Status, }) } ``` ```java // Store in your database - one entry per (recipient, channel) pair for (var r : response.data().recipients()) { db.messages().create(MessageRecord.builder() .sentMessageId(r.messageId()) .recipient(r.to()) .channel(r.channel()) .templateId(response.data().templateId()) .templateName(response.data().templateName()) .status(response.data().status()) .build()); } ``` ```csharp // Store in your database - one entry per (recipient, channel) pair foreach (var r in response.Data.Recipients) { await db.Messages.CreateAsync(new MessageRecord { SentMessageId = r.MessageId, Recipient = r.To, Channel = r.Channel, TemplateId = response.Data.TemplateId, TemplateName = response.Data.TemplateName, Status = response.Data.Status }); } ``` ```php // Store in your database - one entry per (recipient, channel) pair foreach ($result->data->recipients as $r) { $db->messages->create([ 'sent_message_id' => $r->message_id, 'recipient' => $r->to, 'channel' => $r->channel, 'template_id' => $result->data->template_id, 'template_name' => $result->data->template_name, 'status' => $result->data->status ]); } ``` ```ruby # Store in your database - one entry per (recipient, channel) pair result.data.recipients.each do |r| db.messages.create( sent_message_id: r.message_id, recipient: r.to, channel: r.channel, template_id: result.data.template_id, template_name: result.data.template_name, status: result.data.status ) end ``` ## Make Critical Sends Idempotent [#make-critical-sends-idempotent] For critical messages (OTP, payments), use idempotency keys via the `Idempotency-Key` header so a retry after a network failure can't double-send: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: otp_user_123_20250115" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }' ``` ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } }, { idempotencyKey: 'otp_user_123_20250115' }); ``` ```python response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, idempotency_key="otp_user_123_20250115" ) ``` ```go response, err := client.Messages.Send( context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), }, }, option.WithIdempotencyKey("otp_user_123_20250115"), ) ``` ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .build()) .build(); var response = client.messages().send(params, RequestOptions.builder() .idempotencyKey("otp_user_123_20250115") .build()); ``` ```csharp MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }; var response = await client.Messages.Send( parameters, new RequestOptions { IdempotencyKey = "otp_user_123_20250115" } ); ``` ```php $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8' ], idempotencyKey: 'otp_user_123_20250115' ); ``` ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, idempotency_key: "otp_user_123_20250115" ) ``` Keys are cached for 24 hours. Reusing a key returns the original response without sending a duplicate message. ## Handle Failures [#handle-failures] Classify errors before reacting: back off on `429` rate limits, fix rather than retry `4xx` validation failures, and retry `5xx` with exponential backoff. The [Error Handling guide](/start/guides/error-handling) owns these patterns, including retry loops, circuit breakers, and channel fallbacks. ## Track Status with Webhooks [#track-status-with-webhooks] Don't poll for status. Configure [webhooks](/start/webhooks/getting-started) and update the message records you stored in [Store Message IDs](#store-message-ids) as status events arrive. Refer to [Message Status Tracking](/start/guides/message-status-tracking) for handler examples, payload shapes, and the full status lifecycle. ## RCS Best Practices [#rcs-best-practices] When sending on RCS, a few channel-specific considerations improve delivery and engagement: - **Use suggestion chips for interaction**: Template buttons render as tappable suggestion chips below the message: quick reply, open URL, and dial number actions. Sent maps up to four template buttons to chips and truncates chip labels to 25 characters, so keep button text short. - **Don't add manual opt-out text**: Every RCS message automatically includes a STOP suggestion chip. Adding your own opt-out footer is redundant and clutters the message. - **Handle inbound opt-out keywords**: Taps on the built-in STOP chip arrive as `message.received` webhook events, and Sent's consent engine flips the contact's `opt_out` flag automatically. Refer to [RCS Suggestion Chips](/start/guides/two-way-conversations#rcs-suggestion-chips) for how chip taps and keywords are processed, and mirror the suppression in your own datastore. - **Always include SMS fallback**: Use `"channel": ["rcs", "sms"]` rather than `["rcs"]` alone. This ensures delivery to recipients on devices or carriers without RCS support. Rich cards and carousel cards are part of the RCS standard but are not yet available through Sent. RCS messages currently render as text plus suggestion chips. ## Estimate Costs Before a Bulk Send [#estimate-costs-before-a-bulk-send] Rates vary by channel, by destination country, and on SMS, by segment count: each segment of a multi-segment body bills as a separate message (refer to [SMS Length & Cost](/start/guides/sms-length-and-cost)). The API doesn't expose a rate card, so build an estimate from two numbers it does give you. **Count messages with a sandbox request.** Add `sandbox: true` to the bulk request. The response echoes one recipient entry per (recipient, channel) pair without sending anything, so the length of `recipients` is your exact message count. List channels explicitly; if you omit `channel` (auto-detect), entries return `channel: null` and you can't attribute the count to a channel's rate. [Testing & Debugging](/start/guides/testing-debugging#sandbox-mode) documents sandbox mode itself. **Read real prices from a pilot send.** After a real send, `GET /v3/messages/{id}` returns `price` (channel cost) and `active_contact_price` (markup applied on top) for that message. Send the template to a small pilot group in the target country, average the sum of both fields, and multiply by the message count: ```typescript // 1. Count messages without sending - sandbox echoes the real fan-out const test = await client.messages.send({ to: recipients, // the full bulk list channel: ['sms'], // explicit channel keeps the count attributable template: { id: templateId }, sandbox: true }); const messageCount = test.data.recipients.length; // 2. Average actual per-message price from an earlier pilot send const pilot = await Promise.all( pilotMessageIds.map((id) => client.messages.retrieveStatus(id)) ); const perMessage = pilot.reduce( (sum, m) => sum + (m.data.price ?? 0) + (m.data.active_contact_price ?? 0), 0 ) / pilot.length; console.log( `~${messageCount} messages x $${perMessage.toFixed(4)} each = ~$${(messageCount * perMessage).toFixed(2)}` ); ``` Sandbox `message_id` values are simulated and reference no stored message, so price lookups only work for messages from real sends. ## Related Guides [#related-guides] # Message Response Handling (/start/guides/message-responses.md) # Message Response Handling [#message-response-handling] This page is a lookup for the responses `POST /v3/messages` returns: the `success`/`data`/`error` envelope, per-recipient message IDs, and the error payloads for validation, authentication, and rate-limit failures. For production retry patterns, refer to [Error Handling](/start/guides/error-handling). For inbound messages and RCS suggestion-chip taps, refer to [Two-Way Conversations](/start/guides/two-way-conversations). ## Response Structure [#response-structure] All API responses follow a consistent structure: ```json { "success": boolean, "data": object | null, "error": object | null, "meta": { "request_id": string, "timestamp": string, "version": "v3" } } ``` | Field | Type | Description | |-------|------|-------------| | `success` | boolean | `true` for 2xx responses, `false` for errors | | `data` | object \| null | Response payload (null on error) | | `error` | object \| null | Error details (null on success) | | `meta` | object | Request metadata including `request_id` for support | ## Success Response (202 Accepted) [#success-response-202-accepted] When a message is successfully accepted: ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+14155551234", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: 'tmpl_123' } }); // Access response data console.log(response.data.status); // "QUEUED" console.log(response.data.template_id); // Template UUID console.log(response.data.template_name); // Access recipient info const recipient = response.data.recipients[0]; console.log(recipient.message_id); // Message UUID for tracking console.log(recipient.to); // Phone number console.log(recipient.channel); // "sms", "whatsapp", or "rcs" // Access metadata console.log(response.meta.request_id); // For support inquiries console.log(response.meta.timestamp); // Response timestamp ``` ```python response = client.messages.send( to=["+1234567890"], template={"id": "tmpl_123"} ) # Access response data print(response.data.status) # "QUEUED" print(response.data.template_id) # Template UUID print(response.data.template_name) # Access recipient info recipient = response.data.recipients[0] print(recipient.message_id) # Message UUID for tracking print(recipient.to) # Phone number print(recipient.channel) # "sms", "whatsapp", or "rcs" # Access metadata print(response.meta.request_id) # For support inquiries print(response.meta.timestamp) # Response timestamp ``` ```go response, err := client.Messages.Send(context.Background(), params) if err != nil { log.Fatal(err) } // Access response data fmt.Println(response.Data.Status) // "QUEUED" fmt.Println(response.Data.TemplateID) // Template UUID fmt.Println(response.Data.TemplateName) // Access recipient info recipient := response.Data.Recipients[0] fmt.Println(recipient.MessageID) // Message UUID for tracking fmt.Println(recipient.To) // Phone number fmt.Println(recipient.Channel) // "sms", "whatsapp", or "rcs" // Access metadata fmt.Println(response.Meta.RequestID) // For support inquiries fmt.Println(response.Meta.Timestamp) // Response timestamp ``` ```java var response = client.messages().send(params); // Access response data System.out.println(response.data().status()); // "QUEUED" System.out.println(response.data().templateId()); // Template UUID System.out.println(response.data().templateName()); // Access recipient info var recipient = response.data().recipients().get(0); System.out.println(recipient.messageId()); // Message UUID for tracking System.out.println(recipient.to()); // Phone number System.out.println(recipient.channel()); // "sms", "whatsapp", or "rcs" // Access metadata System.out.println(response.meta().requestId()); // For support inquiries System.out.println(response.meta().timestamp()); // Response timestamp ``` ```csharp var response = await client.Messages.Send(parameters); // Access response data Console.WriteLine(response.Data.Status); // "QUEUED" Console.WriteLine(response.Data.TemplateId); // Template UUID Console.WriteLine(response.Data.TemplateName); // Access recipient info var recipient = response.Data.Recipients[0]; Console.WriteLine(recipient.MessageId); // Message UUID for tracking Console.WriteLine(recipient.To); // Phone number Console.WriteLine(recipient.Channel); // "sms", "whatsapp", or "rcs" // Access metadata Console.WriteLine(response.Meta.RequestId); // For support inquiries Console.WriteLine(response.Meta.Timestamp); // Response timestamp ``` ```php $result = $client->messages->send( to: ['+1234567890'], template: ['id' => 'tmpl_123'] ); // Access response data echo $result->data->status; // "QUEUED" echo $result->data->template_id; // Template UUID echo $result->data->template_name; // Access recipient info $recipient = $result->data->recipients[0]; echo $recipient->message_id; // Message UUID for tracking echo $recipient->to; // Phone number echo $recipient->channel; // "sms", "whatsapp", or "rcs" // Access metadata echo $result->meta->request_id; // For support inquiries echo $result->meta->timestamp; // Response timestamp ``` ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "tmpl_123" } ) # Access response data puts result.data.status # "QUEUED" puts result.data.template_id # Template UUID puts result.data.template_name # Access recipient info recipient = result.data.recipients[0] puts recipient.message_id # Message UUID for tracking puts recipient.to # Phone number puts recipient.channel # "sms", "whatsapp", or "rcs" # Access metadata puts result.meta.request_id # For support inquiries puts result.meta.timestamp # Response timestamp ``` ### Multi-Channel Response [#multi-channel-response] When sending to multiple channels, you get one recipient entry per (recipient, channel) pair: ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "msg-uuid-1", "to": "+14155551234", "channel": "whatsapp" }, { "message_id": "msg-uuid-2", "to": "+14155551234", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` ## Error Responses [#error-responses] ### 400 Bad Request (Validation Error) [#400-bad-request-validation-error] ```json { "success": false, "status": 400, "error": { "code": "VALIDATION_004", "message": "Request validation failed", "details": { "to": ["'to' must contain at least one recipient"], "template": ["'template' is required"] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` ```typescript import { ValidationError } from '@sentdm/sentdm'; try { const response = await client.messages.send({ to: [], // Empty array - will fail validation template: { id: 'tmpl_123' } }); } catch (error) { if (error instanceof ValidationError) { console.log(error.code); // "VALIDATION_004" console.log(error.message); // "Request validation failed" console.log(error.details); // { to: [...], template: [...] } console.log(error.docUrl); // Documentation URL } } ``` ```python from sent_dm.errors import ValidationError try: response = client.messages.send( to=[], # Empty list - will fail validation template={"id": "tmpl_123"} ) except ValidationError as e: print(e.code) # "VALIDATION_004" print(e.message) # "Request validation failed" print(e.details) # {"to": [...], "template": [...]} print(e.doc_url) # Documentation URL ``` ```go response, err := client.Messages.Send(context.Background(), params) if err != nil { if validationErr, ok := err.(*sentdm.ValidationError); ok { fmt.Println(validationErr.Code) // "VALIDATION_004" fmt.Println(validationErr.Message) // "Request validation failed" fmt.Println(validationErr.Details) // Field-specific errors fmt.Println(validationErr.DocURL) // Documentation URL } } ``` ```java try { var response = client.messages().send(params); } catch (ValidationException e) { System.out.println(e.getCode()); // "VALIDATION_004" System.out.println(e.getMessage()); // "Request validation failed" System.out.println(e.getDetails()); // Field-specific errors System.out.println(e.getDocUrl()); // Documentation URL } ``` ```csharp try { var response = await client.Messages.Send(parameters); } catch (ValidationException ex) { Console.WriteLine(ex.Code); // "VALIDATION_004" Console.WriteLine(ex.Message); // "Request validation failed" Console.WriteLine(ex.Details); // Field-specific errors Console.WriteLine(ex.DocUrl); // Documentation URL } ``` ```php use SentDM\Exceptions\ValidationException; try { $result = $client->messages->send(to: [], template: ['id' => 'tmpl_123']); } catch (ValidationException $e) { echo $e->getCode(); // "VALIDATION_004" echo $e->getMessage(); // "Request validation failed" print_r($e->getDetails()); // Field-specific errors echo $e->getDocUrl(); // Documentation URL } ``` ```ruby begin result = sent_dm.messages.send_(to: [], template: { id: "tmpl_123" }) rescue Sentdm::ValidationError => e puts e.code # "VALIDATION_004" puts e.message # "Request validation failed" puts e.details # Field-specific errors puts e.doc_url # Documentation URL end ``` ### 401 Unauthorized [#401-unauthorized] Invalid or missing API key: ```json { "success": false, "status": 401, "error": { "code": "AUTH_001", "message": "Invalid API key", "doc_url": "https://docs.sent.dm/reference/api/authentication" } } ``` ### 404 Not Found [#404-not-found] Template not found: ```json { "success": false, "status": 404, "error": { "code": "RESOURCE_002", "message": "Template not found", "doc_url": "https://docs.sent.dm/reference/api/error-catalog" } } ``` ### 429 Rate Limit [#429-rate-limit] Too many requests: ```json { "success": false, "status": 429, "error": { "code": "BUSINESS_002", "message": "Rate limit exceeded. Retry after 60 seconds", "details": { "retry_after": 60, "limit": 200, "window": "60s" }, "doc_url": "https://docs.sent.dm/reference/api/rate-limits" } } ``` ### Insufficient Balance (Asynchronous) [#insufficient-balance-asynchronous] `POST /v3/messages` does not return a synchronous payment error. Sends are accepted with `202` even when your balance is too low; each affected message is then finalized as `BLOCKED` and fires a [`message.blocked` webhook event](/start/webhooks/event-types). Refer to [Queue for Later](/start/guides/error-handling#queue-for-later) in the Error Handling guide for the recovery pattern, and to [`BUSINESS_003`](/reference/api/error-catalog#business_003-insufficient-account-balance) in the Error Catalog for the legacy v2 behavior. ## Error Code Reference [#error-code-reference] The preceding examples show the response shapes your handler parses. For the complete enumeration of error codes with causes and remediation steps, refer to the [Error Catalog](/reference/api/error-catalog). ## Handling Errors in Production [#handling-errors-in-production] The [Error Handling guide](/start/guides/error-handling) owns production error handling: classifying retryable failures, exponential backoff with jitter, circuit breakers, and channel fallbacks. For safe re-sends with idempotency keys, refer to [How to retry Sent API requests safely](/start/guides/retrying-requests-safely). ## Related Guides [#related-guides] --- # Message Status Tracking (/start/guides/message-status-tracking.md) # Message Status Tracking [#message-status-tracking] Track the delivery status of your messages in real-time using webhooks, the API, or the Sent Dashboard. ## Overview [#overview] After sending a message, it progresses through several statuses: API accepts request"] --> R["**ROUTED**
Carrier assigned"] R --> B["**SENT**
With provider"] B --> C["**DELIVERED**
To device"] C --> D["**READ**
WhatsApp & RCS"] A --> E["**FAILED**
Error recorded"] R --> E B --> E A --> FL["**FILTERED**
Policy suppression"] A --> BL["**BLOCKED**
Account gate"] A --> SC["**SCHEDULED**
Scheduled or quiet-hours hold"] SC --> R SC --> CA["**CANCELLED**
Called off before release"] X["**RECEIVED**
Inbound message"] style A fill:#e1f5fe style R fill:#e8eaf6 style B fill:#f3e5f5 style C fill:#e8f5e8 style D fill:#fff3e0 style E fill:#ffebee style FL fill:#fff8e1 style BL fill:#fce4ec style SC fill:#e8eaf6 style CA fill:#ffebee style X fill:#fce4ec `} darkTextAlways /> ## Tracking Methods [#tracking-methods] ### Method 1: Webhooks (Recommended) [#method-1-webhooks-recommended] Receive real-time status updates via HTTP callbacks to your server. **Advantages:** - Real-time updates (within seconds) - No polling required - Scalable for high volume **Setup:** 1. Create a webhook endpoint in your app 2. Configure the webhook URL in your [Sent Dashboard](https://app.sent.dm/dashboard/webhooks) 3. Handle incoming events ```typescript import express from 'express'; const app = express(); app.use(express.json()); app.post('/webhooks/sent', async (req, res) => { res.sendStatus(200); // Acknowledge quickly const { field, event, payload } = req.body; if (field === 'message') { if (event === 'message.received') { // Inbound message — see the Two-Way Conversations guide await handleInboundMessage(payload); return; } // Outbound message status update const { message_id, message_status, channel } = payload; // Update your database await db.messages.update(message_id, { status: message_status, channel: channel, updatedAt: new Date() }); // Trigger business logic if (message_status === 'DELIVERED') { await handleDeliveryConfirmation(message_id); } else if (message_status === 'FAILED') { await handleDeliveryFailure(message_id); } else if (message_status === 'FILTERED' || message_status === 'BLOCKED') { // Terminal, but not a delivery failure: no carrier attempt was made await handleSuppressed(message_id, message_status); } else if (message_status === 'SCHEDULED') { // Held until the recipient's quiet hours end, then released automatically await markHeld(message_id); } else if (message_status === 'CANCELLED') { // You called the held send off: terminal, and there is no future send to wait for await markCancelled(message_id); } } }); ``` ```python from flask import Flask, request app = Flask(__name__) @app.route('/webhooks/sent', methods=['POST']) def handle_webhook(): data = request.json field = data['field'] event = data.get('event') if field == 'message': p = data['payload'] if event == 'message.received': # Inbound message — see the Two-Way Conversations guide handle_inbound_message(p) return '', 200 # Outbound message status update message_id = p['message_id'] message_status = p['message_status'] channel = p['channel'] # Update database db.messages.update(message_id, status=message_status, channel=channel) # Business logic if message_status == 'DELIVERED': handle_delivery_confirmation(message_id) elif message_status == 'FAILED': handle_delivery_failure(message_id) elif message_status in ('FILTERED', 'BLOCKED'): # Terminal, but not a delivery failure handle_suppressed(message_id, message_status) elif message_status == 'SCHEDULED': # Held until quiet hours end, then released automatically mark_held(message_id) elif message_status == 'CANCELLED': # You called the held send off: terminal, nothing further arrives mark_cancelled(message_id) return '', 200 ``` ```go func webhookHandler(w http.ResponseWriter, r *http.Request) { var event WebhookEvent json.NewDecoder(r.Body).Decode(&event) w.WriteHeader(http.StatusOK) // Acknowledge quickly if event.Field == "message" { if event.Event == "message.received" { // Inbound message — see the Two-Way Conversations guide handleInboundMessage(event.Payload) return } // Outbound message status update messageID := event.Payload.MessageID messageStatus := event.Payload.MessageStatus channel := event.Payload.Channel // Update database db.Messages.Update(messageID, messageStatus, channel) // Business logic if messageStatus == "DELIVERED" { handleDeliveryConfirmation(messageID) } else if messageStatus == "FAILED" { handleDeliveryFailure(messageID) } else if messageStatus == "FILTERED" || messageStatus == "BLOCKED" { // Terminal, but not a delivery failure handleSuppressed(messageID, messageStatus) } else if messageStatus == "SCHEDULED" { // Held until quiet hours end, then released automatically markHeld(messageID) } else if messageStatus == "CANCELLED" { // You called the held send off: terminal, nothing further arrives markCancelled(messageID) } } } ``` **Webhook Event Structure:** ```json { "field": "message", "event": "message.delivered", "timestamp": "2025-01-15T08:30:15Z", "payload": { "updated_at": "2025-01-15T08:30:15Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "DELIVERED", "channel": "sms" } } ``` See the [Webhooks Guide](/start/webhooks/getting-started) for complete setup instructions. ### Method 2: API Polling [#method-2-api-polling] Query message status via the API. Useful for one-off checks or debugging. ```bash curl "https://api.sent.dm/v3/messages/8ba7b830-9dad-11d1-80b4-00c04fd430c8" \ -H "x-api-key: $SENT_API_KEY" ``` ```typescript const message = await client.messages.retrieveStatus('8ba7b830-9dad-11d1-80b4-00c04fd430c8'); console.log(`Status: ${message.data.status}`); console.log(`Events:`, message.data.events); ``` ```python message = client.messages.retrieve_status("8ba7b830-9dad-11d1-80b4-00c04fd430c8") print(f"Status: {message.data.status}") print(f"Events: {message.data.events}") ``` ```go message, err := client.Messages.RetrieveStatus(context.Background(), "8ba7b830-9dad-11d1-80b4-00c04fd430c8") fmt.Printf("Status: %s\n", message.Data.Status) fmt.Printf("Events: %v\n", message.Data.Events) ``` ```java var message = client.messages().retrieveStatus("8ba7b830-9dad-11d1-80b4-00c04fd430c8"); System.out.println("Status: " + message.data().status()); System.out.println("Events: " + message.data().events()); ``` ```csharp var message = await client.Messages.RetrieveStatus("8ba7b830-9dad-11d1-80b4-00c04fd430c8"); Console.WriteLine($"Status: {message.Data.Status}"); Console.WriteLine($"Events: {message.Data.Events}"); ``` ```php $message = $client->messages->retrieveStatus("8ba7b830-9dad-11d1-80b4-00c04fd430c8"); echo "Status: {$message->data->status}\n"; echo "Events: " . json_encode($message->data->events) . "\n"; ``` ```ruby message = sent_dm.messages.retrieve_status("8ba7b830-9dad-11d1-80b4-00c04fd430c8") puts "Status: #{message.data.status}" puts "Events: #{message.data.events}" ``` **Response:** ```json { "success": true, "data": { "id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "customer_id": "5ba7b800-9dad-11d1-80b4-00c04fd430c8", "contact_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "phone": "+1234567890", "phone_international": "+1 234-567-890", "region_code": "US", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "template_category": "UTILITY", "channel": "sms", "message_body": { "header": null, "content": "Your order #12345 has been shipped!", "footer": null, "buttons": null }, "status": "DELIVERED", "direction": "OUTBOUND", "created_at": "2025-01-15T08:30:00Z", "price": 0.0055, "active_contact_price": 0.001, "events": [ { "status": "QUEUED", "timestamp": "2025-01-15T08:30:00Z", "description": "Message queued for sending" }, { "status": "SENT", "timestamp": "2025-01-15T08:30:01Z", "description": "Message sent via SMS" }, { "status": "DELIVERED", "timestamp": "2025-01-15T08:30:15Z", "description": "Message delivered to recipient" } ] }, "error": null, "meta": { "request_id": "req_xyz789", "timestamp": "2025-01-15T08:30:16Z", "version": "v3" } } ``` **Don't poll for status updates in production.** Use webhooks instead. Polling is only recommended for debugging or one-off checks. ### Method 3: Dashboard [#method-3-dashboard] View message status in the [Sent Dashboard](https://app.sent.dm/dashboard/activities): 1. Go to the **Activities** page 2. Filter by one or more message statuses, date range, or template 3. Click on any message for detailed information 4. View delivery timeline and any errors ## Status Reference [#status-reference] A status is terminal when no further status events follow it. The one exception is `READ`, which can still arrive after a terminal `DELIVERED` on WhatsApp and RCS. | Status | Direction | Terminal | Description | Next States | |--------|-----------|:--------:|-------------|-------------| | `QUEUED` | Outbound | No | Message accepted, awaiting processing | `ROUTED`, `SCHEDULED`, `FILTERED`, `BLOCKED`, `FAILED` | | `ROUTED` | Outbound | No | Message assigned to a carrier or provider | `SENT`, `FAILED` | | `SENT` | Outbound | No | Dispatched to channel provider | `DELIVERED`, `FAILED` | | `DELIVERED` | Outbound | Yes | Confirmed delivery to device. On some SMS routes, the carrier accepted the message ([why](/start/webhooks/lifecycle)) | `READ` (WhatsApp and RCS) | | `READ` | Outbound | Yes | Recipient opened the message (WhatsApp and RCS). Follows `DELIVERED` | None | | `FAILED` | Outbound | Yes | A send was attempted and failed downstream: carrier reject, network error, invalid number, or no route matched. **The only status that counts against your deliverability rate.** | None | | `FILTERED` | Outbound | Yes | A policy gate suppressed the message before dispatch: the recipient opted out, the number is on your suppression list, or a routing rule denied the send. Expected behavior, not a failure, so it does not count against your deliverability rate. | None | | `BLOCKED` | Outbound | Yes | A precondition stopped the message before send evaluation: insufficient balance, an unmet onboarding quota, a template that is not approved for sending, a free-form send to a contact with no open conversation, or a listed sending number that is not active on the account. Does not count against your deliverability rate. | None | | `SCHEDULED` | Outbound | No | Message is held until a future release time. Triggered by a `scheduled_at` value on the send request, or when the send time falls inside the recipient's quiet hours. Sent releases the message automatically when the release instant arrives or the quiet-hours window closes. | `ROUTED`, `CANCELLED` | | `CANCELLED` | Outbound | Yes | You called a held message off with `POST /v3/messages/{id}/cancel` before it was released. Reachable only from `SCHEDULED`. Nothing was sent and nothing was charged, so it does not count against your deliverability rate. | None | | `RECEIVED` | Inbound | Yes | Inbound message received from a contact | None | Every status change fires a matching webhook event, including `message.filtered`, `message.blocked`, `message.scheduled`, and `message.cancelled`. See the [Events Reference](/start/webhooks/event-types) for the full status catalog and every webhook payload shape. ## Direction Field [#direction-field] Every message retrieved via `retrieveStatus` includes a `direction` field: | Value | Meaning | |-------|---------| | `OUTBOUND` | Message sent by you to a contact | | `INBOUND` | Message received from an end user (such as a reply, or STOP/START/HELP opt-out keywords) | ```typescript const status = await client.messages.retrieveStatus('8ba7b830-9dad-11d1-80b4-00c04fd430c8'); console.log(status.data.direction); // "OUTBOUND" | "INBOUND" ``` Inbound messages include opt-out/opt-in keyword responses (STOP/START/HELP on SMS), general SMS replies, and WhatsApp replies. They have a `direction` of `"INBOUND"` and a `status` of `"RECEIVED"`. Subscribe to `message.received` webhooks to be notified in real time when a contact sends you a message on any channel. See [Two-Way Conversations](/start/guides/two-way-conversations) for inbound handling. ## Handling Failed Messages [#handling-failed-messages] When a send fails downstream, Sent fires `message.failed`. The payload reports the status but not the cause: ```json { "field": "message", "event": "message.failed", "timestamp": "2025-01-15T08:30:15Z", "payload": { "updated_at": "2025-01-15T08:30:15Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "FAILED", "channel": "sms", "body": "Hi Jane, your order has been confirmed.", "reason_code": "DELIVERY_013", "reason": "The recipient could not be reached: their phone was switched off, out of coverage, busy or out of message storage, or their line was not active on the network when delivery was attempted" } } ``` ### Common Failure Reasons [#common-failure-reasons] `message.failed`, `message.filtered` and `message.blocked` carry `payload.reason_code` and `payload.reason`, and `GET /v3/messages/{id}` reports the same pair. Branch on `reason_code`; show `reason` to a person. Every code is in the [Error Catalog](/reference/api/error-catalog). | `reason_code` | Status | Description | Action | |---------------|--------|-------------|--------| | `VALIDATION_002` | `FAILED` | The recipient's number is invalid or not in service | Verify the number; stop sending to it | | `BUSINESS_004` | `FILTERED` | The recipient opted out or is on your phone-channel suppression list | Suppress the contact until renewed consent | | `BUSINESS_003` | `BLOCKED` | The account balance is too low | Add funds | | `BUSINESS_020` | `BLOCKED` | The account reached its onboarding-stage message limit | Complete the next onboarding step | | `BUSINESS_029` | `BLOCKED` | A number listed in `channels.sms` is not an active sender on the account | Remove or replace the number at the position `reason` names | | `BUSINESS_005` | `BLOCKED` or `FAILED` | The template is not approved for sending | Wait for approval or use a different template | | `DELIVERY_004` | `FILTERED` | A routing rule denied the destination, or its sender is still being set up | Check the market with `GET /v3/channels` | | `DELIVERY_012` | `FAILED` | Carrier screening blocked the message | Revise the content; check the sender's registration | | `DELIVERY_013` | `FAILED` | The recipient's handset couldn't be reached | Try again later | | `BUSINESS_002` | `FAILED` | Sending was throttled | Implement backoff | ## Suppressed and Held Messages [#suppressed-and-held-messages] `FILTERED` and `BLOCKED` are terminal non-delivery outcomes. Unlike `FAILED`, no send attempt ever reached a carrier, so neither counts against your deliverability rate and neither is retried: - `FILTERED` fires `message.filtered`. A policy gate suppressed the send: the recipient opted out, the number is on your phone-channel suppression list, or routing rules denied every candidate route. - `BLOCKED` fires `message.blocked`. A precondition stopped the send before evaluation: insufficient balance, an unmet onboarding quota, a template that is not approved for sending, or a free-form send to a contact who has never replied and has no template inside the 7-day window (see [Conversation Windows](/start/guides/two-way-conversations#conversation-windows)). `SCHEDULED` is a hold rather than an outcome. It is triggered in two ways: by a `scheduled_at` value on the send request (the message parks until that instant), or when the send lands inside the recipient's quiet hours (Sent defers it until the window closes). In both cases, `message.scheduled` fires when the message is first held, the message continues through the normal pipeline once released, and `message.routed`, `message.sent`, and `message.delivered` follow. If a quiet-hours window shifts the release time of a `scheduled_at` message, `message.scheduled` fires again with the updated release instant. `CANCELLED` is the one way out of that hold that is not a release. It fires `message.cancelled` once, carrying the `scheduled_at` that was called off, and it is terminal: the message is never routed and never sent. Only a message that is currently `SCHEDULED` can be cancelled, so a cancellation sent after the release sweeper has claimed the message is refused with `409`. See [Cancelling scheduled messages](/start/guides/cancelling-messages). All four use the same payload shape as any other outbound status event: ```json { "field": "message", "event": "message.filtered", "timestamp": "2025-01-15T08:30:02Z", "payload": { "updated_at": "2025-01-15T08:30:02Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "FILTERED", "channel": "sms", "body": "Hi Jane, your order has been confirmed.", "reason_code": "BUSINESS_004", "reason": "The contact has opted out: they unsubscribed or replied STOP to this sender, or they stopped marketing messages from this business on WhatsApp" } } ``` A filtered, blocked, or failed message says why in `reason_code` and `reason`, on the webhook and on `GET /v3/messages/{id}`. Both are omitted on every other status. ## Best Practices [#best-practices] ### 1. Implement Idempotency [#1-implement-idempotency] Webhooks may be delivered multiple times. Handle this gracefully: ```typescript async function handleWebhook(eventData: any) { const { message_id, message_status } = eventData.payload; // Check if already processed const existing = await db.messages.findById(message_id); if (existing?.status === message_status) { return; // Already at this status — skip } // Process update await db.messages.update(message_id, { status: message_status }); } ``` ### 2. Queue Webhook Processing [#2-queue-webhook-processing] Don't do heavy work in the webhook handler: ```typescript app.post('/webhooks/sent', async (req, res) => { // Acknowledge immediately res.sendStatus(200); // Queue for background processing await queue.add('process-webhook', req.body); }); // Worker processes in background queue.process('process-webhook', async (job) => { await processWebhookEvent(job.data); }); ``` ### 3. Handle Late Deliveries [#3-handle-late-deliveries] Some messages may be delivered hours later (for example, when the device is offline): ```typescript if (message_status === 'DELIVERED') { const sentAt = new Date(message.sent_at); // Your stored send time const deliveredAt = new Date(eventData.timestamp); const delayHours = (deliveredAt - sentAt) / (1000 * 60 * 60); if (delayHours > 1) { console.log(`Late delivery: ${delayHours} hours`); } } ``` ### 4. Monitor Delivery Rates [#4-monitor-delivery-rates] Leave `FILTERED` and `BLOCKED` out of the deliverability denominator. They represent policy suppression, not delivery failures, so only `FAILED` counts against the rate. `SCHEDULED` messages have not reached an outcome yet, so leave those out too until they are released, and leave `CANCELLED` out permanently: it was never a send attempt. ```typescript // Daily delivery rate: exclude FILTERED, BLOCKED, SCHEDULED, CANCELLED, RECEIVED from the denominator const stats = await db.messages.aggregate([ { $match: { createdAt: { $gte: new Date(Date.now() - 24 * 60 * 60 * 1000) }, direction: 'OUTBOUND' } }, { $group: { _id: '$status', count: { $sum: 1 } } } ]); const byStatus = Object.fromEntries(stats.map(s => [s._id, s.count])); const delivered = byStatus['DELIVERED'] || 0; // Denominator: only statuses that represent a send attempt const denominator = ['QUEUED', 'ROUTED', 'SENT', 'DELIVERED', 'READ', 'FAILED'] .reduce((sum, s) => sum + (byStatus[s] || 0), 0); const deliveryRate = denominator > 0 ? (delivered / denominator) * 100 : 0; console.log(`Delivery rate: ${deliveryRate.toFixed(1)}%`); console.log(`Filtered (policy suppressed): ${byStatus['FILTERED'] || 0}`); console.log(`Blocked (account-level gate): ${byStatus['BLOCKED'] || 0}`); ``` ## Read Receipts (WhatsApp & RCS) [#read-receipts-whatsapp--rcs] WhatsApp and RCS both support read receipts when the recipient opens the message. The `message.read` event is fired for both channels. Check the `channel` field in the payload to distinguish them: ```json { "field": "message", "event": "message.read", "timestamp": "2025-01-15T09:15:30Z", "payload": { "updated_at": "2025-01-15T09:15:30Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "READ", "channel": "rcs" } } ``` Read receipts are available for WhatsApp (when the recipient has read receipts enabled in privacy settings) and for RCS. SMS has no read receipt equivalent. ## Inbound Messages (`message.received`) [#inbound-messages-messagereceived] When a contact sends a message to one of your provisioned numbers (a reply, or a keyword like STOP/START/HELP), Sent fires a `message.received` webhook whose payload shape differs from outbound status events. The [Two-Way Conversations guide](/start/guides/two-way-conversations#receiving-inbound-messages-via-webhook) owns inbound handling: storage, keyword and opt-out processing, auto-replies, and handler examples. The inbound payload shape is in the [Events Reference](/start/webhooks/event-types). The inbound message is also stored in your message log with `direction: "INBOUND"` and `status: "RECEIVED"`. You can retrieve it via `GET /v3/messages/{id}` like any outbound message. ## Troubleshooting [#troubleshooting] ### Webhook not receiving events? [#webhook-not-receiving-events] - Verify webhook URL is accessible from the internet - Check that your endpoint returns 2xx status - Review webhook delivery logs in the dashboard - Verify the webhook is configured for the correct event types ### Status stuck in `QUEUED`? [#status-stuck-in-queued] - Normal for first few seconds - Check if account has sufficient balance - Verify KYC is approved - Contact Sent if stuck > 5 minutes ### Status stuck in `SCHEDULED`? [#status-stuck-in-scheduled] - If triggered by quiet hours: the send landed inside the recipient's quiet hours and is held, not lost. Sent releases it automatically when the window closes; no action is required. - If triggered by `scheduled_at`: the message is intentionally parked until the release instant you specified. Check the `scheduled_at` field via `GET /v3/messages/{id}` to confirm the release time. - The follow-on `message.sent` and `message.delivered` events confirm dispatch after release. - To stop the send instead of waiting for it, cancel it: see [Cancelling scheduled messages](/start/guides/cancelling-messages). ### Missing status updates? [#missing-status-updates] - Ensure webhook endpoint is responding quickly (< 5 seconds) - Check for duplicate event handling (idempotency) - Review failed webhook deliveries in dashboard --- # Sending MMS (/start/guides/mms.md) # Sending MMS [#sending-mms] MMS is a carrier messaging channel that delivers images, video, vCard contacts, and plain text over the same number and carrier infrastructure as SMS. This guide covers how to send MMS using the Sent API. ## Availability [#availability] Whether a message can go out over MMS depends on your routes: the recipient's market, the sending number, and whether that number carries MMS. MMS is priced per message at a higher rate than SMS. A message goes out over MMS only when it carries an attachment, so a text-only send is never billed at MMS rates. ## Sending an MMS Message [#sending-an-mms-message] MMS uses the same `POST /v3/messages` endpoint as every other channel. Set `channel: ["mms"]` to pin the send to MMS. A pinned MMS send needs an attachment, which can come from two places: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "channel": ["mms"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "customerName": "Jane" } } }' ``` ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); const response = await client.messages.send({ to: ['+1234567890'], channel: ['mms'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { customerName: 'Jane' } } }); console.log(`Message ID: ${response.data.recipients[0].message_id}`); ``` ```python from sent_dm import SentDm client = SentDm() response = client.messages.send( to=["+1234567890"], channel=["mms"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": {"customerName": "Jane"} } ) print(f"Message ID: {response.data.recipients[0].message_id}") ``` ```go import ( "context" "github.com/sentdm/sent-dm-go" ) client := sentdm.NewClient() response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Channel: []string{"mms"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Parameters: map[string]interface{}{ "customerName": "Jane", }, }, }) ``` ```java import dm.sent.client.SentDmClient; import dm.sent.client.okhttp.SentDmOkHttpClient; import dm.sent.core.JsonValue; import dm.sent.models.messages.MessageSendParams; SentDmClient client = SentDmOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addChannel("mms") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("customerName", JsonValue.from("Jane")) .build()) .build()) .build(); var response = client.messages().send(params); ``` ```csharp using Sentdm; using Sentdm.Models.Messages; SentDmClient client = new(); MessageSendParams parameters = new() { To = new List { "+1234567890" }, Channel = new List { "mms" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Parameters = new Dictionary { { "customerName", "Jane" } } } }; var response = await client.Messages.Send(parameters); ``` Two optional fields on `POST /v3/messages` carry MMS content: | Field | Description | |-------|-------------| | `media_urls` | Array holding one `https` URL to attach. MMS carries one attachment, so a second is rejected with `400`. Replaces the template's own media rather than adding to it. | | `subject` | Subject line shown above the body on most handsets. Maximum 80 characters. | When neither field is supplied, the template's own MMS body provides the media. The text comes from the template's `mms` body, or its shared `multiChannel` body if it has no `mms` body, or its `sms` body if it has neither. The subject and attachments come only from an `mms` body, so a template without one needs `media_urls` to send as MMS. When `media_urls` is supplied, it overrides whatever the template carries, so a template can hold a default creative while a caller sends something recipient-specific. A template saved with more than one attachment before the one-attachment limit still sends, carrying only its first. Each media URL must be an absolute `https` URL on a hostname. A literal IP address is refused with `400`. ## Supported Media Types [#supported-media-types] These are the formats Sent supports on an outbound MMS: | Format | `mediaType` to declare | |------|---------| | JPEG, PNG, GIF | `image` | | MP4, 3GP | `video` | | vCard contact cards | `contact` | | Plain text | Omit the field | The carrier fetches the media from the URL at delivery time and reads the content type off the object it fetched. Keep media files publicly accessible and hosted on a stable URL. `mediaType` is a label, not a guarantee. The API accepts four values (`image`, `video`, `document`, `contact`) and rejects `audio` when a template is saved. It does not check the label against the file: Sent reads only the size your server declares for it (see [Media Size Limits](#media-size-limits)), never its content. Declaring `document` on a PDF is accepted at send time, but PDF is not in the preceding set, and the failure surfaces at the carrier long after Sent answered `202`. Send only the formats listed. The field is optional, so omit it when none of the four describes your file. It exists so an authoring UI can preview the attachment, not to select a delivery path. ## Media Size Limits [#media-size-limits] **An attachment must be 600 KB or smaller.** That is the size the carrier network delivers end to end. Over it, a carrier can accept and charge for a message and then discard the attachment before it reaches the handset. Sent checks the size on the send itself, after your `202`. It sends one `HEAD` request to the media URL and reads the `Content-Length` your server declares. It does not download the file. | Result of the check | Auto-detect | `channel: ["mms"]` | |---|---|---| | 600 KB or smaller | Sent as MMS | Sent as MMS | | Over 600 KB | Falls to the SMS route on the same number, with the attachment as a link when it fits (see [Auto-Detect Routing and MMS](#auto-detect-routing-and-mms)) | Fails | | Size unknown: no `Content-Length`, a non-2xx response, or an unreachable server | Sent as MMS | Sent as MMS | An unknown size never blocks a send, because a check that learned nothing about the file is no reason to fail it. The carrier still applies its own limits to that message after acceptance. Host media on a server that answers `HEAD` with a `Content-Length`, as most CDNs and object stores do, so the check can protect the send. An oversized attachment produces no validation error on the request. The send is accepted, and the outcome arrives later as a delivery status, or on auto-detect as an SMS. The ceiling a carrier delivers intact depends on its tier: | Carriers | Delivered intact up to | |---|---| | Tier 2 carriers | 600 KB | | Tier 3 carriers | 300 KB | Images and video over a carrier's ceiling are resized automatically on the way out. Resizing is lossy, so treat it as a safety net rather than a workflow, and design for 300 KB if you need tier 3 carriers to deliver the attachment intact. ## Auto-Detect Routing and MMS [#auto-detect-routing-and-mms] When you omit `channel`, auto-detect selects the best-matching route per recipient based on your routing rules. MMS routes sit above SMS routes in priority for the same sender number, so a message with media prefers MMS over SMS when both are available. RCS and WhatsApp routes typically outrank MMS when the recipient is reachable there. The exact channel always depends on which routes are configured for your account and the recipient. MMS only enters auto-detect consideration when the send carries an attachment. A text-only send never produces an MMS candidate, regardless of routing rules: the pipeline drops MMS candidates without media before routing resolves. This prevents a plain-text message from being billed at MMS rates. Attachments reach the send from either the template's `mms` body (see [Template Definition](/reference/api/template-definition#mms-body-content-object)) or the per-send `media_urls` field. If neither provides media, auto-detect skips MMS and falls to SMS. When a message with an attachment falls to SMS, including when its MMS candidate fails after routing chose it (for example, an attachment over 600 KB), the attachment URL is appended to the text as a link. The link is added only when it fits without adding a billed segment. Otherwise the SMS carries the text alone. ## Pinned vs. Auto-Detect [#pinned-vs-auto-detect] | | `channel: ["mms"]` (pinned) | `channel` omitted (auto-detect) | |---|---|---| | Falls back if no MMS route | No (fails with `ERR_NO_ROUTE_MATCHED`) | Yes (falls to SMS) | | Requires media | Yes (refused with `400` without one) | MMS only fires when message has media | | Attachment over 600 KB | Fails | Falls to SMS, with the attachment as a link when it fits | Pinning `channel: ["mms"]` without an attachment is refused with `400` (`VALIDATION_001`) before anything is sent: add `media_urls`, or use a template with media in its `mms` body. Send text-only messages on `sms`. If you pin MMS and the recipient has no MMS-capable route, the message fails rather than falling back. ## Template Approval [#template-approval] When Meta approves a template, the approval covers its MMS channel too, the same way it covers SMS and RCS. Meta reviews the template's text; it never sees the MMS media. ## Quiet Hours [#quiet-hours] MMS follows the same quiet-hours rules as SMS. Sends scheduled inside a recipient's legally protected quiet-hours window are deferred rather than failed. ## Delivery Reports [#delivery-reports] MMS delivery reports arrive on the same webhook you configure for other channels. The message moves through the normal lifecycle (`QUEUED` → `ROUTED` → `SENT` → `DELIVERED` / `FAILED`) and fires the same `message.delivered` and `message.failed` events. ## Inbound MMS [#inbound-mms] Sent identifies an inbound MMS as one: the message is recorded with `channel: "mms"` and relayed to your webhook as an ordinary `message.received` event, including when it carries no caption. **Attachments arrive as links to the carrier's copy.** `message.received` carries a `media` array with one entry per attachment. Sent records where the carrier holds each file; it does not download or store the file itself. ```json { "field": "message", "event": "message.received", "timestamp": "2025-10-31T10:10:42Z", "payload": { "message_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "updated_at": "2025-10-31T10:10:40Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "inbound_number": "+1234567890", "outbound_number": "+1987654321", "text": null, "channel": "mms", "media": [ { "url": "https://media.example-carrier.com/7f3c2a9e/photo.jpg", "mime_type": "image/jpeg", "size_bytes": 245760, "hash_sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" } ], "received_at": "2025-10-31T10:10:40Z" } } ``` | Field | Description | | --- | --- | | `url` | Where the carrier hosts the file. Always present | | `mime_type` | The content type the carrier reported, for example `image/jpeg`. Omitted when the carrier declared none | | `size_bytes` | The size the carrier declared. Omitted when it declared none | | `hash_sha256` | The SHA-256 the carrier declared for the file. Omitted when it declared none | Only `url` is guaranteed. Some carriers declare the type, size, and hash; others send only the address. Sent never guesses a missing value, so read the type from the response when you fetch the file. Only `https` links are relayed. **Download attachments when they arrive.** The `url` is the carrier's own link. It needs no authentication, so anyone holding it can fetch the file, and it expires on the carrier's schedule, which varies: assume days, not months. The webhook is the only place Sent gives you the link, and Sent can't fetch the file once the link lapses. Copy anything you need to keep into your own storage, and verify it against `hash_sha256` when that's present. `media` is omitted when a message carries no attachments, so an SMS payload keeps exactly the shape it has always had. A media-only MMS arrives with `text: null`; treat that as a normal value rather than an empty message. ## Next Steps [#next-steps] # Handling Opt-Outs and Consent (/start/guides/opt-out-and-consent.md) # Handling Opt-Outs and Consent [#handling-opt-outs-and-consent] This guide shows you how to keep consent state consistent between Sent and your own systems: mirror keyword opt-outs into your database, opt contacts out or back in through the API, detect consent-blocked sends, and apply a send window stricter than the platform's quiet hours. **Prerequisites:** - A Sent API key, passed in the `x-api-key` header - A webhook endpoint subscribed to `message` events (see [Getting Started with Webhooks](/start/webhooks/getting-started)) Sent already enforces the consent gate at send time, so you do not need a pre-send opt-out check of your own. [Compliance & Regulations](/start/advanced/compliance-regulations) describes everything the platform enforces automatically. ## Mirror keyword opt-outs into your database [#mirror-keyword-opt-outs-into-your-database] When a contact texts an opt-out keyword, Sent records the opt-out on the contact and fires a `message.received` webhook carrying the raw text. The webhook fires for every inbound message, keywords included. Match the keyword in your handler and update your own subscriber store: ```typescript const OPT_OUT_KEYWORDS = new Set(['STOP', 'CANCEL', 'UNSUBSCRIBE', 'QUIT', 'END']); const OPT_IN_KEYWORDS = new Set(['START', 'UNSTOP', 'SUBSCRIBE']); app.post('/webhooks/sent', async (req, res) => { // Acknowledge first; process after responding. res.sendStatus(200); const { field, event, payload } = req.body; if (field !== 'message' || event !== 'message.received') return; // payload.inbound_number is the contact's phone number. const keyword = (payload.text ?? '').trim().toUpperCase(); if (OPT_OUT_KEYWORDS.has(keyword)) { // Update your own subscriber store. await db.subscribers.update(payload.inbound_number, { messagingConsent: false, optedOutAt: new Date(), }); } else if (OPT_IN_KEYWORDS.has(keyword)) { await db.subscribers.update(payload.inbound_number, { messagingConsent: true, optedOutAt: null, }); } }); ``` If you configured custom keywords in the dashboard (**Compliance → Opt-Out Keywords**), add them to the `OPT_OUT_KEYWORDS` and `OPT_IN_KEYWORDS` sets. Sent matches keywords exactly and case-insensitively: the entire trimmed message body must equal the keyword. Mirror that rule rather than substring-matching. The contact record's `opt_out` field is what Sent checks on every send; when in doubt, read it back with `GET /v3/contacts?phone=...`. ## Opt a contact out or in through the API [#opt-a-contact-out-or-in-through-the-api] If you collect opt-outs on other surfaces (a web preference center, support tickets, email unsubscribes), write them to Sent so the send-time gate enforces them everywhere. ### Find the contact [#find-the-contact] Look up the contact by phone number (URL-encode the `+` as `%2B`): ```bash curl "https://api.sent.dm/v3/contacts?phone=%2B15551234567" \ -H "x-api-key: YOUR_API_KEY" ``` The contact ID is in `data.contacts[0].id`. ### Set the opt-out flag [#set-the-opt-out-flag] ```bash curl -X PATCH "https://api.sent.dm/v3/contacts/8ba7b830-9dad-11d1-80b4-00c04fd430c8" \ -H "x-api-key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"opt_out": true}' ``` To restore consent, send `{"opt_out": false}`. Opt a contact back in only when you hold their documented consent; the API does not check how the opt-out was created. Opt-out is per contact, not per channel: setting the flag suppresses SMS, WhatsApp, and RCS alike. ## Detect consent-blocked sends [#detect-consent-blocked-sends] A send to an opted-out contact is still accepted with `202`; the message is then finalized as `FILTERED` with reason code `ERR_CONSENT_BLOCKED`, and a `message.filtered` webhook fires. Treat it as an expected policy outcome: do not retry, and reconcile your local consent state if it disagrees. Extend the same webhook handler: ```typescript // Inside the same webhook handler: if (field === 'message' && event === 'message.filtered') { // payload.outbound_number is the recipient's phone number. FILTERED also // covers routing DENY rules, so confirm the contact's opt-out state // before mirroring it. const resp = await fetch( `https://api.sent.dm/v3/contacts?phone=${encodeURIComponent(payload.outbound_number)}`, { headers: { 'x-api-key': process.env.SENT_API_KEY } }, ); const { data } = await resp.json(); const contact = data?.contacts?.[0]; if (contact?.opt_out) { await db.subscribers.update(contact.format_e164, { messagingConsent: false, optedOutAt: new Date(), }); } } ``` For per-message detail, `GET /v3/messages/{id}` shows the `FILTERED` status; refer to the [Error Catalog](/reference/api/error-catalog) for `ERR_CONSENT_BLOCKED` remediation. ## Apply a stricter send window [#apply-a-stricter-send-window] Sent's quiet-hours gate already holds sends that land inside a protected window for the destination country: the message is parked as `SCHEDULED` and released automatically, with a `message.scheduled` webhook on the hold. If your legal review requires a stricter window (for example, the US TCPA limits telephone solicitations to 8 AM–9 PM recipient local time, and several states go further), gate the send in your own scheduler: ```typescript // TCPA window: 8 AM-9 PM recipient local time (47 CFR § 64.1200(c)(1)). // This check deliberately keeps a one-hour buffer inside the federal window // (sending only 9 AM-8 PM) to absorb clock skew and stricter state rules. function isInsideSendWindow(timeZone: string, now = new Date()): boolean { const hour = Number( new Intl.DateTimeFormat('en-US', { timeZone, hour: 'numeric', hourCycle: 'h23', }).format(now), ); return hour >= 9 && hour < 20; } if (isInsideSendWindow(subscriber.timeZone)) { await sendMessage(subscriber); } else { await queueForNextWindow(subscriber); } ``` If the platform's quiet-hours rules are sufficient for you, skip this section and subscribe to `message.scheduled` webhooks to observe holds. ## Verify your integration [#verify-your-integration] - Set `opt_out: true` on a test contact and send it a message: the API returns `202`, and `GET /v3/messages/{id}` shows `FILTERED` shortly after. - Text `STOP` to your number from a test phone: a `message.received` webhook arrives with the text, and the contact's `opt_out` flag reads `true` on the next `GET /v3/contacts/{id}`. - Text `START` from the same phone: the flag returns to `false`. ## Related pages [#related-pages] - [Two-Way Conversations](/start/guides/two-way-conversations): keyword matching rules, auto-replies, and cross-channel opt-out - [Compliance & Regulations](/start/advanced/compliance-regulations): what Sent enforces automatically, plus per-region regulation summaries - [Events Reference](/start/webhooks/event-types): full webhook payloads for `message.received` and `message.filtered` - [Managing Contacts](/start/guides/managing-contacts): the full contact API surface # How to retry Sent API requests safely (/start/guides/retrying-requests-safely.md) # How to retry Sent API requests safely [#how-to-retry-sent-api-requests-safely] This guide shows you how to retry failed Sent API v3 mutations (after timeouts, network drops, or 5xx errors) without sending the same message or creating the same resource twice. It assumes you know the [idempotency contract](/reference/api/idempotency): key format, 24-hour expiry, and replay semantics. The pattern has three parts: derive a stable key for the operation, reuse that exact key on every retry attempt, and handle the conflict case when two attempts overlap. ## Derive the key from a business identifier [#derive-the-key-from-a-business-identifier] Generate the key once per logical operation, from identifiers your system already tracks. A retry must present the same key, so the key cannot depend on when or how the attempt happens: ```typescript // Good: derived from the business operation — any retry reproduces it const key = `payment-${userId}-${invoiceId}`; // Good: derived from a client-generated request ID stored with the operation const key = `contact-create-${clientRequestId}`; // Bad: static key (blocks every later operation of this type for 24 hours) const key = 'create-message'; // Bad: fresh random value per attempt (each retry becomes a new operation) const key = crypto.randomUUID(); ``` ```python # Good: derived from the business operation — any retry reproduces it key = f"payment-{user_id}-{invoice_id}" # Good: derived from a client-generated request ID stored with the operation key = f"contact-create-{client_request_id}" # Bad: static key (blocks every later operation of this type for 24 hours) key = "create-message" # Bad: fresh random value per attempt (each retry becomes a new operation) key = str(uuid.uuid4()) ``` ```go // Good: derived from the business operation — any retry reproduces it key := fmt.Sprintf("payment-%s-%s", userID, invoiceID) // Good: derived from a client-generated request ID stored with the operation key := fmt.Sprintf("contact-create-%s", clientRequestID) // Bad: static key (blocks every later operation of this type for 24 hours) key := "create-message" // Bad: fresh random value per attempt (each retry becomes a new operation) key := uuid.New().String() ``` If an operation can legitimately repeat (the same invoice reminder sent weekly), include the occurrence in the identifier: for example `invoice-1234-reminder-2026-07`, not a timestamp captured at send time. A random UUID is only safe if you generate it when the operation is created and persist it alongside the operation. A UUID generated inside the send path produces a different key on each retry and defeats idempotency. ## Reuse the same key across retry attempts [#reuse-the-same-key-across-retry-attempts] Send the key on the first attempt and on every retry. Retry 5xx and network errors with exponential backoff. Don't retry 4xx errors; they fail the same way every time until you fix the request: ```typescript async function sendMessageWithRetry( payload: MessagePayload, operationId: string, // stable, caller-supplied (e.g. an order ID) maxRetries = 3 ): Promise { const idempotencyKey = `msg-${operationId}`; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { const response = await fetch('https://api.sent.dm/v3/messages', { method: 'POST', headers: { 'x-api-key': API_KEY, 'Idempotency-Key': idempotencyKey, // Same key on retry 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (response.ok) { return await response.json(); } // Don't retry on 4xx errors (client errors) if (response.status >= 400 && response.status < 500) { throw new Error(`Client error: ${response.status}`); } // Retry on 5xx or network errors if (attempt < maxRetries) { await sleep(Math.pow(2, attempt) * 1000); } } catch (error) { if (attempt === maxRetries) throw error; } } throw new Error('Max retries exceeded'); } function sleep(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } ``` ```python import time import requests def send_message_with_retry( payload: dict, operation_id: str, # stable, caller-supplied (e.g. an order ID) max_retries: int = 3, ) -> dict: """Send message with idempotency and retry logic.""" idempotency_key = f"msg-{operation_id}" for attempt in range(1, max_retries + 1): try: response = requests.post( 'https://api.sent.dm/v3/messages', headers={ 'x-api-key': API_KEY, 'Idempotency-Key': idempotency_key, # Same key on retry 'Content-Type': 'application/json' }, json=payload ) if response.ok: return response.json() # Don't retry on 4xx errors (client errors) if 400 <= response.status_code < 500: raise Exception(f"Client error: {response.status_code}") # Retry on 5xx or network errors if attempt < max_retries: time.sleep(2 ** attempt) except Exception as e: if attempt == max_retries: raise e raise Exception('Max retries exceeded') ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" "time" ) // operationID is stable and caller-supplied (e.g. an order ID) func sendMessageWithRetry(payload map[string]interface{}, operationID string, maxRetries int) (map[string]interface{}, error) { idempotencyKey := fmt.Sprintf("msg-%s", operationID) for attempt := 1; attempt <= maxRetries; attempt++ { body, _ := json.Marshal(payload) req, _ := http.NewRequest( "POST", "https://api.sent.dm/v3/messages", bytes.NewBuffer(body), ) req.Header.Set("x-api-key", API_KEY) req.Header.Set("Idempotency-Key", idempotencyKey) // Same key on retry req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { if attempt == maxRetries { return nil, err } time.Sleep(time.Duration(1<= 200 && resp.StatusCode < 300 { var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) return result, nil } // Don't retry on 4xx errors (client errors) if resp.StatusCode >= 400 && resp.StatusCode < 500 { return nil, fmt.Errorf("client error: %d", resp.StatusCode) } // Retry on 5xx or network errors if attempt < maxRetries { time.Sleep(time.Duration(1< The API caches only 2xx responses for replay, so a retry after a 5xx error executes the request again. With the same key, at most one attempt ever takes effect. ## Handle concurrent duplicates [#handle-concurrent-duplicates] If a duplicate request arrives while the original is still executing and the original does not finish within about 5 seconds, the API returns `409 Conflict` with code `CONFLICT_001`. Wait briefly and retry with the same key to receive the cached response: ```typescript async function sendWithIdempotency( url: string, payload: object, key: string ): Promise { try { return await apiRequest(url, payload, key); } catch (error: any) { if (error.code === 'CONFLICT_001') { // Wait for the original request to complete await sleep(500); return await apiRequest(url, payload, key); } throw error; } } function sleep(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } ``` ```python import time def send_with_idempotency(url: str, payload: dict, key: str) -> dict: """Send request with handling for concurrent idempotent requests.""" try: return api_request(url, payload, key) except Exception as e: error_code = getattr(e, 'code', None) if error_code == 'CONFLICT_001': # Wait for the original request to complete time.sleep(0.5) return api_request(url, payload, key) raise ``` ```go package main import ( "time" ) func sendWithIdempotency(url string, payload map[string]interface{}, key string) (map[string]interface{}, error) { result, err := apiRequest(url, payload, key) if err != nil { if err.Error() == "CONFLICT_001" { // Wait for the original request to complete time.Sleep(500 * time.Millisecond) return apiRequest(url, payload, key) } return nil, err } return result, nil } ``` ## Wrap the pattern in a reusable client [#wrap-the-pattern-in-a-reusable-client] For codebases with many call sites, centralize the header handling and replay detection in one client class. The caller supplies the operation identifier, so keys stay stable across retries and are easy to trace in logs: ```typescript class IdempotentClient { constructor(private apiKey: string, private baseUrl = 'https://api.sent.dm') {} async request( method: string, endpoint: string, payload?: object, options: { idempotencyKey?: string } = {} ) { const headers: Record = { 'x-api-key': this.apiKey, 'Content-Type': 'application/json' }; // Add idempotency key if provided if (options.idempotencyKey) { headers['Idempotency-Key'] = options.idempotencyKey; } const response = await fetch(`${this.baseUrl}${endpoint}`, { method, headers, body: payload ? JSON.stringify(payload) : undefined }); const data = await response.json(); // Check if this was a replay if (response.headers.get('Idempotent-Replayed')) { console.log('Idempotent replay detected'); console.log('Original request ID:', response.headers.get('X-Original-Request-Id')); } if (!data.success) { throw new Error(`${data.error.code}: ${data.error.message}`); } return data.data; } // Send a message; the caller supplies a stable operation ID async sendMessage( to: string[], templateId: string, operationId: string, parameters?: Record ) { return this.request('POST', '/v3/messages', { to, template: { id: templateId, parameters } }, { idempotencyKey: `msg-${operationId}` }); } } // Usage const client = new IdempotentClient(process.env.SENT_API_KEY!); // The order ID makes the send idempotent per order await client.sendMessage( ['+1234567890'], 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'order-confirmation-8412', { name: 'John' } ); // Or provide your own key for other operations await client.request('POST', '/v3/contacts', { phone_number: '+1234567890' }, { idempotencyKey: 'import-user-12345' }); ``` ```python import requests from typing import Any, Dict, List, Optional class IdempotentClient: def __init__(self, api_key: str, base_url: str = 'https://api.sent.dm'): self.api_key = api_key self.base_url = base_url def request( self, method: str, endpoint: str, payload: Optional[Dict] = None, idempotency_key: Optional[str] = None ) -> Dict[str, Any]: headers = { 'x-api-key': self.api_key, 'Content-Type': 'application/json' } if idempotency_key: headers['Idempotency-Key'] = idempotency_key response = requests.request( method, f'{self.base_url}{endpoint}', headers=headers, json=payload ) # Check for replay if response.headers.get('Idempotent-Replayed'): print('Idempotent replay detected') print(f'Original request ID: {response.headers.get("X-Original-Request-Id")}') data = response.json() if not data.get('success'): raise Exception(f"{data['error']['code']}: {data['error']['message']}") return data['data'] def send_message( self, to: List[str], template_id: str, operation_id: str, parameters: Optional[Dict[str, str]] = None ) -> Dict[str, Any]: """Send a message; the caller supplies a stable operation ID.""" return self.request('POST', '/v3/messages', { 'to': to, 'template': {'id': template_id, 'parameters': parameters or {}} }, idempotency_key=f"msg-{operation_id}") def create_contact(self, phone_number: str, operation_id: str) -> Dict[str, Any]: """Create a contact; the caller supplies a stable operation ID.""" return self.request('POST', '/v3/contacts', { 'phone_number': phone_number }, idempotency_key=f"contact-{operation_id}") # Usage client = IdempotentClient(api_key='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') # The order ID makes the send idempotent per order message = client.send_message( ['+1234567890'], 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'order-confirmation-8412', {'customer_name': 'John'} ) # The CSV row makes each import idempotent per row contact = client.create_contact('+1234567890', operation_id='import-csv-row-42') ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" "os" ) type IdempotentClient struct { APIKey string BaseURL string } func NewIdempotentClient(apiKey string) *IdempotentClient { return &IdempotentClient{ APIKey: apiKey, BaseURL: "https://api.sent.dm", } } func (c *IdempotentClient) Request( method string, endpoint string, payload interface{}, idempotencyKey string, ) (map[string]interface{}, error) { var body []byte if payload != nil { body, _ = json.Marshal(payload) } req, err := http.NewRequest( method, c.BaseURL+endpoint, bytes.NewBuffer(body), ) if err != nil { return nil, err } req.Header.Set("x-api-key", c.APIKey) req.Header.Set("Content-Type", "application/json") if idempotencyKey != "" { req.Header.Set("Idempotency-Key", idempotencyKey) } client := &http.Client{} resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() // Check for replay if resp.Header.Get("Idempotent-Replayed") == "true" { fmt.Println("Idempotent replay detected") fmt.Printf("Original request ID: %s\n", resp.Header.Get("X-Original-Request-Id")) } var result map[string]interface{} if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { return nil, err } if success, ok := result["success"].(bool); !ok || !success { errorData := result["error"].(map[string]interface{}) return nil, fmt.Errorf("%s: %s", errorData["code"], errorData["message"]) } return result["data"].(map[string]interface{}), nil } // SendMessage sends a message; the caller supplies a stable operation ID func (c *IdempotentClient) SendMessage( to []string, templateID string, operationID string, parameters map[string]string, ) (map[string]interface{}, error) { payload := map[string]interface{}{ "to": to, "template": map[string]interface{}{ "id": templateID, "parameters": parameters, }, } return c.Request("POST", "/v3/messages", payload, fmt.Sprintf("msg-%s", operationID)) } // Usage func main() { client := NewIdempotentClient(os.Getenv("SENT_API_KEY")) // The order ID makes the send idempotent per order message, err := client.SendMessage( []string{"+1234567890"}, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "order-confirmation-8412", map[string]string{"customer_name": "John"}, ) if err != nil { panic(err) } fmt.Printf("Messages queued: %v\n", message["recipients"]) // Or provide your own key for other operations contact, err := client.Request( "POST", "/v3/contacts", map[string]string{"phone_number": "+1234567890"}, "import-user-12345", ) if err != nil { panic(err) } fmt.Printf("Contact created: %v\n", contact["id"]) } ``` ## Verify the behavior [#verify-the-behavior] Confirm your retries are safe by forcing a replay: send the same request twice with the same key. The second response returns the original status and body with the `Idempotent-Replayed: true` header, and `X-Original-Request-Id` names the first request. If the second call creates a second resource instead, the key changed between attempts. Check that it derives only from stable identifiers. ## Troubleshooting [#troubleshooting] | Symptom | Likely cause | Fix | | --- | --- | --- | | Retry executed again even though the key matched | Key contains characters outside `A-Z a-z 0-9 - _` or exceeds 255 chars, so the API ignored it | Sanitize the identifiers you build keys from | | `409` with `CONFLICT_001` | Duplicate sent while the original is still executing | Wait briefly, retry with the same key | | `422` with `CONFLICT_005` | Key reused within 24 hours for a request with a different method, path, query, or body | Use a new key for a new operation; resend the original request unchanged when retrying | | Retry executed as a new operation | More than 24 hours passed and the key expired, or the key changed between attempts | Retry within 24 hours; derive keys from stable identifiers | ## Related [#related] - Refer to the [Idempotency reference](/reference/api/idempotency) for the full contract: key format, caching rules, and response headers. - [How to handle Sent API errors](/start/guides/handling-api-errors) - [How to handle Sent API rate limits](/start/guides/handling-rate-limits) # Scheduled Messages (/start/guides/scheduled-messages.md) # Scheduled Messages [#scheduled-messages] Schedule a message to deliver at a specific future time by including `scheduled_at` in the send request. The API accepts the request immediately (returning `QUEUED`), then holds each message as `SCHEDULED` until the release instant, at which point it routes and dispatches like any other message. ## How It Works [#how-it-works] API accepts request"] -->|consumer parks row| S["**SCHEDULED**
Held until scheduled_at"] S -->|release tick| R["**ROUTED**
Carrier assigned"] R --> B["**SENT**
Dispatched to provider"] B --> C["**DELIVERED**
To device"] B --> E["**FAILED**
Delivery error"] R --> E S -->|quiet-hours re-defer| S S -->|POST /cancel| X["**CANCELLED**
Called off, never sent"] style A fill:#e1f5fe style S fill:#e8eaf6 style R fill:#e8eaf6 style B fill:#f3e5f5 style C fill:#e8f5e8 style E fill:#ffebee style X fill:#ffebee `} darkTextAlways /> The send endpoint returns `202 Accepted` with `status: "QUEUED"`. Each message then moves to `SCHEDULED` once the consumer parks it. A `message.scheduled` webhook fires at that point. The release sweeper checks every 30 seconds and dispatches any message whose `scheduled_at` has passed. ## Schedule a Message [#schedule-a-message] Add `scheduled_at` to any send request. Everything else (template, recipients, channel) works the same as an immediate send: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "customerName": "Jane", "appointmentTime": "2pm tomorrow" } }, "scheduled_at": "2026-09-24T14:00:00-05:00" }' ``` ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { customerName: 'Jane', appointmentTime: '2pm tomorrow' } }, scheduled_at: '2026-09-24T14:00:00-05:00' }); console.log(`Message ID: ${response.data.recipients[0].message_id}`); console.log(`Releases at: ${response.data.scheduled_at}`); ``` ```python from sent_dm import SentDm client = SentDm() response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "customerName": "Jane", "appointmentTime": "2pm tomorrow" } }, scheduled_at="2026-09-24T14:00:00-05:00" ) print(f"Message ID: {response.data.recipients[0].message_id}") print(f"Releases at: {response.data.scheduled_at}") ``` ```go import ( "context" "github.com/sentdm/sent-dm-go" ) client := sentdm.NewClient() response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Parameters: map[string]interface{}{ "customerName": "Jane", "appointmentTime": "2pm tomorrow", }, }, ScheduledAt: sentdm.String("2026-09-24T14:00:00-05:00"), }) ``` ```java import dm.sent.client.SentDmClient; import dm.sent.client.okhttp.SentDmOkHttpClient; import dm.sent.core.JsonValue; import dm.sent.models.messages.MessageSendParams; SentDmClient client = SentDmOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("customerName", JsonValue.from("Jane")) .putAdditionalProperty("appointmentTime", JsonValue.from("2pm tomorrow")) .build()) .build()) .scheduledAt("2026-09-24T14:00:00-05:00") .build(); var response = client.messages().send(params); System.out.println("Releases at: " + response.data().scheduledAt()); ``` ```csharp using Sentdm; using Sentdm.Models.Messages; SentDmClient client = new(); MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Parameters = new Dictionary { { "customerName", "Jane" }, { "appointmentTime", "2pm tomorrow" } } }, ScheduledAt = "2026-09-24T14:00:00-05:00" }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Releases at: {response.Data.ScheduledAt}"); ``` ```php messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'parameters' => [ 'customerName' => 'Jane', 'appointmentTime' => '2pm tomorrow' ] ], scheduled_at: '2026-09-24T14:00:00-05:00' ); echo "Releases at: " . $result->data->scheduled_at . "\n"; ``` ```ruby require "sentdm" sent_dm = Sentdm::Client.new result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", parameters: { customerName: "Jane", appointmentTime: "2pm tomorrow" } }, scheduled_at: "2026-09-24T14:00:00-05:00" ) puts "Releases at: #{result.data.scheduled_at}" ``` ## `scheduled_at` Rules [#scheduled_at-rules] | Rule | Detail | |------|--------| | Explicit UTC offset required | `2026-10-01T09:00:00+02:00` or `2026-10-01T07:00:00Z`. A value with no offset is rejected with `400`. | | Minimum 1 minute ahead | Less than 1 minute from now is rejected with `400`. | | Maximum 30 days ahead | More than 30 days from now is rejected with `400`. | | Stored and echoed in UTC | The offset you send is used only to fix the instant. `scheduled_at` on the response and `GET /v3/messages/{id}` is always UTC. | ## Response [#response] A scheduled send returns `202 Accepted` with a `ScheduledSendMessageResponse`. The top-level `status` is `QUEUED`, the same as an immediate send. The extra `scheduled_at` field on the response is the release instant in UTC: ```json { "success": true, "data": { "status": "QUEUED", "scheduled_at": "2026-09-24T19:00:00Z", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "appointment_reminder", "recipients": [ { "message_id": "9ca8b840-9dad-11d1-80b4-00c04fd430c9", "to": "+1234567890", "channel": null } ] }, "error": null, "meta": { "request_id": "req_8Y0aLq3kEx", "timestamp": "2026-09-23T10:00:00Z", "version": "v3" } } ``` The recipient's `channel` is `null` at this point: channel selection happens at release, once the message exits `SCHEDULED`. Each recipient's message moves from `QUEUED` to `SCHEDULED` once the consumer parks it. You see this via `GET /v3/messages/{id}` or the `message.scheduled` webhook. ## Retrieve a Scheduled Message [#retrieve-a-scheduled-message] `GET /v3/messages/{id}` returns a `ScheduledMessageResponse` for any message that is or was held, including one you cancelled while it was held: the same fields as a regular message response, plus `scheduled_at`: ```bash curl "https://api.sent.dm/v3/messages/9ca8b840-9dad-11d1-80b4-00c04fd430c9" \ -H "x-api-key: $SENT_API_KEY" ``` ```typescript const message = await client.messages.get('9ca8b840-9dad-11d1-80b4-00c04fd430c9'); if (message.data.status === 'SCHEDULED') { console.log(`Waiting until: ${message.data.scheduled_at}`); } ``` ```python message = client.messages.get("9ca8b840-9dad-11d1-80b4-00c04fd430c9") if message.data.status == "SCHEDULED": print(f"Waiting until: {message.data.scheduled_at}") ``` ```go message, err := client.Messages.Get(context.Background(), "9ca8b840-9dad-11d1-80b4-00c04fd430c9") if message.Data.Status == "SCHEDULED" { fmt.Printf("Waiting until: %s\n", message.Data.ScheduledAt) } ``` ```java import dm.sent.client.SentDmClient; import dm.sent.client.okhttp.SentDmOkHttpClient; SentDmClient client = SentDmOkHttpClient.fromEnv(); var message = client.messages().retrieve("9ca8b840-9dad-11d1-80b4-00c04fd430c9"); if ("SCHEDULED".equals(message.data().status())) { System.out.println("Waiting until: " + message.data().scheduledAt()); } ``` ```csharp using Sentdm; SentDmClient client = new(); var message = await client.Messages.Retrieve("9ca8b840-9dad-11d1-80b4-00c04fd430c9"); if (message.Data.Status == "SCHEDULED") { Console.WriteLine($"Waiting until: {message.Data.ScheduledAt}"); } ``` ```php messages->retrieve('9ca8b840-9dad-11d1-80b4-00c04fd430c9'); if ($message->data->status === 'SCHEDULED') { echo "Waiting until: " . $message->data->scheduled_at . "\n"; } ``` ```ruby require "sentdm" sent_dm = Sentdm::Client.new message = sent_dm.messages.retrieve("9ca8b840-9dad-11d1-80b4-00c04fd430c9") if message.data.status == "SCHEDULED" puts "Waiting until: #{message.data.scheduled_at}" end ``` ## Cancel a Scheduled Message [#cancel-a-scheduled-message] `POST /v3/messages/{id}/cancel` calls off a message that is still `SCHEDULED`: ```bash curl -X POST "https://api.sent.dm/v3/messages/9ca8b840-9dad-11d1-80b4-00c04fd430c9/cancel" \ -H "x-api-key: $SENT_API_KEY" ``` The message moves to `CANCELLED`, which is terminal, and it is never released. The call is free, fires `message.cancelled`, and names one message: cancel each recipient's message ID separately. A message that has already been released returns `409`. See [Cancelling scheduled messages](/start/guides/cancelling-messages) for the full endpoint. ## Webhooks for Scheduled Messages [#webhooks-for-scheduled-messages] | Event | When it fires | |-------|--------------| | `message.scheduled` | Each time the message is parked or re-deferred: fires when the message is first held as `SCHEDULED`, and again each time a quiet-hours window shifts the release time (with the updated `scheduled_at`) | | `message.cancelled` | Once, when you cancel the held message with `POST /v3/messages/{id}/cancel`. Carries the `scheduled_at` that was called off | | `message.sent` | After release, when the message is dispatched to the provider | | `message.delivered` | When the provider confirms delivery to the device | | `message.failed` | If the send fails after release | The activity log from `GET /v3/messages/{id}/activities` includes a `SCHEDULED` entry that carries `scheduled_at`. A message re-deferred by quiet hours has two `SCHEDULED` entries, each with the instant as it stood at that moment. A cancelled message has a `CANCELLED` entry carrying the instant that was called off. ## Things to Know [#things-to-know] **Evaluation happens at release, not at the API call.** Account credit balance, template approval, and quiet hours are checked when the message is released, not when you schedule it. A message scheduled for a time inside a recipient's legally protected quiet-hours window is moved to the next allowed time at release, and `message.scheduled` fires again with the new `scheduled_at`. **Template parameters are captured at send time.** The template body and parameters you supply are frozen when the API call is made. If you update the template's content and resubmit it for review before release, the channel moves to `PENDING` and the message is blocked at release. If you update the template without resubmitting, the message sends with the content from the time of the API call. **Outstanding scheduled messages are capped at 1,000,000 per account.** If accepting the request would push your account past that limit, the API returns `429` with error code `LIMIT_001`. Wait for scheduled messages to send, [cancel](/start/guides/cancelling-messages) ones you no longer need, or schedule fewer at once. Scheduled messages use the same `POST /v3/messages` endpoint as immediate sends. The only addition is `scheduled_at`. All other options — channel selection, sender profile scoping, multiple recipients — work identically. ## Next Steps [#next-steps] # Sending Messages (/start/guides/sending-messages.md) # Sending Messages [#sending-messages] This guide shows you how to send SMS, WhatsApp, and RCS messages with the Sent API, using a template or free-form text. ## Overview [#overview] A **Message** in Sent represents a single communication sent to a contact through a specific channel (SMS, WhatsApp, or RCS). This guide covers the core aspects of message sending. ## The Message Lifecycle [#the-message-lifecycle] API accepts request
Message in queue"] --> R["**ROUTED**
Carrier assigned"] R --> B["**SENT**
Dispatched to provider"] B --> C["**DELIVERED**
Provider confirms
delivery to device"] C --> D["**READ**
(WhatsApp & RCS)
Recipient opened"] A --> E["**FAILED**
Delivery failed
Error recorded"] R --> E B --> E style A fill:#e1f5fe style R fill:#e8eaf6 style B fill:#f3e5f5 style C fill:#e8f5e8 style D fill:#fff3e0 style E fill:#ffebee `} darkTextAlways /> ## Sending Methods [#sending-methods] ### 1. Send to Phone Number [#1-send-to-phone-number] The simplest approach - send directly to any phone number: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "customerName": "John Doe", "orderNumber": "#12345" } } }' ``` ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { customerName: 'John Doe', orderNumber: '#12345' } } }); console.log(`Message ID: ${response.data.recipients[0].message_id}`); ``` ```python from sent_dm import SentDm client = SentDm() response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "customerName": "John Doe", "orderNumber": "#12345" } } ) print(f"Message ID: {response.data.recipients[0].message_id}") ``` ```go import ( "context" "github.com/sentdm/sent-dm-go" "github.com/sentdm/sent-dm-go/option" ) client := sentdm.NewClient() response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Parameters: map[string]interface{}{ "customerName": "John Doe", "orderNumber": "#12345", }, }, }) ``` ```java import dm.sent.client.SentDmClient; import dm.sent.client.okhttp.SentDmOkHttpClient; import dm.sent.core.JsonValue; import dm.sent.models.messages.MessageSendParams; SentDmClient client = SentDmOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("customerName", JsonValue.from("John Doe")) .putAdditionalProperty("orderNumber", JsonValue.from("#12345")) .build()) .build()) .build(); var response = client.messages().send(params); System.out.println("Sent: " + response.data().recipients().get(0).messageId()); ``` ```csharp using Sentdm; using Sentdm.Models.Messages; using System.Collections.Generic; SentDmClient client = new(); MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Parameters = new Dictionary { { "customerName", "John Doe" }, { "orderNumber", "#12345" } } } }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Sent: {response.Data.Recipients[0].MessageId}"); ``` ```php messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'parameters' => [ 'customerName' => 'John Doe', 'orderNumber' => '#12345' ] ] ); var_dump($result->data->recipients[0]->message_id); ``` ```ruby require "sentdm" sent_dm = Sentdm::Client.new result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", parameters: { customerName: "John Doe", orderNumber: "#12345" } } ) puts result.data.recipients[0].message_id ``` ### 2. Send to Multiple Recipients [#2-send-to-multiple-recipients] Send the same message to multiple recipients in one request: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890", "+1987654321", "+1555555555"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "announcement": "Our store is now open!" } } }' ``` ```typescript const response = await client.messages.send({ to: ['+1234567890', '+1987654321', '+1555555555'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { announcement: 'Our store is now open!' } } }); console.log(`Sent to ${response.data.recipients.length} recipients`); ``` ```python response = client.messages.send( to=["+1234567890", "+1987654321", "+1555555555"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": { "announcement": "Our store is now open!" } } ) print(f"Sent to {len(response.data.recipients)} recipients") ``` ```go response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890", "+1987654321", "+1555555555"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), Parameters: map[string]interface{}{ "announcement": "Our store is now open!", }, }, }) fmt.Printf("Sent to %d recipients\n", len(response.Data.Recipients)) ``` ```java import dm.sent.models.messages.MessageSendParams; import dm.sent.core.JsonValue; MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addTo("+1987654321") .addTo("+1555555555") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .parameters(MessageSendParams.Template.Parameters.builder() .putAdditionalProperty("announcement", JsonValue.from("Our store is now open!")) .build()) .build()) .build(); var response = client.messages().send(params); System.out.println("Sent to " + response.data().recipients().size() + " recipients"); ``` ```csharp using Sentdm.Models.Messages; MessageSendParams parameters = new() { To = new List { "+1234567890", "+1987654321", "+1555555555" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8", Parameters = new Dictionary { { "announcement", "Our store is now open!" } } } }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Sent to {response.Data.Recipients.Count} recipients"); ``` ```php $result = $client->messages->send( to: ['+1234567890', '+1987654321', '+1555555555'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8', 'parameters' => [ 'announcement' => 'Our store is now open!' ] ] ); echo "Sent to " . count($result->data->recipients) . " recipients\n"; ``` ```ruby result = sent_dm.messages.send_( to: ["+1234567890", "+1987654321", "+1555555555"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8", parameters: { announcement: "Our store is now open!" } } ) puts "Sent to #{result.data.recipients.length} recipients" ``` **Recipient Limit:** A single request can include up to **1000 recipients**. For campaigns larger than 1000, split into multiple requests. Each API call counts as one request toward the 10,000 req/min rate limit. ### 3. Send on Behalf of a Sender Profile [#3-send-on-behalf-of-a-sender-profile] If your account is an organization with child [Sender Profiles](/start/concepts/sender-profiles), an organization API key can send as any of its profiles by adding the `x-profile-id` header (the profile UUID). The request then executes as that profile, so its templates, contacts, sender numbers, and compliance settings apply, and the response echoes the scope in an `X-Profile-Id` header. ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_ORGANIZATION_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }' ``` ```typescript const response = await client.messages.send({ 'x-profile-id': profileId, to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } }); ``` ```python response = client.messages.send( x_profile_id=profile_id, to=["+1234567890"], template={"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8"} ) ``` ```go response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ XProfileID: sentdm.String(profileID), To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), }, }) ``` ```java MessageSendParams params = MessageSendParams.builder() .xProfileId(profileId) .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .build()) .build(); var response = client.messages().send(params); ``` ```csharp MessageSendParams parameters = new() { XProfileID = profileId, To = new List { "+1234567890" }, Template = new Template { ID = "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }; var response = await client.Messages.Send(parameters); ``` ```php $result = $client->messages->send( to: ['+1234567890'], template: ['id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8'], xProfileID: $profileId ); ``` ```ruby result = sent_dm.messages.send_( x_profile_id: profile_id, to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } ) ``` Only organization API keys may send `x-profile-id`. A profile-scoped key is rejected with `403` (`AUTH_004`), a value that is not a UUID with `400` (`VALIDATION_003`), and a profile outside your organization with `404` (`RESOURCE_013`). Requests scoped this way draw from the organization's rate limit pool. The alternative is to authenticate with the profile's own API key, which needs no header. Both patterns, plus per-language customer-to-profile mapping, are in [Integrating Sender Profiles into Your Application](/start/guides/integrating-sender-profiles); the provisioning flow is [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api). ## Sending Free-Form Text (Without a Template) [#sending-free-form-text-without-a-template] To send an ad-hoc message body without creating a template, pass `text` instead of `template`. Provide exactly one of the two: the API rejects a request that includes both, or neither, with a `400` validation error. ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "text": "Thanks for reaching out! Your order shipped this morning." }' ``` ```typescript const response = await client.messages.send({ to: ['+1234567890'], text: 'Thanks for reaching out! Your order shipped this morning.' }); console.log(`Message ID: ${response.data.recipients[0].message_id}`); ``` ```python response = client.messages.send( to=["+1234567890"], text="Thanks for reaching out! Your order shipped this morning." ) print(f"Message ID: {response.data.recipients[0].message_id}") ``` ```go response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Text: sentdm.String("Thanks for reaching out! Your order shipped this morning."), }) ``` ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .text("Thanks for reaching out! Your order shipped this morning.") .build(); var response = client.messages().send(params); ``` ```csharp MessageSendParams parameters = new() { To = new List { "+1234567890" }, Text = "Thanks for reaching out! Your order shipped this morning." }; var response = await client.Messages.Send(parameters); ``` ```php $result = $client->messages->send( to: ['+1234567890'], text: 'Thanks for reaching out! Your order shipped this morning.' ); var_dump($result->data->recipients[0]->message_id); ``` ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], text: "Thanks for reaching out! Your order shipped this morning." ) puts result.data.recipients[0].message_id ``` To pin a free-form send to one channel, set `channel` exactly as for template sends; see [Channel Selection Strategies](#channel-selection-strategies). On SMS, a free-form body follows the same segmentation rules as template output; see [SMS encoding and length](/start/concepts/sms-encoding-and-length). The response to a free-form send still includes a `template_id` and `template_name` (`FREE_TEXT_SYS_TEMPLATE`). Free-form messages ride Sent's internal free-text system template, and your text renders verbatim as the message body. Free-form text can span several lines. Line breaks, tabs, and runs of spaces are kept as written on every channel, so WhatsApp list and quote formatting, which relies on line breaks, works in free-form text. The rule against newlines, tabs, and more than four consecutive spaces applies only to template variable values; see [VALIDATION_008](/reference/api/error-catalog#validation_008-invalid-template-variable-value). ### When You Can Send Free-Form Text [#when-you-can-send-free-form-text] Free-form text is for replying inside an open conversation. The first message to a contact you have no conversation with must use a template. Per channel: | Channel | Free-form text allowed | |---------|------------------------| | SMS | If the contact has ever replied on any channel, always. Otherwise within 7 days of the last approved template you sent them on any channel. | | RCS | Same rule as SMS. | | WhatsApp (pinned with `channel: "whatsapp"`) | Only inside Meta's customer-service window: the contact must have sent an inbound WhatsApp message in the last 24 hours. Sent's rule does not apply, and a template never opens this window. | | Auto-detect (`channel` omitted or `["sent"]`) | Same rule as SMS and RCS. Sent does not route a free-form send to WhatsApp unless Meta's 24-hour window is also open; it falls back to RCS or SMS instead. | A reply from the contact is what makes free-form durable: once they have answered on any channel, free-form stays available on SMS, RCS, and auto-detect until they opt out. An outbound template only helps a contact who has never replied, opening a 7-day window on any channel. It never opens Meta's 24-hour WhatsApp window, which only an inbound WhatsApp message can open, so a WhatsApp-pinned free-form send needs a recent reply regardless of how many templates you sent. Your own free-form messages count for neither rule. Standalone opt-out keywords from the contact, such as STOP, do not count as a reply; `START` and `HELP` do. For how the two rules work, see [Conversation Windows](/start/guides/two-way-conversations#conversation-windows). To start a conversation with a contact who has never replied, use a template; see [Working with Templates](/start/guides/working-with-templates). ### Free-Form Send Errors [#free-form-send-errors] If the request contains both `text` and `template`, or neither, the API rejects it synchronously: ```json { "success": false, "status": 400, "error": { "code": "VALIDATION_001", "message": "Request validation failed", "details": { "template": ["Provide exactly one of 'template' or 'text'"] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" } } ``` If the request is valid but the send doesn't meet the per-channel rules, the API still returns `202 Accepted`. The delivery pipeline enforces the gate, and the outcome is recorded on the message asynchronously: - SMS, RCS, or auto-detect to a contact who has never replied and has had no approved template in the last 7 days: status `BLOCKED` with error code `CONVERSATION_TEMPLATE_REQUIRED`. - WhatsApp pinned with `channel: "whatsapp"` outside Meta's 24-hour window: status `FAILED` with error code `WHATSAPP_TEMPLATE_REQUIRED` Note the different terminal statuses. The conversation gate runs before routing and nothing is handed to a carrier, so it records `BLOCKED` and is excluded from your deliverability rate; it fires `message.blocked`, not `message.failed`. The WhatsApp gate still records `FAILED`. Both call for an approved template as the first step, but what that buys you differs by channel. On SMS, RCS, and auto-detect a template makes free-form available for 7 days, and once the contact replies even once it stays available indefinitely. On a send pinned to `channel: "whatsapp"` the template itself delivers, but free-form stays gated until the contact replies **within the last 24 hours**, because only a recent inbound opens Meta's window; omit `channel` to reach the contact over RCS or SMS in the meantime. Neither code is returned on the response. Each arrives as the message's `reason_code`, on `GET /v3/messages/{id}` and on the webhook; see [Status Tracking](/start/guides/message-status-tracking). ## Channel Selection Strategies [#channel-selection-strategies] ### Automatic Selection (Default) [#automatic-selection-default] Let Sent choose the optimal channel by omitting the `channel` field: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }' ``` ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' } // No channel field - automatic selection }); ``` ```python response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } # No channel parameter - automatic selection ) ``` ```go response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), }, // No channel field - automatic selection }) ``` ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .build()) // No channel - automatic selection .build(); var response = client.messages().send(params); ``` ```csharp MessageSendParams parameters = new() { To = new List { "+1234567890" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } // No channel - automatic selection }; var response = await client.Messages.Send(parameters); ``` ```php $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8' ] // No channel - automatic selection ); ``` ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } # No channel - automatic selection ) ``` Sent considers: - Contact's available channels - Historical delivery success rates - Cost optimization - Regional preferences Omitting the field is equivalent to `channel: ["sent"]`, the auto-detect value. Automatic selection is also the only mode with cross-channel fallback: when the preferred channel can't deliver, Sent can route the message over another one. ### Force Specific Channel [#force-specific-channel] Override automatic selection by specifying the `channel` field. An explicit channel **pins** each message to that channel and disables cross-channel fallback: if the pinned channel can't deliver to a recipient, the message fails rather than switching channels. The request shape is identical for every channel: only the `channel` value changes. This example pins the send to SMS: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, "channel": ["sms"] }' ``` ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' }, channel: ['sms'] }); ``` ```python response = client.messages.send( to=["+1234567890"], template={ "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, channel=["sms"] ) ``` ```go response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Channel: []string{"sms"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), }, }) ``` ```java MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addChannel("sms") .template(MessageSendParams.Template.builder() .id("7ba7b820-9dad-11d1-80b4-00c04fd430c8") .build()) .build(); var response = client.messages().send(params); ``` ```csharp MessageSendParams parameters = new() { To = new List { "+1234567890" }, Channel = new List { "sms" }, Template = new MessageSendParamsTemplate { Id = "7ba7b820-9dad-11d1-80b4-00c04fd430c8" } }; var response = await client.Messages.Send(parameters); ``` ```php $result = $client->messages->send( to: ['+1234567890'], template: [ 'id' => '7ba7b820-9dad-11d1-80b4-00c04fd430c8' ], channel: ['sms'] ); ``` ```ruby result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, channel: ["sms"] ) ``` #### Channel Values [#channel-values] | `channel` value | Behavior | |-----------------|----------| | Omitted or `["sent"]` | Automatic selection with cross-channel fallback ([the default](#automatic-selection-default)). | | `["sms"]` | Pins every message to SMS. | | `["whatsapp"]` | Pins every message to WhatsApp. Fails for contacts not reachable on WhatsApp. | | `["rcs"]` | Pins every message to RCS. Fails when the recipient's device or carrier doesn't support RCS. | | `["mms"]` | Pins every message to MMS. Requires an attachment (`media_urls`, or media in the template's `mms` body) and an MMS-capable route for the recipient. Without an attachment the request is refused with `400`. See [Sending MMS](/start/guides/mms). | | Multiple values, for example `["whatsapp", "sms", "rcs"]` | Broadcasts on every listed channel: a separate message per (recipient, channel) pair. | Any other value fails request validation with a `400` error. Refer to the [Channel Routing reference](/reference/channel-routing) for the full resolution and fallback rules. A pinned message never falls back to another channel: if the pinned channel can't deliver to a recipient, that message fails. To reach each recipient over the best available channel, omit the `channel` field ([automatic selection](#automatic-selection-default)). #### Broadcasting to Multiple Channels [#broadcasting-to-multiple-channels] The `channel` array is a **broadcast list, not a fallback order**. When you specify multiple channels, Sent creates a separate message for each (recipient, channel) pair and dispatches them all. Each message gets its own `message_id` and is billed independently: `["whatsapp", "sms", "rcs"]` sends every recipient three messages. ### Send From Specific Numbers [#send-from-specific-numbers] When your account holds several SMS numbers, `channels` chooses which of them a send may go out from. `channels.sms` is a list of entries, and each entry lists numbers in `from`: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+12125551234", "+14155551234"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, "channel": ["sms"], "channels": { "sms": [ { "from": ["+12125550000", "+14155550000"] } ] } }' ``` How it works: - **`channel` and `channels` combine.** `channel` chooses the channel and `channels` chooses the numbers, so `"channel": ["sms"]` with an `sms` list sends on SMS from those numbers. - **Routing picks among the listed numbers.** Each recipient is matched against your routes the usual way, and routes pinned to a number you did not list are removed. The numbers from every entry in the list apply to every recipient. - **A matching area code is preferred.** When several of the listed numbers could serve a recipient, the one whose area code matches the recipient's wins: in the example, the `212` number serves the `212` recipient and the `415` number serves the `415` recipient. A recipient in a third area code still gets the message. - **`country` and `strategy` are optional.** Each entry accepts them, for example `{ "country": "US", "from": [...] }`. Both are stored with the message but do not change routing yet. A request is rejected with a `400` error if `channels` names a key that is not a channel (including `sent`), names the same channel twice, holds an empty list, has an entry with an empty `from`, or has an entry in `from` that is not a valid E.164 number. Every listed number must be an active SMS sender on your account. This is checked for each message when it is sent, not when the request arrives. The request is still accepted with `202`, and each message that names an unusable number ends `BLOCKED` with `reason_code` `BUSINESS_029`, on `GET /v3/messages/{id}` and on the `message.blocked` webhook. The `reason` names the number by its position, for example `channels.sms[0].from[1]`, never by the number itself. The whole message is blocked rather than sent from the remaining numbers. A blocked message is not charged and does not count against your deliverability rate. The choice stays with the message. A message held for `scheduled_at` or quiet hours, a resend, and a reroute after a delivery failure all keep the numbers you listed, and a scheduled message is checked against your account as it stands when it is released. [Sandbox mode](/start/guides/testing-with-sandbox-mode) does not check the numbers. See [Choosing the sending number](/reference/channel-routing#choosing-the-sending-number) for the routing rules. ## Response Overview [#response-overview] ### Success Response (202 Accepted) [#success-response-202-accepted] ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+14155551234", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` **Important:** Store the `message_id` from each recipient object. You'll need it to track delivery status. ### Error Response (4xx/5xx) [#error-response-4xx5xx] ```json { "success": false, "status": 402, "error": { "code": "BUSINESS_003", "message": "Account balance is insufficient to send this message", "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` Common error codes: - `RESOURCE_002` - Template not found or not approved - `BUSINESS_003` - Insufficient account balance - `BUSINESS_002` - Rate limit exceeded (10,000 req/min standard, 10 req/min sensitive) - `VALIDATION_001` - Request validation failed (for example, both or neither of `text` and `template` supplied) - `VALIDATION_002` - Invalid phone number format - `BUSINESS_005` - Template not approved for sending - `BUSINESS_007` - Channel not available for this contact - `BUSINESS_008` - Operation would exceed quota These two are not returned on the response. The send is accepted with `202`, and the code arrives as the message's `reason_code` on `GET /v3/messages/{id}` and on its `message.failed` or `message.blocked` webhook: - `WHATSAPP_TEMPLATE_REQUIRED` - Free-form WhatsApp message outside Meta's 24-hour customer-service window - `CONVERSATION_TEMPLATE_REQUIRED` - Free-form message with no open conversation on SMS, RCS, or auto-detect ## Next Steps [#next-steps] --- # SMS Length, Segments & Cost (/start/guides/sms-length-and-cost.md) # SMS Length, Segments & Cost [#sms-length-segments--cost] On SMS, **length is cost**. A message longer than a single SMS is split into multiple *segments*, and each segment is billed as a separate message. Because the per-message limit depends on the characters you use, the same-looking message can cost one SMS or three. This guide is the practical companion to [SMS Encoding & Message Length](/start/concepts/sms-encoding-and-length), which explains the underlying GSM-7 vs Unicode mechanics. Start there if the terms *GSM-7*, *UCS-2*, or *concatenation* are new. ## Try it: SMS length calculator [#try-it-sms-length-calculator] Type or paste a message to see its encoding, character count, and how many billable segments it becomes. Toggle **character detail** to see exactly which characters are expensive. Things worth trying: {/* vale Sent.Emoji = NO */} {/* The emoji is the subject matter: it demonstrates the flip to UCS-2. */} - Paste a plain English message just over 160 characters and watch it become 2 segments of 153. - Add a single emoji (😀) and watch the encoding flip to Unicode and the limit drop to 70. - Replace a straight quote `"` with a curly quote `"`: same flip, no visible difference in the text. {/* vale Sent.Emoji = YES */} ## How Sent counts segments [#how-sent-counts-segments] Sent computes the segment count from the message body using the standard GSM 03.38 rules (the **same logic used for billing**), so the count you see is the count you're charged for. - The **dashboard** shows the segment count on each message in the activity view (such as "3 parts") for multi-part SMS, with a per-segment breakdown when you expand the message. - The **calculator on this page** applies the same counting rules, so you can check any message body before sending it. - The **API** does not return a segment count: the `GET /v3/messages/{id}` response carries the per-message `price` but no segments field. Segment count is a property of **SMS only**. WhatsApp and RCS are billed per message (or per conversation), not per SMS segment. ## How segments map to cost [#how-segments-map-to-cost] Each SMS segment is billed as one message. The math follows directly from the [encoding rules](/start/concepts/sms-encoding-and-length): {/* vale Sent.Emoji = NO */} {/* The emoji is the subject matter: it is what forces the row into Unicode. */} | Your message | Encoding | Segments | Billed as | |---|---|---|---| | "Your code is 1234" (17 chars) | GSM-7 | 1 | 1 SMS | | 200 characters of plain English | GSM-7 | 2 | 2 SMS | | 480 characters of plain English | GSM-7 | 4 | 4 SMS | | "Votre colis est arrivé 📦" | Unicode | 1 | 1 SMS | | 80 characters including one emoji | Unicode | 2 | 2 SMS | {/* vale Sent.Emoji = YES */} A 10-character message with one emoji and a 70-character all-text message both fit in one Unicode segment, but an 80-character message with an emoji is two. The emoji didn't add much length; it changed the *limit*. ## Keep messages short and predictable [#keep-messages-short-and-predictable] **The single most common surprise: accidental Unicode.** A message you wrote as pure GSM-7 can silently become Unicode, and lose more than half its per-segment room, because of a character you can't see the difference of: - **Curly quotes** `" " ' '` instead of straight `" '` (auto-inserted by many editors and phones) - **En/em dashes** `– —` instead of a hyphen `-` - **Ellipsis** `…` instead of three dots `...` - Any **emoji** If a message should be GSM-7, normalize these characters before sending. Practical guidance: - **Aim for a single segment.** Under 160 GSM-7 characters (or 70 if the content is inherently Unicode) is the cheapest, most reliable outcome. - **Budget for variables.** A template that's 150 characters with a short name can blow past 160, into a second segment, when the name or a URL is long. Test with realistic, worst-case variable values, not "John." - **Budget for translation.** A message comfortably within 160 GSM-7 characters in English will encode as Unicode (70-character segments) in Arabic, Chinese, Cyrillic, and most non-Latin scripts. The same content can be 1 segment in one language and 3 in another. - **Fewer parts, fewer failures.** Beyond cost, each additional segment is another part that must arrive and be reassembled by the recipient's device and network. Long concatenated messages are marginally more prone to delivery issues than single ones. ## Check the count before sending [#check-the-count-before-sending] Segment count is derived purely from the message body, so you can verify it without spending on real delivery: paste the final rendered message (with realistic, worst-case variable values) into the calculator at the top of this page. It applies the same GSM 03.38 rules Sent bills with. After a live send, confirm the billed part count in the dashboard's activity view. ## Related [#related] --- # Testing & Debugging (/start/guides/testing-debugging.md) # Testing & Debugging [#testing--debugging] Validate your integration, debug issues, and ensure reliable message delivery before going to production. ## Sandbox Mode [#sandbox-mode] Use sandbox mode to validate requests without sending real messages or incurring charges. ### Enabling Sandbox Mode [#enabling-sandbox-mode] Add `"sandbox": true` to the request body to validate without side effects: ```bash curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, "sandbox": true }' ``` ```typescript const response = await client.messages.send({ to: ['+1234567890'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' }, sandbox: true }); // Sandbox mode returns realistic response without side effects console.log('Status:', response.data.status); console.log('Recipients:', response.data.recipients); console.log('Sandbox mode:', response.headers['X-Sandbox']); ``` ```python response = client.messages.send( to=["+1234567890"], template={"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8"}, sandbox=True ) # Sandbox mode returns realistic response without side effects print(f"Status: {response.data.status}") print(f"Recipients: {response.data.recipients}") ``` ```go response, err := client.Messages.Send(ctx, sentdm.MessageSendParams{ To: []string{"+1234567890"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("7ba7b820-9dad-11d1-80b4-00c04fd430c8"), }, Sandbox: sentdm.Bool(true), }) ``` ### Sandbox Mode Response [#sandbox-mode-response] The API returns a realistic response (202 Accepted) **without executing side effects**. Check the `X-Sandbox: true` header: ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "welcome_message", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+1234567890", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_test_001", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` ### What Sandbox Mode Validates [#what-sandbox-mode-validates] | Check | Description | |-------|-------------| | **Authentication** | API key is valid | | **Template** | Template exists and is accessible | | **Variables** | All required template parameters provided | | **Recipients** | Phone numbers are valid format | | **Rate Limits** | Request is within rate limits | | **Idempotency** | Key uniqueness (if provided) | Sandbox mode returns 202 Accepted with realistic fake data. No database writes, no messages sent, no external API calls. ## Testing Scenarios [#testing-scenarios] ### Unit Testing [#unit-testing] Test your message sending logic in isolation: ```typescript // messageService.test.ts import { describe, it, expect, vi } from 'vitest'; import { sendWelcomeMessage } from './messageService'; describe('sendWelcomeMessage', () => { it('should send welcome message successfully', async () => { const result = await sendWelcomeMessage('+1234567890', 'John'); expect(result.success).toBe(true); expect(result.messageId).toBeDefined(); }); it('should handle invalid phone number', async () => { const result = await sendWelcomeMessage('invalid', 'John'); expect(result.success).toBe(false); expect(result.error).toContain('phone number'); }); it('should use sandbox mode in development', async () => { process.env.NODE_ENV = 'development'; const result = await sendWelcomeMessage('+1234567890', 'John'); expect(result.sandbox).toBe(true); }); }); ``` ### Integration Testing [#integration-testing] Test the full flow with the actual API: ```typescript // integration.test.ts describe('Sent API Integration', () => { it('should send and track message delivery', async () => { // Send message const sendResult = await client.messages.send({ to: [TEST_PHONE_NUMBER], template: { id: TEST_TEMPLATE_ID }, sandbox: true }); expect(sendResult.data.recipients[0].message_id).toBeDefined(); // Query status const messageId = sendResult.data.recipients[0].message_id; const statusResult = await client.messages.retrieveStatus(messageId); expect(statusResult.data.status).toBe('QUEUED'); }); }); ``` ### Load Testing [#load-testing] Test your integration under load: ```typescript // loadTest.ts async function loadTest() { const concurrency = 10; const totalMessages = 100; const startTime = Date.now(); // Send messages in batches for (let i = 0; i < totalMessages; i += concurrency) { const batch = Array(concurrency).fill(null).map((_, j) => client.messages.send({ to: [TEST_PHONE_NUMBER], template: { id: TEST_TEMPLATE_ID }, sandbox: true }) ); await Promise.all(batch); console.log(`Sent batch ${i / concurrency + 1}`); } const duration = Date.now() - startTime; const rate = totalMessages / (duration / 1000); console.log(`Rate: ${rate.toFixed(2)} messages/second`); } ``` ## Debugging Failed Messages [#debugging-failed-messages] ### 1. Check Response Details [#1-check-response-details] ```typescript try { const response = await client.messages.send({...}); } catch (error) { console.log('Status:', error.status); console.log('Code:', error.code); console.log('Message:', error.message); console.log('Request ID:', error.meta?.request_id); // For support tickets } ``` ### 2. Enable Debug Logging [#2-enable-debug-logging] ```typescript const client = new SentDm({ logLevel: 'debug' }); // Or via environment variable process.env.SENT_DM_LOG = 'debug'; ``` ### 3. Use the Dashboard [#3-use-the-dashboard] 1. Go to [Activities](https://app.sent.dm/dashboard/activities) 2. Find the failed message 3. Click for detailed error information 4. View request/response payloads ### 4. Common Issues and Solutions [#4-common-issues-and-solutions] | Symptom | Possible Cause | Solution | |---------|---------------|----------| | `401` `AUTH_001` | Invalid API key | Verify key in dashboard | | `400` `VALIDATION_001` | Invalid request format | Check request body | | `404` `RESOURCE_002` | Template not found | Verify template ID | | `422` `VALIDATION_002` | Invalid phone number | Use E.164 format | | Message finalized as `BLOCKED` (`message.blocked` webhook) | Insufficient balance or another account-level precondition | Add funds to account | | `429` `BUSINESS_002` | Rate limit exceeded | Implement backoff (10,000 req/min std) | | Message stuck in "QUEUED" | KYC pending | Complete verification | | Webhook not received | Invalid URL | Verify endpoint returns 2xx | ## Webhook Testing [#webhook-testing] ### Local Development with ngrok [#local-development-with-ngrok] ```bash # Start your local server npm run dev # Running on http://localhost:3000 # Create tunnel npx ngrok http 3000 # Use the HTTPS URL in webhook configuration # https://abc123.ngrok.io/webhooks/sent ``` ### Webhook Testing Tools [#webhook-testing-tools] Test webhook handlers without sending real messages. For the production handler implementations under test, refer to [Message Status Tracking](/start/guides/message-status-tracking) (status events) and [Two-Way Conversations](/start/guides/two-way-conversations) (inbound messages): ```typescript // webhook.test.ts const mockEvent = { field: 'message', event: 'message.delivered', timestamp: new Date().toISOString(), payload: { updated_at: new Date().toISOString(), account_id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', message_id: '8ba7b830-9dad-11d1-80b4-00c04fd430c8', template_id: '9ba7b840-9dad-11d1-80b4-00c04fd430c8', template_name: 'order_confirmation', outbound_number: '+1987654321', message_status: 'DELIVERED', channel: 'sms' } }; describe('Webhook Handler', () => { it('should handle message delivered event', async () => { await request(app) .post('/webhooks/sent') .send(mockEvent) .expect(200); // Verify database was updated const message = await db.messages.findById(mockEvent.payload.message_id); expect(message.status).toBe('DELIVERED'); }); it('should verify webhook signature', async () => { const rawBody = JSON.stringify(mockEvent); const webhookId = '550e8400-e29b-41d4-a716-446655440000'; const timestamp = Math.floor(Date.now() / 1000).toString(); // HMAC-SHA256 over `${webhookId}.${timestamp}.${rawBody}`, formatted as `v1,{base64}` const signature = generateSignature(webhookId, timestamp, rawBody, WEBHOOK_SECRET); await request(app) .post('/webhooks/sent') .set('X-Webhook-ID', webhookId) .set('X-Webhook-Timestamp', timestamp) .set('X-Webhook-Signature', signature) .set('Content-Type', 'application/json') .send(rawBody) .expect(200); }); }); ``` Refer to [Webhook Security](/start/webhooks/signature-verification) for the full signature scheme and a verification implementation. ### Replay Webhook Events [#replay-webhook-events] ```bash # Using curl to replay a webhook curl -X POST http://localhost:3000/webhooks/sent \ -H "Content-Type: application/json" \ -H "X-Webhook-ID: test-event-id" \ -H "X-Webhook-Timestamp: $(date +%s)" \ -H "X-Webhook-Signature: v1," \ -d '{ "field": "message", "event": "message.delivered", "timestamp": "2025-01-15T08:30:15Z", "payload": { "updated_at": "2025-01-15T08:30:15Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "DELIVERED", "channel": "sms" } }' ``` ## Test Environment [#test-environment] ### Isolated Testing [#isolated-testing] Sent does not provide a separate test environment, and KYC verification requires real business details: placeholder details lead to a rejected verification. Follow the supported process in [Account Setup](/start/quickstart/account-setup), then keep test traffic isolated on your verified account: 1. Create a dedicated API key for development so you can rotate or revoke it without touching production. See [API keys](/start/guides/api-keys). 2. Send with `"sandbox": true` to validate requests without dispatching messages or incurring charges. 3. For end-to-end delivery tests, send real (billed) messages to phone numbers your team controls. Sandbox requests never dispatch a message, so any validly formatted E.164 recipient works. Sent has no reserved test phone numbers with simulated delivery outcomes. ## Monitoring in Production [#monitoring-in-production] ### Health Checks [#health-checks] ```typescript // healthcheck.ts async function healthCheck() { try { // Test API connectivity const response = await client.templates.list({ limit: 1 }); return { status: 'healthy', api: 'connected', timestamp: new Date().toISOString() }; } catch (error) { return { status: 'unhealthy', api: 'disconnected', error: error.message }; } } ``` ### Metrics to Track [#metrics-to-track] ```typescript // Track key metrics metrics.histogram('message_send_duration'); metrics.counter('message_send_total', { status: 'success' }); metrics.counter('message_send_total', { status: 'failed' }); metrics.gauge('messages_queued'); ``` ## Troubleshooting Checklist [#troubleshooting-checklist] When something isn't working: - [ ] Check API key is correct and active - [ ] Verify KYC is approved - [ ] Confirm account has sufficient balance - [ ] Check template exists and is approved - [ ] Validate phone number format (E.164) - [ ] Review rate limit status - [ ] Check webhook endpoint is responding 200 - [ ] Enable debug logging - [ ] Test in sandbox mode first - [ ] Review dashboard activity logs ## Support Resources [#support-resources] If you're stuck: 1. **Check the [Error Catalog](/reference/api/error-catalog)** - Detailed error codes 2. **Review [Troubleshooting Guide](/start/reference-guides/troubleshooting)** - Common issues 3. **Contact Support** - email [support@sent.dm](mailto:support@sent.dm) with: - Request ID (from error response) - Timestamp of issue - Code snippet (with API keys removed) - Expected vs actual behavior --- # Testing with Sandbox Mode (/start/guides/testing-with-sandbox-mode.md) # Testing with Sandbox Mode [#testing-with-sandbox-mode] This guide shows you how to test a Sent integration against the live API without sending messages: in your test suite, in CI, and when reproducing a production failure. It assumes you have a working integration and a valid API key. For the exact behavior of the `sandbox` field and the endpoints that support it, refer to the [sandbox mode reference](/reference/api/test-mode). ## Assert Against Real Responses [#assert-against-real-responses] Add `"sandbox": true` to the request body in your integration tests. The API authenticates and validates the request, then returns the production response schema with sample data, so your assertions exercise the real contract while nothing is sent. ```ts // tests/messages.sandbox.spec.ts import { describe, expect, it } from 'vitest'; const BASE_URL = 'https://api.sent.dm'; describe('POST /v3/messages (sandbox)', () => { it('accepts a valid payload without sending anything', async () => { const response = await fetch(`${BASE_URL}/v3/messages`, { method: 'POST', headers: { 'x-api-key': process.env.SENT_API_KEY!, 'Content-Type': 'application/json', }, body: JSON.stringify({ sandbox: true, // validated, never sent to: ['+14155550123'], channel: ['sms'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { name: 'Test' }, }, }), }); const body = await response.json(); expect(response.status).toBe(202); expect(response.headers.get('X-Sandbox')).toBe('true'); expect(body.success).toBe(true); expect(body.data.status).toBe('QUEUED'); expect(body.data.recipients[0].message_id).toBeDefined(); }); }); ``` ```python # tests/test_messages_sandbox.py import os import requests BASE_URL = "https://api.sent.dm" def test_send_accepts_valid_payload_without_sending(): response = requests.post( f"{BASE_URL}/v3/messages", headers={"x-api-key": os.environ["SENT_API_KEY"]}, json={ "sandbox": True, # validated, never sent "to": ["+14155550123"], "channel": ["sms"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "parameters": {"name": "Test"}, }, }, ) body = response.json() assert response.status_code == 202 assert response.headers["X-Sandbox"] == "true" assert body["success"] is True assert body["data"]["status"] == "QUEUED" assert body["data"]["recipients"][0]["message_id"] ``` The same pattern works for any endpoint in the [supported endpoints table](/reference/api/test-mode#supported-endpoints); sandbox delete requests, for example, return `204` without deleting anything. Sandbox responses contain sample data. A simulated `message_id` references no stored message, so do not follow it up with a `GET /v3/messages/{id}` assertion; that returns `404`. ## Run Sandbox Tests in CI [#run-sandbox-tests-in-ci] Make the flag injectable so the same suite runs simulated in CI and live where you explicitly choose to. Read one environment variable in a shared helper: ```ts // tests/helpers/payload.ts export function withSandbox(payload: T) { // CI sets SENT_SANDBOX=true; a live run leaves it unset. return { ...payload, sandbox: process.env.SENT_SANDBOX === 'true' }; } ``` ```python # tests/helpers.py import os def with_sandbox(payload: dict) -> dict: # CI sets SENT_SANDBOX=true; a live run leaves it unset. return {**payload, "sandbox": os.environ.get("SENT_SANDBOX") == "true"} ``` Then set the variable in the pipeline: ```yaml # .github/workflows/test.yml - name: Integration tests env: SENT_API_KEY: ${{ secrets.SENT_API_KEY }} # The helper reads this and adds sandbox: true to every request, # so the run sends no messages and consumes no balance. SENT_SANDBOX: "true" run: npm run test:integration ``` ## Reproduce a Production Failure [#reproduce-a-production-failure] To debug a failed request without risking another live send, replay the exact production payload with the `sandbox` flag added: ```ts const failedPayload = { to: ['+14155550123'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8' }, }; const response = await fetch('https://api.sent.dm/v3/messages', { method: 'POST', headers: { 'x-api-key': process.env.SENT_API_KEY!, 'Content-Type': 'application/json', }, // Same payload as production, plus the sandbox flag. body: JSON.stringify({ ...failedPayload, sandbox: true }), }); console.log(response.status, await response.json()); ``` ```python import os import requests failed_payload = { "to": ["+14155550123"], "template": {"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8"}, } response = requests.post( "https://api.sent.dm/v3/messages", headers={"x-api-key": os.environ["SENT_API_KEY"]}, # Same payload as production, plus the sandbox flag. json={**failed_payload, "sandbox": True}, ) print(response.status_code, response.json()) ``` Sandbox mode reproduces authentication and validation failures only. Failures that happen after a request is accepted, such as delivery errors, never occur in sandbox mode because execution is skipped. ## Keep Sandbox Mode Out of Production [#keep-sandbox-mode-out-of-production] `sandbox` is a per-request body field, not an account setting or a key type, so the same running service can emit both simulated and live requests. If you toggle it by environment, make the production value an explicit `false`: ```ts // config.ts // Only production sends for real. export const sandbox = process.env.NODE_ENV !== 'production'; ``` ```python # config.py import os # Only production sends for real. SANDBOX = os.environ.get("ENVIRONMENT") != "production" ``` A `sandbox: true` that leaks into production silently drops real messages: the API returns `202` with `"status": "QUEUED"` as if the send were accepted, but nothing is delivered. Add a go-live check that asserts the toggle is off, and confirm production responses do not carry the `X-Sandbox` header. ## Verify the Result [#verify-the-result] Every simulated response carries the `X-Sandbox: true` header, including error responses. Assert it in any test that must not send; if it is missing, the request executed for real. ## Troubleshooting [#troubleshooting] | Symptom | Likely cause | Fix | | --- | --- | --- | | No `X-Sandbox` header on the response | `sandbox` was not the JSON boolean `true`, or the endpoint does not support it | Send `"sandbox": true` in the request body and check the [supported endpoints table](/reference/api/test-mode#supported-endpoints). | | Tests fail with `401` | Missing or invalid API key | Sandbox requests still authenticate. Set `SENT_API_KEY` in the test environment. | | Follow-up reads return `404` | Sandbox responses contain generated sample IDs | Assert on the sandbox response itself, not on stored state. | ## Related [#related] # Two-Way Conversations (/start/guides/two-way-conversations.md) # Two-Way Conversations [#two-way-conversations] Sent's conversation window lets you hold a free-form, two-way conversation with a contact without managing per-channel session rules yourself. Sent owns the transport: the window state, cross-channel continuity, and compliance teardown. Your own agent (human or AI) owns the dialogue, integrating over webhooks and the freeform-send API. ## Conversation Windows [#conversation-windows] Free-form text (a message sent with `text` instead of `template`) is only allowed while a conversation with the contact is open. Two separate windows govern that, with two different clocks, and which ones apply depends on the channel. | | Sent's conversation rule | WhatsApp's customer-service window | |---|---|---| | Applies to | SMS, RCS, and auto-detect (`channel` omitted or `["sent"]`) | Sends pinned to `channel: "whatsapp"` | | Free-form allowed when | The contact has **ever** replied, at any time, on any channel | The contact messaged you on WhatsApp in the last **24 hours** | | If they have never replied | An approved template you sent in the last **7 days** on any channel | Not applicable: only an inbound opens Meta's window | | Whose rule | Sent's | Meta's | | Can be waived | No | No: the rule is Meta's | The two are independent. A send pinned to `channel: "whatsapp"` answers to Meta's window alone, so Sent's rule cannot rescue it and a template never opens it. Everything else answers to Sent's rule alone. ### Sent's conversation rule (SMS, RCS, auto-detect) [#sents-conversation-rule-sms-rcs-auto-detect] Once the contact has replied to you even once, free-form stays available indefinitely. A reply is consent to converse and it does not expire, so a contact who answered you months ago is still reachable with free-form text today. Only an opt-out ends it. The 7-day clock applies **only to contacts who have never replied**. It exists to stop a one-sided stream of free-form content riding on the back of a single template: with no reply, free-form is allowed for 7 days after the last approved template you sent, and then the conversation lapses until another template re-opens it. Both halves are cross-channel. A reply on WhatsApp unlocks free-form on SMS, and a template sent on SMS opens the 7-day window for RCS. Three things deliberately do not count: - **Your own free-form messages.** Only a reply from the contact or an outbound template counts, so sending free-form text every few days cannot extend the 7-day window of a contact who has never answered. - **A STOP exchange.** Neither an inbound opt-out keyword nor the opt-out confirmation you send back counts as engagement. `START` and `HELP` are treated as genuine engagement instead, and either leg of that exchange counts: the contact's inbound keyword does, and so does the auto-reply you send back, because it is an ordinary approved template and only opt-out auto-replies are excluded. Separately, Sent's compliance auto-replies are exempt from the gate itself, so an opt-out confirmation always goes out even when the contact's first-ever message is a STOP. - **An opt-out.** Consent is enforced before this gate, so an opted-out contact is blocked outright no matter how recently they replied. ### WhatsApp's 24-hour window [#whatsapps-24-hour-window] The 24-hour window applies to **WhatsApp only**, and it is Meta's rule rather than Sent's. When the contact messages you on WhatsApp, Meta opens a 24-hour window from the moment their message is received. While that window is open, you can respond with free-form text, no template required. An outbound template does **not** open Meta's window: only the contact can. This is why a past reply is not enough on WhatsApp the way it is on SMS and RCS. Meta requires a *recent* one, so a reply from last month leaves Meta's window shut even though Sent's rule is satisfied. The 24-hour countdown starts from the contact's last inbound WhatsApp message, not from when you sent the original outbound. Each new inbound from the contact resets the window. If the contact replies with an opt-out keyword (see [Keyword Detection](#keyword-detection)), it does not open a window. No free-text reply is sent; the keyword is handled by the compliance engine only. ### When WhatsApp's window is shut [#when-whatsapps-window-is-shut] On a send with `channel` omitted, Sent treats WhatsApp as unreachable while Meta's window is closed and falls back to RCS or SMS, so the message still goes out on the strength of Sent's rule. A send pinned to `channel: "whatsapp"` has nowhere to fall back to and fails with `WHATSAPP_TEMPLATE_REQUIRED`; see [Free-Form Send Errors](/start/guides/sending-messages#free-form-send-errors). --- ## How Inbound Messages Work [#how-inbound-messages-work] P["Contact receives\nthe message"] P --> A["Contact replies"] A --> B["Sent receives reply\non provisioned number"] B --> C{"Channel-scoped resolution"} C -- "No provider configured\nfor this channel" --> Z["Dropped, conversation\nhandling does not run"] C -- "Account matched" --> D["Persisted as RECEIVED\nReply-from-same-sender route seeded"] D --> KW{"Compliance keyword?\nSTOP · CANCEL · UNSUBSCRIBE · QUIT · END\nSTART · UNSTOP · SUBSCRIBE · HELP · INFO"} KW -- "Yes" --> KWA["Compliance engine runs\nNo free-text reply sent\n(keyword auto-reply template only)"] KW -- "No" --> CH{"Channel?"} CH -- "WhatsApp" --> WIN{"Within Meta's\n24-hour window?"} WIN -- "Yes" --> FREE1["Reply with free text"] WIN -- "No" --> EXP["Meta's window shut\nTemplate required on WhatsApp\n(auto-detect falls back to RCS or SMS)"] CH -- "SMS · RCS" --> FREE2["Reply with free text"] style O fill:#e8eaf6 style P fill:#e8eaf6 style D fill:#e8f5e8 style KWA fill:#fce4ec style FREE1 fill:#e1f5fe style FREE2 fill:#e1f5fe style EXP fill:#fff3e0 style Z fill:#ffebee `} darkTextAlways /> The chart follows a contact's reply, so Sent's rule is satisfied by definition on every path through it: the inbound *is* the reply that unlocks free-form. The lapsed case only arises for a contact who has never replied; see [Free-form send blocked after a quiet period](#free-form-send-blocked-after-a-quiet-period). ### 1. Account Resolution [#1-account-resolution] Sent matches an inbound message to your account using the **receiving number on that channel**: - **SMS**: matched via the phone number provisioned to your account - **WhatsApp**: matched via your WhatsApp number's `PhoneNumberId` If the receiving number isn't provisioned to any account on that channel, the inbound message is dropped. No account match, no storage. If a message arrives from a contact you have never interacted with or don't have registered, Sent automatically creates the contact record before responding. If the contact already exists, Sent replies directly without any additional steps. ### 2. Every Inbound Is Stored [#2-every-inbound-is-stored] Once the number resolves to your account, all inbound messages are stored as `RECEIVED` in the Sent backend, including keyword messages like `STOP` or `HELP`. Only non-keyword replies are surfaced in the message log and visible in the dashboard. If you have no provider configured for the inbound channel, that channel's conversation handling does not run and nothing is stored. ### 3. Reply From Same Sender Routing [#3-reply-from-same-sender-routing] When an inbound arrives, Sent records the channel, provider, and sender number it came in on. Future outbound messages to that contact will prefer the same sender, so your reply comes from the same number the contact originally wrote to. --- ## Keyword Detection [#keyword-detection] Sent enforces CTIA/TCPA rules for keyword handling. The rules are strict by design. Keywords fall into three groups: opt-out keywords such as `STOP` and `CANCEL`, opt-in keywords such as `START`, and help keywords such as `HELP`. The full default list and matching rules live in the [Two-Way Messaging Reference](/reference/two-way-messaging#default-keywords). **Exact match only.** The entire trimmed message body must equal the keyword, and case is ignored: `stop`, `Stop`, and `STOP` all match. `"Please stop messaging me"` does not. ### Custom Opt-Out Keywords [#custom-opt-out-keywords] You can extend the defaults with words that fit your brand or audience. For example, instead of `STOP` you could configure `NDALO` or any word your contacts are more likely to use. Custom keywords are configured in the dashboard under **Compliance → Opt Keywords**. The same exact-match rule applies: the entire trimmed message body must equal the configured keyword. Default keywords are seeded for every account and remain active alongside any custom keywords you add. ### RCS Suggestion Chips [#rcs-suggestion-chips] Sent appends a STOP suggestion chip to every outbound RCS message, so recipients can opt out with a single tap. Chip taps arrive as `message.received` events with the chip's reply text in `payload.text`. There is no separate event type, so handle them in the same webhook handler as typed replies. Taps on the built-in STOP chip carry opt-out postback data and are processed by the consent engine directly: the contact's `opt_out` flag is flipped without relying on keyword matching. Typed RCS replies go through standard keyword detection. ### STOP: Always Honored [#stop-always-honored] When a contact sends `STOP` (or any opt-out keyword), opt-out is recorded unconditionally. Sent does not check whether the receiving number is currently active or assigned. Consent suppression always wins. **Timing:** The auto-reply confirmation is sent **before** the consent write. This is intentional: TCPA permits one final message to confirm opt-out, so the reply goes out first, then the opt-out flag is set. ### START: Always Honored [#start-always-honored] When a contact sends `START` (or any opt-in keyword), opt-in is recorded unconditionally. If the sending number is not yet a contact, Sent creates the contact record first, then writes the opt-in consent, then sends the auto-reply. ### Cross-Channel Opt-Out [#cross-channel-opt-out] Opt-out is **contact-level and channel-agnostic**. A `STOP` received on any channel (SMS, RCS, or WhatsApp) suppresses the contact across all channels. Consent lives in one place: the `opt_out` flag on the contact record in your account. All outbound messages, including auto-replies, check this flag before sending, regardless of which channel they use. If you mirror consent into your own systems, see [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent). --- ## Auto-Replies [#auto-replies] Auto-replies are not special-cased messages. They go through the **same send pipeline** as any outbound message. That means they require: - An approved template configured for the action (STOP reply, START reply, HELP reply) - Consent to be valid (checked after the opt-out write for START; before for STOP) - A matching message route with a valid E.164 sender number **WhatsApp delivery format:** On WhatsApp, keyword auto-replies are delivered as free-form session text; opt templates are not registered with Meta. The reply is exempt from Sent's 24-hour window check, so it goes out even when the contact's previous WhatsApp message is older than 24 hours. The approval requirement is unchanged: the configured STOP/START/HELP template must still be approved, or the reply is silently skipped, exactly as on SMS and RCS. **Template must be approved (all channels).** Auto-replies using a template in `DRAFT` or `PAUSED` status will fail silently: the keyword is still processed, but no reply is sent. Make sure your STOP, START, and HELP templates are published. ### Routing Auto-Replies [#routing-auto-replies] Auto-replies are routed through the standard routing engine: the provider and sender number are resolved by the same routing rules as any outbound message (see [Channel Routing](/reference/channel-routing)). Phone numbers must be in **canonical E.164 format** (for example, `+14155551234`) on both the stored route and the contact record for a match to succeed. --- ## Channel Scope [#channel-scope] Two-way conversation features are not uniform across channels. The [feature matrix and provider support tables](/reference/two-way-messaging#channel-support) enumerate exactly what each channel supports; the short version: - **WhatsApp** runs the same keyword detection, opt-out, and auto-reply pipeline as SMS and RCS. A free-form send pinned to `channel: "whatsapp"` is governed by Meta's 24-hour customer-service window alone; auto-replies are delivered as free-form text and are exempt from the 24-hour window check, and the configured auto-reply template must still be approved for the reply to send. Meta also enforces its own opt-out natively (in-app block and report, quality rating); this is in addition to Sent's pipeline, not instead of it. - **RCS** supports the full two-way pipeline, gated by Sent's conversation rule, and every outbound RCS message carries a built-in STOP chip (see [RCS Suggestion Chips](#rcs-suggestion-chips)). - **SMS** two-way messaging is gated by the same conversation rule as RCS, and depends on the provider and number type. Only long codes and short codes on a route with an inbound (MO) path can receive inbound messages. Alphanumeric sender IDs are send-only, and Sent's SMPP routes have no inbound path. If you are using an alphanumeric sender ID, or a route that runs over one of Sent's SMPP connections, and contacts send keywords (STOP, START, HELP), those messages never reach Sent. --- ## Common Failure Scenarios [#common-failure-scenarios] These are the most frequent reasons two-way conversation handling silently stops working. ### SMS channel removed or unprovisioned [#sms-channel-removed-or-unprovisioned] If your SMS channel is removed or the provisioned number is no longer assigned, inbound messages on that number cannot be matched to your account. The opt-out (or any other keyword) is dropped. It is never processed. **Channel resolution must succeed before anything else runs.** If contacts are texting in and nothing is happening, verify that the SMS provider and number are still active and assigned under your channel settings. ### SMS provider or number type does not support inbound [#sms-provider-or-number-type-does-not-support-inbound] Two-way messaging on SMS requires both an MO-capable provider and a supported number type. **MO (Mobile Originated)** refers to a message that originates from a contact's phone and travels toward your app. An MO path is the provider's ability to receive those inbound messages and forward them to Sent. Providers that only support **MT (Mobile Terminated)** can deliver messages *to* a phone but cannot receive replies *from* one, making two-way messaging impossible on those routes. Two common silent failure points: - **Sent's SMPP routes**: carry delivery receipts only. No inbound message reaches your account, so nothing is stored or keyword-processed on these routes. This is a property of the routes Sent runs over SMPP today, not of the SMPP protocol, which is two-way. - **Alphanumeric sender IDs**: send-only by design. Contacts cannot reply to an alphanumeric sender; any attempt is dropped at the carrier level before it reaches Sent. If contacts are sending keywords and nothing is happening, start with the sender type, which you can read yourself. `GET /v3/channels` reports `number_type` for each market: a market on `ALPHANUMERIC` cannot receive replies at all, so that answers it. For the other sender types the inbound path depends on the provider Sent routes that market through, and the API does not report which provider that is. Ask [support@sent.dm](mailto:support@sent.dm) to confirm a market has an inbound path before you build a two-way flow on it. ### Free-form opt-out phrases are not recognized [#free-form-opt-out-phrases-are-not-recognized] Messages like `"Cancel my subscription"`, `"Please remove me"`, or `"I don't want these anymore"` do not trigger opt-out. Only an exact keyword match does. Contacts who send free-form messages will continue to receive outbound messages until they send an exact keyword (`STOP`, `CANCEL`, or a configured custom keyword). If your contacts are likely to use natural language, consider adding a custom keyword that matches a common phrase, but it must still be a single, exact token, not a sentence. ### Free-form send blocked after a quiet period [#free-form-send-blocked-after-a-quiet-period] This only affects contacts who have **never replied**. If the contact has answered you at any point, free-form stays available and a quiet period changes nothing. For a contact who has never replied, the conversation lapses 7 days after the last approved template you sent, and free-form sends are blocked with `CONVERSATION_TEMPLATE_REQUIRED` on SMS, RCS, and auto-detect until another template re-opens it. Your own free-form messages do not refresh that window, so a one-way stream of free-form text cannot keep it open. If a contact was reachable yesterday and is not today, check whether they have ever replied to you, and if not, when they last received a template; see [Conversation Windows](#conversation-windows). ### Auto-reply template not approved [#auto-reply-template-not-approved] If the template configured for a STOP, START, or HELP auto-reply is in `DRAFT` or `PAUSED` status, the keyword is still processed (the opt-out is written) but no confirmation reply is sent. Contacts will not receive any acknowledgement. Resolve this by publishing the template in the dashboard. See [Working with Templates](/start/guides/working-with-templates) for approval steps. --- ## Receiving Inbound Messages via Webhook [#receiving-inbound-messages-via-webhook] Subscribe to `message.received` events to be notified in real time when a contact replies. The webhook fires for every inbound message, keywords included, and carries the message text, channel, and sender number. Use `message_id` as your idempotency key, because the same event can be delivered more than once. [Receiving Inbound Messages](/start/webhooks/receiving-inbound-messages) walks through a complete handler: acknowledging deliveries, deduplicating, storing the message, and skipping compliance keywords. Payload fields are documented in the [Events Reference](/start/webhooks/event-types). --- ## Retrieving Conversations [#retrieving-conversations] Sent groups the messages between you and a single contact into a conversation: one continuous thread across every channel. The conversation id is deterministic, computed from your account's customer id and the contact id, so the same pair always produces the same id no matter which sender number or channel carried the messages. The reason for this design is continuity: a contact who replies over SMS today and WhatsApp tomorrow is still one conversation. Two endpoints expose conversation history, `GET /v3/conversations` and `GET /v3/conversations/{id}`. Parameters, response shapes, and the id derivation are documented in the [conversation history endpoints reference](/reference/two-way-messaging#conversation-history-endpoints). --- ## Where to Go Next [#where-to-go-next] Sent owns the transport of a two-way conversation: inbound matching and storage, keyword compliance, auto-replies, and cross-channel continuity. You own the dialogue, through webhooks and the send API. - [Receiving Inbound Messages](/start/webhooks/receiving-inbound-messages): build the webhook handler for contact replies - [Two-Way Messaging Reference](/reference/two-way-messaging): keywords, channel support, and conversation endpoints - [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent): mirror consent state into your own systems - [Working with Templates](/start/guides/working-with-templates): publish the templates that auto-replies depend on # Connect a voice agent (Preview) (/start/guides/voice-agent-connect.md) # Connect a voice agent (Preview) [#connect-a-voice-agent-preview] **Preview.** This page describes version 0.2.0 of the Sent Voice Agents protocol, spoken over the `sent.voice.v1` WebSocket subprotocol. A 0.x release can still change frames before 1.0. The specification, the JSON Schema of every frame and the conformance scenarios are in the [sent-dm-voice-protocol](https://github.com/sentdm/sent-dm-voice-protocol) repository. A voice agent is on a call as a session over a WebSocket. Either your agent opens the connection to Sent and holds it, or Sent opens one to your agent for each call. The frames are the same either way: Sent tells the agent a call has started, the two exchange text or audio, the agent acts on the call with tools, and Sent tells the agent when the call has left it. This guide covers getting connected and keeping the connection healthy. The frames themselves are in the [voice agent protocol](/reference/api/voice-agent-protocol). ## Prerequisites [#prerequisites] - A voice agent, created with `POST /v3/voice/agents`. See [Voice agents](/start/guides/voice-agents). - Phone calls enabled for your account, and a number bound to the agent, so that a call can reach it. - A WebSocket client, or a WebSocket server when Sent connects to you, in your agent's language. Frames are JSON text messages, one per message, plus binary messages for audio. The [sample agents](https://github.com/sentdm/sent-dm-voice-protocol/tree/main/examples) in the protocol repository connect in, answer pings, play the caller's audio back in an audio session, and move their sessions when a connection drains. ## Your agent connects to Sent [#your-agent-connects-to-sent] This is how an agent without a `websocket_url` works. Open one WebSocket to Sent with your account API key as a bearer token, and ask for the `sent.voice.v1` subprotocol: ``` GET wss://voice.sent.dm/v1/agents/connect?agent_id=agent_9f2ab000-0000-4000-8000-000000000001 Authorization: Bearer sk_live_... Sec-WebSocket-Protocol: sent.voice.v1 ``` Never put the key in the URL. Sent refuses the upgrade with: | Status | When | | :--- | :--- | | `400` | `agent_id` or the `sent.voice.v1` subprotocol is missing | | `401` | The key isn't valid | | `403` | Phone calls aren't enabled for your account, or the key's account doesn't own the agent | | `404` | The agent doesn't exist | Once connected, the first frame Sent sends is `connection.ready`. It carries the `protocol_version` Sent speaks, `heartbeat_interval_ms`, and `max_sessions`, the most sessions Sent puts on this connection at once. From then on, every call to a number bound to the agent arrives as a `session.start` frame. ```typescript import WebSocket from 'ws'; const ws = new WebSocket( 'wss://voice.sent.dm/v1/agents/connect?agent_id=agent_9f2ab000-0000-4000-8000-000000000001', 'sent.voice.v1', { headers: { Authorization: `Bearer ${process.env.SENT_API_KEY}` } }, ); const send = (frame) => ws.send(JSON.stringify(frame)); ws.on('message', (data, isBinary) => { if (isBinary) return; // audio sessions only, see the protocol reference const frame = JSON.parse(data.toString()); switch (frame.type) { case 'ping': send({ type: 'pong', ts: frame.ts }); break; case 'session.start': // A text session. With a greeting set on the agent, Sent speaks it first. send({ type: 'agent.say', session_id: frame.session_id, text: 'Hi, this is Acme. How can I help?' }); break; case 'user.said': // Hand frame.text to your model, then speak the reply send({ type: 'agent.say', session_id: frame.session_id, text: replyTo(frame.text) }); break; case 'session.end': console.log(`Session ${frame.session_id} ended: ${frame.reason}`); break; } }); ``` ```python import asyncio, json, os import websockets URL = "wss://voice.sent.dm/v1/agents/connect?agent_id=agent_9f2ab000-0000-4000-8000-000000000001" async def run(): async with websockets.connect( URL, subprotocols=["sent.voice.v1"], additional_headers={"Authorization": f"Bearer {os.environ['SENT_API_KEY']}"}, ) as ws: async for message in ws: if isinstance(message, bytes): continue # audio sessions only, see the protocol reference frame = json.loads(message) if frame["type"] == "ping": await ws.send(json.dumps({"type": "pong", "ts": frame["ts"]})) elif frame["type"] == "session.start": await ws.send(json.dumps({"type": "agent.say", "session_id": frame["session_id"], "text": "Hi, this is Acme. How can I help?"})) elif frame["type"] == "user.said": await ws.send(json.dumps({"type": "agent.say", "session_id": frame["session_id"], "text": reply_to(frame["text"])})) elif frame["type"] == "session.end": print(f"Session {frame['session_id']} ended: {frame['reason']}") asyncio.run(run()) ``` ### One connection, many sessions [#one-connection-many-sessions] Sessions on one connection run at the same time, each named by its `session_id`, and their frames interleave. Frames for one session arrive in the order they were sent. To take more calls than `max_sessions`, open more connections, for example one per process. Sent spreads calls across the connections you hold open, and the agent's `limits.max_concurrent_calls` caps the total. Sent checks the key behind every open connection again about once a minute. A key you revoke, an agent you delete, or phone calls turned off for the account close the connection with code `4003` within about two minutes, and its sessions end. ### Answer every ping [#answer-every-ping] Sent sends a `ping` frame on every connection at `heartbeat_interval_ms`, 5,000 ms. Answer each one with a `pong` carrying the same `ts`. When three pings in a row go unanswered, Sent closes the connection with code `4008` and its sessions detach, as [Resume a session after a lost connection](#resume-a-session-after-a-lost-connection) describes. When no `ping` reaches you for three intervals, treat the connection as dead, open a new one, and resume your sessions there. Heartbeats also keep idle proxies and load balancers from closing the connection between calls. ### When Sent drains the connection [#when-sent-drains-the-connection] A `connection.draining` frame means Sent starts no more sessions on this connection, while the sessions already on it go on. Sent sends it before it restarts the side that holds your connection, so an agent that handles it keeps its callers through a Sent deploy. 1. Open a new connection for the same `agent_id` with the same key, straight away, so that new calls keep reaching the agent. 2. After its `connection.ready`, send `session.resume` on the new connection for each session on the old one, with the session's latest `token`, from its `session.start` or its last `session.resumed`, and `received`, how many of Sent's counted frames for the session you've read. See [Resume a session after a lost connection](#resume-a-session-after-a-lost-connection). 3. Once `session.resumed` arrives, the session is on the new connection, and the old one carries nothing more for it. Sent closes the drained connection with code `1001` once no session is left on it. The [sample agents](https://github.com/sentdm/sent-dm-voice-protocol/tree/main/examples) do this. Close a connection with code `1000` only when the agent means to stop serving its calls: its sessions end at once and the calls follow the agent's `fallback`. Any other close is treated as a loss, and the sessions wait for a resume. ## Sent connects to your agent [#sent-connects-to-your-agent] This is how an agent with a `websocket_url` works. For each call, Sent opens one WebSocket to that URL, offering the `sent.voice.v1` subprotocol, sends `connection.ready` with room for one session, then `session.start`, and closes the connection with code `1000` after `session.end`. Your server may select the subprotocol or none. The URL must use `wss` and resolve to a public address. Sent resolves the host when it connects, refuses a private, loopback, or link-local address, follows no redirect, and uses no proxy. A handshake that isn't accepted within 5 seconds declines the call, which then follows the agent's `fallback`. ### Verify the handshake [#verify-the-handshake] Sent signs the handshake the way it signs every webhook, with the agent's `signing_secret`: | Header | Value | | :--- | :--- | | `X-Webhook-ID` | The agent id, whose `signing_secret` signed the handshake | | `X-Webhook-Event-ID` | The session id, to deduplicate on | | `X-Webhook-Timestamp` | Unix seconds when Sent signed the handshake | | `X-Webhook-Signature` | `v1,` followed by the Base64 HMAC-SHA256 described below | The signature is HMAC-SHA256 of `{X-Webhook-ID}.{X-Webhook-Timestamp}.` followed by an empty payload, because a handshake has no body. The key is the `signing_secret` with its `whsec_` prefix removed, then Base64-decoded. The verifier you run for [webhooks](/start/webhooks/signature-verification) works unchanged with an empty payload. Refuse the handshake with `401` when the signature doesn't match, when the timestamp is more than 5 minutes from your clock, or when you've seen the `X-Webhook-Event-ID` before. ```typescript import { createHmac, timingSafeEqual } from 'node:crypto'; import { WebSocketServer } from 'ws'; const TOLERANCE_SECONDS = 300; const seen = new Set(); // session ids already accepted; bound its size in a real server function verifySentHandshake(headers, secret) { const id = headers['x-webhook-id']; const eventId = headers['x-webhook-event-id']; const timestamp = headers['x-webhook-timestamp']; const signature = headers['x-webhook-signature']; if (!id || !eventId || !timestamp || !signature) return false; const skew = Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)); if (!Number.isFinite(skew) || skew > TOLERANCE_SECONDS) return false; if (seen.has(eventId)) return false; const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const expected = createHmac('sha256', key).update(`${id}.${timestamp}.`).digest(); const ok = signature .split(/\s+/) .filter((part) => part.startsWith('v1,')) .some((part) => { const provided = Buffer.from(part.slice(3), 'base64'); return provided.length === expected.length && timingSafeEqual(provided, expected); }); if (ok) seen.add(eventId); return ok; } // Behind TLS: the agent's websocket_url is wss://, so terminate TLS in front of this server const server = new WebSocketServer({ port: 8080, handleProtocols: (protocols) => (protocols.has('sent.voice.v1') ? 'sent.voice.v1' : false), verifyClient: ({ req }, done) => { const ok = verifySentHandshake(req.headers, process.env.SENT_AGENT_SIGNING_SECRET); done(ok, ok ? 200 : 401, ok ? undefined : 'Invalid signature'); }, }); server.on('connection', (ws) => { // One session per connection: connection.ready, session.start, the call, session.end, then Sent closes with 1000 }); ``` `POST /v3/voice/agents/{id}/rotate-secret` answers with the new `signing_secret` and the old one stops signing at once, so install the new secret on the server straight after the call. Handshakes in between fail verification, so rotate at a quiet moment, and let the verifier accept both secrets while the switch is under way if calls can't wait. A session on a connection Sent opened can't be resumed: when the connection is lost, the session ends with `agent_unreachable` at once and the call follows the agent's `fallback`. ## A session, start to end [#a-session-start-to-end] For each session, Sent's first frame is `session.start` and its last is `session.end`. After `session.end` the agent sends nothing more for that session. 1. **`session.start`** names the session, the call, the agent, the parties and the `session_type`. On a text session it carries the `language` from the agent's `speech`. On an audio session it carries `audio.stream` and `audio.sample_rate`. 2. **The greeting**, when the agent has one, is spoken by Sent right after `session.start`. Otherwise the agent speaks first or waits for the caller. 3. **Text sessions** exchange `user.said` and `agent.say`. **Audio sessions** exchange binary messages of 16-bit little-endian mono PCM at `audio.sample_rate`, each with a 2-byte big-endian stream id in front, 20 ms of audio per message. Both can send `agent.clear` to drop what Sent hasn't played yet. 4. **Tools** act on the call: `tool.call` from the agent, answered by exactly one `tool.result`. 5. **`session.end`** says why the call left the agent: the caller hung up, the agent hung up or transferred, the call reached `max_call_seconds`, or the agent became unreachable. Every frame and field is in the [voice agent protocol](/reference/api/voice-agent-protocol), with a worked text session. ## Resume a session after a lost connection [#resume-a-session-after-a-lost-connection] The calls on a connection your agent opened outlive the connection. A network fault, your own deploy or a load balancer closing a long-lived socket ends the connection while the callers are still on the line. The agent picks their sessions up on a new connection, within a window. A session that can be resumed has `resume` in its `session.start`: a `token` and `window_ms`, how long Sent keeps the session after its connection is lost. Each `session.resumed` brings the next token. The token is a secret that resumes this one session, once, on a connection opened for the same `agent_id` with the same key. Keep it out of URLs and logs. While a session is detached: - Speech and audio the agent sent, and Sent hasn't played yet, keep playing, and a tool queued behind them still runs. - The caller's audio is dropped and isn't replayed. - Sent keeps the frames it would have sent, such as `user.said` and `tool.result`, to replay on the new connection. A call that ends meanwhile keeps its `session.end` for the replay too. When `window_ms` passes with the session still detached, Sent ends it with `agent_unreachable`, and the call follows the agent's `fallback`. To resume, open a new connection for the same `agent_id` with the same key. After `connection.ready`, send one `session.resume` per session, with its latest `token` and `received`, how many of Sent's frames for the session you've read: ```json { "type": "session.resume", "session_id": "vs_7Hq2Lm9xQa", "token": "vsr_example_token_000000000000000001", "received": 4 } ``` Sent answers each one with: | Answer | What it means | | :--- | :--- | | `session.resumed` | The session is on this connection. Sent's frames you haven't read follow, in order, then the session goes on | | `error` with `connection_full` | This connection already carries `max_sessions` sessions. Resume on another connection, with the same token | | `error` with `resume_failed` | The token isn't valid, or the session can no longer be resumed. Treat it as ended with `agent_unreachable` | `session.resumed` carries `received`, how many of your frames Sent read. Send the later ones again if they still matter: a `tool.call` Sent never read gets no `tool.result`. It carries the next `resume` token while the session is live, and on an audio session the `stream` number to use on this connection. Once you've sent `session.resume`, read and send nothing more for the session on the old connection, and nothing on the new one before `session.resumed`. Each side counts the frames it sends for a session, and keeps its last 32 to send again. The agent's counted frames are `agent.say`, `tool.call` and `agent.clear`. Sent's are `user.said`, `tool.result` and `session.end`. `session.start`, `session.resume`, `session.resumed`, `error` and binary audio aren't counted. A frame type you don't know counts when it carries your session's `session_id`. An agent that streams one reply in more than 32 pieces can outrun the window. To resume after your own restart, the new process needs each session's token and count, and what the agent knows about the call. An agent that ignores `resume` keeps working, but when its connection is lost its calls wait `window_ms` before they follow `fallback`. ## Next steps [#next-steps] # Voice agents (/start/guides/voice-agents.md) # Voice agents [#voice-agents] A voice agent is a program of yours that takes phone calls to your numbers over a WebSocket, instead of your callback URL deciding each call. You describe the agent to Sent once with `POST /v3/voice/agents`: whether it works in text or in audio, how the caller is spoken to, what it may do to a call, and where it may transfer one. Then you bind a number to it. Every call to that number reaches your agent as a session, and the `call.*` webhooks and `GET /v3/voice/calls` report it like any other call. This guide covers the agent record. How the agent connects, and what it exchanges with Sent while a call is on, is in [Connect a voice agent](/start/guides/voice-agent-connect) and the [voice agent protocol](/reference/api/voice-agent-protocol). ## Prerequisites [#prerequisites] Phone calls must be enabled for your account. This is set by Sent: contact [support@sent.dm](mailto:support@sent.dm) to request it. You can create agents before that, but no call reaches them and no agent can connect until calls are on. You also need: - A number with calls turned on. See [Voice](/start/guides/managing-channels#voice) in the channels guide. - A webhook subscribed to `call` events, so you learn when an agent takes a call and when the call ends. See the [`call` events](/start/webhooks/event-types#call). - A WebSocket client in the language your agent is written in, or a [Voice Agents SDK](/sdks/voice-agents/python) (Python, TypeScript, .NET, Go, Rust and Java). The protocol is JSON frames, plus binary messages for audio, so no SDK is needed. The [sample agents](https://github.com/sentdm/sent-dm-voice-protocol/tree/main/examples) in the protocol repository show the frames in use. All requests authenticate with the `x-api-key` header. Agent ids look like `agent_9f2ab000-0000-4000-8000-000000000001`. Anything else in the path is refused with `400`. ## Text or audio [#text-or-audio] Every agent has a `session_type`, which decides what travels between Sent and the agent while a call is on. | `session_type` | What the agent exchanges | Choose it when | | :--- | :--- | :--- | | `text` | Sent turns the caller's speech into text and sends it to the agent as `user.said` frames. The agent answers with `agent.say` frames, which Sent speaks to the caller in the voice and language from `speech`. | Your agent is a language model or a script that works in text, and you don't run speech recognition or synthesis yourself | | `audio` | Sent sends the caller's audio as 16-bit PCM and plays the audio the agent sends back, at `audio.sample_rate`. | Your agent runs its own speech, for example a speech-to-speech model | A text agent carries `speech` and may carry a `greeting`. An audio agent carries `audio`. Sending the other type's settings is refused with `400`. ## Create an agent [#create-an-agent] [`POST /v3/voice/agents`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsCreateVoiceAgentEndpoint) creates an agent and returns it with its signing secret: ```bash curl -X POST "https://api.sent.dm/v3/voice/agents" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Receptionist", "session_type": "text", "websocket_url": "wss://agent.example.com/calls", "greeting": "Thanks for calling Example. How can I help?", "tools": ["hangup", "transfer"], "transfer_targets": [{ "kind": "number", "value": "+12125550100" }], "fallback": { "kind": "number", "value": "+12125550100" } }' ``` Only `name` and `session_type` are required. Every other field has a default. | Field | Description | | :--- | :--- | | `name` | A name for your own reference, 1 to 100 characters. Required | | `session_type` | `text` or `audio`. Required. See [Text or audio](#text-or-audio) | | `websocket_url` | Where Sent connects to your agent for each call: an absolute `wss://` URL on a public host, without credentials, at most 2,048 characters. Leave it out and your agent connects to Sent instead. See [Connect in, or be connected to](#connect-in-or-be-connected-to) | | `speech` | Text agents only. `setting` is `standard`, the one setting accepted. `voice` and `language` are names from `GET /v3/voice/voices`, `emma` and `en-US` when left out. See [Voices and languages](#voices-and-languages) | | `audio` | Audio agents only. `sample_rate` is the samples per second of the audio exchanged, `8000`, `16000` or `24000`, `16000` when left out | | `greeting` | Text agents only. What the caller hears as soon as the call is answered, before the agent's first turn, 1 to 4,096 characters. Leave it out and the agent speaks first | | `tools` | What the agent may do to a call: any of `transfer`, `hangup`, `send_dtmf` and `hold`. `["hangup"]` when left out. `transfer` needs at least one entry in `transfer_targets`. See [Tools and transfer targets](#tools-and-transfer-targets) | | `transfer_targets` | Where the agent may transfer a call, up to 20 parties, each `{ "kind": ..., "value": ... }`. The agent can only transfer to a party listed here | | `fallback` | Who takes a call the agent can't: a phone number, as `{ "kind": "number", "value": "+12125550100" }`. Leave it out and such a call is hung up. See [Fallback](#fallback) | | `limits` | `max_call_seconds`, `max_concurrent_calls` and `allowed_countries`. See [Limits](#limits) | | `transcripts` | `store` and `retention_days`. See [Transcripts](#transcripts) | The response is the agent as stored, every default filled in, plus `signing_secret`: ```json { "success": true, "data": { "id": "agent_9f2ab000-0000-4000-8000-000000000001", "name": "Receptionist", "session_type": "text", "websocket_url": "wss://agent.example.com/calls", "speech": { "setting": "standard", "voice": "emma", "language": "en-US" }, "audio": null, "greeting": "Thanks for calling Example. How can I help?", "tools": ["transfer", "hangup"], "transfer_targets": [{ "kind": "number", "value": "+12125550100" }], "fallback": { "kind": "number", "value": "+12125550100" }, "limits": { "max_call_seconds": 3600, "max_concurrent_calls": 10, "allowed_countries": null }, "transcripts": { "store": false, "retention_days": 30 }, "signing_secret": "whsec_MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA=", "created_at": "2026-10-23T12:00:00+00:00", "updated_at": null }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-10-23T12:00:00+00:00", "version": "v3" } } ``` `signing_secret` is shown here and by `POST /v3/voice/agents/{id}/rotate-secret`, nowhere else. Store it now. It's the key Sent signs the handshake with when it connects to your `websocket_url`, so an agent that is connected to needs it to verify that a connection came from Sent. See [Verify the handshake](/start/guides/voice-agent-connect#verify-the-handshake). `id` is also what the agent connects to Sent as. `tools` comes back as a set in one fixed order, whatever order you sent, so two bodies naming the same tools read the same. | Status | Meaning | | :--- | :--- | | `201` | The agent, with `signing_secret` | | `202` | Sandbox: what would have been written, under an id and a secret nothing stores | | `400` `VALIDATION_001` | A field is missing or out of range. `error.details` names each field at fault | | `409` `BUSINESS_031` | Your account holds as many voice agents as it may. The message says how many. Delete one first | ### What is refused [#what-is-refused] A `400` carries `details` keyed by the path of each field at fault, so one response reports every problem: ```json { "success": false, "status": 400, "error": { "code": "VALIDATION_001", "message": "The agent is invalid", "details": { "tools[1]": ["Must be one of transfer, hangup, send_dtmf, hold."], "transfer_targets": ["Required when tools includes transfer: name at least one target."] }, "doc_url": "https://docs.sent.dm/reference/api/error-catalog" }, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-10-23T12:00:00+00:00", "version": "v3" } } ``` The rules, by field: - `name`: 1 to 100 characters after trimming. - `session_type`: `text` or `audio`, matched ignoring case. - `websocket_url`: an absolute URL with the `wss` scheme, no username or password, at most 2,048 characters, on a public host. A literal private, loopback or link-local address is refused here. A hostname is accepted here and judged when Sent connects, so a name that resolves to a private address fails the call, not the request. - `speech.setting`: `standard`. `speech.voice` and `speech.language`: a voice name and a language from `GET /v3/voice/voices`, matched ignoring case. `speech` on an audio agent is refused. - `audio.sample_rate`: `8000`, `16000` or `24000`. `audio` on a text agent is refused. - `greeting`: 1 to 4,096 characters, text agents only. - `tools[i]`: one of the four tools. A tool named twice counts once. - `transfer_targets`: at most 20 entries. `kind` is `number`, `user` or `agent`. A `number` is written in E.164 and must be in a country Sent allows calls to. A `user` is an identity: letters, digits, `-` and `_`. An `agent` is an agent id of one of your own agents, and not the agent being written. A party listed twice counts once. - `fallback`: `kind` is `number` only, with the same number rules. - `limits.max_call_seconds`: 60 to 14,400. `limits.max_concurrent_calls`: from 1 up to a cap on your account. `limits.allowed_countries`: at least one ISO 3166-1 alpha-2 code when the field is sent, a code listed twice counts once. - `transcripts.retention_days`: 1 to 365. ## Voices and languages [#voices-and-languages] [`GET /v3/voice/voices`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceVoicesGetVoicesEndpoint) lists the names a text agent's `speech.voice` and `speech.language` accept: ```bash curl "https://api.sent.dm/v3/voice/voices" \ -H "x-api-key: $SENT_API_KEY" ``` ```json { "success": true, "data": { "voices": [ { "name": "emma", "language": "en-US", "description": "US English, female. The voice a call uses when the agent names none.", "default": true }, { "name": "joanna", "language": "en-US", "description": "US English, female.", "default": false } ], "languages": ["en-US"] }, "error": null } ``` | Field | Description | | :--- | :--- | | `voices[].name` | The value to send as `speech.voice` | | `voices[].language` | The language the voice speaks | | `voices[].default` | `true` on the voice an agent uses when it names none | | `languages` | The BCP 47 tags accepted as `speech.language`. The language is what Sent listens for as well as what it speaks | The catalogue grows as voices are added, and a name is never removed without notice, so read it rather than hard-coding a list. The names are Sent's own. An audio agent uses none of this, because it runs its own speech. ## Connect in, or be connected to [#connect-in-or-be-connected-to] An agent reaches Sent in one of two ways, decided by `websocket_url`. The frames are the same either way. | `websocket_url` | Who connects | What authenticates | | :--- | :--- | :--- | | Left out | Your agent opens one long-lived WebSocket to `wss://voice.sent.dm/v1/agents/connect` and holds it. Every call to a number bound to the agent arrives on it as a session | Your account API key, as a bearer token on the handshake | | Set | Sent opens one WebSocket to your URL for each call, and closes it when the call leaves the agent | The handshake Sent sends is signed with the agent's `signing_secret`, the way your webhooks are | Choose the first when your agent is a service you run that can hold a connection open. Choose the second when you'd rather be called, for example from a serverless platform that accepts WebSockets. The handshake, the frames and how a session survives a lost connection are in [Connect a voice agent](/start/guides/voice-agent-connect). ## Tools and transfer targets [#tools-and-transfer-targets] `tools` says what the agent may do to a call, beyond talking. The agent asks with a `tool.call` frame, and Sent answers with a `tool.result`. | Tool | What it does | | :--- | :--- | | `hangup` | Ends the call. The session ends with reason `agent_hung_up` | | `transfer` | Dials a party in `transfer_targets` while the caller stays with the agent. When the target answers, the caller and the target are bridged, the session ends with reason `transferred`, and the call goes on without the agent. A target that doesn't connect answers the tool with `failed` and the message `The transfer did not connect.`, and the caller stays with the agent | | `send_dtmf` | Plays keypad tones on the call, to work a menu on the other end | | `hold` | Puts the caller on hold with music, and takes them off again | A tool the agent isn't allowed answers `tool_not_allowed`, and a transfer to a party that isn't listed answers `target_not_allowed`. Keep `tools` to what the agent needs. An agent that only answers questions needs `["hangup"]`, the default. `transfer_targets` is the whole list of where the agent may send a call: ```json { "tools": ["hangup", "transfer"], "transfer_targets": [ { "kind": "number", "value": "+12125550100" }, { "kind": "user", "value": "support-desk" }, { "kind": "agent", "value": "agent_4c1d2e3f-0000-4000-8000-000000000002" } ] } ``` | `kind` | `value` | Where the call goes | | :--- | :--- | :--- | | `number` | A phone number in E.164 format | The number is dialled with your number as the caller id, and the caller is bridged to it once it answers | | `user` | The identity of one of your app users | Accepted as a target. A transfer to it answers `failed` with a message that says it's not available, and the caller stays with the agent | | `agent` | The id of another of your agents | Accepted as a target. A transfer to it answers `failed` with a message that says it's not available, and the caller stays with the agent | Only a `number` target connects a transfer. List a `user` or an `agent` when you want the agent to know about them, and have the agent treat a `failed` result as the caller still being on the line. An agent that lists another agent as a target holds that agent: the other one can't be deleted until it's removed from the list. See [Delete an agent](#delete-an-agent). ## Fallback [#fallback] `fallback` is who takes a call to the agent's number when the agent can't. It's a phone number. A call goes there when: - the agent connects in and isn't connected when the call arrives, - the agent is connected to and the connection to `websocket_url` fails or isn't accepted in time, - the agent's connection is lost during a call and the session isn't resumed within the resume window. Without a `fallback`, such a call ends as `FAILED` with reason `agent_unreachable`, and you receive `call.failed`. A fallback leg to a phone number costs money for as long as it runs, like any other phone leg, and needs a balance that affords it. The call record names the number in `connected_number` and is billed for both legs, listed in `legs`. See [The Call Record](/start/guides/managing-calls#the-call-record). A call the agent refuses for being over `max_concurrent_calls` doesn't go to the fallback: it fails with `agent_busy`. ## Limits [#limits] | Field | Description | | :--- | :--- | | `max_call_seconds` | The longest a call to the agent may last, 60 to 14,400 seconds, 3,600 when left out. The session ends with reason `max_duration` when it's reached, and the call ends `COMPLETED`. A call also ends when your balance stops affording it | | `max_concurrent_calls` | How many calls the agent may have going at once, from 1, 10 when left out. A call past it isn't offered to the agent: it fails with `agent_busy`. Your account has a cap on this value, and a body over it is `400` | | `allowed_countries` | ISO 3166-1 alpha-2 codes of the countries the agent may call. Leave it out to allow every country. An empty list is refused. A transfer is checked against `transfer_targets`, not against this list | ## Transcripts [#transcripts] `transcripts.store` and `transcripts.retention_days` are stored on the agent: whether Sent keeps the transcript of every call the agent takes, and for how many days, 1 to 365. They default to `false` and 30. No endpoint reads a transcript, so an agent that needs a record of a call keeps its own: a text agent sees every utterance as `user.said` and `agent.say` frames. ## Bind a number to the agent [#bind-a-number-to-the-agent] A call reaches the agent through one of your voice numbers. Bind the number with `agent_id` on [`PATCH /v3/channels/voice/{number}`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsPatchVoiceChannelEndpoint), or on [`POST /v3/channels/voice`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddVoiceChannelEndpoint) when you turn calls on for the number: ```bash curl -X PATCH "https://api.sent.dm/v3/channels/voice/%2B12125550100" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "agent_id": "agent_9f2ab000-0000-4000-8000-000000000001" }' ``` ```json { "success": true, "data": { "number": "+12125550100", "status": "ACTIVE", "default_for_app_calls": true, "callback_url": "https://example.com/voice", "agent_id": "agent_9f2ab000-0000-4000-8000-000000000001", "routes_to": "agent_pending", "created_at": "2026-07-22T12:00:00+00:00", "updated_at": "2026-10-23T12:00:00+00:00" }, "error": null } ``` `routes_to` says who answers calls to the number: | `routes_to` | Who answers | | :--- | :--- | | `agent` | The agent in `agent_id` | | `agent_pending` | That agent, once the provider has finished moving the number to it. The response to the bind often reads this, because the provider applies the move on its own clock. Read the number again: it settles to `agent` once the provider has recorded the move | | `callback` | Your `callback_url`, as in [Answering calls](/start/guides/answering-calls) | | `none` | Nobody. Calls to the number are declined | Calls follow the change within about an hour, both ways: a call to the number in that hour may still reach your callback, or be declined, and after an unbind may still reach the agent. `routes_to` says what Sent has recorded, not which calls have moved yet, so bind a number before you need it and test with a call. The agent wins over `callback_url` for calls to the number. Calls your app places from the number, with a voice token bound to it, still go through your callback, so one number can serve both. Send `"agent_id": null` to unbind the agent, after which `callback_url` answers again. An `agent_id` that isn't one of your agents is `404`. A number the provider couldn't move to or from the agent is `502` with `BUSINESS_027`, and nothing is written, so repeat the request. The rest of the number's settings are in [Managing channels](/start/guides/managing-channels#voice). ## List and read agents [#list-and-read-agents] [`GET /v3/voice/agents`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsGetVoiceAgentsEndpoint) lists your agents, newest first, in pages of `page_size` (1 to 100, default 20) starting at `page` 1: ```bash curl "https://api.sent.dm/v3/voice/agents?page=1&page_size=20" \ -H "x-api-key: $SENT_API_KEY" ``` The response carries the page under `agents` and a `pagination` object, as every paginated list does. [`GET /v3/voice/agents/{id}`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsGetVoiceAgentEndpoint) reads one agent, in the shape the create returned. Neither carries `signing_secret`: it's never on a read. An agent that isn't yours is `404`, not `403`. ## Change an agent [#change-an-agent] [`PATCH /v3/voice/agents/{id}`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsPatchVoiceAgentEndpoint) changes the fields you name and answers with the agent as stored, the same shape `GET` returns: ```bash curl -X PATCH "https://api.sent.dm/v3/voice/agents/agent_9f2ab000-0000-4000-8000-000000000001" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "greeting": null, "tools": ["hangup", "transfer", "hold"], "limits": { "max_call_seconds": 1800, "max_concurrent_calls": 10 } }' ``` | Body | Effect | | :--- | :--- | | Key left out | Left exactly as it is | | Key sent as `null` | Cleared. `websocket_url` makes the agent connect in. `greeting` and `fallback` go. `transfer_targets` empties. `speech`, `audio`, `tools`, `limits` and `transcripts` return to their defaults | | Key sent with a value | Replaced whole. Send the whole `limits` object, not the one key you're changing, because the keys you leave out return to their defaults | | `session_type` changed | `speech`, `audio` and `greeting` are dropped unless the body sends them, because the other type can't carry them | The result is checked by the same rules as a new agent, so a `PATCH` that leaves `transfer` in `tools` while emptying `transfer_targets` is `400`. A body that changes nothing is `400` too, and so is a body that names no field at all. The signing secret is never touched here. A change reaches calls that start after it. Calls already on the agent keep the settings they started with. With `sandbox: true` nothing is written: the request is validated against the stored agent and the agent is reported with `200` as it would read after the change. ## Rotate the signing secret [#rotate-the-signing-secret] [`POST /v3/voice/agents/{id}/rotate-secret`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsRotateVoiceAgentSecretEndpoint) generates a new `signing_secret` and returns it: ```bash curl -X POST "https://api.sent.dm/v3/voice/agents/agent_9f2ab000-0000-4000-8000-000000000001/rotate-secret" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' ``` ```json { "success": true, "data": { "signing_secret": "whsec_MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA=" }, "error": null } ``` The previous secret stops signing the moment the response is returned, so install the new one on your agent straight after the call. Handshakes in between fail verification: rotate at a quiet moment, and let the verifier accept both secrets while the switch is under way if calls can't wait. The secret only matters to an agent Sent connects to. An agent that connects in authenticates with your API key, and rotating its secret changes nothing it uses. With `sandbox: true` a secret is generated and returned with `202`, and nothing is written. ## Delete an agent [#delete-an-agent] [`DELETE /v3/voice/agents/{id}`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceAgentsDeleteVoiceAgentEndpoint) removes the agent. The response is `204`. Calls it already took keep their `agent_id`, so your call history stays readable. An agent that something still points at isn't deleted: | Response | Meaning | | :--- | :--- | | `404` `RESOURCE_013` | Your account has no such agent | | `409` `CONFLICT_014` | A voice number of yours routes calls to the agent, or another of your agents lists it in `transfer_targets`. The message names the numbers and the agents | To delete it, first unbind each number with `PATCH /v3/channels/voice/{number}` and `"agent_id": null`, and take the agent out of the other agents' `transfer_targets` or delete them. With `sandbox: true` nothing is written: the agent is looked up and the answer is the one a real delete would give. ## Calls an agent answers [#calls-an-agent-answers] A call to a number bound to an agent is a call like any other, with two more facts on it. The call record and every `call.*` event carry `mode`, which is `agent` for a call an agent answers and `inapp` for a call your callback decides, and an agent call carries `agent_id` as well. A `call.agent_connected` event is sent once the agent's session starts, after `call.answered`. Filter your calls with `GET /v3/voice/calls?mode=agent&agent_id=agent_...`. | What happens | How it's reported | | :--- | :--- | | The agent takes the call | `call.answered`, then `call.agent_connected` | | The agent hangs up, or the caller does | `call.completed`, with `duration_seconds` and `price` | | The agent transfers the call | The session ends `transferred` once the target answers. The call goes on between the caller and the target, and ends `COMPLETED` as one call. A transfer that didn't connect leaves the call with the agent, and nothing is reported | | The agent is over `max_concurrent_calls` | `call.failed` with reason `agent_busy` | | The agent isn't connected, or can't be reached, and has no `fallback` | `call.failed` with reason `agent_unreachable` | | The agent isn't connected, or can't be reached, and has a `fallback` | The fallback number is dialled, and the call ends `COMPLETED` once it ends | `POST /v3/voice/calls/{id}/hangup` and `POST /v3/voice/calls/{id}/recordings` on a live agent call answer `409` with `CONFLICT_015`. The agent ends its own calls with the `hangup` tool. See [Calls, recordings, and participants](/start/guides/managing-calls). ## Next steps [#next-steps] # Voice Recipes (/start/guides/voice-recipes.md) # Voice Recipes [#voice-recipes] These are the routing patterns the Sent voice example app implements, written down as the answers its callback gives. Each one is an answer to a question Sent asks. It uses the actions and instructions of the [callback contract](/reference/api/voice-callback). The JSON examples are the contract's own fixtures where one exists. Every pattern here has been run end to end with the example app. ## Prerequisites [#prerequisites] - A callback that verifies each question and answers within 2.5 seconds. See [Answering Calls](/start/guides/answering-calls). - For the patterns that ring an app user, agents registered with `@sentdm/voice-client`. See [Calls From Your App](/start/guides/in-app-calls). ## Ring an App User, Fall Back to a Phone [#ring-an-app-user-fall-back-to-a-phone] The example app's default routing decides from `to` and from who is online. Who is online is your backend's own knowledge, for example a heartbeat each registered browser sends you; Sent does not store presence. When the call is for an app user and that user is online, ring them: ```json { "action": { "action": "connectToUser", "identity": "ben", "record": false } } ``` When the user is offline, dial a fallback phone instead, presenting one of your numbers as the caller id: ```json { "action": { "action": "connectToNumber", "number": "+38349123456", "callerId": "+14155551234", "dialTimeoutSeconds": 30, "record": false } } ``` When there is no fallback either, turn the call away as busy: ```json { "action": { "action": "reject", "reason": "busy" } } ``` A call for a room joins it with `connectToConference`. A call an app user placed to a phone number dials that number with `connectToNumber`. An inbound call to one of your numbers rings a preferred agent when they are online, otherwise the first agent who is, and falls back the same way. ## Basic IVR [#basic-ivr] A menu plays a prompt and collects keypresses. Answer the `call.request` with `playMenu`: ```json { "action": { "action": "playMenu", "prompt": { "text": "Press 1 for sales, 2 for support" }, "maxDigits": 1, "timeoutSeconds": 5, "repeats": 2 } } ``` The keypress comes back as a `call.input` question for the same `callId`: ```json { "type": "call.input", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:07+00:00", "digits": "1" } ``` Branch on `digits`. The example app maps a key to an app user, a room, a hold, or a hangup. `1` rings an app user: ```json { "action": { "action": "connectToUser", "identity": "ben", "record": false } } ``` `2` puts the caller into a room: ```json { "action": { "action": "connectToConference", "name": "daily-standup", "record": false } } ``` `digits` is an empty string when the menu timed out. For an empty or unknown value, say so, count the attempt in a cookie, and play the menu again: ```json { "instructions": [ { "instruction": "say", "text": "That was not a valid choice." }, { "instruction": "setCookie", "key": "menuAttempts", "value": "2" } ], "action": { "action": "playMenu", "prompt": { "text": "Press 1 for sales, 2 for support" }, "maxDigits": 1, "timeoutSeconds": 5, "repeats": 2 } } ``` The cookie comes back on the next `call.input`, so your callback can read `menuAttempts` and give up after the second attempt: ```json { "instructions": [ { "instruction": "say", "text": "Goodbye." } ], "action": { "action": "hangup" } } ``` Menus chain. A menu that collects several digits, such as an account number, sets `maxDigits` and uses a cookie to remember which step the caller is on: ```json { "instructions": [ { "instruction": "setCookie", "key": "step", "value": "account-number" } ], "action": { "action": "playMenu", "prompt": { "text": "Enter your four digit account number" }, "maxDigits": 4, "timeoutSeconds": 8 } } ``` Every cookie set earlier in the call comes back on the next question, so the callback stays stateless: ```json { "type": "call.input", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:00:07+00:00", "digits": "1", "cookies": { "step": "greeted", "department": "sales" } } ``` ## Hold [#hold] To hold a call, answer `park` with an intro prompt played once, a hold prompt that repeats, and how long to hold for: ```json { "action": { "action": "park", "introPrompt": { "text": "Please hold" }, "holdPrompt": { "text": "Still with you" }, "maxDurationSeconds": 600 } } ``` The example app holds for 120 seconds, both as an answer to an incoming call and as a menu key. A hold is a bounded wait: when it reaches `maxDurationSeconds` the call ends, so say how long the caller may wait in the prompts and keep `maxDurationSeconds` honest. One hold can last at most 600 seconds; a larger value is refused with `park_duration_exceeded`. ## Record a Call [#record-a-call] Set `record: true` on the connect action to record a call to a phone number or a room: ```json { "action": { "action": "connectToNumber", "number": "+38349123456", "callerId": "+14155551234", "dialTimeoutSeconds": 30, "record": true } } ``` The recording starts when the legs join, so everything from that moment is captured. A `startRecording` instruction records from the moment it runs instead, and a `stopRecording` instruction ends a recording early. The example app's routing panel does both: a record switch that sets `record: true` on every connect, and a free list of instructions it sends before the action. ```json { "instructions": [ { "instruction": "say", "text": "This call may be recorded.", "locale": "en-US" }, { "instruction": "startRecording" } ], "action": { "action": "connectToConference", "name": "daily-standup", "record": false } } ``` A call connected to an app user cannot be recorded, whether the caller is a phone or another app user. `record: true` on `connectToUser` is accepted and the call connects without a recording, and a `startRecording` instruction in the same answer is left out. Once a recording is stored, a `call.recording_ready` webhook arrives with its `recording_id`, and `GET /v3/voice/calls/{id}/recordings` lists it with a download link. When call recording is not available, the start is left out and the call carries on, and `POST /v3/voice/calls/{id}/recordings` answers `403` with `BUSINESS_026`. See [Record a Call](/start/guides/managing-calls#record-a-call). ## Room Per Call [#room-per-call] To add people to a call later, or to transfer it, answer with a room named after the call instead of connecting the two parties directly. The example app derives the name from the call id, `r` followed by the first 26 hex characters of the id, which fits the 27 character limit: ```json { "action": { "action": "connectToConference", "name": "r9f2ab000000040008000000000", "record": false } } ``` Then, from your backend, dial the intended party into the room with [`POST /v3/voice/calls/{id}/participants`](/reference/api/voice/SentDmServicesEndpointsCustomerAPIv3VoiceCallsAddCallParticipantEndpoint): ```bash curl -X POST "https://api.sent.dm/v3/voice/calls/call_9f2ab000-0000-4000-8000-000000000001/participants" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": { "kind": "user", "value": "ben" } }' ``` Sent records the room on the call as it reads your answer, so a request sent right after answering can see `409` with `CONFLICT_009` for a moment. The example app waits a second and retries, up to eight times. Do not make this request inside the callback handler; Sent is waiting for your answer there. Each participant is a call of its own, with its own id. Mute, remove or transfer with the participant endpoints, and read who is in the room with `GET /v3/voice/calls/{id}/participants`. See [Conference Participants](/start/guides/managing-calls#conference-participants). ## Department Routing [#department-routing] Give each department its own voice number, and mint your agents' tokens with `number` set to their department's line. See [Route by Department](/start/guides/in-app-calls#route-by-department). Every question carries `number`, the line the call belongs to. On an inbound `call.request` it is the number the caller dialed: ```json { "type": "call.request", "version": "1", "callId": "call_9f2ab000-0000-4000-8000-000000000001", "number": "+38349111222", "timestamp": "2026-07-22T12:05:00+00:00", "direction": "inbound", "from": { "kind": "number", "number": "+38344555666" }, "to": { "kind": "number", "number": "+38349111222" } } ``` Branch on `number`. Ring an agent of that department who is online with `connectToUser`. When nobody is online, dial the department's fallback phone with `connectToNumber`, and when there is no fallback either, `reject` the call as busy, exactly as in [Ring an App User, Fall Back to a Phone](#ring-an-app-user-fall-back-to-a-phone). `callerId` must be a number you hold through Sent; the call's own number is used when it is omitted. ## Next Steps [#next-steps] # Onboard client WhatsApp accounts with a Meta Multi-Partner Solution (/start/guides/whatsapp-partner-solution.md) # Onboard client WhatsApp accounts with a Meta Multi-Partner Solution [#onboard-client-whatsapp-accounts-with-a-meta-multi-partner-solution] This guide shows you how to set up a Meta **Multi-Partner Solution** with Sent, onboard your clients' WhatsApp Business Accounts (WABAs) into it, and send from each one through its own [Sender Profile](/start/concepts/sender-profiles). A Multi-Partner Solution is Meta's arrangement for two partners serving the same WhatsApp clients. You are the **Tech Provider**: you own the Meta app and the client relationship. Sent is the **Solution Partner** and sends messages on your behalf. A client shares their account into the partnership once, and from then on Sent sends from it and obtains the access token for it. You never handle a client's token. ## When to use a partner solution [#when-to-use-a-partner-solution] Before Sender Profiles are enabled, the Sender Profiles page offers two ways to start: | Choice | What it means | | :--- | :--- | | **Become a Partner** | Your clients share their WABAs into your partnership with Sent. Use it when you own a Meta app as a Tech Provider. It opens the partnership setup and doesn't enable Sender Profiles. Only Owners and Admins working in the organization see it. | | **Continue with dedicated WABAs** | Enables Sender Profiles. Each profile connects its own WABA with **Log in with Meta**, as in [Connect a WhatsApp Business Account](/start/guides/connect-whatsapp). There is no partnership. | You don't have to choose one or the other. A partnership doesn't stop any profile from connecting a dedicated account, and you can create a partnership later from the Sender Profiles page. ## Before you start [#before-you-start] - **An organization account.** A partnership belongs to your organization, never to a single profile, and the accounts in it are attached to profiles. - **The Owner or Admin role** in that organization. The controls that create the partnership and onboard clients are hidden from other roles. - **A Meta app you own.** Sent creates the partnership on that app, and you sign in with the Meta account that owns it. - **To attach accounts to profiles:** Sender Profiles enabled, and your organization's own WhatsApp Business Account connected to Sent. Sent finds your clients' shared accounts through your organization's account, so without it none can be listed or attached. Connect it with [Connect a WhatsApp Business Account](/start/guides/connect-whatsapp). Neither is needed to create the partnership or onboard clients. ## Set up the partnership and onboard clients [#set-up-the-partnership-and-onboard-clients] **Create the partnership** Open [Sender Profiles](https://app.sent.dm/dashboard/sender-profiles) and select **Partner Solution**. If Sender Profiles aren't enabled yet, select **Become a Partner** instead. Under **1. The partnership**, enter a **Partnership name**. It defaults to your organization's name followed by `+ Sent`. Then select **Authorize with Meta**. In Meta's window, sign in with the Meta account that owns your app, pick the app Sent should manage, and grant permission. This step creates the partnership only. No WhatsApp account is connected yet. When it finishes, the dialog shows **Partnership created** and the partnership's **Solution ID**. You do this once. Your organization holds one partnership, and when you open **Partner Solution** again it shows the existing one. **Onboard a client** Under **2. Onboard a client**, select **Launch client signup**. This opens WhatsApp signup, and your **client**, not you, signs in to it with their own business account. The account they finish with is shared into your partnership. When the client finishes, the dialog shows **Client onboarded** and the account's **WABA ID**. Copy it if you plan to attach the account through the API. Select **Onboard another client** for the next one. **Attach the account to a Sender Profile** In the Sender Profile's setup, on the WhatsApp step, select **Use a shared account**. The button appears once your organization has a partnership. Pick the client's account and one of its numbers, then select **Attach account**. Only accounts marked **Approved** can be picked, and only verified numbers. A number that isn't verified yet shows **Needs verification in Meta**, and the client verifies it in Meta before it can be attached. A number sends for one profile only. To attach the account without the dashboard, use the API as described in the next section. ## Attach a shared account through the API [#attach-a-shared-account-through-the-api] Connect a shared account to an existing profile with [`POST /v3/channels/whatsapp`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsAddWhatsappChannelEndpoint). Use an organization API key and send `x-profile-id` for the profile that should send from the account, or use that profile's own API key: ```bash curl -X POST "https://api.sent.dm/v3/channels/whatsapp" \ -H "x-api-key: $ORG_API_KEY" \ -H "x-profile-id: $PROFILE_ID" \ -H "Content-Type: application/json" \ -d '{ "waba_id": "123456789012345", "phone_number_id": "987654321098765" }' ``` - `waba_id` is required. Take it from **Client onboarded** in the dashboard. The API has no endpoint that lists your shared accounts; the dashboard's **Use a shared account** list shows them. - `phone_number_id` is optional. You can omit it to connect the account now, then call the endpoint again with the same `waba_id` and a `phone_number_id` to name the number. - Don't send `access_token`, `solution_id` or `owner_business_id`; they're ignored. Sent works all three out from your partnership. The token is issued for each client business and rotates roughly every sixty days, so a token you sent would soon go stale. Each call replaces the profile's WhatsApp account with what you send. A call without `phone_number_id` clears a number that was already named, and a call with a different `waba_id` swaps the account. The response is the WhatsApp account: `waba_id`, `phone_number_id`, `solution_id`, `owner_business_id`, `status`, and a `reason_code` and `reason` whenever `status` isn't `ACTIVE`. It never returns the token. This endpoint doesn't check the number with Meta. A `phone_number_id` that isn't on the account still reads `ACTIVE`, and the profile's WhatsApp messages then fail when sent. Copy the ID carefully, or attach from the dashboard, which only offers the account's own numbers. To attach an account while you create the profile, pass the same two fields as `channels.whatsapp` on [`POST /v3/sender-profiles`](/reference/api/sender/SentDmServicesEndpointsCustomerAPIv3SenderProfilesCreateSenderProfileEndpoint). Sent fills in the solution, business, and token the same way. Creating a profile also checks the account and number with Meta, and refuses with `409` an account or number already recorded on any other profile or on an organization. A profile with its own WhatsApp account also needs a sender of its own, so `channels.whatsapp` requires `channels.sms`. See [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api). Call `POST /v3/channels/whatsapp` for a profile, not for the organization. Your organization's own account is the one the partnership belongs to, so attaching a shared account to the organization itself is refused with `400`. ## Confirm the account can send [#confirm-the-account-can-send] Read the profile's WhatsApp channel with [`GET /v3/channels`](/reference/api/channels/SentDmServicesEndpointsCustomerAPIv3ChannelsGetChannelsEndpoint), sending `x-profile-id` for the profile. [Managing channels](/start/guides/managing-channels) explains the full response. | `whatsapp` | Meaning | | :--- | :--- | | `status` `ACTIVE` | The account and its number are connected. The profile sends from them. | | `status` `ACTION_NEEDED`, `reason_code` `CHANNEL_007` | The account is connected but no number is named. Call `POST /v3/channels/whatsapp` again with the same `waba_id` and a `phone_number_id`. | | `null` | No WhatsApp account is connected to this profile. | Until a number is named, the profile's WhatsApp messages fail with reason code [`DELIVERY_003`](/reference/api/error-catalog#message-outcome-codes). They don't fall back to your organization's account, because a client's traffic going out under your business's name would show recipients the wrong sender. ## Tokens, and when a client leaves [#tokens-and-when-a-client-leaves] **You don't manage tokens.** Sent obtains each client's token when the account is attached. If Meta rejects the token while a message is being sent, Sent obtains a new one and retries the message. If Meta won't issue a new one, the message fails with reason code [`DELIVERY_009`](/reference/api/error-catalog#message-outcome-codes). Contact [support](mailto:support@sent.dm) if you see it. **When the relationship ends in Meta, Sent stops using WhatsApp for the affected senders.** - If a client removes the partnership from their WhatsApp account, this applies to every profile that sends from that account. - If Meta deactivates or rejects the partnership itself, it applies to every profile attached through it **and to your organization's own account**. Your organization's own account is included in the second case even though you connected it with **Log in with Meta**, because the partnership belongs to it. Sender Profiles on dedicated accounts aren't affected in either case. A message that lets Sent pick the channel goes out on another available channel instead of WhatsApp. Contact [support](mailto:support@sent.dm) to restore WhatsApp. `GET /v3/channels` can still show the WhatsApp channel as `ACTIVE` after the relationship ends. Don't rely on the status alone to tell whether a profile still sends on WhatsApp. **Removing an account is not self-service.** To detach a shared account from a profile, or move a client off your partnership, contact [support](mailto:support@sent.dm). Deleting a Sender Profile deregisters its WhatsApp number from Meta. For a client's shared account, that takes the client's own number off WhatsApp. To stop sending for a client without that, contact [support](mailto:support@sent.dm) instead of deleting the profile. ## Troubleshooting [#troubleshooting] | What you see | Cause | What to do | | :--- | :--- | :--- | | No **Partner Solution** button | You aren't an Owner or Admin, you aren't working in organization mode, or Sender Profiles aren't enabled | Switch to the organization and use an Owner or Admin login. Before Sender Profiles are enabled, use **Become a Partner** | | **Authorization cancelled** | Sent wasn't granted permission to manage the app | Run **Authorize with Meta** again and grant the permission | | **2. Onboard a client** shows "Create the partnership first" | The partnership doesn't exist yet | Complete step 1 first. Meta shows the client an error until Sent has accepted the partnership | | **Signup did not return an account** | No WhatsApp Business Account came back from the signup window | Ask the client to run signup again | | "No WhatsApp accounts are shared with this organization yet" | No client has finished signup, or your organization's own WhatsApp account isn't connected | Onboard a client, and confirm your organization's WhatsApp channel is connected | | **Needs verification in Meta** on a number | The number isn't verified in Meta | Ask the client to verify the number in Meta, then attach it | | `400` "WhatsApp Business Account not found" | The `waba_id` isn't shared into your partnership, or your organization's own WhatsApp account isn't connected | Check the ID, onboard the client if they haven't finished signup, and confirm your organization's WhatsApp channel is connected | | `400` "Organization has no Multi-Partner Solution configured" | Your organization has no partnership | Create one in the dashboard | | `400` "is already used by profile" | The number is attached to another profile | Name a different `phone_number_id` | | `409` `RESOURCE_007` on `POST /v3/sender-profiles` | The account or the number is already recorded on another profile or organization | Meta registers a number to one business account, so supply an account and number nobody else uses | | Messages fail with `DELIVERY_003` | The profile's account has no number named | Name the number, as in [Confirm the account can send](#confirm-the-account-can-send) | ## Related [#related] - [Connect a WhatsApp Business Account](/start/guides/connect-whatsapp): dedicated accounts, and your organization's own - [Managing channels](/start/guides/managing-channels): reading WhatsApp channel status - [Multi-tenant architectures](/start/advanced/multi-tenant-architectures): choosing a tenant model - [Create and activate Sender Profiles via the API](/start/advanced/sender-profiles-api): `channels.whatsapp` at create time # Working with Templates (/start/guides/working-with-templates.md) # Working with Templates [#working-with-templates] A **template** is a reusable message blueprint: structured content with dynamic variables, links, media, and interactive buttons that adapts automatically to SMS, WhatsApp, and RCS. You build a template once, get it approved, and then send personalized messages at scale by referencing its template ID. **Start sending right away.** Sent includes 6 pre-built OTP and verification templates available immediately after email and phone verification, no custom template creation or approval needed. Custom templates require a [completed account setup](/start/quickstart/account-setup). ## Template documentation [#template-documentation] Build a template in the visual builder: header, body, dynamic variables, footer, buttons, and submitting for review. Every field, limit, and status of the template definition JSON used by the API and by the builder's View JSON action. Why templates are channel-agnostic, how content adapts per channel, and how the template lifecycle is managed. A guided quickstart for creating and submitting your first template. ## How template approval works [#how-template-approval-works] Every custom template starts as a draft, and drafts cannot be sent on any channel. Submitting a template for review starts approval: - With a connected WhatsApp Business Account, **Meta** reviews the template. A Meta approval applies to every channel; a Meta rejection blocks only WhatsApp. - Without a connected WhatsApp Business Account, **Sent's compliance team** reviews the template, and each channel is approved or rejected individually. Approval is tracked per channel: a message sends on a channel only after the template is approved for that channel, and sends against unapproved templates are blocked. The pre-built OTP and verification templates are already approved on all channels. Refer to [template statuses](/reference/api/template-definition#template-statuses) for the full status list and review routing details. ## Template best practices [#template-best-practices] Following these guidelines helps you avoid common issues with template creation and approval. **Keep templates concise and transactional.** Templates that clearly serve a transactional or utility purpose (order updates, appointment reminders, verification codes) are approved faster and categorized correctly more often than templates with ambiguous intent. **Avoid marketing language in utility templates.** Even a single promotional phrase can cause Meta to re-categorize your utility template as marketing. Stick to factual, action-oriented language that directly relates to the triggering event. **Test with a simple text-only template first.** Before building a template with media, buttons, and multiple variables, first create and send a basic text-only template. This confirms your WhatsApp Business Account connection, permissions, and API integration are all working correctly. Add complexity from there. **Use meaningful template names.** Use descriptive, consistent names like `order_confirmation`, `shipping_update`, or `otp_verification` rather than generic names like `template1` or `test`. Send requests can reference a template by name, and renaming later means updating every place that name appears in your code. **Plan for approval time.** Build template review time into your development workflow. Submit templates for approval well before you need them in production. Having a library of pre-approved templates ready to go prevents delays when launching new features. If a template is failing to save, stuck in review, or miscategorized, see [WhatsApp Template Issues](/troubleshooting/template-issues) for symptom-by-symptom fixes. ## Manage templates via the API [#manage-templates-via-the-api] | Action | Endpoint | | :--- | :--- | | [Create a template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesCreateTemplateEndpoint) | `POST /v3/templates` | | [List templates](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesGetTemplatesEndpoint) | `GET /v3/templates` | | [Get a template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesGetTemplateEndpoint) | `GET /v3/templates/{id}` | | [Update a template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesUpdateTemplateEndpoint) | `PUT /v3/templates/{id}` | | [Delete a template](/reference/api/templates/SentDmServicesEndpointsCustomerAPIv3TemplatesDeleteTemplateEndpoint) | `DELETE /v3/templates/{id}` | Template status changes are delivered to your webhook endpoint as `templates` events; see [webhook event types](/start/webhooks/event-types). # One API for SMS, WhatsApp, and RCS (/start.md) # One API for SMS, WhatsApp, and RCS [#one-api-for-sms-whatsapp-and-rcs] Build intelligent multi-channel messaging into your applications with the Sent unified API. Send SMS, WhatsApp, and RCS messages through a single interface with automatic routing, fallback, and cost optimization. **Try before you commit.** All you need is a verified email and phone number: get API access, 6 pre-built OTP templates, and 500 sends/day in ~2 minutes. [Start now →](/start/try-sent) ## New to Sent? [#new-to-sent] Follow this structured learning path from understanding the platform to production deployment: } /> } /> } /> ## Implementation Guides [#implementation-guides] Practical guides for building with Sent: } /> } /> } /> } /> } /> } /> ## Webhooks & Events [#webhooks--events] Receive real-time notifications about your messages: } /> } /> } /> } /> ## Advanced Topics [#advanced-topics] Deep dives for power users and enterprises: } /> } /> } /> } /> ## Help & Reference [#help--reference] } /> } /> } /> } /> For the v3 authentication scheme, sandbox mode, and the shape of every request and response, see the [API Reference](/reference/api); for webhook payloads, see the [webhook event types reference](/start/webhooks/event-types). --- # Docs for LLMs & AI Agents (/start/llm-docs.md) # Docs for LLMs & AI Agents [#docs-for-llms--ai-agents] All Sent documentation is also available in plain-text format, following the [llms.txt standard](https://llmstxt.org/). These files are optimized for LLMs, AI coding assistants (Cursor, Copilot, Windsurf), and autonomous agents that need structured, crawlable content without HTML noise. ## Available Files [#available-files] | File | URL | Best for | |------|-----|----------| | **Index** (`llms.txt`) | [docs.sent.dm/llms.txt](https://docs.sent.dm/llms.txt) | Agents that discover and selectively fetch only relevant articles | | **Full docs** (`llms-full.txt`) | [docs.sent.dm/llms-full.txt](https://docs.sent.dm/llms-full.txt) | One-shot context loading: every article in a single file | ### Per-Article Files [#per-article-files] Every documentation page has its own plain-text file at a predictable URL: ``` https://docs.sent.dm/llms/
/
.txt ``` Examples: | Article | Plain-text URL | |---------|---------------| | Sending Messages guide | [`/llms/start/guides/sending-messages.txt`](https://docs.sent.dm/llms/start/guides/sending-messages.txt) | | Send Message endpoint | [`/llms/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesSendMessageV3Endpoint.txt`](https://docs.sent.dm/llms/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesSendMessageV3Endpoint.txt) | | Channels concept | [`/llms/start/concepts/channels.txt`](https://docs.sent.dm/llms/start/concepts/channels.txt) | The full list of per-article URLs is in [`llms.txt`](https://docs.sent.dm/llms.txt). ## How to Use [#how-to-use] ### With Cursor / Windsurf / Copilot [#with-cursor--windsurf--copilot] Add the index URL as a documentation source in your editor's AI settings: ``` https://docs.sent.dm/llms.txt ``` The tool will fetch the index and selectively load the relevant articles into context as you work. ### With Claude (claude.ai or API) [#with-claude-claudeai-or-api] Paste the full documentation directly into your conversation or system prompt: ``` https://docs.sent.dm/llms-full.txt ``` Or point an agent tool at the index to let it fetch only what it needs: ``` https://docs.sent.dm/llms.txt ``` ### With Autonomous Agents [#with-autonomous-agents] Agents can discover available content by fetching `llms.txt` first, then requesting individual `.txt` files. Every per-article file begins with a `URL:` line so the agent always has the canonical source, even when files are cached or passed out of context. ``` URL: https://docs.sent.dm/llms/start/guides/sending-messages.txt # Sending Messages ... ``` These files are regenerated automatically on every commit that touches documentation source files, so they are always in sync with the live docs. ## Autodiscovery [#autodiscovery] The `` tag is present in the HTML `` of every page on this site, allowing AI crawlers and browser-level agents to discover the index without prior knowledge of the URL: ```html ``` --- # Sent MCP Server (/start/llm-docs/mcp-server.md) # Sent MCP Server [#sent-mcp-server] The Sent MCP server exposes Sent's messaging tools (send, lookup, contacts, templates, analytics, Sender Profiles, SMS compliance, and feedback) directly inside your AI agent. No API keys to paste, no context-switching to another tab. Your agent can send a real SMS, look up a contact, or check deliverability without leaving your editor. The MCP server is available at **[mcp.sent.dm](https://mcp.sent.dm)**. It implements the [Model Context Protocol](https://modelcontextprotocol.io/) over HTTP with OAuth 2.1 authentication. ## What you can do [#what-you-can-do] | Category | Available tools | |---|---| | **Messaging** | Send SMS, WhatsApp, and RCS · Get message status · List message activity | | **Contacts** | List, get, create, delete contacts · Message summary per contact | | **Templates** | List, get, and delete templates · Look up by name | | **Lookup & Analytics** | Phone number lookup · Messages sent · Deliverability · Contact stats | | **Account** | Get account info · Check balance · Onboarding status | | **Sender Profiles** | List, get, create, update, and delete Sender Profiles | | **SMS compliance** | Market requirements · Setup plan for a market | | **Feedback** | Send user-authorized feedback to the Sent team | 27 tools in total. Connections through Claude's hosted connector get 25 of them; see [Claude connector policy](#claude-connector-policy). --- ## Setup [#setup] ### Add the MCP server to your agent [#add-the-mcp-server-to-your-agent] Pick your agent below and follow the one-time setup. In Claude, open **Settings → Connectors**, add a custom connector, and enter this URL: ```text https://mcp.sent.dm/mcp ``` The connector works in claude.ai, Claude Desktop, and Claude mobile. Claude opens the Sent authorization page the first time you connect. These connections follow the [Claude connector policy](#claude-connector-policy). Run this command in your terminal: ```bash claude mcp add --transport http sent https://mcp.sent.dm/mcp ``` That's it. Claude Code registers the server and handles authentication on first use. Open or create `~/.cursor/mcp.json` and add: ```json { "mcpServers": { "sent": { "url": "https://mcp.sent.dm/mcp" } } } ``` Restart Cursor after saving. The server will appear under **Settings → MCP**. Add a `.vscode/mcp.json` file at the root of your project (or your user settings): ```json { "servers": { "sent": { "type": "http", "url": "https://mcp.sent.dm/mcp" } } } ``` VS Code Copilot will pick up the server automatically on next activation. ### Authenticate [#authenticate] The first time your agent calls a Sent tool, it will trigger an OAuth 2.1 authorization flow: 1. Your agent opens a browser tab to `app.sent.dm/mcp-authorization` 2. You log in with your Sent account and select the organization or Sender Profile to grant access to 3. An access token is issued and stored by the agent, no copy-pasting required The token has no expiry. To revoke access, deactivate the connection's key in **Dashboard → API Keys**. Claude connections get a dedicated key named `Claude connector YYYY-MM-DD`. ### Use it [#use-it] Ask your agent anything that involves messaging: ``` Send a WhatsApp message to +1234567890 using the order_confirmation template with customerName="Alex" and orderNumber="#9981" ``` ``` Look up the phone number +447911123456 and tell me what channel it supports ``` ``` Show me deliverability stats for the last 7 days ``` The agent selects the right tool, constructs the call, and shows you the result inline. --- ## Available tools reference [#available-tools-reference] The **Available in Claude** column shows which tools connections through Claude's hosted connector can use. Every tool is available to Claude Code and other MCP clients. ### Messaging [#messaging] | Tool | Description | Available in Claude | |---|---|---| | `messages.send` | Send a message via SMS, WhatsApp, or RCS | Yes, one recipient per call, no MARKETING templates | | `messages.get` | Retrieve a single message by ID | Yes | | `messages.activities.list` | Get the full lifecycle timeline for a message | Yes | ### Contacts [#contacts] | Tool | Description | Available in Claude | |---|---|---| | `contacts.list` | List contacts in your account | Yes | | `contacts.get` | Get a single contact by ID | Yes | | `contacts.create_many` | Bulk-create contacts | Yes | | `contacts.delete` | Delete a contact | Yes | | `contacts.message_summary` | Get messaging history summary for a contact | Yes | ### Templates [#templates] | Tool | Description | Available in Claude | |---|---|---| | `templates.list` | List all templates | Yes | | `templates.get` | Get a template by ID | Yes | | `templates.get_by_name` | Get a template by name | Yes | | `templates.delete` | Delete a template | Yes | ### Lookup & Analytics [#lookup--analytics] | Tool | Description | Available in Claude | |---|---|---| | `numbers.lookup` | Look up a phone number (channel support, validity) | Yes | | `dashboard.messages_sent` | Messages sent over a time range | Yes | | `dashboard.deliverability` | Delivery rate stats | Yes | | `dashboard.contacts` | Contact growth and activity stats | Yes | ### Account [#account] | Tool | Description | Available in Claude | |---|---|---| | `account.get` | Get account details | Yes | | `balance.get` | Check current balance | Yes | | `onboarding.status` | Check onboarding and KYC status | Yes | ### Sender Profiles [#sender-profiles] | Tool | Description | Available in Claude | |---|---|---| | `sender_profiles.list` | List the organization's Sender Profiles and their channel readiness | Yes | | `sender_profiles.get` | Get a single Sender Profile by ID | Yes | | `sender_profiles.create` | Create a Sender Profile, which can claim a number and incur registration fees | No, use the Dashboard | | `sender_profiles.update` | Change a Sender Profile's name, short name, or description | Yes | | `sender_profiles.delete` | Delete a Sender Profile, which can release its numbers and disconnect WhatsApp | No, use the Dashboard | ### SMS Compliance [#sms-compliance] | Tool | Description | Available in Claude | |---|---|---| | `compliance.requirements` | List the fields and documents an SMS market requires | Yes | | `compliance.setup_plan` | Get the setup steps for an SMS market | Yes, returns a Dashboard link | ### Feedback [#feedback] | Tool | Description | Available in Claude | |---|---|---| | `feedback.send` | Send feedback you approve to the Sent team | Yes | --- ## Claude connector policy [#claude-connector-policy] Connections authorized through Claude's hosted connector (claude.ai, Claude Desktop, Claude mobile, and Cowork) get a restricted policy. The Sent server enforces it on every request from that connection, even when no plugin is installed: - **No Sender Profile provisioning.** `sender_profiles.create` and `sender_profiles.delete` are not listed and refuse direct calls. Create and delete Sender Profiles in the [Sent Dashboard](https://app.sent.dm). `compliance.setup_plan` returns a Dashboard link instead of a create call. - **One recipient per send.** `messages.send` accepts one phone number per call. Use the Dashboard or the REST API for bulk sends. - **No MARKETING templates.** `messages.send` refuses a template in the MARKETING category. UTILITY and AUTHENTICATION templates send as usual. Send marketing campaigns from the Dashboard or the REST API. - **Organization send quota.** All Claude connections in an organization share one quota, by default 10 sends per minute and 100 sends per day. A send on several channels counts once per channel. Adding connections or Sender Profiles does not reset it. - **Opt-outs.** A recipient who has opted out is refused before anything is queued, from Claude or from any other client. Claude Code and other MCP clients keep the full set of 27 tools. Claude connections authorized before this policy were moved onto it when they used a key the connector had created for them (named `MCP-YYYY-MM-DD`). A Claude connection you authorized with one of your own API keys keeps that key's access until you deactivate the key in **Dashboard → API Keys** and reconnect the connector. ## Example use cases [#example-use-cases] - Send one approved template message to a customer and check its delivery status. - Review a message's activity timeline when a send looks stuck. - Find, add, or remove contacts, and summarize a contact's message history. - Find an approved template by name, or delete one you no longer use. - Check messages sent, deliverability, and contact totals, or look up a phone number's capabilities. - Check account details, balance, onboarding status, and the SMS requirements for a market. - Rename a Sender Profile or update its description. - Send feedback about the tools to the Sent team when you ask for it. --- ## Authentication details [#authentication-details] The Sent MCP server uses **OAuth 2.1 with PKCE** (RFC 7636) and **Dynamic Client Registration** (RFC 7591). Your agent registers itself automatically. No manual client ID setup required. - **Token expiry:** None. Tokens are long-lived. - **Phone verification:** Connecting requires a verified phone number on your Sent account, the same as the dashboard. An account that has not verified one is sent to verify it first, then returned to finish connecting. - **Revocation:** Dashboard → API Keys → deactivate the key the connection uses. Deactivating a key that other tools share signs those tools out too. Claude connections always get their own key, named `Claude connector YYYY-MM-DD`. - **Scope:** Tied to the organization or Sender Profile chosen during authorization. To grant access to a different one, re-authorize. --- ## Related [#related] --- # Account Setup (/start/quickstart/account-setup.md) # Account Setup [#account-setup] Complete your account setup and KYC verification to unlock full access to the Sent platform. **What you'll accomplish**: Create account → Verify identity → Complete KYC → Set up billing **⏳ Time required**: ~10 minutes **Not ready to commit yet?** You can [start with light onboarding](/start/try-sent): just a verified email and phone number gets you API access, 6 pre-built templates, and 500 sends/day. Come back here when you're ready for custom templates or your own sender number. ## Prerequisites [#prerequisites] - Business email address - Business registration details - Government-issued ID or business documents (for some countries) - Payment method (credit/debit card) ## KYC Process Overview [#kyc-process-overview] B[Verify Email] B --> C[Start KYC] C --> D[Business Details] D --> E[Select Countries] E --> F[Messaging Use Case] F --> G[Set Up Billing] G --> H[Submit] H --> I{Review} I -->|Approved| J[Ready to Send!] I -->|Rejected| K[Fix Issues] K --> C style A fill:#e1f5fe style J fill:#e8f5e8 style K fill:#ffebee `} /> ## Create Your Account [#create-your-account] 1. Visit [app.sent.dm/sign-up](https://app.sent.dm/sign-up) 2. Enter your business email address 3. Check your email for the magic verification link 4. Click the link to verify your account {/* TODO(verify): production (dashboard-managed) Supabase otp_expiry. The repo config sent-dm-app-nextjs/supabase/config.toml:184 sets 3600s (1 hour); confirm hosted value with engineering. */} The verification link expires after 1 hour. If it expires, you can request a new one on the login page. ## Verify Your Phone Number [#verify-your-phone-number] After clicking the magic link, you will be prompted to verify your phone number. A verification code will be sent via WhatsApp, or SMS if WhatsApp is not available for your number. 1. Complete the **bot challenge** on the verification page 2. Enter your phone number to receive a verification code via WhatsApp or SMS 3. Enter the code to confirm your number and continue If you have WhatsApp installed on the provided number, the code will be delivered there. Otherwise, it will arrive via SMS. ## Start KYC Verification [#start-kyc-verification] From your [Sent Dashboard](https://app.sent.dm/dashboard), click the **"Start Verification"** button to begin KYC. KYC (Know Your Customer) verification is required to: - Comply with messaging regulations - Prevent fraud and abuse - Unlock full platform access ## Business Contact Details [#business-contact-details] Fill in your business contact information: Required information: - Business name - Contact email - Business phone number - Business address ## Business Details [#business-details] Provide your business registration information: Required information: - Business registration number - Legal business name - Business type/structure - Industry category ## Select Destination Countries [#select-destination-countries] Choose the countries you plan to send messages to: - **United States** - For US-only messaging - **Global** - For worldwide messaging - **Selected Countries** - Choose specific countries Some countries require additional compliance documents. The table below lists known examples; the verification flow shows the exact document requirements for each country you select. ### Country-Specific Requirements [#country-specific-requirements] | Country | Required Documents | |---------|-------------------| | Australia (AU) | Utility Bill | | Belgium (BE) | Proof of Local Address, Passport, Business Registration Certificate | | Poland (PL) | Proof of Local Address | | South Africa (ZA) | Proof of Local Address | | Sweden (SE) | Proof of Local Address | | Thailand (TH) | Proof of Worldwide Address, Business Registration Certificate | | United Kingdom (UK) | Proof of Local Address | ## Messaging Use Case [#messaging-use-case] Select your messaging use case and campaign details: Common use cases: - **Authentication** - 2FA, OTP, password resets - **Notifications** - Order updates, shipping alerts - **Marketing** - Promotional campaigns - **Customer Service** - Support messages - **High Volume** - Multiple use cases Use the **"Suggest"** button to automatically fill campaign details based on your use case. ## Set Up Billing [#set-up-billing] Add your payment method: Payment options: - Credit/debit card (Visa, Mastercard, American Express) - Pre-load account credits (optional) You can use the **"Use Business Address"** button to copy your business address to billing. ## Submit Your Application [#submit-your-application] Review all details and submit your KYC application: **Timeline:** Usually approved within a few hours, sometimes minutes. You'll receive an email confirmation. While verification is processing, you can continue with channel setup to save time. ## What's Next? [#whats-next] Once your KYC is approved: 1. **[Set up your channels](/start/quickstart/channel-setup)** - Configure SMS, WhatsApp, and RCS 2. **[Create your first template](/start/quickstart/first-template)** - Prepare message content 3. **[Send your first message](/start/quickstart/first-message)** - Make your first API call ## Troubleshooting [#troubleshooting] **KYC rejected?** Common reasons: - Incomplete business information - Mismatched business registration details - Missing required documents for selected countries Contact [support@sent.dm](mailto:support@sent.dm) with your KYC submission ID for assistance. --- # Channel Setup (/start/quickstart/channel-setup.md) # Channel Setup [#channel-setup] Configure your own SMS, WhatsApp, and RCS sender for production use. **What you'll accomplish**: Select phone number → Connect WhatsApp → Enable RCS → Configure billing **⏳ Time required**: ~5 minutes **Just exploring?** You don't need this step to start sending. [Light onboarding](/start/try-sent) gives you API access and 6 pre-built templates with just a verified email and phone number. Come back here when you're ready to send from your own number. ## Prerequisites [#prerequisites] - [Completed KYC verification](/start/quickstart/account-setup) - [Meta Business Portfolio](https://business.facebook.com) account (for WhatsApp) - Payment method on file ## Start Channel Setup [#start-channel-setup] From your [Sent Dashboard](https://app.sent.dm/dashboard), click the **"Continue Channel Setup"** button. ## Select Your Phone Number [#select-your-phone-number] Choose a phone number that will be your business identity across SMS, WhatsApp, and RCS: **Important considerations:** - Recipients will see this number on all communications - Choose a number local to your target market - This number cannot be changed easily later - We recommend using the same number for SMS, WhatsApp, and RCS ## Connect WhatsApp Business [#connect-whatsapp-business] Link your WhatsApp Business account: **Steps:** 1. Log in with your Facebook/Meta account 2. Select or create a [WhatsApp Business account](https://developers.facebook.com/start/whatsapp/overview/business-accounts) 3. Grant Sent permission to manage messages 4. Add payment details to your Meta Business account Don't have a Meta Business Portfolio? You can create one during this process. We strongly recommend using the **same number** for SMS, WhatsApp, and RCS to ensure smooth operation. ## Enable RCS [#enable-rcs] RCS (Rich Communication Services) delivers carrier-native rich messages (suggestion chips, rich cards, carousels, and branded sender identity) to Android (Google Messages) users without requiring a separate app install. **Key points:** - RCS is delivered over carrier networks to Android (Google Messages) users - Messages display your company logo, name, and a verified checkmark instead of a phone number - Rich features (images, carousels, branded sender identity, suggestion chips) require an approved RCS sender profile - Falls back to SMS automatically for devices or carriers without RCS support To send RCS, register an RCS Agent (your branded sender). Open the **RCS** tab on the [Channels](https://app.sent.dm/dashboard/channels) page and click **Register Agent**. The button is available once you have completed onboarding. Until you register, the tab lists the agent's fees: what each one is for, the amount, and when it is charged. The registration has three parts: 1. **Brand contact**: the business details U.S. carriers require, including legal company name, entity type, EIN, official address, brand and customer support contacts, website, privacy policy, and terms and conditions. 2. **Agent setup**: how the agent appears to recipients: display name, use case, description, brand color, logo, and banner. 3. **Message keywords & opt-in**: your START, HELP, and STOP messages, a description of your opt-in process, sample RCS messages, and an optional screenshot of your opt-in form. You can also register the agent through the API; see [Managing channels](/start/guides/managing-channels#rcs). After you submit, Sent reviews the registration and hands it to the carriers for vetting. Editing is locked while it is under review. The **RCS** tab shows where the registration stands: | Dashboard state | What it means | | --- | --- | | **Registration in progress** | Your details are saved but not submitted. Click **Continue** to finish. | | **Submitted for review** | Sent is reviewing your submission. | | `VERIFICATION_PENDING` | Carrier vetting is in progress. | | `VERIFICATION_APPROVED` | Vetting passed. Click **Request Launch** to go live. | | `LAUNCH_PENDING` | The launch is in progress. | | **Launched** | The agent is live and can send RCS. | | `VERIFICATION_REJECTED`, `LAUNCH_REJECTED`, `SUSPENDED`, `PROVISIONING_FAILED` | The agent can't send. The tab shows the reason when one is available; contact [support](mailto:support@sent.dm) for next steps. | If Sent asks for changes, the tab shows **Changes requested** and an **Update Application** button. Correct your details in the wizard and submit again. You can't send RCS until the agent is launched. Through the API, `GET /v3/channels` reports the agent's `status` as `ACTIVE` once it is launched; see [`reason_code` and `reason`](/start/guides/managing-channels#reason_code-and-reason) for the other values. RCS availability depends on carrier support in the recipient's region. Sent automatically handles fallback to SMS when RCS is unavailable. Use `"channel": ["rcs", "sms"]` in your API requests to enable this pattern explicitly. ## Add Sent Billing Details and a Payment Method [#add-sent-billing-details-and-a-payment-method] Enter your billing address for your Sent account: Then add a payment method (credit or debit card): The payment method is optional at this stage (you can add one later in the [Billing section](https://app.sent.dm/dashboard/billing)), but messages are blocked when your credit balance runs out, so we recommend adding it now. This step configures billing for your **Sent account** (message credits). WhatsApp per-message charges are billed separately by **Meta**, through the payment method you added to your Meta Business account when connecting WhatsApp. ## Complete Setup [#complete-setup] Wait for the channel setup to complete (usually takes a few seconds): 🎉 **Congratulations!** Your account is now ready to send messages. **Copy your API credentials** from this page, or access them later in the [API Keys](https://app.sent.dm/dashboard/api-keys) section. **Security reminder:** NEVER share your Sender ID and API Key(s) with anyone. Store them securely in environment variables. ## API Credentials [#api-credentials] You'll receive two credentials: ```http x-sender-id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx x-api-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` For the current v3 API, you only need the `x-api-key` header. The `x-sender-id` is for legacy v2 API. ## What's Next? [#whats-next] Now that your channels are configured: 1. **[Create your first template](/start/quickstart/first-template)** - Prepare message content 2. **[Send your first message](/start/quickstart/first-message)** - Make your first API call 3. **[Explore the dashboard](/start/quickstart/dashboard-walkthrough)** - Learn dashboard features ## Troubleshooting [#troubleshooting] **WhatsApp connection failed?** - Ensure your Meta Business account is verified - Check that your phone number is not already registered with WhatsApp - Verify you have administrator access to the Meta Business Portfolio **SMS not working?** - Verify your KYC is fully approved - Check that your payment method is valid - Contact [support@sent.dm](mailto:support@sent.dm) --- # The Sent Dashboard (/start/quickstart/dashboard-walkthrough.md) # The Sent Dashboard [#the-sent-dashboard] The Sent Dashboard is your central hub for sending messages, managing contacts, templates, generating API keys, and managing your account. - You will need a [Sent](https://app.sent.dm) account to be able to access the Sent Dashboard - If you don't have one, you can [create a Sent account](https://app.sent.dm/sign-up) - You will receive an email with a magic verification link to verify your account ## Getting Started [#getting-started] The dashboard is available at two levels depending on your onboarding stage: - **Light onboarding** (email + phone verified): Access templates, API keys, playground, contacts, activities, and number lookup. The 6 pre-built templates are ready to use immediately. - **Full setup** (KYC + channels complete): Unlocks all features including your own sender number, custom templates, compliance management, and billing. If you haven't started yet, follow the [Quickstart](/start/quickstart): you can have API access in ~2 minutes with just email and phone verification. ### Dashboard features [#dashboard-features] The Sent Dashboard is a web-based platform that allows you to: - Have an overview of your account, messaging statistics, deliverability and balance - Manage your contacts and templates - Perform number lookup and validation - For developers - A dynamic playground to send messages directly from the dashboard - Generate and manage API keys and credentials - View your messaging activity and logs, including webhook interactions - Manage Sender Profiles (your outbound identities for SMS and WhatsApp) - Configure messaging channels and destination countries - Invite and manage organization users with role-based access - Manage account settings and billing ### Sidebar layout [#sidebar-layout] The Sent Dashboard sidebar is organized into five sections that group related features: - **Main**: Overview, Templates, Playground, Contacts, Profiles - **Tools**: Number Lookup - **Development**: Activities, API Keys, Webhooks, Documentation - **Account**: Compliance, Channels, Users, Settings, Billing - **Help**: email support, Help Center At the top of the sidebar you'll also find the **Context switcher**, which lets you switch between organizations you belong to. New sidebar entries (such as **Profiles** and **Users**) are marked with a New badge. ## Dashboard Comparison (Before and after full setup) [#dashboard-comparison-before-and-after-full-setup] Drag the slider to compare the dashboard before and after completing KYC and channel setup. Note: with light onboarding (email + phone only), you already have access to templates, API keys, and the playground. The slider shows the additional features unlocked by full setup. ## The Dashboard in detail [#the-dashboard-in-detail] ### Overview Page [#overview-page] The [Overview](https://app.sent.dm/dashboard) page is the first page you will see when you log in to your Sent Dashboard. It gives you a quick overview of your account with the following sections: - **Message Templates**: shortcut to create a new template or view all existing ones - **Total Contacts**: total number of contacts in your account - **Deliverability**: your overall message deliverability rate - **Balance**: your current credit balance with a link to manage billing - **Messages**: a bar chart showing SMS and WhatsApp messages sent in the last 24 hours - **Contacts**: a preview of your most recently messaged or added contacts ### Templates Page [#templates-page] The [Templates](https://app.sent.dm/dashboard/templates) page is where you can create and manage your message templates. At the top of the page you'll see four creation cards covering every way to build a template: - **Create from Scratch**: start with a blank template - **Import from Meta**: import an approved template from your WhatsApp Business Account (WABA). The list shows how many templates the account holds and loads more as you go - **Create From Definition**: build a template from a JSON definition - **Create from Sample**: choose from pre-designed templates Below the creation cards, the **Your Templates** section lists every template in your account. You can: - Search templates by name, category, or description - Filter by status (Draft, Approved, Pending, Rejected) and category (Marketing, Utility) - View per-template analytics - Edit and delete existing templates Template creation requires full onboarding. With light onboarding you can still use the 6 pre-built sample templates. Once you create a custom template, it is automatically submitted to Meta for WhatsApp approval. You can still send SMS messages while the template is being reviewed. **Want to learn more about templates?** Check out the [Templates](/start/guides/working-with-templates) guide. ### Playground Page [#playground-page] The [Playground](https://app.sent.dm/dashboard/playground) page lets you send messages directly from the dashboard without writing any code. To send a test message: 1. **Select a template** from the dropdown 2. **Pick a recipient**: either enter a phone number directly or choose an existing contact from your saved list 3. Click **Send Message** The **Activity** pane on the right tracks delivery in real time so you can confirm the message status (Sent, Delivered, Failed) without leaving the page. ### Contacts Page [#contacts-page] The [Contacts](https://app.sent.dm/dashboard/contacts) page is where you can manage your contacts. In this page, you can: - Create new contacts individually or in bulk via the **Create Contacts** button - Search contacts and use the **Filter** menu to narrow results by channel or country - View each contact's ID, country, phone number, default channel, and all available channels - Take per-row actions (edit, delete, copy the contact ID) Each row shows: **CONTACT ID**, **COUNTRY**, **PHONE NUMBER**, **DEFAULT CHANNEL**, **AVAILABLE CHANNELS**, and **ACTIONS**. **Want to learn more about contacts?** Check out the [Contacts](/start/guides/managing-contacts) guide. ### Profiles Page [#profiles-page] The [Profiles](https://app.sent.dm/dashboard/sender-profiles) page is where you manage your **Sender Profiles**, the outbound identities used when sending SMS and WhatsApp messages. Each Sender Profile card shows: - A **display name** and **brand description** - The profile's unique ID, labeled **Profile ID** (with a one-click copy icon). Organization API keys pass this UUID in the `x-profile-id` header to scope v3 API requests to that profile; see [Send on Behalf of a Sender Profile](/start/guides/sending-messages#send-on-behalf-of-a-sender-profile) - **SMS** and **WhatsApp** channel configuration and status (for example, _Not configured_, _Active_, _Failed_) - A **More options** menu to edit or remove the profile Click **Create Sender Profile** to add a new one. You can create multiple Sender Profiles to represent different brands, use cases, or regions within the same account. ### Number Lookup Page [#number-lookup-page] The [Number Lookup](https://app.sent.dm/dashboard/phone-number-lookup) page is where you can look up and validate any phone number. Select the country dialing code, enter a phone number, and click **Lookup** to get detailed information including its format, region, type, validity, and timezone data. Use **Clear** to reset the form and run another lookup. ### Activities Page [#activities-page] The [Activities](https://app.sent.dm/dashboard/activities) page is where you can view your messaging logs. Every message sent through Sent, via API or the Playground, appears here with the following details: - **Message ID**: unique identifier for each message (sortable) - **Contact Phone**: recipient phone number (sortable) - **Channel**: SMS or WhatsApp - **Template**: the template used - **Direction**: Outbound or Inbound - **Status**: Sent, Delivered, or Failed - **Initiated At**: timestamp of when the message was sent (sortable) Clicking a message row opens the message detail panel. The cost section shows a single **Price** field, the total amount charged for that message, alongside the pricing model applied. Use the **Search** bar to find a specific message and the **Filter** menu to narrow results by channel, direction, or status. **Status** takes several values at once, for messages and for calls. Phone calls are listed with the channel filter set to **Voice**, and the default view lists messages only. ### API Keys Page [#api-keys-page] The [API Keys](https://app.sent.dm/dashboard/api-keys) page is where you can generate and manage your API keys and credentials. The page displays the ID of whatever you have selected in the profile switcher at the top: **Organization ID** in organization mode, or **Profile ID** when a Sender Profile is selected. v3 API requests authenticate with the `x-api-key` header alone; this ID is not a credential, and v3 never reads it as one. You pass it only as the `x-profile-id` header when an organization key sends on behalf of a profile (see [Send on Behalf of a Sender Profile](/start/guides/sending-messages#send-on-behalf-of-a-sender-profile)), or as `x-sender-id` on the legacy v2 API. Below that, click **Add API Key** to create a new key, and use the table to manage existing keys (each row shows the key's name, masked value, status, creation date, and actions to enable, edit, or delete). **Security reminder:** NEVER share your API Key(s) with anyone. **Quick tip:** Use the copy icon next to the ID and each `x-api-key` to copy them without errors. ### Webhooks Page [#webhooks-page] The [Webhooks](https://app.sent.dm/dashboard/webhooks) page is where you can manage your webhooks. Webhooks are used to receive real-time updates and events about the status of your messages. Click **Add Webhook** to register a new endpoint. The table lists every webhook with its display name, endpoint URL, status (Active/Inactive), and creation date. Use the **Search** bar and **Filter** menu to quickly find a specific webhook. **Want to learn more about webhooks?** Check out the [Webhooks](/start/webhooks/getting-started) guide. #### Webhook Details [#webhook-details] Clicking a webhook row opens its detail page. The header shows the display name and endpoint URL, with a summary row underneath: - **Created**: when the endpoint was registered - **Status**: Active or Inactive - **Listening for**: how many event types the endpoint subscribes to. Hover the info icon to list them, including any per-event filters - **Signing secret**: shown only when the webhook is created or its secret is rotated. Copy it then, and [verify request signatures](/start/webhooks/signature-verification) in your handler The actions menu in the top right holds the endpoint operations: | Action | Effect | |--------|--------| | **Edit endpoint** | Change the display name, URL, or subscribed event types | | **Disable** or **Enable endpoint** | Stop or resume deliveries without deleting the endpoint or losing its secret | | **Rotate signing secret** | Issue a new signing secret and show it once. On a version 2 webhook, deliveries are signed with both the old and the new secret for 24 hours, so update your handler within that window. On a version 1 webhook the old secret stops working immediately, so store the new one in your handler as part of the same change | | **Test Webhook** | Send a sample payload for any subscribed event to your endpoint. See [local development](/start/webhooks/local-development) | | **Delete endpoint** | Remove the endpoint permanently, along with its secret and delivery history | Below the summary, the **Events** table lists every delivery attempt for the endpoint, with the event type, delivery status, number of **Attempts**, and the created, started, and completed timestamps. Click a row to open **Webhook Event Data**, which shows the stored event record as formatted JSON with a **Copy JSON** button. Use **Refresh** to pull the latest deliveries, and the search bar to find a specific event. Failed deliveries are retried automatically. For the retry schedule and how to make your handler safe to call more than once, see [handling retries](/start/webhooks/handling-retries). ### Documentation [#documentation] The **Documentation** entry in the sidebar opens these docs ([docs.sent.dm](https://docs.sent.dm)) in a new tab: your reference for guides, API specs, and SDK documentation. ### Compliance Page [#compliance-page] The [Compliance](https://app.sent.dm/dashboard/country-compliance) page is where you can view and manage your compliance details across four tabs: - **Brand**: view your business and contact information submitted during the KYC process, including business details, address, and tax information - **Messaging**: view your registered 10DLC campaigns. Each campaign lists its description, the use cases it covers (for example Marketing, Account Notification, Customer Care, 2FA, Delivery Notification), and the sample messages submitted for each one - **Documents**: view and manage your uploaded compliance documents - **Auto Reply**: manage the automatic replies that fire on opt keywords. Each entry pairs a category (**OPT OUT**, **OPT IN**, **HELP**, or **OTHER**) with one or more keywords and the reply text sent when a contact texts one of them. The table lists Category, Keywords, Reply Text, Status, and Updated At; use **Add Auto Reply** to create an entry, and the row actions to edit or delete one. Keywords and their replies are configured together here. Some rows are marked **Protected** and have no row actions. These are the entries holding a category's carrier-mandated keyword (`STOP` for opt-out, `START` for opt-in, `HELP` for help), which is seeded onto every account and answers consent signals that arrive with no keyword behind them, such as a provider-signalled opt-out. They can't be edited or deleted. You can still add your own entries to those same categories, and those behave normally. **OTHER** mandates nothing, so its entries are never protected. A row awaiting approval shows **Pending** in Status and a lock instead of the edit action until it's approved.
### Channels Page [#channels-page] The [Channels](https://app.sent.dm/dashboard/channels) page is where you configure your messaging channels, split across tabs: - **SMS tab**: set your default **alphanumeric Sender ID** (used for all outgoing SMS messages across configured countries) and manage **Destination Countries**. The countries table lists every sender you hold in each country (for example, short code or dedicated number), live or still provisioning, each with its status and, where it has one, a copyable campaign ID. Search matches any of a country's numbers. Use **Add Country** to enable a new destination or request a dedicated sender identity per country. - **WhatsApp tab**: connect and manage your WhatsApp Business Account (WABA) configuration. - **RCS tab**: register your RCS Agent with **Register Agent** and track its review and launch status. Before you register, the tab lists the agent's fees: what each one is for, the amount, and when it is charged. See [Enable RCS](/start/quickstart/channel-setup#enable-rcs). ### Users Page [#users-page] The [Users](https://app.sent.dm/dashboard/users) page is where you manage who has access to your Sent organization and what they can do. Click **Invite Users** to add a new team member by email. The **Organization Users** table lists every member with the following columns: - **NAME**: the user's full name - **EMAIL**: the email tied to their account - **ROLE**: their assigned role in the organization - **STATUS**: Active, Invited, or Disabled - **LAST SEEN**: when they were last active in the dashboard - **ACTIONS**: edit role or remove from the organization Use the **Search** bar and **Filter** menu to quickly find a user. Supported roles are: | Role | Description | |------|-------------| | **Owner** | Full access to all settings and billing | | **Admin** | Full access except billing ownership transfer | | **Billing** | Access to billing and payment settings only | | **Developer** | Access to API keys, webhooks, and development tools | ### Settings Page [#settings-page] The [Settings](https://app.sent.dm/dashboard/settings) page is where you can update your organization's account information: - **Business Info**: update your legal business name, tax ID type, and tax ID - **Details**: additional organization details and account configuration When you switch the context switcher from your organization to an individual Sender Profile, two more tabs appear, scoped to that profile: - **Basic Info**: the profile's name, short name, and description - **Data Sharing**: whether the profile shares its contacts and message templates with other profiles, and whether it inherits them from the organization ### Billing Page [#billing-page] The [Billing](https://app.sent.dm/dashboard/billing) page is where you manage your Sent account's finances. It includes four tabs: - **Overview**: view your current credit **Balance**, top up manually with **Add to credit balance**, and configure **Auto Charge** to keep your balance funded automatically - **Payment Methods**: add or change your payment method - **Billing History**: view past and current invoices - **Preferences**: manage billing information and notification preferences #### Auto Charge [#auto-charge] Auto Charge automatically tops up your credit balance by charging your default payment method whenever your balance falls below a threshold you set. This prevents service interruptions when credits run low. To configure it, click the gear icon on the Overview tab: | Setting | Description | |---|---| | **When credit balance reaches** | The minimum balance threshold that triggers a top-up (for example, `$10.00`) | | **Recharge amount** | How much to charge your card when the threshold is hit (for example, `$100.00`, max `$10,000`) | Once enabled, a status banner on the Overview tab confirms the active settings. You can update or turn off Auto Charge at any time from the same gear icon. #### Failed payment alert [#failed-payment-alert] If your last payment didn't go through, a red alert banner appears at the top of the main Dashboard page: > *Your last payment didn't go through. Please **update your payment method or add funds** to avoid any interruption to your service.* Clicking the link takes you directly to the Billing page. The banner clears automatically once a payment succeeds. #### Payment email notifications [#payment-email-notifications] Sent sends transactional emails for Auto Charge and manual top-up events: | Event | Subject | Key content | |---|---|---| | **Payment failed** | `Your payment didn't go through` | Decline reason, **Update payment method** CTA linking to Billing | | **Payment succeeded** | `Payment received — $X.XX added` | Amount added, new balance, transaction reference | For Auto Charge failures, the email body states that Sent tried to automatically top up your account with $X.XX, but the payment didn't go through. For manual top-up failures, the email states that Sent couldn't process your $X.XX top-up payment. ### Help [#help] The **Help** section at the bottom of the sidebar gives you two quick ways to get assistance: - **email support**: opens your mail client to send a message to [support@sent.dm](mailto:support@sent.dm) - **Help Center**: opens the [help center](https://help.sent.dm) in a new tab for guides, FAQs, and troubleshooting articles --- # Send Your First Message (/start/quickstart/first-message.md) # Send Your First Message [#send-your-first-message] Make your first API call to send an SMS, WhatsApp, or RCS message. **What you'll accomplish**: Get API keys → Send a message → Track delivery **⏳ Time required**: ~2 minutes ## Prerequisites [#prerequisites] **Light onboarding path** (email + phone verified): - [ ] [email and phone verified](/start/try-sent) - [ ] API key copied from dashboard - [ ] Pre-built template ID copied from dashboard **Full production setup path**: - [ ] [Account set up and KYC approved](/start/quickstart/account-setup) - [ ] [Channels configured](/start/quickstart/channel-setup) - [ ] [Custom template created and approved](/start/quickstart/first-template) - [ ] API key copied from dashboard ## How Message Sending Works [#how-message-sending-works] >API: POST /v3/messages Note over App,API: to, template, channel API-->>App: 202 Accepted (message_id) API->>Provider: Dispatch message Provider-->>API: Sent confirmation Provider->>Device: Deliver message Device-->>Provider: Delivery receipt Provider-->>API: Delivery status API->>App: Webhook: status = DELIVERED `} /> ## Get Your API Keys [#get-your-api-keys] From your [Sent Dashboard](https://app.sent.dm/dashboard/api-keys), copy your API key: **Security reminder:** Never commit API keys to version control. Use environment variables. ## Send a Message [#send-a-message] Choose your preferred method: ```bash # Set your API key and template ID export SENT_API_KEY="your_api_key_here" export TEMPLATE_ID="your_template_id_here" export RECIPIENT="+1234567890" curl -X POST "https://api.sent.dm/v3/messages" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": ["'"$RECIPIENT"'"], "template": { "id": "'"$TEMPLATE_ID"'" }, "channel": ["sms", "whatsapp", "rcs"] }' ``` ```typescript import SentDm from '@sentdm/sentdm'; const client = new SentDm(); // Uses SENT_DM_API_KEY env var const response = await client.messages.send({ to: ['+1234567890'], template: { id: 'your_template_id_here' }, channel: ['sms', 'whatsapp', 'rcs'] }); console.log('Message sent:', response.data.recipients[0].message_id); ``` ```python from sent_dm import SentDm client = SentDm() # Uses SENT_DM_API_KEY env var response = client.messages.send( to=["+1234567890"], template={ "id": "your_template_id_here" }, channel=["sms", "whatsapp", "rcs"] ) print(f"Message sent: {response.data.recipients[0].message_id}") ``` ```go package main import ( "context" "fmt" "github.com/sentdm/sent-dm-go" "github.com/sentdm/sent-dm-go/option" ) func main() { client := sentdm.NewClient( option.WithAPIKey("your_api_key_here"), ) response, err := client.Messages.Send(context.Background(), sentdm.MessageSendParams{ To: []string{"+1234567890"}, Channel: []string{"sms", "whatsapp", "rcs"}, Template: sentdm.MessageSendParamsTemplate{ ID: sentdm.String("your_template_id_here"), }, }) if err != nil { panic(err) } fmt.Println("Message sent:", response.Data.Recipients[0].MessageID) } ``` ```java import dm.sent.client.SentDmClient; import dm.sent.client.okhttp.SentDmOkHttpClient; import dm.sent.models.messages.MessageSendParams; SentDmClient client = SentDmOkHttpClient.fromEnv(); MessageSendParams params = MessageSendParams.builder() .addTo("+1234567890") .addChannel("sms") .addChannel("whatsapp") .addChannel("rcs") .template(MessageSendParams.Template.builder() .id("your_template_id_here") .build()) .build(); var response = client.messages().send(params); System.out.println("Message sent: " + response.data().recipients().get(0).messageId()); ``` ```csharp using Sentdm; using Sentdm.Models.Messages; using System.Collections.Generic; SentDmClient client = new(); // Uses SENT_DM_API_KEY env var MessageSendParams parameters = new() { To = new List { "+1234567890" }, Channels = new List { "sms", "whatsapp", "rcs" }, Template = new MessageSendParamsTemplate { Id = "your_template_id_here" } }; var response = await client.Messages.Send(parameters); Console.WriteLine($"Message sent: {response.Data.Recipients[0].MessageId}"); ``` ```php messages->send( to: ['+1234567890'], template: [ 'id' => 'your_template_id_here' ], channels: ['sms', 'whatsapp', 'rcs'] ); echo "Message sent: " . $result->data->recipients[0]->message_id . "\n"; ``` ```ruby require "sentdm" sent_dm = Sentdm::Client.new( api_key: ENV["SENT_DM_API_KEY"] ) result = sent_dm.messages.send_( to: ["+1234567890"], template: { id: "your_template_id_here" }, channels: ["sms", "whatsapp", "rcs"] ) puts "Message sent: #{result.data.recipients[0].message_id}" ``` Use the [Sent Dashboard Playground](https://app.sent.dm/dashboard/playground): 1. Select your template 2. Enter recipient phone number 3. Choose channels (SMS/WhatsApp/RCS) 4. Click "Send Message" ## Understanding the Response [#understanding-the-response] **Success (HTTP 202):** ```json { "success": true, "data": { "status": "QUEUED", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "recipients": [ { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "to": "+14155551234", "channel": "sms" } ] }, "error": null, "meta": { "request_id": "req_7X9zKp2jDw", "timestamp": "2026-03-04T11:28:25.2096416+00:00", "version": "v3" } } ``` **Key fields:** - `recipients[].message_id` - Save this to track the message - `recipients[].channel` - Which channel was used (automatically selected) - `status` - `QUEUED` on success; the message is now in the sending pipeline - `meta.request_id` - Use this for support inquiries ## Track Delivery Status [#track-delivery-status] ### Via Dashboard [#via-dashboard] View message status in the [Activities page](https://app.sent.dm/dashboard/activities): ### Via Webhooks (Recommended) [#via-webhooks-recommended] Set up [webhooks](/start/webhooks/getting-started) to receive real-time status updates: ```json { "field": "message", "event": "message.delivered", "timestamp": "2026-01-15T10:35:00Z", "payload": { "updated_at": "2026-01-15T10:35:00Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+14155551234", "message_status": "DELIVERED", "channel": "sms" } } ``` The full envelope and payload schemas are in the [Events Reference](/start/webhooks/event-types). ### Via API [#via-api] Query message status: ```bash curl "https://api.sent.dm/v3/messages/{message_id}" \ -H "x-api-key: $SENT_API_KEY" ``` Refer to the [Message Status Tracking guide](/start/guides/message-status-tracking) for the full status lifecycle and tracking patterns, and to the [Sending Messages guide](/start/guides/sending-messages) and the [Send a message API reference](/reference/api/messages/SentDmServicesEndpointsCustomerAPIv3MessagesSendMessageV3Endpoint) for all send options, including channel selection and template variables. ## Sandbox Mode [#sandbox-mode] Test without sending real messages by adding `"sandbox": true` to your request body: ```json { "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, "channel": ["sms"], "sandbox": true } ``` The API validates your request and returns a realistic fake response **without executing any side effects**: it writes nothing to the database, sends no message, and calls no external API. Look for the `X-Sandbox: true` header in the response. ## Next Steps [#next-steps] You've sent your first message. Here's what to explore next: ## Troubleshooting [#troubleshooting] **401 Unauthorized (AUTH_002)?** - Check your API key is correct - Ensure the `x-api-key` header is set (not `x-sender-id` - that's v2 legacy) **Message shows `BLOCKED` (insufficient balance)?** - The v3 API accepts the send with `202`, then blocks the message asynchronously when your balance is too low - Add funds or a payment method in [Billing](https://app.sent.dm/dashboard/billing) **400 Bad Request?** - Verify template ID is correct - Check phone number format (E.164: +1234567890) - Ensure template is approved (for WhatsApp) **Message stuck in "queued" status?** - Normal for first few seconds - Check [Activities page](https://app.sent.dm/dashboard/activities) - Set up webhooks for real-time updates --- # Create Your First Template (/start/quickstart/first-template.md) # Create Your First Template [#create-your-first-template] Templates are reusable message blueprints that enable consistent, personalized communication across SMS, WhatsApp, and RCS. **What you'll accomplish**: Create a template → Customize content → Submit for approval → Get template ID **⏳ Time required**: ~5 minutes **Using light onboarding?** You already have access to 6 pre-built OTP and verification templates, no custom template needed to get started. Find them in your dashboard under **Templates**. Create a custom template here when you're ready to go beyond those defaults (requires completed [account setup](/start/quickstart/account-setup)). ## What is a Template? [#what-is-a-template] A template in Sent is: - A reusable message format with dynamic variables - Automatically adapted for SMS, WhatsApp, and RCS - Submitted for channel approval (WhatsApp via Meta, RCS via your RCS Sender Profile) - Referenced by ID when sending messages ## Navigate to Templates [#navigate-to-templates] Go to the [Templates page](https://app.sent.dm/dashboard/templates) in your Sent Dashboard. ## Choose Creation Method [#choose-creation-method] You have several options: | Method | Best For | |--------|----------| | **Create from Sample** | Quick start with pre-designed templates | | **Create from Scratch** | Full customization control | | **Import from Meta** | Using existing WhatsApp templates | | **From JSON Definition** | Programmatic template creation | For this guide, we'll use **"Create from Sample"**. ## Select a Sample Template [#select-a-sample-template] Choose a template that matches your use case: Recommended for beginners: - **"Hello with SMS, WhatsApp, and RCS"** - Simple greeting template - **"Order Confirmation"** - E-commerce notification - **"Appointment Reminder"** - Service business reminder Click **"Use Sample"** to proceed. ## Customize Your Template [#customize-your-template] Modify the template content for your business: Templates are built from a body plus optional header, footer, and buttons; component support differs per channel. Refer to the [Working with Templates guide](/start/guides/working-with-templates) for the full component and channel-support matrix. ### Dynamic Variables [#dynamic-variables] Use variables for personalized content: ``` Hello {{customerName}}, your order {{orderNumber}} has been shipped! ``` Variables are shown in yellow boxes in the editor. In the underlying JSON the builder writes them in the canonical `{{0:variable}}` form, where the number is the variable's `id`; see [variable placeholder forms](/reference/api/template-definition#variable-object) for the forms the API accepts. ## Submit for Review [#submit-for-review] Once satisfied with your template, click **"Submit for Review"**: WhatsApp templates require Meta approval (typically 24-48 hours). You can still send SMS messages using the template while waiting for approval. Template statuses: - **Draft** - Editing in progress - **Pending** - Submitted for review - **Approved** - Ready to use - **Rejected** - Needs modifications ## Get Your Template ID [#get-your-template-id] Once created, copy your template ID: You'll need this ID when sending messages via the API: ```json { "to": ["+1234567890"], "template": { "id": "YOUR_TEMPLATE_ID" } } ``` ## Template Best Practices [#template-best-practices] ### Content Guidelines [#content-guidelines] **Do:** - Keep messages concise and clear - Use variables for personalization - Include clear call-to-action - Test on SMS, WhatsApp, and RCS **Don't:** - Use promotional language in utility templates - Include excessive punctuation (!!!) - Use all caps - Include URLs in the body (use button links instead) ### Character Limits [#character-limits] Character limits differ per channel and component. Refer to [SMS Encoding & Message Length](/start/concepts/sms-encoding-and-length) for SMS segment rules and to the [Working with Templates guide](/start/guides/working-with-templates) for per-channel template limits. ## What's Next? [#whats-next] Now that you have a template: 1. **[Send your first message](/start/quickstart/first-message)** - Use your template to send a message 2. **[Learn more about templates](/start/guides/working-with-templates)** - Advanced template features 3. **[Set up webhooks](/start/webhooks/getting-started)** - Track template approval status ## Troubleshooting [#troubleshooting] **Template rejected?** Common reasons: - Violates Meta's commerce policy - Contains promotional content in utility category - Poor grammar or spelling - Missing context **Template stuck in "Pending" status?** - Normal for WhatsApp approval (24-48 hours) - Use SMS in the meantime - Check [template status in dashboard](https://app.sent.dm/dashboard/templates) --- # Quickstart Overview (/start/quickstart.md) # Quickstart Overview [#quickstart-overview] Send your first message in minutes. A verified email address and phone number are enough to start; compliance paperwork comes later. **Light onboarding is live.** All you need is a verified email and phone number to access the API, 6 pre-built templates, and 500 sends/day per template. Compliance comes later, when you're ready to create your own templates or send from your own number. ## Start Here [#start-here] --- ## Ready for Production? [#ready-for-production] When you want to create your own templates or send from your own number, complete the full setup: ### Account Setup [#account-setup] Create your account and complete KYC verification. [Learn more →](/start/quickstart/account-setup) ⏱️ ~10 minutes - Sign up at [app.sent.dm](https://app.sent.dm) - Verify your phone number via WhatsApp - Complete business verification (KYC) - Set up billing ### Channel Setup [#channel-setup] Configure your SMS, WhatsApp, and RCS sender. [Learn more →](/start/quickstart/channel-setup) ⏱️ ~5 minutes - Select your business phone number - Connect WhatsApp Business account - Enable RCS messaging - Configure payment methods ### Create Your First Template [#create-your-first-template] Build a custom message template. [Learn more →](/start/quickstart/first-template) ⏱️ ~5 minutes - Choose from samples or build from scratch - Add dynamic variables - Submit for approval ### Send Your First Message [#send-your-first-message] Make your first API call. [Learn more →](/start/quickstart/first-message) ⏱️ ~2 minutes - Get your API keys from the dashboard - Send via API, SDK, or Playground - Track delivery status ## What Full Setup Unlocks [#what-full-setup-unlocks] | | Light Onboarding | Full Setup | |---|:---:|:---:| | Pre-built templates (OTP & verification) | 6 | 6 + custom | | Sends per day (per template) | 500 | Unlimited | | REST API | Yes | Yes | | Custom templates | No | Yes | | Your own sender number | No | Yes | ## Next Steps After Setup [#next-steps-after-setup] - **[Explore the Dashboard](/start/quickstart/dashboard-walkthrough)**: Learn all dashboard features - **[Set up Webhooks](/start/webhooks/getting-started)**: Receive real-time delivery notifications - **[Install an SDK](/sdks)**: Integrate Sent into your app - **[Read the Concepts](/start/concepts)**: Understand the architecture ## Need Help? [#need-help] - [Troubleshooting](/start/reference-guides/troubleshooting): Common issues and solutions - [email support](mailto:support@sent.dm): contact the Sent team --- # Frequently Asked Questions (/start/reference-guides/faq.md) # Frequently Asked Questions [#frequently-asked-questions] ## Getting Started [#getting-started] ### Do you need to complete KYC to start sending? [#do-you-need-to-complete-kyc-to-start-sending] No. **Light onboarding** lets you start sending immediately with just a verified email and phone number: - 6 pre-built OTP and verification templates - 500 sends/day per template - Full REST API access - Send to any phone number Full account verification is required when you want to create your own custom templates or send from your own number. [Start with light onboarding →](/start/try-sent) ### How long does setup take? [#how-long-does-setup-take] **Light onboarding**: ~2 minutes to verify your email and phone. **Full production setup**: 10-15 minutes: - Account creation: 2 minutes - KYC verification: 5-10 minutes (usually approved within hours) - Channel setup: 3-5 minutes - First message: 2 minutes ### Do you need a Meta Business account? [#do-you-need-a-meta-business-account] Only if you want to send **WhatsApp messages**. SMS works without Meta. You can create a Meta Business Portfolio during the WhatsApp setup process. ### Is there a free trial? [#is-there-a-free-trial] Yes, and you can start sending real messages immediately: - **Light onboarding**: Verify your email and phone and get 6 pre-built templates, 500 real sends/day, and full API access. No credit card required. [Start here →](/start/try-sent) - **Playground**: Send messages directly from the dashboard with no code - see the [Playground page](/start/quickstart/dashboard-walkthrough#playground-page) walkthrough. - **Sandbox mode**: Add `"sandbox": true` to any API request to validate without sending real messages or incurring charges. ## Pricing & Billing [#pricing--billing] ### How much does Sent cost? [#how-much-does-sent-cost] Pricing is usage-based: you pay for the contacts you message plus carrier pass-through fees, which vary by channel and destination country. See the [Sent pricing page](https://sent.dm/pricing) for current rates and an interactive cost calculator. ### What happens if you run out of balance? [#what-happens-if-you-run-out-of-balance] {/* Resolved 2026-09-01: the v3 spec no longer declares 402 on POST /v3/messages — its documented responses are 202/400/401/403/404/500, which agrees with the async balance gate described below. */} Your send requests are still accepted with a `202` response, but each message is finalized as `BLOCKED` instead of being dispatched. The `BLOCKED` status appears on `GET /v3/messages/{id}` and arrives as a `message.blocked` webhook, and you are not charged. Add credits manually from the [Billing page](https://app.sent.dm/dashboard/billing), or enable **Auto Charge** to top up automatically before your balance hits zero. See [Auto Charge](/start/quickstart/dashboard-walkthrough#auto-charge) in the dashboard walkthrough for setup instructions. Only the legacy v2 send endpoints reject an out-of-balance request synchronously with a `402` error and code `BUSINESS_003`. ### Why did your Auto Charge payment fail? [#why-did-your-auto-charge-payment-fail] The most common reasons are an expired card, insufficient funds, or your bank blocking an off-session (automatic) charge. If a payment fails, you'll receive a **"Your payment didn't go through"** email with the decline reason, and a red alert banner will appear on your Dashboard. Go to [Billing → Payment Methods](https://app.sent.dm/dashboard/billing) to update your card. Auto Charge resumes automatically once a valid method is on file. ### Do you offer volume discounts? [#do-you-offer-volume-discounts] Yes. Contact [sales@sent.dm](mailto:sales@sent.dm) for custom pricing on high volumes (1M+ messages/month). ## Messaging [#messaging] ### What's the difference between SMS, WhatsApp, and RCS? [#whats-the-difference-between-sms-whatsapp-and-rcs] | Feature | SMS | RCS | WhatsApp | |---------|-----|-----|----------| | **Delivery** | Universal (all phones) | Android (Google Messages), carrier-native | Requires WhatsApp app | | **Rich content** | Text only | Images, carousels, buttons, branded sender | Images, buttons, videos | | **Read receipts** | No | Yes (carrier dependent) | Yes | | **Cost** | Higher per message | Varies by carrier | Lower per conversation | | **Approval** | Template approval required | Template approval required | Template approval required | | **App required** | No | No | Yes | ### How fast are messages delivered? [#how-fast-are-messages-delivered] - **Queued to Sent:** < 100 ms - **Sent to provider:** < 1 second - **Delivered to device:** 1-30 seconds (carrier dependent) ### Can you send messages internationally? [#can-you-send-messages-internationally] Yes. Sent supports messaging to 200+ countries. Compliance requirements vary by destination - check the [Compliance Guide](/start/advanced/compliance-regulations). ## Templates [#templates] ### Does RCS require template approval? [#does-rcs-require-template-approval] Yes. Like WhatsApp, RCS requires template approval before you can send. All channels go through the same onboarding and template approval procedures. ### How long does WhatsApp template approval take? [#how-long-does-whatsapp-template-approval-take] Typically **24-48 hours**. You can send SMS messages using the template while waiting for approval. ### Why was your template rejected? [#why-was-your-template-rejected] Common reasons: - Promotional content in utility category - Violating Meta's commerce policies - Missing context or poor grammar - URLs in body (use buttons instead) ### Can you edit an approved template? [#can-you-edit-an-approved-template] No. Approved templates are locked to ensure consistency. Create a new template version instead. ## Webhooks [#webhooks] ### Do you need webhooks? [#do-you-need-webhooks] Not required, but **strongly recommended** for: - Delivery confirmations - Real-time status updates - Template approval notifications - Failed message handling ### What URL should you use for webhooks? [#what-url-should-you-use-for-webhooks] Your webhook endpoint must be: - Publicly accessible HTTPS URL - Return 2xx status codes - Respond within 5 seconds ### Can you test webhooks locally? [#can-you-test-webhooks-locally] Yes. Use [ngrok](/start/webhooks/local-development) or similar tools to expose your local server. ## Technical [#technical] ### Which SDK should you use? [#which-sdk-should-you-use] Choose based on your stack: - **TypeScript/Node.js:** `@sentdm/sentdm` - **Python:** `sentdm` - **Go:** `github.com/sentdm/sent-dm-go` - **Other languages:** Raw HTTP or community SDKs ### What's the API rate limit? [#whats-the-api-rate-limit] Limits are enforced per minute and differ between standard and sensitive endpoints. See the [rate limits reference](/reference/api/rate-limits) for the current limits, response headers, and backoff guidance. ### How do you handle errors? [#how-do-you-handle-errors] See the [Error Handling Guide](/start/guides/error-handling) for retry strategies, circuit breakers, and best practices. ## Security [#security] ### Is Sent SOC 2 compliant? [#is-sent-soc-2-compliant] Yes, Sent is SOC 2 Type II certified. Contact Sent for compliance documentation. ### Where is data stored? [#where-is-data-stored] Data is stored in AWS regions (US and EU). Contact Sent for data residency requirements. ### How do you rotate your API keys? [#how-do-you-rotate-your-api-keys] 1. Generate new key in [Dashboard](https://app.sent.dm/dashboard/api-keys) 2. Update your app 3. Deploy changes 4. Delete old key ## Support [#support] ### How do you get help? [#how-do-you-get-help] 1. Check this FAQ 2. Review [Troubleshooting](/start/reference-guides/troubleshooting) 3. Search [documentation](/docs) 4. email [support@sent.dm](mailto:support@sent.dm) ### What's the support response time? [#whats-the-support-response-time] Response times vary by plan. See [support response times](/start/reference-guides/support#support-response-times) for the current matrix. --- # Help & Reference Overview (/start/reference-guides.md) # Help & Reference Overview [#help--reference-overview] Quick answers and resources when you need help with Sent. ## What do you need help with? [#what-do-you-need-help-with] ## Quick Reference [#quick-reference] | Resource | Link | |----------|------| | **Error Codes** | [Error Catalog](/reference/api/error-catalog) | | **API Reference** | [API Documentation](/reference/api) | | **SDKs** | [SDK Guides](/sdks) | | **Glossary** | [Terms & Definitions](/reference/glossary) | | **Changelog** | [Platform Updates](/reference/changelog) | ## Search by Error [#search-by-error] Common errors and quick fixes: | Error | Quick Fix | |-------|-----------| | `401 Unauthorized` | [Check API key](/start/reference-guides/troubleshooting) | | `429 Rate Limited` | [Implement backoff](/start/guides/error-handling) | | `Template not approved` | [Check template status](/start/guides/working-with-templates) | | `Insufficient balance` | [Add payment method](https://app.sent.dm/dashboard/billing) | ## Support Channels [#support-channels] ### Self-Service [#self-service] - [Documentation](/docs) - Complete guides - [API Reference](/reference/api) - Endpoint details - [Error Catalog](/reference/api/error-catalog) - Error codes ### Community [#community] - [Sent on GitHub](https://github.com/sentdm) - SDK repositories and issue trackers ### Direct Support [#direct-support] - **email:** [support@sent.dm](mailto:support@sent.dm) - **Response times:** Vary by plan - see [support response times](/start/reference-guides/support#support-response-times) **Submitting a support ticket?** Include your request ID, timestamp, and code snippet (with API keys removed) for faster resolution. --- # Support & Developer Resources (/start/reference-guides/support.md) # Support & Developer Resources [#support--developer-resources] Developer support resources, troubleshooting guides, and reference materials to help you get the most out of Sent's messaging platform. ## Support Resources [#support-resources] ## Getting Help [#getting-help] ### Self-Service Resources [#self-service-resources] - [Troubleshooting](/start/reference-guides/troubleshooting) - common issues and step-by-step solutions - [FAQ](/start/reference-guides/faq) - answers to frequent setup, billing, and messaging questions - [API reference](/reference/api) - complete endpoint documentation - [SDKs and integration guides](/sdks) - code examples and implementation patterns - [API Status](https://status.sent.dm) - real-time service status and incident reports ### Contact Support [#contact-support] email [support@sent.dm](mailto:support@sent.dm) for technical questions and integration help. Include the request ID (`meta.request_id`), the error code, and a code snippet with API keys removed - see [what to include in a support request](/start/reference-guides/troubleshooting#getting-support). For volume pricing or custom plans, contact [sales@sent.dm](mailto:sales@sent.dm). ### Support Response Times [#support-response-times] | Plan | Response time | Channel | |------|---------------|---------| | Starter/Growth | 24-48 hours | email | | Scale | 8-12 hours | email | | Enterprise | 2-4 hours | dedicated channels | Need immediate help? Check the [Error Reference](/reference/api/errors) and [Error Catalog](/reference/api/error-catalog) for the fastest resolution to common issues. --- # Troubleshooting Common Issues (/start/reference-guides/troubleshooting.md) # Troubleshooting Common Issues [#troubleshooting-common-issues] Common issues and step-by-step solutions. ## Authentication Issues [#authentication-issues] ### 401 Unauthorized [#401-unauthorized] **Symptoms:** API returns `401 Unauthorized` with error code `AUTH_002` (invalid or missing API key) **Solutions:** 1. Verify your API key is correct 2. Check the `x-api-key` header is set (not `x-sender-id` - that's v2 legacy) 3. Ensure no extra whitespace in the key 4. Verify the key hasn't been revoked ```bash # Test your API key curl -H "x-api-key: YOUR_API_KEY" \ https://api.sent.dm/v3/templates ``` ### 403 Forbidden [#403-forbidden] **Symptoms:** API returns `403 Forbidden` with an `AUTH_004`–`AUTH_007` error code **Solutions:** 1. `AUTH_004`: your API key doesn't have permission for this operation; use a key with the required access 2. `AUTH_005`: account onboarding is not complete; finish onboarding in the [dashboard](https://app.sent.dm) 3. `AUTH_006`: KYC verification is not complete; submit KYC and wait for approval 4. `AUTH_007`: channel setup is not complete; finish setup for the channel you're sending on 5. A suspended account also returns `403` with code `BUSINESS_014`; contact support ## Message Sending Issues [#message-sending-issues] ### Messages Stuck in "Queued" [#messages-stuck-in-queued] **Symptoms:** Message status doesn't change from `QUEUED` A message normally leaves `QUEUED` within the first few seconds after a send. If it stays queued longer: **Solutions:** 1. Check KYC status is approved 2. Verify account has sufficient balance 3. Check [dashboard](https://app.sent.dm/dashboard/activities) for errors ### Insufficient Balance [#insufficient-balance] {/* Resolved 2026-09-01: the v3 spec no longer declares 402 on POST /v3/messages — its documented responses are 202/400/401/403/404/500, which agrees with the async balance gate described below. */} **Symptoms:** The send returns `202 Accepted`, but the message is finalized as `BLOCKED` (insufficient balance). The status appears on `GET /v3/messages/{id}/activities` and arrives as a `message.blocked` webhook. Legacy v2 send endpoints instead return `402` with error code `BUSINESS_003`. **Solutions:** 1. Add credits manually from [Billing → Overview](https://app.sent.dm/dashboard/billing) 2. Enable **Auto Charge** (Billing → Overview → gear icon) to automatically top up when your balance falls below a set threshold. This prevents the block from recurring 3. Check [Billing → Billing History](https://app.sent.dm/dashboard/billing) for failed payments ### Payment failed (Auto Charge or manual top-up) [#payment-failed-auto-charge-or-manual-top-up] **Symptoms:** Red alert banner on the Dashboard reads *"Your last payment didn't go through,"* or you received a **"Your payment didn't go through"** email. **Common causes:** - Card declined (insufficient funds, expired card, or bank block on off-session charges) - No default payment method on file - No Stripe customer record linked to the account **Solutions:** 1. Go to [Billing → Payment Methods](https://app.sent.dm/dashboard/billing) and update or re-add your card 2. After updating, add credits manually to confirm the new payment method works 3. Auto Charge will resume automatically on the next trigger once a valid payment method is on file 4. If the problem persists, contact [support@sent.dm](mailto:support@sent.dm) with the decline reason from the email ### 429 Rate Limited (BUSINESS_002) [#429-rate-limited-business_002] **Symptoms:** API returns `429` with error code `BUSINESS_002` **Rate Limits:** - Standard endpoints: 10,000 requests per minute - Sensitive endpoints: 10 requests per minute **Solutions:** 1. Implement exponential backoff 2. Reduce request frequency 3. Consider batching requests 4. Check rate limit headers for reset time ```typescript // Implement backoff const retryAfter = error.headers['retry-after'] || 60; await sleep(retryAfter * 1000); ``` ### Invalid Phone Number (VALIDATION_002) [#invalid-phone-number-validation_002] **Symptoms:** Error code `VALIDATION_002` **Solutions:** 1. Use E.164 format (+1234567890) 2. Include country code 3. Remove spaces and special characters 4. Validate before sending ```typescript function validateE164(phone: string): boolean { return /^\+[1-9]\d{1,14}$/.test(phone); } ``` ## Template Issues [#template-issues] ### Template Not Found (RESOURCE_002) [#template-not-found-resource_002] **Symptoms:** Error code `RESOURCE_002` **Solutions:** 1. Verify template ID is correct (use `template.id` in request body, not `template_id`) 2. Check template exists in [dashboard](https://app.sent.dm/dashboard/templates) 3. Ensure you're using the right account ### Template Pending Approval [#template-pending-approval] **Symptoms:** WhatsApp messages not sending **Solutions:** 1. Wait for Meta approval (24-48 hours) 2. Use SMS in the meantime 3. Check [template status](https://app.sent.dm/dashboard/templates) 4. Review rejection reason if applicable ### Template Rejected [#template-rejected] **Symptoms:** Template status `rejected` **Solutions:** 1. Review Meta's feedback 2. Fix identified issues 3. Resubmit template 4. Contact support if unclear ## Webhook Issues [#webhook-issues] ### Webhooks Not Received [#webhooks-not-received] **Symptoms:** No webhook events arriving **Solutions:** 1. Verify webhook URL is correct 2. Check endpoint returns 2xx status 3. Ensure endpoint responds within 5 seconds 4. Verify HTTPS is working 5. Check webhook is enabled in dashboard ### Duplicate Webhooks [#duplicate-webhooks] **Symptoms:** Same event received multiple times **Solutions:** 1. Implement idempotency using event ID 2. Store processed event IDs 3. Use database transactions See [Handling Retries](/start/webhooks/handling-retries). ### Webhook Signature Invalid [#webhook-signature-invalid] **Symptoms:** Signature verification fails **Solutions:** 1. Use raw request body (not parsed JSON) 2. Check secret key is correct 3. Use constant-time comparison 4. Verify timestamp is recent ## Channel Issues [#channel-issues] ### WhatsApp Not Working [#whatsapp-not-working] **Symptoms:** WhatsApp messages failing **Solutions:** 1. Verify WhatsApp Business account is connected 2. Check template is approved 3. Confirm recipient has WhatsApp 4. Verify Meta Business account is in good standing ### SMS Delivery Failed [#sms-delivery-failed] **Symptoms:** SMS messages failing **Solutions:** 1. Check phone number format 2. Verify recipient hasn't opted out 3. Check for carrier blocks 4. Review message content compliance ## Performance Issues [#performance-issues] ### Slow API Responses [#slow-api-responses] **Symptoms:** API calls taking > 5 seconds **Solutions:** 1. Check your network connection 2. Verify server location (use closest region) 3. Implement connection pooling 4. Check for rate limiting ### High Error Rate [#high-error-rate] **Symptoms:** > 5% of requests failing **Solutions:** 1. Check error logs for patterns 2. Review recent code changes 3. Verify API key validity 4. Check account status ## Dashboard Issues [#dashboard-issues] ### Can't Access Dashboard [#cant-access-dashboard] **Solutions:** 1. Check [API Status](https://status.sent.dm) for ongoing incidents 2. Verify your account hasn't been suspended - suspended accounts also receive `403` responses with code `BUSINESS_014` on API calls 3. If access still fails, email [support@sent.dm](mailto:support@sent.dm) with your account email and the time of the failure ### Data Not Loading [#data-not-loading] **Solutions:** 1. Check [API Status](https://status.sent.dm) for ongoing incidents 2. Check the browser console for JavaScript errors and include them in your support ticket 3. Contact [support@sent.dm](mailto:support@sent.dm) if the problem persists ## Debugging Steps [#debugging-steps] ### General Debugging Process [#general-debugging-process] 1. **Enable debug logging** ```typescript const client = new SentDm({ logLevel: 'debug' }); ``` 2. **Check request/response** ```typescript console.log('Request:', request); console.log('Response:', response); console.log('Error:', error); ``` 3. **Test in sandbox mode** ```typescript await client.messages.send({ to: ['+1234567890'], template: { id: 'tmpl_123' }, sandbox: true }); ``` 4. **Check dashboard logs** - [Activities](https://app.sent.dm/dashboard/activities) - [Webhook logs](https://app.sent.dm/dashboard/webhooks) ### Getting Support [#getting-support] When contacting support, include: 1. Request ID (from `meta.request_id` in error response) 2. Timestamp of issue (from `meta.timestamp`) 3. Error code (from `error.code`) 4. Code snippet (remove API keys) 5. Expected vs actual behavior 6. Steps to reproduce email: [support@sent.dm](mailto:support@sent.dm) --- # Try Sent: Send Your First Message in 2 Minutes, No Code (/start/try-sent.md) # Try Sent: Send Your First Message in 2 Minutes, No Code [#try-sent-send-your-first-message-in-2-minutes-no-code] The fastest way to experience Sent is through the Dashboard Playground: send real messages using pre-built templates directly from your browser, no code required. **What you get on sign-up**: 6 pre-built message templates · 500 sends/day · Dashboard Playground · REST API access **Time to first send**: ~2 minutes ## What's Included [#whats-included] | Feature | Light Onboarding | Full Setup | |---------|:----------:|:-----------:| | Pre-built OTP & verification templates | 6 | 6 + custom | | Sends per day (per template) | 500 | Unlimited | | Custom variables | Yes | Yes | | Dashboard Playground | Yes | Yes | | REST API access | Yes | Yes | | Create custom templates | No | Yes | | Send from your own number | No | Yes | | Choose destination countries | No | Yes | ## Get Started [#get-started] ### Sign Up [#sign-up] Visit [app.sent.dm/sign-up](https://app.sent.dm/sign-up), enter your email, and click the magic link in your inbox. ### Verify Your Phone Number [#verify-your-phone-number] After clicking the magic link, you'll be prompted to verify your phone number. Sent delivers the verification code via WhatsApp, or SMS if WhatsApp is not available for your number. Enter the code you receive to continue. ### Try the Playground [#try-the-playground] Open the [Dashboard Playground](https://app.sent.dm/dashboard/playground). Pick one of the pre-built templates, enter a phone number, and send a real message, all from your browser. The Activity pane on the right updates in real time as your message moves through delivery: queued, sent, delivered. ## Pre-Built Templates [#pre-built-templates] The 6 included templates cover the most common OTP and verification use cases. Find them in your dashboard under **Templates**. They support custom variables so you can pass in dynamic codes, names, or expiry times. ## Ready to Go Further? [#ready-to-go-further] Your API key is already active: find it in the dashboard under **API Keys**. When you're ready to create custom templates or send from your own number, complete the full account setup: --- # Events Reference (/start/webhooks/event-types.md) # Platform Events Reference [#platform-events-reference] This section is the definitive source for all webhook event types emitted by Sent. For an end-to-end view of delivery, retries, and the full event catalogue at a glance, see the [Webhooks Lifecycle](/start/webhooks/lifecycle) page. ## Event Structure [#event-structure] Every event that your webhook endpoint receives has a consistent envelope: ```json { "field": "message", "event": "message.delivered", "timestamp": "2025-10-31T10:10:42Z", "payload": { "updated_at": "2025-10-31T10:10:41Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "agent_id": "agent_abc123", "message_status": "DELIVERED", "channel": "sms", "body": "Hi Jane, your order has been confirmed." } } ``` ```json { "field": "message", "event": "message.received", "timestamp": "2025-10-31T10:10:42Z", "payload": { "message_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "updated_at": "2025-10-31T10:10:40Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "inbound_number": "+1234567890", "outbound_number": "+1987654321", "text": "Hello, I have a question about my order", "channel": "sms", "received_at": "2025-10-31T10:10:40Z" } } ``` ```json { "field": "templates", "event": "templates.approved", "timestamp": "2025-10-31T12:18:14Z", "payload": { "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "whatsapp_template_id": "1234567890123456", "status": "APPROVED", "language": "en_US", "category": "UTILITY", "channel": "whatsapp" } } ``` ```json { "field": "channel", "event": "channel.activated", "timestamp": "2025-10-31T14:22:09Z", "request_id": "req_7X9zKp2jDw", "payload": { "channel": "sms", "status": "ACTIVE", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "country": "XK", "number_type": "ALPHANUMERIC", "sender_value": "SENTDM", "updated_at": "2025-10-31T14:22:09Z" } } ``` ```json { "field": "contact", "event": "contact.opt_out", "timestamp": "2026-09-24T14:00:00Z", "request_id": "req_9Y0aLq3kEx", "payload": { "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "contact_id": "a1b2c3d4-9dad-11d1-80b4-00c04fd430c8", "from": "+14155551234", "to": "+18005550100", "opt_out": true, "source": "INBOUND_KEYWORD", "channel": "sms", "text": "STOP", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c9" } } ``` ```json { "field": "link", "event": "link.clicked", "timestamp": "2025-10-31T15:04:02Z", "payload": { "customer_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "sender_profile_id": null, "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "record_id": "A78B2BU0", "link_kind": "url", "channel": "sms", "reference_key": "body:0", "occurred_at": "2025-10-31T15:04:00Z", "request_method": "GET", "status_code": 302, "traffic_class": "likely_human", "access_country": "US", "device": "mobile", "browser": "chrome" } } ``` ```json { "field": "call", "event": "call.completed", "timestamp": "2026-07-22T12:00:49Z", "payload": { "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "call_id": "call_9f2ab000-0000-4000-8000-000000000001", "channel": "voice", "number": "+12025550123", "mode": "inapp", "updated_at": "2026-07-22T12:00:47Z", "duration_seconds": 42, "price": 0.0105 } } ``` | Field | Type | Description | |-------|------|-------------| | `field` | string | The parent event type: `message`, `templates`, `channel`, `contact`, `link`, or `call` | | `event` | string \| omitted | Granular sub-type (for example, `message.delivered`). Present on every message event, and on every template event whose status maps to a published sub-type. Omitted when the status has no published sub-type (see [Template sub-types](#template-sub-types)) | | `timestamp` | string | ISO 8601 timestamp of event creation | | `request_id` | string \| omitted | Correlates the deliveries produced by one action, when the action had a request id. Channel events carry it; the other families, call events included, omit it | | `payload` | object | Nested object containing event-specific data | ## Event Types & Details [#event-types--details] Your handler receives the full event object: `field`, `event`, `timestamp`, and the nested `payload`. ### `message` [#message] Triggered whenever a message's delivery status changes, or when an inbound message is received. Each status transition fires a separate event with a matching `event`. **Outbound message status events:** All outbound status events share one payload shape. Only `event`, `payload.message_status`, and the timestamps change between sub-types; the **Status Definitions** table below lists every pairing. ```json { "field": "message", "event": "message.delivered", "timestamp": "2025-10-31T12:15:42Z", "payload": { "updated_at": "2025-10-31T12:15:42Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "DELIVERED", "channel": "sms", "body": "Hi Jane, your order has been confirmed." } } ``` Messages that are held, cancelled, or suppressed by platform policy emit four additional sub-types with the same payload shape: - `message.scheduled`: the send is held for a later instant, either a `scheduled_at` you set or because it fell inside the recipient's quiet hours, where it is deferred rather than failed. Sent evaluates quiet-hours windows per channel against the rules for the recipient's country and time zone, both derived from the recipient's phone number. The event carries `message_status: "SCHEDULED"`, `payload.scheduled_at` for the release instant, and `payload.schedule_reason` for which of the two held it. Sent releases the message automatically when that instant arrives and it continues through the normal send pipeline, so later status events (`message.sent`, `message.delivered`, and so on) follow. `SCHEDULED` is not a terminal status. - `message.cancelled`: you called a held send off with `POST /v3/messages/{id}/cancel`. The event carries `message_status: "CANCELLED"` and `payload.scheduled_at`, the release instant that was called off, which is the same value `message.scheduled` carried for this message. It fires exactly once per cancellation: cancelling the same message again publishes nothing. `CANCELLED` is terminal, so no further status event follows and the message is never sent. It carries no `schedule_reason` and no `reason_code`, because Sent has nothing to explain about a send you stopped yourself. See [Cancelling scheduled messages](/start/guides/cancelling-messages). - `message.filtered`: a policy gate suppressed the send before any provider call. Either the recipient opted out or is on your phone-channel suppression list, or your routing rules denied the send. The message is not dispatched. `payload.reason_code` says which: `BUSINESS_004` for an opted-out or suppressed recipient, `DELIVERY_004` for a denied destination. - `message.blocked`: a precondition gated the send: an account-level one such as insufficient balance or an onboarding message quota, a template that is not approved for sending, or a free-form send to a contact with no open conversation. The message is not dispatched. `payload.reason_code` names the precondition, for example `BUSINESS_003` for the balance, `BUSINESS_020` for the onboarding limit, or `BUSINESS_029` for a number listed in `channels.sms` that is not an active sender on the account. **Why a message didn't go out.** `message.failed`, `message.filtered` and `message.blocked` carry `payload.reason_code` and `payload.reason`. `reason_code` is a stable code from the [Error Catalog](/reference/api/error-catalog) to branch on; `reason` is a sentence to show a person, and its wording may improve. A cause the API also rejects synchronously keeps the same code on the message: an opted-out recipient is `BUSINESS_004` whether the send request was refused or a later filter stopped it. Causes only a message outcome can have are `DELIVERY_001` to `DELIVERY_016`. The codes are Sent's classification of the outcome, never a carrier's or provider's own code. Both fields are omitted on every other sub-type. ```json { "field": "message", "event": "message.blocked", "timestamp": "2025-10-31T12:15:42Z", "payload": { "updated_at": "2025-10-31T12:15:42Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "outbound_number": "+1987654321", "message_status": "BLOCKED", "channel": "sent", "body": null, "reason_code": "BUSINESS_003", "reason": "The account balance is too low to send this message. Add funds to resume sending" } } ``` **The rendered body.** `payload.body` carries the message text as plain text. The field is always present, so read it and test for `null` rather than testing whether the key exists. When it holds a value, that value is the render for the same event's `channel`, which lets you read the two fields as one fact: the copy that was dispatched on `message.sent`, `message.delivered`, `message.read` and a carrier-reported `message.failed`, and the copy that would have gone out on `message.filtered`, `message.blocked` and a pipeline-side `message.failed`. `null` means Sent is not asserting a body for the event. Three cases produce it: - `message.queued`, `message.routed`, `message.scheduled` and `message.cancelled`, which all fire before routing picks a channel. - A `message.filtered`, `message.blocked` or `message.failed` whose `channel` is a pseudo-channel (`sent` or `auto`). The send was stopped before routing picked a channel, and a template can author different copy per channel, so there is no single body to name. - A delivery report for an attempt the message has since been rerouted away from. Two limits to build the handler around. The body is plain text only: a WhatsApp or RCS header, footer and buttons are not published here, so a short `body` does not mean the message had no header, and a message with buttons looks the same as one without. And the body is truncated at 3072 characters. Call `GET /v3/messages/{id}` when you need the full composed message. The inbound counterpart is `text` on `message.received`, which carries what the contact sent. The names differ, so a handler that threads a conversation together reads `body` on the outbound events and `text` on the inbound one. **Outbound Message Event Fields (all outbound sub-types):** | Field | Type | Description | |-------|------|-------------| | `field` | string | Parent event type: `message` | | `event` | string | Granular sub-type: one of `message.queued`, `message.routed`, `message.sent`, `message.delivered`, `message.read`, `message.failed`, `message.scheduled`, `message.cancelled`, `message.filtered`, `message.blocked` | | `timestamp` | string | ISO 8601 timestamp of the event | | `payload.updated_at` | string | ISO 8601 timestamp of the status change | | `payload.account_id` | string | The account the event is about: the Sender Profile for a profile's event, otherwise your account | | `payload.message_id` | string | Message UUID, used to look up the message in your DB | | `payload.template_id` | string \| null | UUID of the template used (null if no template) | | `payload.template_name` | string \| omitted | Name of the template used (omitted when not resolved) | | `payload.outbound_number` | string | Recipient phone number (E.164 format) | | `payload.agent_id` | string \| omitted | Identifier of the agent that originated the message (omitted when not set) | | `payload.message_status` | string | `QUEUED`, `ROUTED`, `SENT`, `DELIVERED`, `READ`, `FAILED`, `SCHEDULED`, `CANCELLED`, `FILTERED`, `BLOCKED` | | `payload.channel` | string | `sms`, `mms`, `whatsapp`, or `rcs` once routing has resolved a channel. Before that, and on a policy-gated outcome for a smart-routed send, it is the pseudo-channel `sent` or `auto`, which means no channel was picked. Treat both the same way | | `payload.body` | string \| null | The rendered message text, plain text only, truncated at 3072 characters. `null` when Sent is not asserting a body for the event, in the cases described in the preceding section | | `payload.scheduled_at` | string \| omitted | `message.scheduled` and `message.cancelled` only, in UTC: the instant the message is held for, or on a cancellation the instant that was called off. Omitted on every other sub-type | | `payload.schedule_reason` | string \| omitted | `message.scheduled` only: whether you scheduled the send or the recipient's quiet hours held it. Omitted on every other sub-type, including `message.cancelled` | | `payload.reason_code` | string \| omitted | Why the message reached `FAILED`, `FILTERED` or `BLOCKED`, as a stable code such as `DELIVERY_013` or `BUSINESS_004`. See the [Error Catalog](/reference/api/error-catalog). Omitted on every other sub-type | | `payload.reason` | string \| omitted | A sentence explaining `reason_code`. Show it rather than branching on it. Omitted whenever `reason_code` is | --- **Inbound message event (`message.received`):** Fires when an end-user sends a message to one of your provisioned numbers, for example, a reply to an outbound campaign, a STOP/START/HELP keyword on SMS, or a free-text reply on WhatsApp. The payload shape is different from outbound status events: ```json { "field": "message", "event": "message.received", "timestamp": "2025-10-31T10:10:42Z", "payload": { "message_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "updated_at": "2025-10-31T10:10:40Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "inbound_number": "+1234567890", "outbound_number": "+1987654321", "text": "Hello, I have a question about my order", "channel": "sms", "received_at": "2025-10-31T10:10:40Z" } } ``` ```json { "field": "message", "event": "message.received", "timestamp": "2025-10-31T10:10:42Z", "payload": { "message_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "updated_at": "2025-10-31T10:10:40Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "inbound_number": "+1234567890", "outbound_number": "+1987654321", "text": "Thanks, got your message!", "channel": "whatsapp", "received_at": "2025-10-31T10:10:40Z" } } ``` ```json { "field": "message", "event": "message.received", "timestamp": "2025-10-31T10:10:42Z", "payload": { "message_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "updated_at": "2025-10-31T10:10:40Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "inbound_number": "+1234567890", "outbound_number": "+1987654321", "text": "Tapped: View order", "channel": "rcs", "received_at": "2025-10-31T10:10:40Z" } } ``` **Inbound Message Event Fields (`message.received`):** | Field | Type | Description | |-------|------|-------------| | `field` | string | Parent event type: `message` | | `event` | string | Always `message.received` | | `timestamp` | string | ISO 8601 timestamp of the event | | `payload.message_id` | string | UUID of the inbound message record; unique per inbound message | | `payload.updated_at` | string | ISO 8601 timestamp of the message update | | `payload.account_id` | string | The account the event is about: the Sender Profile for a profile's event, otherwise your account | | `payload.inbound_number` | string | Sender's phone number (the contact) in E.164 format | | `payload.outbound_number` | string | Your provisioned number that received the message | | `payload.text` | string \| null | Message body text | | `payload.channel` | string | Channel the message arrived on: `sms`, `mms`, `whatsapp`, or `rcs` | | `payload.media` | array \| omitted | The attachments the contact sent, on an inbound MMS. Each entry carries `url`, and `mime_type`, `size_bytes` and `hash_sha256` when the carrier declared them. The `url` is the carrier's own link: it is unauthenticated and expires, so download the file on receipt. Omitted when the message has no attachments. See [Inbound MMS](/start/guides/mms#inbound-mms) | | `payload.received_at` | string | ISO 8601 timestamp when the provider received the message | **Status Definitions:** | Status | Sub-type | Direction | Description | |--------|----------|-----------|-------------| | `QUEUED` | `message.queued` | Outbound | Message accepted and waiting to be dispatched | | `ROUTED` | `message.routed` | Outbound | Message assigned to a carrier or provider | | `SENT` | `message.sent` | Outbound | Message sent to carrier or WhatsApp | | `DELIVERED` | `message.delivered` | Outbound | Message delivered to recipient's device | | `READ` | `message.read` | Outbound | Message read by recipient (WhatsApp & RCS) | | `FAILED` | `message.failed` | Outbound | Message delivery failed permanently | | `SCHEDULED` | `message.scheduled` | Outbound | Message held until a future instant: one you set with `scheduled_at`, or the end of the recipient's quiet hours. Re-enters the send pipeline automatically when the instant arrives | | `CANCELLED` | `message.cancelled` | Outbound | A held message you called off with `POST /v3/messages/{id}/cancel`. Terminal, and never sent | | `FILTERED` | `message.filtered` | Outbound | Message suppressed by a policy gate (consent opt-out, suppression list, or routing deny); not dispatched | | `BLOCKED` | `message.blocked` | Outbound | Message gated by a precondition: account-level (for example, insufficient balance), template not approved, or no open conversation for a free-form send; not dispatched | | `RECEIVED` | `message.received` | Inbound | Inbound message received from a contact |
### `templates` [#templates] Triggered when a template moves through review. Each transition fires a separate event with a matching `event`. Approval is tracked per channel, and who reviews a template depends on the account: - **With a connected WhatsApp Business Account**, Meta reviews it. An `APPROVED` or `PENDING` verdict applies to every channel; a rejection from Meta applies to the WhatsApp leg only, and the other legs keep the state they had. - **Without one**, Sent's compliance team reviews it and decides each channel individually, usually within minutes rather than days. Either way the legs can settle at different times, so each decision reports on its own. `payload.channel` names the leg, and is omitted when a decision applies to the whole template. ```json { "field": "templates", "event": "templates.approved", "timestamp": "2025-10-31T12:18:14Z", "payload": { "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "template_id": "9ba7b840-9dad-11d1-80b4-00c04fd430c8", "template_name": "order_confirmation", "whatsapp_template_id": "1234567890123456", "status": "APPROVED", "language": "en_US", "category": "UTILITY", "channel": "whatsapp" } } ``` #### Template sub-types [#template-sub-types] All template events share one payload shape. Only `event`, `payload.status`, and `payload.reason` change between sub-types. Sent creates three auto-replies for you, answering opt-in, opt-out, and help keywords, and you can add your own for any keyword you choose. All of them are reviewed like any other template, so they raise these events too. `payload.auto_reply_action` is how you tell them apart from the templates you author: the three report `OPT_IN`, `OPT_OUT`, and `HELP`, and one of yours reports `OTHER`. | `payload.status` | `event` | What it means | |---|---|---| | `PENDING` | `templates.pending` | The template was submitted and is in review. A submission covers every channel, so this event names no leg | | `APPROVED` | `templates.approved` | The template is approved and can be sent | | `REJECTED` | `templates.rejected` | The template was rejected. `payload.reason` carries why | | `PAUSED` | `templates.paused` | Low quality paused the template. Sends against it are rejected until it recovers | | `DISABLED` | `templates.disabled` | The template was disabled, for example for a policy violation | | `DELETED`, `PENDING_DELETION` | `templates.deleted` | The template was deleted, including a deletion made outside Sent | | `CATEGORY_UPDATED` | `templates.category_updated` | The category changed, which changes how the template is priced. Two things cause it: Meta setting or moving the category on the WhatsApp leg, which names `whatsapp`, and you changing it on an edit, which names no leg because the category belongs to the template. `payload.reason` reads `Category set to MARKETING` when there was no category before, and `Category changed from UTILITY to MARKETING` otherwise | | `QUALITY_UPDATED` | `templates.quality_updated` | The quality rating changed. `payload.reason` names the transition, for example `Quality changed from GREEN to YELLOW`. Meta reports `UNKNOWN` when it has too little data to rate the template, and a rating that keeps falling ends in `PAUSED` | Meta forwards a wider set of lifecycle values than the preceding table covers, and adds to it without notice. A status outside the table arrives on the bare `templates` parent with no `event` key and the status reported verbatim in `payload.status`, so route on `field` first and treat `event` as optional. **Template Event Fields:** | Field | Type | Description | |-------|------|-------------| | `field` | string | Event type: `templates` | | `event` | string \| omitted | The specific transition, for example `templates.approved` | | `timestamp` | string | ISO 8601 timestamp of the event | | `payload.account_id` | string | The account the event is about: the Sender Profile for a profile's event, otherwise your account | | `payload.template_id` | string | Template UUID in Sent | | `payload.template_name` | string | Template name | | `payload.whatsapp_template_id` | string | Meta's WhatsApp template ID, assigned when the WhatsApp leg is submitted. Empty until then, and empty for the lifetime of a template on an account with no WhatsApp channel | | `payload.status` | string | The status the template reached. See the preceding sub-type table for the values that carry an `event`; any other value Meta forwards is reported here verbatim. | | `payload.language` | string | Template language code (e.g. `en_US`) | | `payload.category` | string | Template category: `MARKETING`, `UTILITY`, `AUTHENTICATION` | | `payload.channel` | string \| omitted | The leg this decision is about: `sms`, `mms`, `whatsapp`, or `rcs`. Omitted when the decision applies to the whole template, which affects every leg | | `payload.auto_reply_action` | string \| omitted | Which consent keyword the template answers, when it is one of the auto-replies Sent creates for you: `OPT_IN`, `OPT_OUT`, `HELP`, or `OTHER` for a keyword you defined. Omitted for an ordinary template, so its presence is the answer to whether the event is about an auto-reply. The same field appears on `GET /v3/templates` | | `payload.reason` | string \| omitted | Reason for the decision (e.g. rejection reason for `REJECTED`, change description for `CATEGORY_UPDATED` and `QUALITY_UPDATED`). Supplied by whichever reviewer decided the leg, or by Sent when the change was yours. Omitted when not set. |
### `channel` [#channel] Triggered when one of your channels moves through provisioning and compliance. Getting a sender live is the longest-running asynchronous process on the platform. A 10DLC registration goes to The Campaign Registry, and a sender ID in some markets pre-registers with the destination's regulator, so these events tell you where a market stands without polling `GET /v3/channels`. The subject is always one market, not the account. `payload.country` names it, and `payload.number_type` and `payload.sender_value` say which sender it uses. A market that registers with nobody reports the same way as one that does. Your WhatsApp number publishes on this family too, with `payload.channel` set to `whatsapp`. See [WhatsApp channel events](#whatsapp-channel-events). Two fields answer two different questions. `event` says what happened; `payload.status` says whether the market can send. They move independently: a resubmission filed against a market whose sender is already live arrives as `channel.submitted` carrying `ACTIVE`. Route on `event` and read `status` for the current state. ```json { "field": "channel", "event": "channel.activated", "timestamp": "2025-10-31T14:22:09Z", "request_id": "req_7X9zKp2jDw", "payload": { "channel": "sms", "status": "ACTIVE", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "country": "XK", "number_type": "ALPHANUMERIC", "sender_value": "SENTDM", "updated_at": "2025-10-31T14:22:09Z" } } ``` ```json { "field": "channel", "event": "channel.activated", "timestamp": "2025-10-31T14:22:09Z", "request_id": "req_7X9zKp2jDw", "payload": { "channel": "sms", "status": "ACTIVE", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "country": "US", "number_type": "TEN_DLC", "sender_value": "+12015550101", "compliance": { "brand": { "inherit": false, "legal_name": "Tenant 42 Coffee Company LLC", "business_name": "Tenant 42 Coffee Co", "tax_id": "12-3456789", "tax_id_type": "us_ein", "ein_issuing_country": "US", "entity_type": "PRIVATE_PROFIT", "street": "123 Main Street", "city": "New York", "state": "NY", "postal_code": "10001", "country": "US", "website": "https://tenant42.example.com", "contact_name": "Jane Doe", "contact_email": "jane@tenant42.example.com", "contact_phone": "+12125550123" }, "campaign": { "inherit": false, "description": "Order and delivery updates for coffee subscriptions", "message_flow": "Customers opt in at checkout on tenant42.example.com by ticking a box that is unchecked by default. Consent is not a condition of purchase.", "use_cases": [ { "use_case": "DELIVERY_NOTIFICATION", "sample_messages": ["Tenant 42 Coffee: your order #1234 ships today. Reply STOP to opt out."] } ], "opt_in_message": "Tenant 42 Coffee: you are subscribed to order updates. Reply STOP to opt out, HELP for help.", "opt_out_message": "Tenant 42 Coffee: you will receive no further messages.", "help_message": "Tenant 42 Coffee: for help, email support@tenant42.example.com. Reply STOP to opt out.", "opt_in_keywords": "START,YES", "opt_out_keywords": "STOP", "help_keywords": "HELP", "privacy_policy_link": "https://tenant42.example.com/privacy", "terms_and_conditions_link": "https://tenant42.example.com/terms", "volume": "1000" }, "documents": [] }, "updated_at": "2025-10-31T14:22:09Z" } } ``` #### Channel sub-types [#channel-sub-types] | `event` | What it means | |---|---| | `channel.submitted` | Your request is filed and it's with Sent or a registry. Fires for a first filing, for a resubmission, and for a sender ID that Sent pre-registers with the destination's regulator on your behalf once that market's documents are in, because to you they are the same fact | | `channel.changes_requested` | Something needs correcting before the market can go forward, and nothing progresses until you act. A market that pre-registers its sender ID arrives here while its required documents are missing. Call `GET /v3/compliance/requirements` for the market to see which fields and documents are outstanding | | `channel.approved` | The verdict is in and the sender is being acquired. For a 10DLC market, this fires once the carriers elect your campaign. Not sendable: wait for `channel.activated` | | `channel.rejected` | The market's sender was turned down before it ever went live, either because The Campaign Registry rejected its campaign or because a sender still being set up was withdrawn. `payload.reason` says why when one was given. This is not `channel.deactivated`, which means a sender that worked stopped | | `channel.activated` | The sender is live and the market can carry traffic. Subscribe to this one alone if all you need is to know when you can send | | `channel.deactivated` | The sender stopped working, whether its number went back to the pool, its campaign lapsed, or Sent switched it off. Stop queueing against the market until it returns. Carries `INACTIVE`, the same value `GET /v3/channels` reports for that market. Do not read it as `PROVISIONING`: that status means the market has never sent yet and Sent is setting it up, where `INACTIVE` means it worked and stopped | | `channel.removed` | Sent removed a sender that had been approved, for example at your request. The sender is gone rather than switched off, so request a new one to send in that market again. Carries `INACTIVE`. Before October 28, 2026 a removal arrived as `channel.deactivated`, so a webhook subscribed to `channel.deactivated` alone no longer receives removals: add `channel.removed` or subscribe to the `channel` parent | #### WhatsApp channel events [#whatsapp-channel-events] Your WhatsApp number reports its milestones as `channel` events with `payload.channel` set to `whatsapp`. The subject is the number, not an SMS market: | What happened | `event` | `payload.status` | |---|---|---| | You claimed a number Sent supplied, and it can't send yet because its registration or its display-name review is still outstanding | `channel.submitted` | `PROVISIONING` | | The number is registered and can send | `channel.activated` | `ACTIVE` | | Meta approved the number's display name. On a Meta-provided +1 555 number this is when it can send at all | `channel.activated` | `ACTIVE` | | Meta rejected the display name. Meta offers no appeal, so the fix is a different name | `channel.changes_requested` | `ACTION_NEEDED` | | The number came off your account: it was deregistered at Meta and returned to Sent, for example after a [disconnect](/start/guides/connect-whatsapp#disconnect-a-whatsapp-business-account) | `channel.deactivated` | `INACTIVE` | A claim that can send straight away publishes `channel.activated` alone, not a `channel.submitted` followed by `channel.activated`. ```json { "field": "channel", "event": "channel.activated", "timestamp": "2026-10-14T09:12:44Z", "request_id": "req_4f1c9a0b7e2d4c6a8b", "payload": { "channel": "whatsapp", "status": "ACTIVE", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "country": "US", "sender_value": "+15550100123", "updated_at": "2026-10-14T09:12:44Z" } } ``` On WhatsApp events: - `payload.sender_value` is the number in E.164, and `payload.country` is that number's country. `country` is an empty string when the number's country isn't known. - `payload.number_type`, `payload.compliance`, and `payload.reason_code` are omitted. - `payload.reason` carries Meta's rejection reason on a rejected display name when Meta gave one, and is omitted otherwise. Unlike on an SMS market, it can be missing on `ACTION_NEEDED`. #### Channel statuses [#channel-statuses] | `payload.status` | What it means | |---|---| | `PROVISIONING` | Sent is working on it and there is nothing for you to do. A number is being procured, or a registration assembled | | `PENDING_REVIEW` | Submitted, and a regulator or carrier is deciding. Their answer moves it to `ACTIVE` or back to `ACTION_NEEDED` | | `ACTION_NEEDED` | Waiting on you. Nothing progresses until you act | | `ACTIVE` | The market can carry traffic | | `INACTIVE` | The market lost its sender and cannot send | `ACTIVE` means provisioning and compliance are complete. It does not promise that the next send succeeds: a suspended account and a destination blocked by a routing rule both report `ACTIVE`. **Channel Event Fields:** | Field | Type | Description | |-------|------|-------------| | `field` | string | Event type: `channel` | | `event` | string | The specific transition, for example `channel.activated` | | `timestamp` | string | ISO 8601 timestamp of the event | | `request_id` | string \| omitted | Correlates the deliveries produced by one action, when the action had a request id | | `payload.channel` | string | The channel the market belongs to: `sms`, `whatsapp`, or `rcs` | | `payload.status` | string | Where the market stands. See the preceding status table | | `payload.account_id` | string | The account the market belongs to: the Sender Profile for a profile's market, otherwise your account | | `payload.country` | string | The market's destination country as an ISO 3166-1 alpha-2 code, for example `XK` | | `payload.number_type` | string \| omitted | The kind of sender the market uses, for example `TEN_DLC`, `LOCAL`, or `ALPHANUMERIC`. Omitted when the market has no sender type of its own | | `payload.sender_value` | string \| omitted | The sender itself, either a number in E.164 or an alphanumeric sender ID. Omitted until one is assigned | | `payload.compliance` | object \| omitted | What the market has supplied for compliance, in the same shape as `GET /v3/channels/sms/{country}/{type}`. Omitted for markets that register with nobody, and on `channel.deactivated` events | | `payload.compliance.brand` | object \| omitted | The identity the market registers under, carrying the same fields you supplied on `POST /v3/channels/sms` or `PATCH /v3/channels/sms/{country}/{type}`. TCR brand IDs are not included. Present on TEN_DLC markets once brand fields have been supplied. Absent for markets that do not register with a compliance regime | | `payload.compliance.brand.inherit` | boolean | `false` when the market has its own dedicated brand registration; `true` when it runs on the organization's brand | | `payload.compliance.campaign` | object \| omitted | The programme the market registers, carrying the same fields you supplied. Keywords (`opt_in_keywords`, `opt_out_keywords`, `help_keywords`) are comma-delimited strings. `volume` is a string or null when not set. TCR campaign IDs are not included. Present on TEN_DLC markets once campaign fields have been supplied. Absent for markets that do not register with a compliance regime | | `payload.compliance.campaign.inherit` | boolean | `false` when the market has its own dedicated campaign; `true` when it runs on the organization's campaign | | `payload.compliance.campaign.use_cases` | array | One entry per declared use case. Each entry carries `use_case` (the use case type string, for example `DELIVERY_NOTIFICATION`) and `sample_messages` (array of example message strings) | | `payload.compliance.documents` | array \| omitted | Documents attached to the market. Each entry carries `key` (the requirement name), `file_name`, and `document_id`. An empty array means the market has been given none; absent means documents were not available for this event | | `payload.reason_code` | string \| omitted | Why the market is not `ACTIVE`, as a stable code from `CHANNEL_001` to `CHANNEL_011`: the same code `GET /v3/channels` reports for the market. Branch on this rather than on `reason`. See [Channel reason codes](/reference/api/error-catalog#channel-status-reasons). Omitted while `ACTIVE` | | `payload.reason` | string \| omitted | Why the market reached this state, as a sentence to show a person: the specific explanation when one was given, such as a reviewer's correction, otherwise what `reason_code` means for this market. Always present for an `ACTION_NEEDED` market. On an `ACTIVE` market it appears only when the event carried its own explanation, such as a correction requested against a sender that still works | | `payload.updated_at` | string | ISO 8601 timestamp of the change | Your organization's webhook receives your organization's own channel events. To receive every Sender Profile's at the same endpoint, select `channel` under `sender_profile`, which clones the webhook onto each profile, and `payload.account_id` names the profile whose market moved. See [Sender Profile Events](#sender-profile-events).
### `contact` [#contact] Triggered when a contact signals a consent change, asks for help, or sends one of your custom auto-reply keywords. These events state the signal outright so you do not have to parse keywords out of `message.received`. They also cover cases that produce no inbound message at all, such as a network handling an opt-out on your behalf. Two of the four sub-types change consent; two do not. `contact.help` and `contact.custom_keyword` report the contact's existing state without changing it. Read `opt_out` for the state and the envelope's `event` for what happened, rather than inferring one from the other. ```json { "field": "contact", "event": "contact.opt_out", "timestamp": "2026-09-24T14:00:00Z", "request_id": "req_9Y0aLq3kEx", "payload": { "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "contact_id": "a1b2c3d4-9dad-11d1-80b4-00c04fd430c8", "from": "+14155551234", "to": "+18005550100", "opt_out": true, "source": "INBOUND_KEYWORD", "channel": "sms", "text": "STOP", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "template_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c9" } } ``` #### Contact sub-types [#contact-sub-types] | `event` | What it means | |---|---| | `contact.opt_in` | Contact sent an opt-in keyword (for example `START`). Sets `opt_out: false` | | `contact.opt_out` | Contact sent an opt-out keyword (for example `STOP`). Sets `opt_out: true` | | `contact.help` | Contact sent a help keyword (for example `HELP`). Does not change consent state | | `contact.custom_keyword` | Contact sent one of your custom auto-reply keywords. Does not change consent state. Use `payload.template_id` to identify which keyword fired | **Contact Event Fields:** | Field | Type | Description | |-------|------|-------------| | `field` | string | Event type: `contact` | | `event` | string | The specific sub-type, for example `contact.opt_out` | | `timestamp` | string | ISO 8601 timestamp of the event | | `request_id` | string \| omitted | Correlates the deliveries produced by one action | | `payload.account_id` | string | The account the contact belongs to: the Sender Profile for a profile's contact, otherwise your account | | `payload.contact_id` | string | The contact who raised the signal. Always resolvable against `GET /v3/contacts/{id}`, including for numbers not messaged before | | `payload.from` | string | The contact's phone number in E.164 format. The same party `message.received` publishes as `inbound_number`. Compare against `contact.format_e164`, not `contact.phone_number`, which holds the original format and may lack the leading `+` | | `payload.to` | string \| null | Your provisioned number that received the signal, in E.164 format. **This is your number, not the contact's.** Null when the signal did not arrive at a number: an RCS signal terminates at an agent rather than a number, and a provider-reported opt-out may name no receiving number at all. The key is always present; check for null rather than checking whether the key exists | | `payload.agent_id` | string \| omitted | The RCS agent the signal reached. Omitted entirely on SMS and WhatsApp payloads. On RCS, exactly one of `to` and `agent_id` is populated | | `payload.opt_out` | boolean | Whether the contact is opted out after this signal. On `contact.help` and `contact.custom_keyword` this reports the contact's existing state, which neither event changes | | `payload.source` | string | How the signal reached Sent: `INBOUND_KEYWORD` (contact sent a matching text) or `PROVIDER_SIGNAL` (network reported it). A provider signal usually carries no `message_id` or `text` | | `payload.channel` | string | The channel the signal arrived on, for example `sms`, `mms`, `whatsapp`, or `rcs`. A keyword sent as an MMS reports `mms`, so a consent handler must accept it | | `payload.text` | string \| null | The text the contact sent, for example `STOP`. Null when the signal did not arrive as text. The key is always present | | `payload.message_id` | string \| null | The inbound message that carried the signal, joinable against `message.received` on `message_id`. Null when the signal was network-reported or when the message belongs to a different account. The key is always present | | `payload.template_id` | string \| null | The auto-reply template whose keyword matched. On `contact.custom_keyword`, use this to identify which keyword fired rather than branching on `text`. Null when no template was involved. The key is always present | `payload.to` is the opposite of `to` on `POST /v3/messages`. On a send, `to` is your list of recipients. On a contact event, `to` is your own provisioned number that received the signal. Reply to `payload.from`, not to `payload.to`. Two signals from the same contact can arrive out of order, because each is queued independently. Compare the envelope `timestamp` before overwriting a stored consent state. Two signals stamped in the same second are unordered; read the contact resource to settle them. `message.received` still names the same two parties `inbound_number` and `outbound_number` rather than `from` and `to`. Join a contact event to its inbound message on `message_id` rather than comparing number fields.
### `link` [#link] Triggered when a tracked link Sent published on your behalf is used, expires, or is revoked. Sent shortens the URLs in your message copy and hosts the media you attach, and serves both from the `s.dm` domain. `payload.link_kind` says which one an event is about: `url` for a destination you supplied, `file` for media Sent hosts. This family is opt-in and delivers nothing until you ask for it. Subscribe to `link` explicitly. A `message` subscription never inherits link events, and neither does a wildcard. A click is a request, not a read receipt. `link.clicked` means Sent served the redirect and `link.downloaded` means bytes went out. Neither proves a person saw anything: messaging providers and link scanners fetch URLs on their own. Filter on `payload.traffic_class` before you report a click-through rate, and treat `likely_human` as a hint rather than as delivery confirmation. ```json { "field": "link", "event": "link.clicked", "timestamp": "2025-10-31T15:04:02Z", "payload": { "customer_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "sender_profile_id": null, "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "record_id": "A78B2BU0", "link_kind": "url", "channel": "sms", "reference_key": "body:0", "occurred_at": "2025-10-31T15:04:00Z", "request_method": "GET", "status_code": 302, "traffic_class": "likely_human", "access_country": "US", "device": "mobile", "browser": "chrome" } } ``` #### Link sub-types [#link-sub-types] | `event` | What it means | |---|---| | `link.clicked` | A tracked short link was followed and Sent served the `302`. Always `link_kind: "url"` | | `link.downloaded` | A hosted file behind a tracked link was served, as a `200` or as a `206` for a ranged request. Always `link_kind: "file"` | | `link.expired` | A published link reached its expiration | | `link.revoked` | A published link was permanently revoked | The first two report a request that was served. The last two report a change to the link itself, so they describe no request and omit every request-shaped field, including `request_method`, `status_code`, `traffic_class`, `access_country`, `device`, and `browser`. `channel` and `reference_key` describe the link rather than the request, so a lifecycle event reports them exactly as an access event does. Both kinds of link can expire or be revoked, so read `link_kind` rather than assuming a lifecycle event is about a URL. Sent forwards these four and no others. `link.created`, `link.requested`, `link.tags_changed`, and `link.purged` exist in Sent's own link analytics and are never delivered to a webhook, so do not build a handler that waits for the moment a link is minted. #### Traffic classes [#traffic-classes] | `payload.traffic_class` | What it means | |---|---| | `likely_human` | The request looks like a person's browser | | `provider` | A messaging platform prefetching the link before or while it delivers the message | | `bot` | A crawler, scanner, or other automated client | | `unknown` | The request supplied too little to classify | Every value is derived from the user agent, which makes this a filter for obvious noise rather than a fact to bill or report on. **Link Event Fields:** | Field | Type | Description | |-------|------|-------------| | `field` | string | Event type: `link` | | `event` | string | The specific sub-type, for example `link.clicked` | | `timestamp` | string | ISO 8601 timestamp of when Sent emitted the event, which is not when the access happened. See `payload.occurred_at` | | `payload.customer_id` | string | The organization the link belongs to. Always the parent account, never a Sender Profile. This family publishes the owner as this pair rather than as the single `account_id` the other families use | | `payload.sender_profile_id` | string \| null | The Sender Profile that owns the link, or null when the organization owns it directly. The key is always present | | `payload.message_id` | string | The message the link was published in. Always present on a delivered event, because a link Sent cannot attribute to a message produces no webhook at all | | `payload.record_id` | string | The link's public identifier, which is the eight-character code in the short URL, for example `A78B2BU0`. Unique across both link kinds and never reused, so it is the key to group one link's events by | | `payload.link_kind` | string | What the link points at: `url` for a destination you supplied, `file` for media Sent hosts. Implied by the sub-type on the two access events, and published as its own field so you can branch on it without parsing the event name | | `payload.channel` | string \| omitted | The channel the message carrying the link went out on: `sms`, `whatsapp`, or `rcs`. Omitted when the link records no channel of its own, which is a property of the link and not of the event: a lifecycle event reports it exactly as an access event does | | `payload.reference_key` | string \| omitted | The label tying this link back to a position in the message, for example `body:0` for the first link in the body. Omitted when the link was created without one | | `payload.occurred_at` | string | ISO 8601 timestamp of when the access or lifecycle change actually happened | | `payload.request_method` | string \| omitted | The HTTP method of the request that was served. Omitted on lifecycle events | | `payload.status_code` | integer \| omitted | The HTTP status Sent answered the request with: `302` for a link, `200` or `206` for a file. Omitted on lifecycle events | | `payload.traffic_class` | string \| omitted | A coarse guess at what made the request. See the preceding table. Omitted when the request supplied nothing to derive it from | | `payload.access_country` | string \| omitted | Where the request appeared to come from, as an ISO 3166-1 alpha-2 code. Omitted when it could not be resolved | | `payload.device` | string \| omitted | The requesting device class: `mobile`, `tablet`, `desktop`, or `unknown` | | `payload.browser` | string \| omitted | The requesting browser family, for example `chrome` or `safari`, or `unknown` | | `payload.referrer_host` | string \| omitted | The host of the page that linked here, when the request supplied one. The host only, never a full referring URL | | `payload.bytes_served` | integer \| omitted | How many bytes were served on a file access. A ranged request reports the bytes in that range rather than the size of the file, so several accesses of one file can each report a part | | `payload.access_outcome` | string \| omitted | How the request was served, when it was recorded. Free text describing the outcome, so show it to a human rather than branching on it | Link events carry no `request_id`. Nothing in this payload identifies the visitor. No IP address and no visitor token crosses the boundary, and there is no field that could carry one. `access_country`, `device`, and `browser` are coarse buckets derived from the request, and each is absent whenever the request supplied too little to derive it. **Grouping and deduplication.** One link accumulates many events, and any one of those events can be delivered more than once, so a handler needs two separate keys. `payload.record_id` identifies the link: group a link's events by it. The `webhook-id` header (`X-Webhook-Event-ID` on version 1) identifies the delivery: deduplicate on it, exactly as on every other family. The payload carries no event identifier of its own. **Two timestamps that genuinely differ.** The envelope's `timestamp` is when Sent emitted the event; `payload.occurred_at` is when the click, download, or lifecycle change happened. Elsewhere the two sit within the same second. Here they are separated by the time it takes Sent to receive the access, and a replay can widen that to days, so report on `occurred_at` and use `timestamp` only to reason about delivery. **The visitor's country is `access_country`, not `country`.** A channel event's `country` is a destination market you registered for. This one is a property of a single visitor, and the two names are kept apart so a handler switching on payload shape cannot confuse them. **A Sender Profile's links go to its own webhooks.** Your organization's webhook doesn't receive them, as with every family. To track every profile's links at one endpoint, select `link` under `sender_profile`, which clones your webhook onto each profile. See [Sender Profile Events](#sender-profile-events). **The event can arrive before the message is readable.** A messaging provider may fetch a link within milliseconds of the send, and nothing delays the event to wait for the message record. If `GET /v3/messages/{id}` does not yet know `payload.message_id`, retry the read rather than treating the id as invalid.
### `call` [#call] Triggered as a phone call moves through its life: a call to one of your numbers, or a call placed from your app with a voice token. The subject is always one call, named by `payload.call_id`. It is the same id the `call.request` question carried to your callback URL and the one `GET /v3/voice/calls/{id}` reads, so the question, the record, and the events all describe one thing. A conference participant is a call of its own, with its own id. It sends no `call.initiated`; its end arrives as `call.completed` or `call.failed`. A call one of your [voice agents](/start/guides/voice-agents) answers is reported through the same events, with `payload.mode` set to `agent` and the agent in `payload.agent_id`, plus one more event, `call.agent_connected`, when the agent's session starts. Three casings, one each per surface. Webhook payloads are `snake_case` (`call_id`, `duration_seconds`), like every other Sent webhook. The REST API is `snake_case` too (`GET /v3/voice/calls` returns `started_at`). The callback contract your backend answers is `camelCase` (`callId`, `dialTimeoutSeconds`). A handler that reads `callId` from a webhook finds nothing. See [Answering Calls](/start/guides/answering-calls). ```json { "field": "call", "event": "call.completed", "timestamp": "2026-07-22T12:00:49Z", "payload": { "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "call_id": "call_9f2ab000-0000-4000-8000-000000000001", "channel": "voice", "number": "+12025550123", "mode": "inapp", "updated_at": "2026-07-22T12:00:47Z", "duration_seconds": 42, "price": 0.0105 } } ``` #### Call sub-types [#call-sub-types] | `event` | What it means | |---|---| | `call.initiated` | The call arrived or was placed. Sent sends it before its own checks run, so a call refused before your callback is asked still has it, followed by `call.failed` | | `call.answered` | The call was answered | | `call.agent_connected` | One of your voice agents took the call: its session started. Sent once per call, after `call.answered`, on calls with `payload.mode` set to `agent` only | | `call.completed` | An answered call ended. Carries `duration_seconds` and, once billing has recorded the charge, `price` | | `call.failed` | The call ended without completing. Carries `reason` when one was recorded | | `call.recording_ready` | One recording of the call is stored and can be listed. Sent once per recording, with the `recording_id` that `GET /v3/voice/calls/{id}/recordings` lists it under | #### Call failure reasons [#call-failure-reasons] `payload.reason` on `call.failed` is one of `callback_timeout`, `invalid_answer`, `insufficient_balance`, `destination_blocked`, `rejected`, `no_answer`, or `callback_not_configured`, and on a call to a number bound to a voice agent also `agent_busy` or `agent_unreachable`. It is omitted when the call failed without a recorded reason. Each value is explained under [Call Failure Reasons](/reference/api/error-catalog#call-failure-reasons) in the Error Catalog. **Call Event Fields:** | Field | Type | Description | |-------|------|-------------| | `field` | string | Event type: `call` | | `event` | string | The specific sub-type, for example `call.completed` | | `timestamp` | string | ISO 8601 timestamp of when Sent emitted the event | | `payload.account_id` | string | The account the call belongs to: your account, or the Sender Profile it acted as | | `payload.call_id` | string | Sent's call id, prefixed `call_`. The same id the `call.request` question carried and `GET /v3/voice/calls/{id}` accepts | | `payload.channel` | string | Always `voice` | | `payload.number` | string | Your number that owns the call, in E.164 format: the dialed number for an inbound call, the caller's bound number for a call placed from your app | | `payload.mode` | string | How the call is handled: `inapp` for a call your number's callback URL decides, `agent` for a call one of your voice agents answers. On every call event, and the same value `GET /v3/voice/calls` returns | | `payload.agent_id` | string \| omitted | The voice agent that answers the call, such as `agent_9f2ab000-0000-4000-8000-000000000001`. Only when `payload.mode` is `agent` | | `payload.updated_at` | string | ISO 8601 timestamp of when the change happened on the call, as opposed to when the event was emitted | | `payload.duration_seconds` | integer \| omitted | How long the call lasted. Only on `call.completed` | | `payload.price` | number \| omitted | What the call was charged. Only on `call.completed`, and omitted there until billing has recorded the charge | | `payload.reason` | string \| omitted | The machine-readable reason the call did not complete. Only on `call.failed`, and omitted when no reason was recorded | | `payload.recording_id` | string \| omitted | The recording that became available, the same id `GET /v3/voice/calls/{id}/recordings` lists it under. Only on `call.recording_ready` | Call events carry no `request_id`. **Grouping and deduplication.** One call produces several events, and any one of them can be delivered more than once. Deduplicate on the `webhook-id` header (`X-Webhook-Event-ID` on version 1), as on every other family, and group a call's events by `payload.call_id`. A `call.recording_ready` is one event per recording, so a call recorded twice produces two of them with different `recording_id` values. **Order is not guaranteed.** Events are emitted as the call reports them, and a retry can deliver one later than the next. `GET /v3/voice/calls/{id}` is the source of truth: its `timeline` lists when the call entered each status, oldest first. See [Calls, Recordings, and Participants](/start/guides/managing-calls). **Testing.** `POST /v3/webhooks/{id}/test` with `event_type` set to `call` delivers a sample `call.completed`, with a duration and a price and a fresh `call_id` each time. Each sub-type can be sampled by its own name. **A Sender Profile's calls go to its own webhooks.** Your organization's webhook does not receive them, as with every family. To receive every profile's call events at one endpoint, select `call` under `sender_profile`, which clones your webhook onto each profile. See [Sender Profile Events](#sender-profile-events).
## Event Filtering [#event-filtering] You can configure which events to receive in the webhook settings in your [Sent Dashboard](https://app.sent.dm/dashboard/webhooks) to reduce noise and improve performance. Subscribe to specific event types when creating or updating a webhook by setting `event_types` and, optionally, `event_filters`: ```json { "event_types": ["message", "templates", "channel", "contact", "link", "call"], "event_filters": { "message": ["delivered", "failed", "read", "received"], "templates": ["approved", "rejected"], "channel": ["activated", "deactivated"], "contact": ["opt_in", "opt_out"], "link": ["clicked", "downloaded"], "call": ["completed", "failed", "recording_ready"] } } ``` The `event_filters` map accepts a parent `event_type` as the key and a list of sub-type suffixes as values. In the preceding example only `message.delivered`, `message.failed`, `message.read`, `message.received`, `templates.approved`, and `templates.rejected` events are delivered. `message.queued`, `message.routed`, `message.sent`, and the other template sub-types are suppressed. Every filter key must also appear in `event_types`, and the values are bare suffixes: send `"delivered"`, not `"message.delivered"`. Either mistake is rejected with `400`. **Available Sub-type Filters for `message`:** | Value | Fires for | Direction | |-------|-----------|-----------| | `queued` | `message.queued` | Outbound | | `routed` | `message.routed` | Outbound | | `sent` | `message.sent` | Outbound | | `delivered` | `message.delivered` | Outbound | | `read` | `message.read` | Outbound (WhatsApp & RCS) | | `failed` | `message.failed` | Outbound | | `scheduled` | `message.scheduled` | Outbound | | `cancelled` | `message.cancelled` | Outbound | | `filtered` | `message.filtered` | Outbound | | `blocked` | `message.blocked` | Outbound | | `received` | `message.received` | Inbound | **Available Sub-type Filters for `templates`:** | Value | Fires for | |-------|-----------| | `pending` | `templates.pending` | | `approved` | `templates.approved` | | `rejected` | `templates.rejected` | | `paused` | `templates.paused` | | `disabled` | `templates.disabled` | | `deleted` | `templates.deleted` | | `category_updated` | `templates.category_updated` | | `quality_updated` | `templates.quality_updated` | **Available Sub-type Filters for `channel`:** | Value | Fires for | |-------|-----------| | `submitted` | `channel.submitted` | | `changes_requested` | `channel.changes_requested` | | `approved` | `channel.approved` | | `rejected` | `channel.rejected` | | `activated` | `channel.activated` | | `deactivated` | `channel.deactivated` | | `removed` | `channel.removed` | **Available Sub-type Filters for `contact`:** | Value | Fires for | |-------|-----------| | `opt_in` | `contact.opt_in` | | `opt_out` | `contact.opt_out` | | `help` | `contact.help` | | `custom_keyword` | `contact.custom_keyword` | **Available Sub-type Filters for `link`:** | Value | Fires for | |-------|-----------| | `clicked` | `link.clicked` | | `downloaded` | `link.downloaded` | | `expired` | `link.expired` | | `revoked` | `link.revoked` | **Available Sub-type Filters for `call`:** | Value | Fires for | |-------|-----------| | `initiated` | `call.initiated` | | `answered` | `call.answered` | | `completed` | `call.completed` | | `failed` | `call.failed` | | `recording_ready` | `call.recording_ready` | A filtered `templates` subscription receives only the sub-types you list. Statuses that carry no sub-type are delivered to `templates` subscriptions that set no filter, so subscribe to the parent if you want every lifecycle value. **Available Filters:** - **Message**: Subscribe to all or specific `message.*` sub-types (outbound status + inbound `message.received`) - **Templates**: Subscribe to all or specific `templates.*` sub-types - **Channel**: Subscribe to all or specific `channel.*` sub-types. `channel.activated` alone answers "can this market send yet" - **Contact**: Subscribe to all or specific `contact.*` sub-types. `contact.opt_out` alone is sufficient for consent tracking - **Link**: Subscribe to all or specific `link.*` sub-types. Nothing is delivered until you subscribe to `link` explicitly - **Call**: Subscribe to all or specific `call.*` sub-types. `call.completed` and `call.failed` together cover every outcome; add `recording_ready` if you download recordings ### Legacy `messages` event type [#legacy-messages-event-type] `messages` (plural) is the retired spelling of the `message` parent, from before event types moved to dot-notation sub-types. Webhooks created before the rename may still store `messages` in their `event_types` array; dispatch treats it as an alias of `message`, so those webhooks receive all `message.*` events. You can't subscribe to `messages` when creating or updating a webhook: it is not a registered event type, and the API accepts only the canonical `message`. ## Sender Profile Events [#sender-profile-events] How your organization's webhook receives its Sender Profiles' events depends on its [version](#webhook-versions): a version 2 webhook is made [inheritable](#inheritable-webhooks-version-2), and a version 1 webhook is cloned with `sender_profile`. `sender_profile` has no effect on a version 2 webhook, and `is_inheritable` on a version 1 webhook is rejected with `400`. ### Inheritable webhooks (version 2) [#inheritable-webhooks-version-2] Set `is_inheritable: true` on your organization's version 2 webhook to also receive every Sender Profile's events at its URL, signed with its secret. Nothing is copied: ```json { "display_name": "Status notifications", "endpoint_url": "https://example.com/webhooks/sent", "event_types": ["message"], "is_inheritable": true } ``` - **Each event arrives once.** `payload.account_id` says whose event it is. - **Each profile sees the webhook** in its webhook list with `customer_id` set to your organization's ID, and its `GET /v3/webhooks/{id}/events` shows only the events about that profile. - **Only your organization can change it.** A profile that tries to update, toggle, test, or delete it gets `409` with `CONFLICT_016`. - **Without `is_inheritable`**, a version 2 webhook receives your organization's own events only, and a webhook a profile creates receives that profile's events only. Only your organization's webhook can set `is_inheritable`. Change it later with `PUT /v3/webhooks/{id}`. ### Clones (version 1) [#clones-version-1] Clone your organization's version 1 webhook onto its Sender Profiles to receive their events at your endpoint. That covers every profile you have and every profile you create later. Select the profile events under `sender_profile` when you create or update the webhook: ```json { "display_name": "Status notifications", "endpoint_url": "https://example.com/webhooks/sent", "event_types": ["message"], "event_filters": { "message": ["failed"] }, "webhook_version": 1, "sender_profile": { "event_types": ["message", "channel"], "event_filters": { "message": ["delivered"] } } } ``` This webhook receives your organization's failed messages. Each Sender Profile gets a clone of it that receives that profile's delivered messages and every channel event from that profile. `sender_profile` takes the same event types and filter rules as the top-level fields. - **A clone is a webhook the profile owns.** It appears in the profile's webhook list, and the profile can edit it, turn it off, or delete it like any of its webhooks. - **Clones use your webhook's URL and signing secret**, so your endpoint verifies every event with one secret. A profile can read that secret, as it can for any of its webhooks. - **Your changes replace the profile's.** Editing your webhook, turning it on or off, or rotating its secret updates every clone, including one a profile edited or turned off. Each clone keeps its own delivery health: a clone switched off after failed deliveries stays off until your next change to the webhook or until the profile turns it back on. - **A clone a profile deleted stays deleted** while `sender_profile` stays set. Clearing `sender_profile` deletes every clone, and setting it again clones the webhook onto every profile. - **Deleting your webhook deletes its clones.** - **Your webhook's event history includes its clones'.** `GET /v3/webhooks/{id}/events` on your organization's webhook lists the events its clones delivered beside its own. A clone's own history lists only its profile's events. A webhook receives only its owner's events. Your organization's webhook receives your organization's events, and each clone receives its profile's, so a profile's event reaches your endpoint once, through its clone. Your organization's own events never reach a profile's webhook, and one profile's events never reach another's. Only your organization's webhook can set `sender_profile`. A request made as a Sender Profile, with its own key or with `x-profile-id`, is rejected with `400`. `event_types` can be empty when `sender_profile.event_types` isn't, so the webhook only feeds its clones. At least one event is required across the two. On `PUT /v3/webhooks/{id}`, omit `sender_profile` to keep the clones' events as they are, or send `"sender_profile": {"event_types": []}` to delete the clones. The rest of the update still reaches every clone. Webhook responses don't include `sender_profile`, so keep a record of what you set. ### Which account an event is about [#which-account-an-event-is-about] `payload.account_id` names the account the event belongs to, which is also the owner of the webhook that delivers it. That's the Sender Profile for an event delivered through its clone, and your organization for your own events. Map `payload.account_id` to your tenant: any value other than your organization's ID is one of your profiles. A Sender Profile's `message.delivered`, as the profile's clone of your webhook delivers it: ```json { "field": "message", "event": "message.delivered", "timestamp": "2025-10-31T10:10:42Z", "payload": { "account_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "message_status": "DELIVERED", "channel": "sms" } } ``` `account_id` is the profile's ID. The other payload fields are unchanged and omitted here. ## Webhook Versions [#webhook-versions] Every webhook has a `webhook_version`, returned on every webhook response. The version is set when the webhook is created and doesn't change afterwards. | | Version 2 (default) | Version 1 | | :--- | :--- | :--- | | Signing | [Standard Webhooks](https://www.standardwebhooks.com) | Sent's original scheme, which will be retired | | Signing headers | `webhook-id`, `webhook-timestamp`, `webhook-signature` | `X-Webhook-*` | | Retries | Automatic, with increasing delays. `retry_count` and `timeout_seconds` are ignored | `retry_count` and `timeout_seconds` | | Sender Profiles | `is_inheritable` | `sender_profile` clones | New webhooks are version 2 unless you send `"webhook_version": 1` on `POST /v3/webhooks`. Webhooks created before version 2 existed stay on version 1. Both versions deliver the same JSON body and are signed with the same `whsec_` secret scheme. ## Delivery Headers & Signing [#delivery-headers--signing] A **version 2** webhook request carries the [Standard Webhooks](https://www.standardwebhooks.com) headers: | Header | Description | |--------|-------------| | `webhook-id` | ID of the message, identical on every attempt at that event, so it is the value to deduplicate on | | `webhook-timestamp` | Unix timestamp in seconds at which this attempt was signed | | `webhook-signature` | One or more space-separated `v1,{base64_hmac}` signatures: HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{raw_body}` using your signing secret | There's no event type header on version 2. Read `event` from the body instead. A **version 1** webhook request includes the following headers: | Header | Description | |--------|-------------| | `X-Webhook-ID` | UUID of the webhook configuration that produced the request | | `X-Webhook-Event-ID` | UUID of the event, identical on every attempt at that event, so it is the value to deduplicate on | | `X-Webhook-Timestamp` | Unix timestamp in seconds at which this attempt was signed. A retry is signed when it is sent, so this moves between attempts | | `X-Webhook-Attempt` | Index of this delivery attempt, starting at `1` | | `X-Webhook-Signature` | `v1,{base64_hmac}`: HMAC-SHA256 over `{webhook_id}.{timestamp}.{raw_body}` using your signing secret | | `X-Webhook-Event-Type` | Fully qualified event type (`message.delivered`, `templates`, etc.) | Signing secrets are issued in the Sent Dashboard prefixed with `whsec_` (Svix-compatible), and the same verifier works for both versions given the matching headers. Always verify the signature server-side before trusting the payload, and compare the timestamp against your clock to reject replayed requests. ## Delivery Statuses & Retries [#delivery-statuses--retries] A version 2 webhook's failed deliveries are retried automatically, so `retry_count` and `timeout_seconds` don't apply: after a failed attempt (non-`2xx`, timeout, or connection error) Sent retries after 5 seconds, 5 minutes, 30 minutes, and 2 hours, 5 attempts in all over about 2.6 hours, then marks the event `FAILED`. If every delivery to the endpoint keeps failing for an hour after the first event runs out of retries, Sent turns the webhook off and emails you, as it does for the version 1 auto-disable; one successful delivery in that time resets the clock. Re-enable it from the Sent Dashboard once the endpoint is healthy. Its deliveries appear in `GET /v3/webhooks/{id}/events` with the same statuses and attempt fields as a version 1 webhook's. On the webhook itself, `consecutive_failures` stays `0` and `last_delivery_attempt_at` and `last_successful_delivery_at` stay `null`. The rest of this section describes version 1. Each webhook delivery is tracked in the Sent Dashboard with its own row and lifecycle: | Status | Meaning | |--------|---------| | `PENDING` | Event created, queued for delivery | | `RETRYING` | A previous attempt failed; the next attempt is scheduled with backoff | | `DELIVERED` | Endpoint returned `2xx`; consecutive-failure counter resets to `0` | | `FAILED` | Exceeded the webhook's configured retry count (`retry_count`, 1–5, defaults to 3) | **Retry schedule:** a delivery attempt counts as failed when your endpoint returns a non-`2xx` status, the request times out, or the connection fails. Failed attempts are retried with exponential backoff: the first retry fires about one minute after the failure and the delay doubles with each subsequent attempt, up to a maximum of 60 minutes between attempts. Retries stop as soon as your endpoint returns `2xx` or the retry count is exhausted. Per-event metadata stored alongside each attempt includes the delivery attempt count, HTTP status code, the first portion of the response body, the error message, and start/completion timestamps, all surfaced in the Sent Dashboard's webhook event detail view. If a webhook accumulates **10 consecutive failed events**, it is automatically disabled. The counter spans events, and only an event's first attempt increments it, so it measures how many distinct events your endpoint failed rather than how many times Sent re-asked about one of them. Any successful delivery, including a retry that succeeds, resets it to `0`. A failed test delivery doesn't count toward it. This guards against expired or compromised endpoints. Re-enable the webhook from the Sent Dashboard once your endpoint is healthy again. {/* "auto-disable" is Sent's product behavior for webhooks, not an instruction to the reader. */} {/* vale Google.WordList = NO */} This section is the canonical statement of the retry schedule, retry budget, and auto-disable threshold. {/* vale Google.WordList = YES */} ## Delivery Constraints [#delivery-constraints] Webhook configuration is subject to the following constraints: - **Per-webhook timeout:** 5–120 seconds, defaults to 30 seconds (configured when you create or update the webhook). Version 1 only - **Retry count:** 1–5 attempts per event, defaults to 3. Version 1 only - **Retry schedule, version 2:** 5 attempts per event over about 2.6 hours (5 seconds, 5 minutes, 30 minutes, 2 hours), not configurable - **URL scheme:** must be `http://` or `https://` - **URL validation:** private IP ranges (`127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, etc.) are rejected at creation, update, and delivery time --- # Webhook Setup (/start/webhooks/getting-started.md) # Webhook Setup [#webhook-setup] This guide shows you how to register a webhook endpoint in the Sent Dashboard and verify it receives events. **Prerequisites:** - A handler that accepts HTTP `POST` requests and responds with a `2xx` status, reachable from the public internet. If your handler runs on `localhost`, expose it through a tunnel first. See [Local Development & Debugging](/start/webhooks/local-development). ## Events You Can Subscribe To [#events-you-can-subscribe-to] Sent delivers two event types to webhook endpoints: | Event type | What it covers | | :--- | :--- | | `message` | Message status updates: delivery progress, failures, read receipts, and inbound messages | | `templates` | Template lifecycle updates: approvals, rejections, and category changes from review | Refer to the [Events Reference](/start/webhooks/event-types) for the envelope structure and full payloads. ## Add a Webhook [#add-a-webhook] ### Open the webhooks page [#open-the-webhooks-page] Go to [Webhooks in the Sent Dashboard](https://app.sent.dm/dashboard/webhooks) and click **Add Webhook**.
→
### Configure the endpoint [#configure-the-endpoint] Fill in the **Add New Webhook** form: | Field | Value | | :--- | :--- | | **Version** | **Version 2** (recommended, and the default) or **Version 1**, the legacy delivery. See [webhook versions](/start/webhooks/event-types#webhook-versions). | | **Display Name** | A label that identifies this endpoint, for example `Order Notifications`. | | **Endpoint URL** | Your handler's public URL. The dashboard prepends `https://`. URLs that resolve to private or loopback IP ranges are rejected. | | **Select events to listen** | The event types to receive. Selecting a type reveals its sub-types, so you can subscribe to specific events only (for example `delivered` and `failed`). | | **Include sender profile events** | Shown to organizations that use Sender Profiles. Switch it on to also receive your Sender Profiles' events. On version 2 the profiles share this webhook (see [inheritable webhooks](/start/webhooks/event-types#inheritable-webhooks-version-2)); on version 1 each Sender Profile gets its own copy. | Click **Add Webhook** to save. To manage webhooks programmatically instead, call [`POST /v3/webhooks`](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksCreateWebhookEndpoint), which accepts the same fields. New webhooks are [version 2](/start/webhooks/event-types#webhook-versions). Send `"webhook_version": 1` for the older delivery, which also accepts `retry_count` (1–5, default 3) and `timeout_seconds` (5–120, default 30). ### Copy the signing secret [#copy-the-signing-secret] When the webhook is saved, the **Webhook Created** dialog shows its signing secret once. Click **Copy**, because the secret isn't shown again: to get a new one, open the webhook and choose **Rotate signing secret**. Store the secret in your handler's environment (for example `SENT_WEBHOOK_SECRET`). You need it to [verify request signatures](/start/webhooks/signature-verification) before processing events. ### Send a test delivery [#send-a-test-delivery] From the webhook's actions menu, select **Test Webhook**. The dialog lists every event the webhook subscribes to. Click **Test** next to one, and Sent sends a sample payload for that event to your endpoint. Your webhook is working when: - the test result reports a successful delivery, or that the test is queued for delivery on a version 2 webhook, and - the delivery appears with status `DELIVERED` in the webhook's **Events** table, together with the attempt count and the HTTP status your endpoint returned. If the delivery shows `FAILED`, your endpoint did not return `2xx` in time (test deliveries make a single attempt, with no retries). Work through [Debug Failed Deliveries](/start/webhooks/local-development#debug-failed-deliveries).
## Next Steps [#next-steps] - [Security](/start/webhooks/signature-verification): verify the HMAC signature on every request before trusting it - [Handling Retries](/start/webhooks/handling-retries): make your handler idempotent against duplicate deliveries - [Events Reference](/start/webhooks/event-types): envelope structure, payloads, and delivery statuses - [Production Checklist](/start/webhooks/production-checklist): what to confirm before going live # Handling Retries (/start/webhooks/handling-retries.md) # Handling Retries [#handling-retries] Sent may deliver the same webhook event multiple times due to retries, network issues, or system recovery. Your handler must be **idempotent** to prevent duplicate processing. ## Why Retries Happen [#why-retries-happen] | Scenario | Behavior | |----------|----------| | **No acknowledgment** | Your endpoint didn't return 2xx | | **Timeout** | Your endpoint exceeded the webhook's configured timeout (5–120 s, default 30 s) | | **Network issues** | Connection failed during delivery | | **System recovery** | Event replay after maintenance | ## Choosing an Idempotency Key [#choosing-an-idempotency-key] Key on the `X-Webhook-Event-ID` header. It is the UUID of the event behind the delivery, so every attempt at that event carries the same value and two different events never share one. On a [version 2](/start/webhooks/event-types#webhook-versions) webhook, key on `webhook-id` instead, which behaves the same way. Two nearby headers are not dedupe keys: - `X-Webhook-ID` (version 1) is the **webhook configuration UUID**, the same value for every delivery from that webhook. Don't confuse it with version 2's `webhook-id`, which is the dedupe key. - `X-Webhook-Timestamp` (`webhook-timestamp` on version 2) is the send time of the attempt in hand, so it moves between retries. A key built on it records one event once per attempt, which is the opposite of what you want. Payload-derived keys are narrower than the event ID and worth using when you also want to collapse events that are logically the same, such as a status transition re-sent after a provider replay: - **Inbound message events (`event` = `message.received`)**: `payload.message_id` is unique per inbound message. - **Outbound message events**: `payload.message_id` + `payload.message_status` is unique per state transition. - **Template events**: `payload.template_id` + `payload.status` is unique per transition. ### Event ID Deduplication [#event-id-deduplication] Store the idempotency key to skip duplicates: ```typescript function idempotencyKey(eventData: any, eventId: string): string { if (eventData.event === 'message.received') { // Inbound: each inbound message has its own UUID return `in:${eventData.payload.message_id}`; } if (eventData.field === 'message' && eventData.payload.message_id) { // Outbound: state transition is unique return `msg:${eventData.payload.message_id}:${eventData.payload.message_status}`; } if (eventData.field === 'templates') { return `tpl:${eventData.payload.template_id}:${eventData.payload.status}`; } // Fallback: the event's own UUID, identical on every attempt return `evt:${eventId}`; } async function handleWebhook(eventData: any, eventId: string) { const key = idempotencyKey(eventData, eventId); const existing = await db.webhookEvents.findUnique({ where: { idempotencyKey: key } }); if (existing) { console.log(`Event ${key} already processed`); return; } await processEvent(eventData); await db.webhookEvents.create({ data: { idempotencyKey: key, eventType: eventData.field, processedAt: new Date() } }); } ``` ```python def idempotency_key(event_data: dict, event_id: str) -> str: if event_data.get('event') == 'message.received': # Inbound: each inbound message has its own UUID return f"in:{event_data['payload']['message_id']}" if event_data.get('field') == 'message' and event_data['payload'].get('message_id'): return f"msg:{event_data['payload']['message_id']}:{event_data['payload']['message_status']}" if event_data.get('field') == 'templates': return f"tpl:{event_data['payload']['template_id']}:{event_data['payload']['status']}" # Fallback: the event's own UUID, identical on every attempt return f"evt:{event_id}" async def handle_webhook(event_data: dict, event_id: str): key = idempotency_key(event_data, event_id) existing = db.webhook_events.find_unique(where={"idempotency_key": key}) if existing: print(f"Event {key} already processed") return await process_event(event_data) db.webhook_events.create({ "idempotency_key": key, "event_type": event_data['field'], "processed_at": datetime.now() }) ``` ```go import "fmt" func idempotencyKey(event WebhookEvent, eventID string) string { // WebhookEvent maps the envelope: Field `json:"field"`, Event `json:"event"`, Payload `json:"payload"` if event.Event != nil && *event.Event == "message.received" { // Inbound: each inbound message has its own UUID return fmt.Sprintf("in:%s", event.Payload.MessageID) } if event.Field == "message" && event.Payload.MessageID != "" { return fmt.Sprintf("msg:%s:%s", event.Payload.MessageID, event.Payload.MessageStatus) } if event.Field == "templates" { return fmt.Sprintf("tpl:%s:%s", event.Payload.TemplateID, event.Payload.Status) } // Fallback: the event's own UUID, identical on every attempt return fmt.Sprintf("evt:%s", eventID) } func handleWebhook(event WebhookEvent, eventID string) error { key := idempotencyKey(event, eventID) var exists bool if err := db.QueryRow("SELECT EXISTS(SELECT 1 FROM webhook_events WHERE idempotency_key = $1)", key).Scan(&exists); err != nil { return err } if exists { log.Printf("Event %s already processed", key) return nil } if err := processEvent(event); err != nil { return err } _, err := db.Exec( "INSERT INTO webhook_events (idempotency_key, event_type, processed_at) VALUES ($1, $2, $3)", key, event.Field, time.Now(), ) return err } ``` ### Database Transaction [#database-transaction] Ensure atomic processing with transactions, keyed by the same idempotency key: ```typescript const key = idempotencyKey(eventData, eventId); await db.$transaction(async (tx) => { // Record event processing start await tx.webhookEvents.create({ data: { idempotencyKey: key, eventType: eventData.field, status: 'processing' } }); // Process business logic if (eventData.field === 'message') { await tx.messages.update({ where: { id: eventData.payload.message_id }, data: { status: eventData.payload.message_status } }); } // Mark as completed await tx.webhookEvents.update({ where: { idempotencyKey: key }, data: { status: 'completed' } }); }); ``` ```python key = idempotency_key(event_data, event_id) with db.transaction(): # Record event processing start webhook_event = WebhookEvent( idempotency_key=key, event_type=event_data['field'], status="processing" ) db.add(webhook_event) # Process business logic if event_data['field'] == 'message': message = db.messages.find_by_id(event_data['payload']['message_id']) message.status = event_data['payload']['message_status'] # Mark as completed webhook_event.status = "completed" db.commit() ``` ### Message ID Deduplication [#message-id-deduplication] For message events, use message ID and status to skip stale updates: ```typescript async function handleMessageEvent(eventData: any) { const { message_id, message_status } = eventData.payload; const { timestamp } = eventData; // Get current status from database const message = await db.messages.findById(message_id); // Only update if this is a newer status // Delivery progression only — see the Events Reference for the full message_status list const statusOrder = ['QUEUED', 'ROUTED', 'SENT', 'DELIVERED', 'READ', 'FAILED']; const currentIndex = statusOrder.indexOf(message.status?.toUpperCase()); const newIndex = statusOrder.indexOf(message_status.toUpperCase()); if (newIndex > currentIndex) { await db.messages.update(message_id, { status: message_status }); } } ``` ## Retry Budget [#retry-budget] Each version 1 webhook has a configurable retry budget (`retry_count`); a version 2 webhook is retried automatically, 5 attempts over about 2.6 hours. When a delivery fails (non-2xx, timeout, or network error), Sent retries with exponential backoff (the first retry fires about a minute after the failure and the delay grows with each attempt) until either the endpoint returns 2xx or the budget is exhausted, at which point the event is marked `FAILED`. Because retries for a single event can arrive well after the original delivery, size your deduplication window generously (the 7-day window shown later on this page is a safe default). On version 1, `X-Webhook-Attempt` carries the index of the attempt in hand, starting at `1`, so you can log a redelivery without keeping state of your own. {/* "auto-disable" is Sent's product behavior for webhooks, not an instruction to the reader. */} {/* vale Google.WordList = NO */} The retry schedule, retry budget, and auto-disable threshold are stated canonically in [Delivery Statuses & Retries](/start/webhooks/event-types#delivery-statuses--retries) on the Events Reference. {/* vale Google.WordList = YES */} After the configured retry budget is exhausted the event is *not* retried indefinitely. It is left in the `FAILED` state. Inspect the failed events in the Sent Dashboard to diagnose endpoint problems and replay if needed. ## Handling Out-of-Order Events [#handling-out-of-order-events] Events may arrive out of order. Use timestamps to ensure correct state: ```typescript async function handleMessageEvent(eventData: any) { const { timestamp } = eventData; const { message_id, message_status } = eventData.payload; // Get existing record const message = await db.messages.findById(message_id); // Only update if this event is newer if (new Date(timestamp) > new Date(message.lastUpdatedAt)) { await db.messages.update(message_id, { status: message_status, lastUpdatedAt: timestamp }); } } ``` ## Cleanup Strategy [#cleanup-strategy] Clean up old event records periodically: ```typescript // Run daily async function cleanupOldEvents() { const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); await db.webhookEvents.deleteMany({ where: { processedAt: { lt: thirtyDaysAgo }, status: 'completed' } }); } ``` ## Best Practices [#best-practices] ### 1. Always Acknowledge Quickly [#1-always-acknowledge-quickly] ```typescript app.post('/webhooks/sent', async (req, res) => { // Acknowledge immediately res.sendStatus(200); // Process asynchronously — derive idempotency key from the payload itself await queue.add('process-webhook', { // webhook-id on version 2, X-Webhook-Event-ID on version 1 eventId: req.headers['webhook-id'] ?? req.headers['x-webhook-event-id'], ...req.body, }); }); ``` ### 2. Handle Duplicate Events Gracefully [#2-handle-duplicate-events-gracefully] ```typescript // Don't throw errors for duplicates if (existing) { console.log('Duplicate event, skipping'); return; // Not an error } ``` ### 3. Use Appropriate Deduplication Window [#3-use-appropriate-deduplication-window] ```typescript // Check last 7 days for duplicates const oneWeekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); const existing = await db.webhookEvents.findFirst({ where: { idempotencyKey: key, processedAt: { gte: oneWeekAgo } } }); ``` ### 4. Log for Debugging [#4-log-for-debugging] ```typescript logger.info('Processing webhook event', { idempotencyKey: key, eventType: field, messageId: eventData.payload?.message_id, status: eventData.payload?.message_status, timestamp: new Date().toISOString() }); ``` --- # Webhooks & Events Overview (/start/webhooks.md) # Webhooks & Events Overview [#webhooks--events-overview] Receive real-time notifications about message delivery status, template approvals, and platform events via HTTP callbacks. ## What are Webhooks? [#what-are-webhooks] Webhooks are HTTP callbacks that Sent sends to your app when events occur. Instead of polling the API for updates, webhooks push events to your endpoint in real-time. >Sent: POST /v3/messages Sent-->>App: 202 Accepted Sent->>Provider: Route message Provider->>Device: Deliver to device Device-->>Provider: Delivery receipt Note over Sent,App: 2. Real-time notification Provider-->>Sent: Status update Sent->>App: POST /your-webhook
status: DELIVERED App-->>Sent: 200 OK `} /> Sent delivers six event types: `message` for delivery status updates and inbound messages, `templates` for template lifecycle updates from Meta, `channel` for sender provisioning and compliance, `contact` for consent signals, `link` for tracked links and hosted files, and `call` for phone calls placed from your app or to your numbers. Refer to the [Events Reference](/start/webhooks/event-types) for the envelope structure, full payloads, and filtering options. ### Webhook vs Polling [#webhook-vs-polling] | Approach | Latency | Efficiency | Complexity | |----------|---------|------------|------------| | **Webhooks** | Seconds | High (push) | Medium | | **Polling** | Minutes | Low (pull) | Low | ## Implementation Paths [#implementation-paths] ### Path A: Simple Webhook (5 minutes) [#path-a-simple-webhook-5-minutes] For basic message status tracking: **[Configure endpoint](/start/webhooks/getting-started)** - Set up your webhook URL **[Verify signatures](/start/webhooks/signature-verification)** - Ensure webhook authenticity **[Handle events](/start/webhooks/event-types)** - Process message status updates ### Path B: Production Webhook (30 minutes) [#path-b-production-webhook-30-minutes] For mission-critical applications: **Complete Path A** **[Implement idempotency](/start/webhooks/handling-retries)** - Handle duplicate events **[Queue-based processing](/start/webhooks/production-checklist)** - Scale with queues **[Local development & debugging](/start/webhooks/local-development)** - Test webhooks locally ## Webhook Guides [#webhook-guides] **New to webhooks?** Start with [Webhook Setup](/start/webhooks/getting-started) to set up your first webhook endpoint. --- # Webhooks Lifecycle (/start/webhooks/lifecycle.md) # Webhooks Lifecycle [#webhooks-lifecycle] This page describes what happens between the moment an event occurs inside Sent and the moment your endpoint receives (or stops receiving) a webhook delivery. Everything below is observable from your side, through the request itself or the delivery history in the Sent Dashboard. ## Delivery Lifecycle [#delivery-lifecycle] {/* "auto-disabled" is Sent's product behavior for webhooks, not an instruction to the reader. */} {/* vale Google.WordList = NO */} The diagram below shows the full lifecycle of a single webhook delivery: from event generation, through HTTP delivery to your endpoint, including retries and the conditions under which a webhook can be auto-disabled. {/* vale Google.WordList = YES */} B{Subscribed?} B -- No --> Z1([Skipped]) B -- Yes --> C[Sign payload
HMAC-SHA256] C --> D[HTTP POST
to your endpoint] D --> E{Your endpoint
responds 2xx?} E -- Yes --> F([Delivered]) E -- "No · timeout · error" --> G[Record attempt
status · body · error] G --> H{Retries left?} H -- Yes --> I[Backoff and
retry delivery] I --> D H -- No --> J([Failed]) G --> K{Consecutive-failure
threshold reached?} K -- Yes --> L([Auto-disabled
re-enable in dashboard]) K -- No --> M([Awaiting next event]) `} /> The same flow drives message, template, channel, contact, and link events; only the envelope contents differ. Filtering by `event_types` and `event_filters` is evaluated when the event is generated. Webhooks whose subscription doesn't match the event's sub-type don't receive a delivery attempt. Each retry uses exponential backoff between attempts. After your configured retry budget is exhausted, the delivery is marked `FAILED`, and too many consecutive failed delivery attempts auto-disable the webhook. You re-enable it from the Sent Dashboard. The retry schedule, retry budget, and auto-disable threshold are stated canonically in [Delivery Statuses & Retries](/start/webhooks/event-types#delivery-statuses--retries). ## End-to-end Message Event Flow [#end-to-end-message-event-flow] The diagram below shows how a single outbound message moves through its sub-types and the points at which it can branch into `message.failed`. Inbound events are shown separately because they don't share the outbound state machine. Q[message.queued] Q --> R[message.routed] R --> S[message.sent] S --> D[message.delivered] D --> RD[message.read
WhatsApp · RCS] Q -. validation / no route .-> F([message.failed]) R -. carrier rejection .-> F S -. handset unreachable .-> F D -. delivery receipt timeout .-> F Q -. DENY rule matched .-> FL([message.filtered]) Q -. account-level gate .-> BL([message.blocked]) Q -. curfew / scheduled send .-> SC([message.scheduled]) SC -- window opens --> R SC -. you cancel the hold .-> CA([message.cancelled]) IN([Recipient replies]) --> REC[message.received] `} /> Not every message travels the whole pipeline. A send held for the recipient's quiet hours, or for a `scheduled_at` you set, surfaces `message.scheduled` while it waits, and `message.cancelled` if you call it off before release. A routing policy such as a recipient opt-out finalizes it as `message.filtered`, and a gate such as insufficient balance, an unapproved template, or a free-form send with no open conversation finalizes it as `message.blocked`. `FILTERED` and `BLOCKED` are policy decisions rather than delivery failures, so neither counts against your deliverability rate. See [Trust & Safety](/start/concepts/trust-and-safety) for the gates behind each one. Not every send produces every event. Channels and carriers vary in how many intermediate statuses they report. For example, some SMS carriers skip straight from `routed` to `delivered`. Treat the sub-types as a *partial order*: if you receive `message.delivered`, you can safely assume the message was queued, routed, and sent. ## Events at a Glance [#events-at-a-glance] Sent emits the parent event categories `message`, `templates`, `channel`, `contact`, `link`, and `call`, each with a set of sub-types. The tables below summarise the message, template, channel, link, and call events: what triggers each one, the direction it travels, and where in the lifecycle it can fail. Contact events are catalogued in the [Events Reference](/start/webhooks/event-types#contact). ### Message events [#message-events] {/* "auto-disable" is Sent's product behavior for webhooks, not an instruction to the reader. */} {/* vale Google.WordList = NO */} | Message Events | Direction | SMS | WhatsApp | RCS | What it means | Where it can go wrong | | :--- | :--- | :---: | :---: | :---: | :--- | :--- | | `QUEUED` | Outbound | Yes | Yes | Yes | Sent has accepted the request and is queueing it for routing. | Validation errors (bad number, missing template params) reject the request before this event is emitted. | | `ROUTED` | Outbound | Yes | Yes | Yes | The message has been assigned to a carrier or channel provider. | Routing can fail if there is no available route to the destination country/channel, which emits `message.failed`. | | `SENT` | Outbound | Yes | Yes | Yes | The carrier or provider has accepted the message for delivery. | Carrier rejects the payload (for example, content policy or a blocked number), which emits `message.failed`. | | `DELIVERED` | Outbound | Yes | Yes | Yes | The message reached the recipient's device. | Handset offline or number unreachable, which emits `message.failed`. On some SMS routes `DELIVERED` means the carrier accepted the message, because handset receipts are unreliable, and a message whose receipt never arrives ends as `DELIVERED` once the carrier's report window closes. | | `READ` | Outbound | No | Yes | Yes | The recipient opened the message. Not emitted for SMS. | Recipient never opens the message, has read receipts turned off, or the channel doesn't support read receipts (SMS). | | `FAILED` | Outbound | Yes | Yes | Yes | Terminal failure: the message will not be delivered. The payload carries `message_status: FAILED` with `reason_code` and `reason` saying why. | This *is* the failure event. Branch on `payload.reason_code`; see the [Error Catalog](/reference/api/error-catalog#message-outcome-codes). | | `SCHEDULED` | Outbound | Yes | Yes | Yes | The send is held until a `scheduled_at` instant you set, or until the recipient's quiet hours end. | The message is held, not lost; it re-enters the pipeline when the instant arrives or the quiet-hours window closes. | | `CANCELLED` | Outbound | Yes | Yes | Yes | You called a held send off with `POST /v3/messages/{id}/cancel`. The payload carries the `scheduled_at` that was called off. | Terminal: the message is never released or sent. A cancellation after the message is released is refused with `409`. | | `FILTERED` | Outbound | Yes | Yes | Yes | A routing policy (for example, a recipient opt-out) suppressed the message before dispatch. | Terminal for that recipient: the message is not dispatched. | | `BLOCKED` | Outbound | Yes | Yes | Yes | An account-level gate (for example, insufficient balance or an unmet onboarding entitlement) stopped the message. | Terminal for that message; new sends stay gated until the account condition is resolved. | | `RECEIVED` | Inbound | Yes | Yes | Yes | A contact replied to one of your numbers (or, on RCS, tapped a quick-reply suggestion chip). | Inbound delivery to your endpoint can still fail at HTTP (see the retry/auto-disable lifecycle in the preceding section). | {/* vale Google.WordList = YES */} ### Template events [#template-events] Template events are emitted under the `templates` parent type as a template moves through review. Each status carries a matching sub-type: | Template Events | Sub-type | What it means | Where it can go wrong | | :--- | :--- | :--- | :--- | | `PENDING` | `templates.pending` | The template was submitted for review. A submission covers every channel, so this is a whole-template event and the per-channel results arrive separately. | None | | `APPROVED` | `templates.approved` | The leg named in `payload.channel` is approved and can be sent. | None | | `REJECTED` | `templates.rejected` | The leg was rejected. The reason is in `payload.reason`. | Fix the template content or category, then re-submit. | | `PAUSED` | `templates.paused` | Meta paused the WhatsApp leg for low quality. Sends against it are rejected until it recovers. | Terminal for WhatsApp sends while the pause holds. | | `DISABLED` | `templates.disabled` | Meta disabled the WhatsApp leg, for example for a policy violation. | That leg is not sendable. Author a replacement rather than appealing in place. | | `DELETED`, `PENDING_DELETION` | `templates.deleted` | The template was deleted, including a deletion made outside Sent. | Sends referencing the template fail after this point. | | `CATEGORY_UPDATED` | `templates.category_updated` | The category changed, which changes how the template is priced. Fires when Meta sets or moves it on the WhatsApp leg, and when you change it on an edit, which is the usual way a rejected template is recategorised before resubmitting. See the [events reference](/start/webhooks/event-types) for the reason strings. | None | | `QUALITY_UPDATED` | `templates.quality_updated` | Meta's quality rating for the WhatsApp leg changed. The change is in `payload.reason`. A declining rating can eventually trigger `PAUSED`. | None | Who reviews a template depends on the account. With a connected WhatsApp Business Account, Meta reviews it, and an `APPROVED` or `PENDING` verdict applies to every channel while a rejection from Meta applies to the WhatsApp leg only. Without one, Sent's compliance team reviews it and decides each channel individually. Either way `payload.channel` names the leg a decision is about, a decision covering the whole template omits the field, and an account with no WhatsApp channel keeps a WhatsApp leg sitting at `PENDING` with nothing to submit it to. Meta forwards a wider set of lifecycle values than the preceding table covers, and adds to it without notice. A status outside the table arrives on the bare `templates` parent with no `event` key and the status reported verbatim in `payload.status`, so route on `field` first and treat `event` as optional. ### Channel events [#channel-events] Channel events are emitted under the `channel` parent type as one market moves through provisioning and compliance. The subject is always one market, named by `payload.country`: | Channel Events | Sub-type | What it means | Where it can go wrong | | :--- | :--- | :--- | :--- | | Filed | `channel.submitted` | Your request is filed and it's with Sent or a registry. Fires for a first filing, for a resubmission, and for a sender ID that Sent pre-registers with the destination's regulator on your behalf once that market's documents are in. | Nothing to do. Registry decisions take days for SMS. | | Corrections wanted | `channel.changes_requested` | Something needs correcting before the market can go forward. A market that pre-registers its sender ID arrives here while its required documents are missing. | Nothing progresses until you act. Call `GET /v3/compliance/requirements` for the market to see which fields and documents are outstanding. | | Verdict in | `channel.approved` | The registry answered and the sender is being acquired. For a 10DLC market, this is when the carriers elect your campaign. | Not sendable. A requested area code can extend this to a full acquisition cycle. | | Turned down | `channel.rejected` | The sender was refused before it ever went live: The Campaign Registry rejected the campaign, or a sender still being set up was withdrawn. `payload.reason` says why when one was given. | The market won't go live as it stands. Correct what `payload.reason` names and resubmit, or request a different sender. | | Live | `channel.activated` | The sender is live and the market can carry traffic. Subscribe to this one alone if all you need is to know when you can send. | None. | | No longer live | `channel.deactivated` | The sender stopped working: released to the pool, unbound because its campaign lapsed, or switched off by Sent. | Stop queueing against the market. Otherwise you learn on the next send. | | Removed | `channel.removed` | Sent removed a sender that had been approved, for example at your request. It is gone, not switched off. | Stop queueing against the market, and request a new sender to send there again. | `payload.status` reports where the market stands (`PROVISIONING`, `PENDING_REVIEW`, `ACTION_NEEDED`, `ACTIVE`, or `INACTIVE`), and is the same value `GET /v3/channels` publishes for that market. It answers a different question from the sub-type: the sub-type says what happened, the status says whether the market can send. A resubmission filed against a market whose sender is already live arrives as `channel.submitted` carrying `ACTIVE`. `ACTIVE` means provisioning and compliance are complete. It does not promise the next send succeeds: a suspended account and a destination blocked by a routing rule both report `ACTIVE`. Your organization's webhook receives your organization's own channel events. To receive every Sender Profile's, select `channel` under `sender_profile`, which clones the webhook onto each profile, and `payload.account_id` names the profile whose market moved. See [Sender Profile Events](/start/webhooks/event-types#sender-profile-events). ### Link events [#link-events] Link events are emitted under the `link` parent type when a tracked short link or a hosted file Sent published on your behalf is used, expires, or is revoked. The subject is always one link, named by `payload.record_id`: | Link Events | Sub-type | What it means | Where it can go wrong | | :--- | :--- | :--- | :--- | | Followed | `link.clicked` | A tracked short link was followed and Sent served the redirect. | Not proof a person opened it. Providers and link scanners fetch URLs on their own, so filter on `payload.traffic_class`. | | Served | `link.downloaded` | A hosted file behind a tracked link was served. | A ranged request reports only the bytes in that range, so one file can produce several events. | | Expired | `link.expired` | A published link reached its expiration. | Later requests no longer resolve. Republish rather than expecting the link to recover. | | Revoked | `link.revoked` | A published link was permanently revoked. | Terminal for that link. | This family is opt-in: subscribe to `link` explicitly, because no other subscription inherits it. Events for a Sender Profile's links go to that profile's webhooks, as every family's do, so select `link` under `sender_profile` to receive them through clones of your organization's webhook. Full payload fields are in the [Events Reference](/start/webhooks/event-types#link). ### Call events [#call-events] Call events are emitted under the `call` parent type as a phone call moves from the moment it starts to the moment it ends, and once more for each recording that becomes available. The subject is always one call, named by `payload.call_id`: | Call Events | Sub-type | What it means | Where it can go wrong | | :--- | :--- | :--- | :--- | | Started | `call.initiated` | The call arrived or was placed. | Sent sends it before its own checks and before your callback is asked, so a call refused for balance, destination or a missing callback URL still has it. Your callback must answer within 2.5 seconds, with one retry, or the call fails with `callback_timeout`. | | Answered | `call.answered` | The call was answered. | A call between two of your app users has no `answered_at` on its record, so do not wait for this one to time the call. | | Agent connected | `call.agent_connected` | One of your voice agents took the call: its session started. | Only on calls with `payload.mode` set to `agent`, once per call, after `call.answered`. A call the agent refuses or cannot be reached for has no such event: it ends with `call.failed` and `agent_busy` or `agent_unreachable`, or goes to the agent's fallback number. | | Completed | `call.completed` | An answered call ended, with its `duration_seconds` and `price`. | `price` is omitted until billing has recorded the charge. Read it from `GET /v3/voice/calls/{id}` later rather than treating it as zero. | | Failed | `call.failed` | The call ended without completing. | `reason` is omitted when none was recorded. The values are listed under [Call Failure Reasons](/reference/api/error-catalog#call-failure-reasons). | | Recording ready | `call.recording_ready` | One recording is stored and can be listed, once per recording. | The download links `GET /v3/voice/calls/{id}/recordings` returns expire. Request the list again for a fresh link rather than storing the URL. | Full payload fields are in the [Events Reference](/start/webhooks/event-types#call). ## What's Next [#whats-next] - Subscribe to the events your app needs in the [Events Reference](/start/webhooks/event-types): full payload schemas and filtering rules. - Verify incoming requests against the signing secret described in [Signature Verification](/start/webhooks/signature-verification). - See [Handling Retries](/start/webhooks/handling-retries) for guidance on idempotency, response codes, and recovery. --- # Local Development & Debugging (/start/webhooks/local-development.md) # Local Development & Debugging [#local-development--debugging] This guide shows you how to receive Sent webhooks on a local development server, send test events on demand, debug failed deliveries, and keep your handler fast with queue-based processing. **Prerequisites:** - A configured webhook endpoint (see [Webhook Setup](/start/webhooks/getting-started)) - A handler that verifies request signatures (see [Security](/start/webhooks/signature-verification)) For idempotency and duplicate-delivery handling, refer to [Handling Retries](/start/webhooks/handling-retries); this page links to those rules rather than restating them. ## Expose Your Local Server [#expose-your-local-server] Webhooks are outbound HTTP requests initiated by Sent towards your app, so Sent must be able to reach your handler: - During development your app usually runs on `localhost`, which sits behind NAT or a firewall and has no public IP, so the Sent webhook delivery service cannot reach it directly. - Sent rejects URLs that resolve to private/loopback IP ranges (for example, `127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`) at registration *and* delivery time, so a raw `http://localhost:5000/…` URL never works. - Both `http://` and `https://` schemes are accepted by the platform, but use HTTPS in production so the signed payload cannot be intercepted in transit. To receive webhooks locally, use a secure tunneling tool that exposes your local server to the internet through a public HTTPS URL. ### Create a tunnel with ngrok [#create-a-tunnel-with-ngrok] ```bash # Install ngrok (if not already installed) npm install -g @ngrok/ngrok # Start your local server npm run dev # Running on http://localhost:5000 # In another terminal, create tunnel ngrok http 5000 ``` This exposes your local server at a public URL: ``` https://abc123.ngrok.io -> http://localhost:5000 ``` Set your webhook's **Endpoint URL** to `https://abc123.ngrok.io/webhooks/sent`, either when [adding the webhook](/start/webhooks/getting-started) or by editing an existing one in the [Sent Dashboard](https://app.sent.dm/dashboard/webhooks). If your tunnel URL changes after a restart, update the webhook's endpoint URL to match. Deliveries to the stale URL show up as `FAILED` in the webhook's Events table. ### Alternative tunneling tools [#alternative-tunneling-tools] If ngrok does not fit your workflow, other options include: - **Cloudflare Tunnel**: persistent URLs and custom domains - **LocalTunnel**: installs from npm, no account required - **serveo.net**: SSH-based, nothing to install - **VS Code port forwarding**: built into the editor - **Tailscale Funnel**: exposes a server from an existing Tailscale network ## Send Test Events [#send-test-events] You do not need to send real messages to exercise your handler. Sent can deliver a sample payload for any event your webhook subscribes to: 1. In the [Sent Dashboard](https://app.sent.dm/dashboard/webhooks), open the webhook's actions menu and select **Test Webhook**. 2. The dialog lists the events the webhook subscribes to. Click **Test** next to an event, and Sent sends a sample payload for it to your endpoint. 3. The result appears immediately, and the delivery is recorded in the webhook's **Events** table like any other delivery. Each test uses fresh sample ids, so you can test the same event as many times as you like and each one is delivered. A failed test doesn't count toward [auto-disable](/start/webhooks/event-types#delivery-statuses--retries), so testing an endpoint that isn't ready yet can't switch the webhook off. A successful test still resets the failure counter. To trigger the same delivery from scripts or CI, call the [test endpoint](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksTestWebhookEndpoint): ```bash curl -X POST "https://api.sent.dm/v3/webhooks/{webhook_id}/test" \ -H "x-api-key: $SENT_API_KEY" \ -H "Content-Type: application/json" \ -d '{"event_type": "message.sent"}' ``` The test endpoint is on the sensitive rate tier (10 requests per minute), so keep automated test-delivery loops slow. ## Debug Failed Deliveries [#debug-failed-deliveries] Every delivery attempt is recorded. In the dashboard, open a webhook to inspect its **Events** table; each delivery shows: - the delivery status: `PENDING`, `RETRYING`, `DELIVERED`, or `FAILED` - the number of delivery attempts - the HTTP status code and the first portion of the response body your endpoint returned - the error message, plus processing start and completion timestamps {/* "auto-disable" is Sent's product behavior for webhooks, not an instruction to the reader. */} {/* vale Google.WordList = NO */} The same data is available over the API via [`GET /v3/webhooks/{id}/events`](/reference/api/webhooks/SentDmServicesEndpointsCustomerAPIv3WebhooksGetWebhookEventsEndpoint). For your organization's webhook, the list also includes the events delivered through its [Sender Profile clones](/start/webhooks/event-types#sender-profile-events), newest first, and the filters and total count cover them too. The retry schedule, retry budget, and auto-disable threshold are stated canonically in [Delivery Statuses & Retries](/start/webhooks/event-types#delivery-statuses--retries). {/* vale Google.WordList = YES */} When a local delivery fails, check these causes in order: 1. **Tunnel not running or URL stale**: restart the tunnel and confirm the webhook's endpoint URL matches its current public URL. 2. **Signature verification rejects the request**: verification must run on the raw request body; a body parsed and re-serialized by your framework produces a different signature. See [Security](/start/webhooks/signature-verification) for the scheme and [raw-body capture patterns](/build/webhook-receiver#why-the-raw-body-matters) per framework. 3. **Handler responds too slowly**: your endpoint must return `2xx` within the webhook's `timeout_seconds` (5–120 s, default 30 s). Move slow work out of the request path with [queue-based processing](#queue-based-processing). ## Queue-Based Processing [#queue-based-processing] Webhooks must return `2xx` quickly. Don't do heavy work inside the handler. Instead, push the event to a queue for background processing. The examples import `verifyWebhookSignature` and `idempotencyKey` from a shared `webhook-utils` module: implement them from the [signature scheme](/start/webhooks/signature-verification) and the [idempotency key rules](/start/webhooks/handling-retries#choosing-an-idempotency-key). **Acknowledge Immediately** - Verify signature, then return success status right away: ```javascript import { verifyWebhookSignature, idempotencyKey } from './webhook-utils.js'; // Use raw body parser app.use('/webhooks/sent', express.raw({ type: 'application/json' })); app.post("/webhooks/sent", (req, res) => { // Extract headers for signature verification (version 2 first, then version 1) const signature = req.get('webhook-signature') ?? req.get('x-webhook-signature'); const webhookId = req.get('webhook-id') ?? req.get('x-webhook-id'); const timestamp = req.get('webhook-timestamp') ?? req.get('x-webhook-timestamp'); const webhookSecret = process.env.SENT_WEBHOOK_SECRET; const rawBody = req.body.toString(); if (!verifyWebhookSignature(rawBody, signature, webhookId, timestamp, webhookSecret)) { return res.status(401).send('Unauthorized'); } // Parse event const event = JSON.parse(rawBody); // Immediate acknowledgment res.sendStatus(200); // Push to queue for background processing with a payload-derived // idempotency key (see the Handling Retries page) queue.add("webhook-processing", { eventId: idempotencyKey(event), field: event.field, payload: event.payload, timestamp: event.timestamp, }); }); ``` ```python from celery import Celery from webhook_utils import verify_webhook_signature, idempotency_key celery_app = Celery('tasks', broker='redis://localhost:6379/0') @app.route('/webhooks/sent', methods=['POST']) def handle_webhook(): # Extract headers for signature verification (version 2 first, then version 1) signature = request.headers.get('webhook-signature') or request.headers.get('x-webhook-signature') webhook_id = request.headers.get('webhook-id') or request.headers.get('x-webhook-id') timestamp = request.headers.get('webhook-timestamp') or request.headers.get('x-webhook-timestamp') webhook_secret = os.environ.get('SENT_WEBHOOK_SECRET') raw_body = request.get_data() if not verify_webhook_signature(raw_body, signature, webhook_id, timestamp, webhook_secret): return 'Unauthorized', 401 # Parse event event = request.get_json() # Immediate acknowledgment # Push to queue for background processing with a payload-derived # idempotency key (see the Handling Retries page) process_webhook.delay( event_id=idempotency_key(event), field=event['field'], payload=event['payload'], timestamp=event['timestamp'] ) return '', 200 ``` ```go import "yourapp/webhook" // WebhookEvent maps the envelope: Field `json:"field"`, Event `json:"event"`, // Timestamp `json:"timestamp"`, Payload `json:"payload"` (json.RawMessage) func webhookHandler(w http.ResponseWriter, r *http.Request) { // Extract headers for signature verification (version 2 first, then version 1) header := func(v2, v1 string) string { if v := r.Header.Get(v2); v != "" { return v } return r.Header.Get(v1) } signature := header("webhook-signature", "x-webhook-signature") webhookID := header("webhook-id", "x-webhook-id") timestamp := header("webhook-timestamp", "x-webhook-timestamp") webhookSecret := os.Getenv("SENT_WEBHOOK_SECRET") body, _ := io.ReadAll(r.Body) if !webhook.VerifyWebhookSignature(body, signature, webhookID, timestamp, webhookSecret) { http.Error(w, "Unauthorized", http.StatusUnauthorized) return } // Parse event var event WebhookEvent json.Unmarshal(body, &event) // Immediate acknowledgment w.WriteHeader(http.StatusOK) // Push to queue for background processing with a payload-derived // idempotency key (idempotencyKey implements the Handling Retries rules) task := &Task{ EventID: idempotencyKey(event), Field: event.Field, Payload: event.Payload, Timestamp: event.Timestamp, } queue.Enqueue(task) } ``` **Process in Background** - Handle the business logic asynchronously: ```javascript // Worker process queue.process("webhook-processing", async (job) => { const { field, payload, timestamp } = job.data; try { if (field === 'message') { await handleMessageEvent(payload); } else if (field === 'templates') { await handleTemplateEvent(payload); } console.log(`Successfully processed ${field} event`); } catch (error) { console.error(`Failed to process ${field} event:`, error); throw error; // Will trigger retry based on queue configuration } }); async function handleMessageEvent(payload) { const { message_id, message_status } = payload; if (message_status === 'DELIVERED') { // Update order status, send notification, etc. await updateOrderStatus(message_id, 'delivered'); } else if (message_status === 'FAILED') { await notifyDeliveryFailure(message_id); } } async function handleTemplateEvent(payload) { const { template_id, status } = payload; if (status === 'APPROVED') { await enableTemplate(template_id); } } ``` ```python @celery_app.task(bind=True, max_retries=3) def process_webhook(self, event_id, field, payload, timestamp): try: if field == 'message': handle_message_event(payload) elif field == 'templates': handle_template_event(payload) print(f"Successfully processed {field} event") except Exception as error: print(f"Failed to process {field} event: {error}") raise self.retry(exc=error, countdown=60) def handle_message_event(payload): message_id = payload['message_id'] message_status = payload['message_status'] if message_status == 'DELIVERED': # Update order status, send notification, etc. update_order_status(message_id, 'delivered') elif message_status == 'FAILED': notify_delivery_failure(message_id) def handle_template_event(payload): template_id = payload['template_id'] template_name = payload['template_name'] status = payload['status'] if status == 'APPROVED': enable_template(template_id) ``` ```go // Worker process func processWebhookWorker(queue *Queue) { for task := range queue.Tasks { field := task.Field event := task.Event var err error switch field { case "message": err = handleMessageEvent(event) case "templates": err = handleTemplateEvent(event) } if err != nil { log.Printf("Failed to process %s event: %v", field, err) // Will trigger retry based on queue configuration queue.Retry(task) } else { log.Printf("Successfully processed %s event", field) } } } func handleMessageEvent(event WebhookEvent) error { var payload MessagePayload if err := json.Unmarshal(event.Payload, &payload); err != nil { return err } if payload.MessageStatus == "DELIVERED" { // Update order status, send notification, etc. return updateOrderStatus(payload.MessageID, "delivered") } else if payload.MessageStatus == "FAILED" { return notifyDeliveryFailure(payload.MessageID) } return nil } func handleTemplateEvent(event WebhookEvent) error { var payload TemplatePayload if err := json.Unmarshal(event.Payload, &payload); err != nil { return err } return syncTemplate(payload.TemplateID) } ``` ### Queue options [#queue-options] Pick whatever queue your stack already runs: for example, BullMQ for Node.js, Celery for Python, or a managed service such as Amazon SQS. Example setup with retry configuration: ```javascript import { Queue, Worker } from 'bullmq'; import { idempotencyKey } from './webhook-utils.js'; const webhookQueue = new Queue("webhook-processing", { connection: { host: "localhost", port: 6379 }, }); // Add to queue (use raw body parser to preserve the raw bytes for signature verification) app.use('/webhooks/sent', express.raw({ type: 'application/json' })); app.post("/webhooks/sent", async (req, res) => { res.sendStatus(200); const event = JSON.parse(req.body.toString()); await webhookQueue.add("process-event", { eventId: idempotencyKey(event), ...event, }, { attempts: 3, backoff: { type: "exponential", delay: 5000, }, }); }); // Process from queue const worker = new Worker( "webhook-processing", async (job) => { const eventData = job.data; await processWebhookEvent(eventData); }, { connection: { host: "localhost", port: 6379 } } ); ``` ```python from celery import Celery from kombu import Exchange, Queue from webhook_utils import idempotency_key # Configure Celery celery_app = Celery('webhook_processor', broker='redis://localhost:6379/0') celery_app.conf.task_routes = { 'process_webhook_event': {'queue': 'webhook-processing'} } celery_app.conf.task_queues = ( Queue('webhook-processing', Exchange('webhook-processing'), routing_key='webhook'), ) # Add to queue @app.route('/webhooks/sent', methods=['POST']) def handle_webhook(): event_data = request.get_json() # Queue with retry configuration and a payload-derived idempotency key process_webhook_event.apply_async( kwargs={ 'event_id': idempotency_key(event_data), 'field': event_data['field'], 'payload': event_data['payload'], 'timestamp': event_data['timestamp'], }, retry=True, retry_policy={ 'max_retries': 3, 'interval_start': 5, 'interval_step': 5, 'interval_max': 15, } ) return '', 200 # Process from queue @celery_app.task(bind=True, max_retries=3) def process_webhook_event(self, event_data): try: # Process webhook event handle_event(event_data) except Exception as exc: raise self.retry(exc=exc, countdown=5) ``` ```go import ( "github.com/gomodule/redigo/redis" "encoding/json" ) // Queue configuration type WebhookQueue struct { pool *redis.Pool } func NewWebhookQueue() *WebhookQueue { return &WebhookQueue{ pool: &redis.Pool{ MaxIdle: 10, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", "localhost:6379") }, }, } } // Add to queue type QueuedEvent struct { EventID string `json:"event_id"` // payload-derived idempotency key (see the Handling Retries page) WebhookEvent } func webhookHandler(w http.ResponseWriter, r *http.Request) { var event WebhookEvent json.NewDecoder(r.Body).Decode(&event) w.WriteHeader(http.StatusOK) // Add to Redis queue with a payload-derived idempotency key conn := queue.pool.Get() defer conn.Close() queued := QueuedEvent{EventID: idempotencyKey(event), WebhookEvent: event} data, _ := json.Marshal(queued) conn.Do("LPUSH", "webhook-processing", data) } // Process from queue func (q *WebhookQueue) ProcessWorker() { conn := q.pool.Get() defer conn.Close() for { reply, err := redis.ByteSlices(conn.Do("BRPOP", "webhook-processing", 0)) if err != nil { log.Printf("Queue error: %v", err) continue } var event WebhookEvent if err := json.Unmarshal(reply[1], &event); err != nil { log.Printf("Unmarshal error: %v", err) continue } if err := processWebhookEvent(event); err != nil { log.Printf("Processing error: %v", err) // Re-queue with retry logic conn.Do("LPUSH", "webhook-processing:retry", reply[1]) } } } ``` ## Related Pages [#related-pages] - [Security](/start/webhooks/signature-verification): the signature scheme and verification steps - [Handling Retries](/start/webhooks/handling-retries): idempotency keys, deduplication, and out-of-order events - [Events Reference](/start/webhooks/event-types): payloads, delivery statuses, and the retry schedule - [Production Checklist](/start/webhooks/production-checklist): what to confirm before going live --- # Production Checklist (/start/webhooks/production-checklist.md) # Production Checklist [#production-checklist] Before deploying your webhook handler to production, ensure you've covered all these critical items. ## Security [#security] ### ✅ HTTPS Only [#-https-only] - [ ] Webhook URL uses `https://` - [ ] SSL certificate is valid - [ ] HTTP requests are redirected to HTTPS ### ✅ Signature Verification [#-signature-verification] - [ ] Implement HMAC signature verification - [ ] Use constant-time comparison - [ ] Reject requests with invalid signatures - [ ] Rotate secrets if compromised ```typescript if (!verifySignature(req)) { return res.status(401).send('Invalid signature'); } ``` ### ✅ Timestamp Validation [#-timestamp-validation] - [ ] Reject old requests (> 5 minutes) - [ ] Prevent replay attacks ```typescript const timestamp = req.headers['webhook-timestamp'] ?? req.headers['x-webhook-timestamp']; const now = Math.floor(Date.now() / 1000); if (Math.abs(now - parseInt(timestamp)) > 300) { return res.status(401).send('Timestamp too old'); } ``` ## Reliability [#reliability] ### ✅ Quick Response [#-quick-response] - [ ] Return 2xx well within the webhook's timeout (on version 1, `timeout_seconds`, 5–120s, default 30s) - [ ] Process asynchronously using queues - [ ] Handle errors without failing the request ```typescript app.post('/webhooks/sent', (req, res) => { // Acknowledge immediately res.sendStatus(200); // Process in background — idempotency key is derived from the payload (see Handling Retries) queue.add('webhook', { timestamp: req.headers['webhook-timestamp'] ?? req.headers['x-webhook-timestamp'], ...req.body, }); }); ``` ### ✅ Idempotency [#-idempotency] - [ ] Key on the `webhook-id` header (`X-Webhook-Event-ID` on a [version 1](/start/webhooks/event-types#webhook-versions) webhook), which carries the same value on every attempt at that event. Version 1's `X-Webhook-ID` is the webhook configuration UUID, *not* a per-event ID, and the timestamp header moves between attempts - [ ] Store processed idempotency keys - [ ] Handle out-of-order events - [ ] Use database transactions See [Handling Retries](/start/webhooks/handling-retries) for implementation. ### ✅ Retry Handling [#-retry-handling] - [ ] Expect duplicate and repeated deliveries. Sent delivers events at least once (see the [retry schedule](/start/webhooks/event-types#delivery-statuses--retries)) - [ ] Make processing idempotent so a redelivered event causes no duplicate side effects - [ ] Implement exponential backoff for your own downstream retries (queue re-processing, database writes) ## Monitoring [#monitoring] ### ✅ Logging [#-logging] - [ ] Log all webhook events - [ ] Include the payload-derived idempotency key, event type, and timestamp - [ ] Use structured logging (JSON) - [ ] Set appropriate log levels ```typescript logger.info('Webhook received', { eventId: req.headers['webhook-id'] ?? req.headers['x-webhook-event-id'], // same on every attempt eventType: req.body.field, event: req.body.event, // granular sub-type, e.g. message.delivered timestamp: new Date().toISOString() }); ``` ### ✅ Alerting [#-alerting] - [ ] Alert on high error rates - [ ] Monitor webhook delivery failures - [ ] Set up PagerDuty/Opsgenie for critical issues ```typescript if (errorRate > 0.05) { // 5% error rate await alertTeam('High webhook error rate', { errorRate }); } ``` ### ✅ Metrics [#-metrics] Track: - [ ] Webhook events received (counter) - [ ] Processing duration (histogram) - [ ] Failed events (counter) - [ ] Queue depth (gauge) ## Error Handling [#error-handling] ### ✅ Graceful Degradation [#-graceful-degradation] - [ ] Handle partial failures - [ ] Continue processing other events - [ ] Don't fail the entire batch ```typescript for (const event of events) { try { await processEvent(event); } catch (error) { logger.error('Event processing failed', { event, error }); // Continue with next event } } ``` ### ✅ Dead Letter Queue [#-dead-letter-queue] - [ ] Failed events go to DLQ - [ ] Manual review process - [ ] Retry from DLQ capability ## Scalability [#scalability] ### ✅ Queue-Based Processing [#-queue-based-processing] - [ ] Use Redis/RabbitMQ/SQS - [ ] Multiple worker processes - [ ] Horizontal scaling ready ```typescript const worker = new Worker('webhooks', processor, { connection: redisConnection, concurrency: 10 }); ``` ### ✅ Rate Limiting [#-rate-limiting] - [ ] Protect downstream services - [ ] Implement backoff - [ ] Queue events if overloaded ## Testing [#testing] ### ✅ Local Testing [#-local-testing] - [ ] Test with ngrok/localtunnel - [ ] Verify signature verification - [ ] Test retry handling See [Local Development](/start/webhooks/local-development). ### ✅ Load Testing [#-load-testing] - [ ] Test with high event volume - [ ] Verify queue doesn't overflow - [ ] Check response times ### ✅ Failure Testing [#-failure-testing] - [ ] Test with invalid signatures - [ ] Test with malformed payloads - [ ] Test database failure scenarios ## Infrastructure [#infrastructure] ### ✅ High Availability [#-high-availability] - [ ] Multiple server instances - [ ] Load balancer configured - [ ] Database replicas - [ ] Redis cluster (if using) ### ✅ Backups [#-backups] - [ ] Database backups - [ ] Configuration backups - [ ] Tested restore procedures ## Pre-Launch Verification [#pre-launch-verification] Run through this final checklist: - [ ] Webhook URL returns 200 quickly (< 1 s response time) - [ ] Signature verification rejects invalid signatures - [ ] Duplicate events are handled correctly - [ ] Logs are flowing to central logging - [ ] Alerts are configured and tested - [ ] Queue workers are running - [ ] Database connections are pooled - [ ] SSL certificate is valid - [ ] Rate limits are configured - [ ] Runbook is documented ## Dashboard Configuration [#dashboard-configuration] Verify in [Sent Dashboard](https://app.sent.dm/dashboard/webhooks): - [ ] Webhook URL is correct - [ ] Event types are selected - [ ] Secret is secure - [ ] Test webhook delivery succeeds ## Runbook Template [#runbook-template] Create a runbook for your team: ```markdown # Webhook Runbook ## High Error Rate Alert 1. Check webhook logs in dashboard 2. Verify endpoint is responding 3. Check application logs 4. If needed, temporarily disable webhook ## Missed Events 1. Check webhook delivery logs 2. Verify idempotency handling 3. Manual replay if needed ## Secret Rotation 1. Generate new secret in dashboard 2. Update application config 3. Deploy new config 4. Test webhook 5. Remove old secret ``` **Ready to go live?** After completing this checklist, enable your webhook in the Sent Dashboard and monitor closely for the first 24 hours. --- # Receiving Inbound Messages via the message.received Webhook (/start/webhooks/receiving-inbound-messages.md) # Receiving Inbound Messages via the message.received Webhook [#receiving-inbound-messages-via-the-messagereceived-webhook] This guide shows you how to process contact replies in real time: identify `message.received` events, acknowledge and deduplicate deliveries, store the inbound message, and trigger a follow-up flow for non-keyword replies. **Prerequisites:** - A webhook endpoint registered in the Sent Dashboard and subscribed to `message` events; see [Webhook Setup](/start/webhooks/getting-started) - A channel that can receive inbound messages. Check `number_type` for the market on `GET /v3/channels`: `ALPHANUMERIC` is send-only, and no inbound event will ever arrive for it. For the other sender types, whether the market has an inbound path depends on the provider Sent routes it through, which the API does not report, so ask [support@sent.dm](mailto:support@sent.dm) if you need it confirmed for a market. Per-channel behavior is in the [channel support table](/reference/two-way-messaging#channel-support) ## Build the Inbound Handler [#build-the-inbound-handler] ### Identify inbound events [#identify-inbound-events] Sent fires `message.received` for every inbound message, free-text replies and compliance keywords alike. Filter on the envelope's `field` and `event` values: ```json { "field": "message", "event": "message.received", "timestamp": "2025-01-15T08:35:00Z", "payload": { "message_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "updated_at": "2025-01-15T08:34:58Z", "account_id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "inbound_number": "+1234567890", "outbound_number": "+1987654321", "text": "Yes, tell me more", "channel": "sms", "received_at": "2025-01-15T08:34:58Z" } } ``` `inbound_number` is the contact's phone number; `outbound_number` is your provisioned number that received the message. The [Events Reference](/start/webhooks/event-types) documents every payload field. ### Acknowledge, then deduplicate [#acknowledge-then-deduplicate] Respond with a `2xx` status before doing any processing; slow handlers cause redeliveries, and Sent retries failed deliveries anyway (see [Handling Retries](/start/webhooks/handling-retries)). If your endpoint verifies signatures, verify before acknowledging; see [Signature Verification](/start/webhooks/signature-verification). Use `payload.message_id` as your idempotency key. The same event can be delivered more than once, so deduplicate on `message_id` before processing to avoid double inserts or duplicate follow-up flows. ### Store the message and trigger follow-ups [#store-the-message-and-trigger-follow-ups] Store every inbound for your CRM or conversation view, then branch: if the text is a compliance keyword, do nothing, because Sent's consent engine already handles it. If it is a real reply, trigger your follow-up flow. ```typescript import express from 'express'; const app = express(); app.use(express.json()); app.post('/webhooks/sent', async (req, res) => { res.sendStatus(200); // Always acknowledge quickly const { field, event, payload } = req.body; if (field === 'message' && event === 'message.received') { const { message_id, inbound_number, outbound_number, text, channel, received_at } = payload; // Store inbound for your CRM / conversation view await db.inbound.insert({ messageId: message_id, from: inbound_number, to: outbound_number, text, channel, receivedAt: received_at }); // Optionally trigger a follow-up flow const COMPLIANCE_KEYWORDS = ['stop', 'cancel', 'unsubscribe', 'quit', 'end', 'start', 'unstop', 'subscribe', 'help', 'info']; if (text && !COMPLIANCE_KEYWORDS.includes(text.toLowerCase().trim())) { await triggerResponseFlow({ from: inbound_number, channel }); } } }); ``` ```python from flask import Flask, request app = Flask(__name__) @app.route('/webhooks/sent', methods=['POST']) def handle_webhook(): data = request.json if data['field'] == 'message' and data.get('event') == 'message.received': p = data['payload'] db.inbound.insert( message_id=p['message_id'], from_number=p['inbound_number'], to=p['outbound_number'], text=p.get('text'), channel=p['channel'], received_at=p['received_at'] ) compliance_keywords = {'STOP', 'CANCEL', 'UNSUBSCRIBE', 'QUIT', 'END', 'START', 'UNSTOP', 'SUBSCRIBE', 'HELP', 'INFO'} text = p.get('text') if text and text.strip().upper() not in compliance_keywords: trigger_response_flow(from_number=p['inbound_number'], channel=p['channel']) return '', 200 ``` ```go package main import ( "encoding/json" "net/http" "strings" ) type Payload struct { MessageID string `json:"message_id"` InboundNumber string `json:"inbound_number"` OutboundNumber string `json:"outbound_number"` Text string `json:"text"` Channel string `json:"channel"` ReceivedAt string `json:"received_at"` } type WebhookEvent struct { Field string `json:"field"` Event string `json:"event"` Payload Payload `json:"payload"` } func webhookHandler(w http.ResponseWriter, r *http.Request) { var event WebhookEvent if err := json.NewDecoder(r.Body).Decode(&event); err != nil { w.WriteHeader(http.StatusBadRequest) return } w.WriteHeader(http.StatusOK) if event.Field == "message" && event.Event == "message.received" { p := event.Payload db.Inbound.Insert(p.MessageID, p.InboundNumber, p.OutboundNumber, p.Text, p.Channel, p.ReceivedAt) complianceKeywords := map[string]bool{ "STOP": true, "CANCEL": true, "UNSUBSCRIBE": true, "QUIT": true, "END": true, "START": true, "UNSTOP": true, "SUBSCRIBE": true, "HELP": true, "INFO": true, } if p.Text != "" && !complianceKeywords[strings.ToUpper(strings.TrimSpace(p.Text))] { triggerResponseFlow(p.InboundNumber, p.Channel) } } } ``` ```csharp [HttpPost("/webhooks/sent")] public async Task HandleWebhook([FromBody] JsonElement body) { var field = body.GetProperty("field").GetString(); var evt = body.GetProperty("event").GetString(); if (field == "message" && evt == "message.received") { var payload = body.GetProperty("payload"); var messageId = payload.GetProperty("message_id").GetString(); var from = payload.GetProperty("inbound_number").GetString(); var to = payload.GetProperty("outbound_number").GetString(); var text = payload.TryGetProperty("text", out var t) ? t.GetString() : null; var channel = payload.GetProperty("channel").GetString(); var receivedAt = payload.GetProperty("received_at").GetString(); await _db.Inbound.InsertAsync(new InboundMessage { MessageId = messageId, From = from, To = to, Text = text, Channel = channel, ReceivedAt = receivedAt }); var complianceKeywords = new HashSet { "STOP", "CANCEL", "UNSUBSCRIBE", "QUIT", "END", "START", "UNSTOP", "SUBSCRIBE", "HELP", "INFO" }; if (text != null && !complianceKeywords.Contains(text.Trim().ToUpper())) { await _flowService.TriggerResponseFlowAsync(from, channel); } } return Ok(); } ``` If you configured custom keywords in the dashboard, add them to the keyword set. Match them the way Sent does (the entire trimmed text equals the keyword, case-insensitive); see the [matching rules](/reference/two-way-messaging#matching-rules). ### Verify the handler [#verify-the-handler] From a test phone, text a free-form reply to your provisioned number: a `message.received` event arrives, your store gains a row, and your follow-up flow triggers. Then text `STOP`: the event still arrives, but your follow-up flow must not trigger; Sent records the opt-out on its own. Delivery attempts, HTTP status codes, and response bodies for each event are visible per webhook in the Sent Dashboard. ## Troubleshooting [#troubleshooting] | Symptom | Likely cause | Fix | |---------|--------------|-----| | No `message.received` events arrive | The sender is an alphanumeric sender ID, or the route runs over one of Sent's SMPP connections, which has no inbound path | Read `number_type` for the market on `GET /v3/channels`. `ALPHANUMERIC` can never receive; for the other sender types, ask [support@sent.dm](mailto:support@sent.dm) whether that market has an inbound path | | Events stopped arriving on one number | The number is no longer provisioned or assigned, so inbounds cannot be matched to your account and are dropped | Verify the provider and number under your channel settings | | The same reply is processed twice | Redelivered event | Deduplicate on `payload.message_id` before processing | | Follow-up flow fires for `STOP` | Keyword filter does not match Sent's rule | Compare the trimmed, case-normalized text against the full keyword list, defaults plus custom | ## Related pages [#related-pages] - [Two-Way Conversations](/start/guides/two-way-conversations): how inbound matching, storage, and keyword handling work - [Events Reference](/start/webhooks/event-types): the full `message.received` payload, per channel - [Two-Way Messaging Reference](/reference/two-way-messaging): keyword list, matching rules, and channel support - [Handling Opt-Outs and Consent](/start/guides/opt-out-and-consent): mirror keyword opt-outs into your own database # Security (/start/webhooks/signature-verification.md) # Webhook Security [#webhook-security] Webhook security is critical to ensure that requests to your endpoint are actually coming from Sent and haven't been tampered with. This page covers how to verify webhook authenticity and implement security best practices. ## Why Webhook Security Matters [#why-webhook-security-matters] Without proper verification, attackers could: * Send fake webhook requests to trigger unwanted actions * Modify payload data to manipulate your app * Overload your webhook endpoint with requests ## How Sent Signs Webhooks [#how-sent-signs-webhooks] Sent signs every webhook request with an **HMAC-SHA256** signature computed from the webhook's signing secret. This creates a unique signature for each request that proves: 1. The request came from Sent 2. The payload hasn't been modified ## Finding Your Secret Key [#finding-your-secret-key] Each webhook endpoint has a unique secret that's used to sign all requests to that endpoint. The [Sent Dashboard](https://app.sent.dm/dashboard/webhooks) shows a webhook's secret once, in the **Webhook Created** dialog when you add the webhook. Click **Copy** there and store it in your handler's environment, because it isn't shown again. To get a new secret, open the webhook and choose **Rotate signing secret** from its actions menu; the new secret is shown once in the same way. Through the API, the secret is returned when you create a webhook with `POST /v3/webhooks` and when you rotate it. Keep your webhook secret secure and never expose it publicly. If you believe your secret has been compromised, rotate it immediately with **Rotate signing secret** on the webhook's page. After you rotate, a [version 2](/start/webhooks/event-types#webhook-versions) webhook is signed with both the new and the old secret for 24 hours, so you can switch over without rejecting deliveries. A version 1 webhook's old secret stops working at once. ## Signature Verification [#signature-verification] ### How Signatures Work [#how-signatures-work] A [version 2](/start/webhooks/event-types#webhook-versions) webhook, the default, sends the [Standard Webhooks](https://www.standardwebhooks.com) headers `webhook-id`, `webhook-timestamp`, and `webhook-signature`. Verify it exactly as described below, using those three headers in place of `x-webhook-id`, `x-webhook-timestamp`, and `x-webhook-signature`. `webhook-signature` can hold several space-separated signatures, and the request is valid if any one matches. Any Standard Webhooks library also verifies it. A version 1 webhook request includes these headers: | Header | Description | Example | | :--- | :--- | :--- | | `x-webhook-signature` | HMAC-SHA256 signature | `v1,abc123...` (base64) | | `x-webhook-id` | Unique webhook endpoint ID | `550e8400-e29b-41d4-a716-446655440000` | | `x-webhook-event-id` | Unique event ID, identical on every attempt at that event | `9f1c2b7e-4d2a-4c36-9f0b-2c8f1d6a5b41` | | `x-webhook-timestamp` | Unix timestamp (seconds) at which this attempt was signed | `1705334531` | | `x-webhook-attempt` | Index of this delivery attempt, starting at `1` | `2` | | `x-webhook-event-type` | Fully qualified event type | `message.delivered`, `message.received`, or `templates.approved` | The signature format is: ``` x-webhook-signature: v1,{base64_encoded_signature} ``` The signature is computed as follows: 1. Strip the `whsec_` prefix from your signing secret 2. Base64-decode the remaining secret to get raw key bytes 3. Concatenate: `{webhookId}.{timestamp}.{payload}` (dot-separated) 4. Compute HMAC-SHA256 using the raw key bytes 5. Base64-encode the result 6. Prefix with `v1,` ### Step-by-Step Verification [#step-by-step-verification] **Extract headers** - Get `x-webhook-signature`, `x-webhook-id`, and `x-webhook-timestamp` **Prepare your secret** - Strip the `whsec_` prefix and Base64-decode to get raw bytes **Build signed content** - Concatenate: `{webhookId}.{timestamp}.{rawBody}` **Compute HMAC-SHA256** using the decoded secret key bytes **Compare signatures** using a timing-safe comparison function **Only process** the webhook if signatures match Verify that the timestamp is recent (within 5 minutes) to prevent replay attacks. Each attempt is signed when it is sent, so a retry carries its own timestamp and clears a 5-minute window however long the backoff ran before it. Deduplicate on `x-webhook-event-id`, or `webhook-id` on version 2, which holds one value for every attempt at the same event. Don't build a dedupe key from the timestamp: it moves between attempts, so it records one event once per attempt. See [Handling Retries](/start/webhooks/handling-retries) for the full pattern. ## Security Best Practices [#security-best-practices] ### Always Validate Signatures [#always-validate-signatures] Never trust a webhook request without signature verification: ```javascript // ❌ BAD - No verification app.post('/webhook', (req, res) => { processWebhook(req.body); // Dangerous! res.status(200).send('OK'); }); // ✅ GOOD - Verified first app.post('/webhook', (req, res) => { if (!verifySignature(req)) { return res.status(401).send('Unauthorized'); } processWebhook(req.body); res.status(200).send('OK'); }); ``` The example calls a `verifySignature` helper that implements the six steps in [Step-by-Step Verification](#step-by-step-verification). Copy a complete implementation for your language from [the verifier in seven languages](/build/signature-verification#the-verifier-in-seven-languages), and always run it against the raw request body. A body parsed and re-serialized by your framework produces a different signature. ### Use Timing-Safe Comparisons [#use-timing-safe-comparisons] Standard string comparison can leak timing information. Use dedicated functions: * **Node.js**: `crypto.timingSafeEqual()` * **Python**: `hmac.compare_digest()` * **Go**: `subtle.ConstantTimeCompare()` * **Other languages**: Look for "constant-time" or "timing-safe" comparison functions Regular string comparison (`==`) can exit early when it finds a mismatch, potentially leaking information about the correct signature through timing analysis. Timing-safe functions always compare the entire string, preventing this attack vector. ### Prefer HTTPS [#prefer-https] Sent accepts both `http://` and `https://` endpoints at registration time, but you should always use HTTPS in production: ```json { "url": "https://your-app.com/webhook" // ✅ Recommended } ``` ```json { "url": "http://your-app.com/webhook" // ⚠️ Not recommended — payload travels in clear text } ``` While the platform allows http URLs (useful for some tunnels and internal testing), all production traffic should be HTTPS so the signed payload cannot be intercepted or modified in transit. --- # Compare Your Options (/start/why-sent/comparison.md) # Compare Your Options [#compare-your-options] Choosing the right messaging infrastructure is a critical decision that impacts your engineering resources, time to market, and ongoing operational costs. This page compares Sent with the main alternatives to help you make an informed choice. ## The Options [#the-options] ## Comparison Matrix [#comparison-matrix] | Factor | Direct Providers | Build In-House | Sent | |--------|-----------------|----------------|------| | **Initial Setup** | 2-4 weeks per provider | 3-6 months | [Light onboarding](/start/try-sent) / 1-2 days (production) | | **Multi-Channel** | Manual integration each | Build yourself | Built-in | | **Automatic Fallback** | Custom logic required | Build yourself | Automatic | | **Cost Optimization** | Manual rate comparison | Build analytics | Real-time routing | | **Compliance** | Self-managed | Self-managed | Built-in | | **Maintenance** | High (API changes) | Very high | Minimal | | **Time to Market** | Slow | Very slow | Fast | ## Detailed Comparison [#detailed-comparison] ### Sent vs Direct Provider Integration [#sent-vs-direct-provider-integration] **Direct Integration Approach:** ```javascript // SMS provider if (useSMS) { await smsProvider.messages.create({ body: message, from: smsNumber, to: phoneNumber }); } // WhatsApp Business API for WhatsApp if (useWhatsApp && await checkWhatsApp(phoneNumber)) { await sendWhatsAppMessage({ to: phoneNumber, template: whatsappTemplate }); } // Handle failures, retries, fallbacks manually ``` **With Sent:** ```javascript // One call, intelligent routing await sent.messages.send({ to: [phoneNumber], template: { id: templateId } // Automatic channel selection and fallback }); ``` | Aspect | Direct Providers | Sent | |--------|-----------------|------| | **Code Complexity** | High - multiple SDKs, formats, error handling | Low - single SDK, unified format | | **Channel Management** | You manage SMS + WhatsApp + RCS separately | Unified: one API for SMS, WhatsApp, and RCS | | **Fallback Logic** | Build and maintain yourself | Automatic with intelligent routing | | **Provider Relationships** | Manage contracts with each | Single relationship | | **Rate Limiting** | Handle per-provider | Managed automatically | | **Cost Optimization** | Manual rate shopping | Real-time intelligent routing | **When to choose Direct Providers:** - Single channel (SMS only) is sufficient - Very low volume (< 1,000 messages/month) - Already deeply integrated with a specific provider - Need provider-specific features not abstracted by Sent ### Sent vs Building In-House [#sent-vs-building-in-house] **Building In-House Requires:** 1. **Integration Layer** - Multiple provider SDKs - Unified API design - Authentication management - Error code normalization 2. **Routing Intelligence** - Channel availability detection - Cost comparison engine - Delivery success tracking - Machine learning for optimization 3. **Operational Complexity** - Provider health monitoring - Failover automation - Rate limit management - API change tracking 4. **Compliance Infrastructure** - GDPR compliance tools - TCPA compliance - Country-specific regulations - Opt-out management **Timeline Comparison:** The timelines below are illustrative estimates for a typical product team adding multi-channel messaging; actual effort depends on scope, channels, and compliance requirements. | Component | Build In-House | With Sent | |-----------|---------------|-----------| | Initial MVP | 3-6 months | 1-2 days | | Multi-provider support | +2-3 months | Included | | Intelligent routing | +3-6 months | Included | | Compliance framework | +2-4 months | Included | | **Total Time** | **8-18 months** | **1-2 days** | **Hidden Costs of Building In-House:** - Engineering headcount: Messaging becomes a permanent line on a dedicated team's roadmap - Ongoing maintenance: Expect a meaningful share of the initial build effort again every year - Opportunity cost: Features delayed while building infrastructure - Technical debt: Legacy code as messaging evolves ### When to Choose Each Option [#when-to-choose-each-option] #### Choose Direct Provider Integration If: [#choose-direct-provider-integration-if] - SMS-only requirement - Low message volume - Simple use case (OTP only) - Already integrated with provider - Need specific provider features #### Build In-House If: [#build-in-house-if] - Have dedicated messaging team - Very specific routing requirements - Regulatory requirements mandate it - Messaging is core competitive advantage - Have 12+ months to invest #### Choose Sent If: [#choose-sent-if] - Want to try before committing ([light onboarding](/start/try-sent) needs only a verified email and phone number) - Multi-channel needs (SMS + WhatsApp + RCS) - Want RCS branded messaging (verified sender, suggestion chips, read receipts) without building separate integrations - Want automatic optimization - Need to move fast - Don't want infrastructure maintenance - Growing message volume - International expansion plans ## Migration Scenarios [#migration-scenarios] ### Migrating from Direct Providers [#migrating-from-direct-providers] Teams migrating from a direct provider typically start with non-critical messages such as notifications, run Sent in parallel with the existing integration to compare delivery rates and costs, then move critical flows (OTP, alerts) before decommissioning the old provider. **Timeline:** 2-4 weeks for a complete migration ### Migrating from an In-House System [#migrating-from-an-in-house-system] The common pattern is an audit of current messaging flows, a mapping of in-house features to Sent capabilities, then a parallel run in which traffic gradually shifts to Sent until the in-house infrastructure can be retired. **Timeline:** 4-8 weeks depending on complexity ## Cost Analysis [#cost-analysis] Actual costs depend on your message volume, destination regions, channel mix, and engineering rates, so treat any specific figure as an illustration rather than a quote. What holds across scenarios is the shape of each option's cost structure: | Cost Component | Direct Providers | Build In-House | Sent | |----------------|-----------------|----------------|------| | Message costs | Provider list rates | Provider rates you negotiate | Platform rates with routing optimization | | Engineering | Ongoing integration work per provider | A dedicated team, permanently | Initial integration only | | Infrastructure | Your own queues and monitoring | The full stack, self-hosted | Included | | Maintenance | Tracking each provider's API changes | The entire system | Included | Per-message rates are broadly similar across all three options, so the comparison usually comes down to engineering time. Once team cost is counted, a shared platform is usually the cheapest option: the engineering is amortized across every customer instead of carried by yours alone. ## Feature Comparison [#feature-comparison] | Feature | Direct Providers | Build In-House | Sent | |---------|-----------------|----------------|------| | **Unified API** | No | Yes (custom) | Yes | | **Multi-channel** | No | Build yourself | Yes | | **Auto-fallback** | No | Build yourself | Yes | | **Smart routing** | No | Build yourself | Yes | | **Real-time analytics** | Partial | Build yourself | Yes | | **Webhook management** | Basic | Build yourself | Yes | | **Template system** | No | Build yourself | Yes | | **Compliance tools** | No | Build yourself | Yes | | **Contact intelligence** | No | Build yourself | Yes | | **SDK availability** | Per-provider | Build yourself | 7 languages | | **SLA guarantees** | Per-provider | Self-managed | Yes | ## Decision Flowchart [#decision-flowchart] Not ready to work through the decision? You can [try Sent](/start/try-sent) with light onboarding first, before committing to any option. B{"Do you have an existing\nprovider integration?"} A -- "Yes" --> C{"Do you have a dedicated\nmessaging engineering team?"} B -- "Yes" --> D["Stick with your\ndirect provider"] B -- "No" --> E["Use Sent"] C -- "No" --> E C -- "Yes" --> F{"Is messaging core to your\ncompetitive advantage?"} F -- "Yes" --> G["Consider building in-house"] F -- "No" --> E `} /> ## Next Steps [#next-steps] **Ready to explore Sent?** - [Try Sent: Quick Start](/start/try-sent) - send your first message with light onboarding, no code required - [Quickstart Guide](/start/quickstart) - Full setup guide for production - [Platform Overview](/start/concepts/platform-overview) - Understand the architecture - [What Sent Solves](/start/why-sent/use-cases) - Check whether your scenario fits **Still evaluating?** - [Contact Sales](mailto:sales@sent.dm) for a personalized consultation - Review the [API Reference](/reference/api) - Check out the [SDKs](/sdks) --- # Built for Scale (/start/why-sent.md) # Built for Scale [#built-for-scale] Messaging infrastructure has followed the same curve as other parts of the stack. At first, you hardcode something simple, and it works. But over time, complexity builds until you need dedicated infrastructure. Just as teams moved from running bare-metal servers to using AWS, or from building their own payment logic to plugging in Stripe, messaging has reached the point where custom code can't keep up. This page explains why that shift happened and why shared infrastructure ends up ahead of anything a single team can build. For the decision itself, whether to build in-house, integrate providers directly, or use Sent, see [Compare Your Options](/start/why-sent/comparison). ## The Infrastructure Pattern [#the-infrastructure-pattern] Every app starts the same way: call an API to send an SMS. Easy. The moment you scale or expand globally, four forces start compounding: - **Channel Sprawl**: SMS isn't enough. Users fragment across WhatsApp, RCS, and whatever arrives next, and the mix shifts by country and demographic. - **Regulatory Overhead**: Every region and channel has its own compliance rules, approvals, and restrictions. Miss one detail and messages don't deliver. - **Cost Pressure**: At scale, every message costs money. Optimizing delivery requires real knowledge of provider pricing quirks, regional routes, and performance. - **Reliability Expectations**: Verification codes, confirmations, and alerts can't fail. That means failover logic, redundancy, and monitoring, none of which can be improvised. None of these forces is a product feature. They are properties of messaging itself, which is why they eventually outgrow app code, no matter how well that code is written. ## Why Shared Infrastructure Wins [#why-shared-infrastructure-wins] The case for a shared platform is structural rather than a set of measured claims: a platform that carries traffic for many customers can learn things no single app can. - **Learning from Aggregate Traffic**: Routing and delivery logic improve with every message the platform carries. One customer's carrier edge case becomes a routing rule that protects everyone else. - **Cross-Region Visibility**: A platform observes carrier and channel performance across every region its customers send to. A single app only ever sees its own traffic, usually too small a sample to optimize against. - **Compliance at the Platform Layer**: Regulations change per country and per channel. When the platform absorbs those updates, no individual team needs to track them. - **Collective Weight with Providers**: A platform negotiates rates, support, and channel access on behalf of its entire customer base, a stronger position than any single app team holds. The same reasoning explains why in-house builds tend to plateau: telecom and compliance are not core skills for most product teams, and the data needed to keep improving is not available to a single tenant. ## Platform-Level Advantages [#platform-level-advantages] Once messaging is treated as infrastructure, improvements land in a different place than they do with an in-app integration: - **Shared Wins**: An optimization discovered for one customer applies to the whole platform. - **Fast Reaction**: When a carrier degrades or a regulation shifts, the fix ships at the infrastructure layer, without waiting on your next deploy. - **Future Channels**: New channels and capabilities show up in the platform, not in your backlog. - **Aligned Incentives**: A per-message provider earns more when you send more. An infrastructure platform competes on delivery quality and total cost, so its incentive is to make each message cheaper and more likely to arrive. ## Where This Leaves Your Team [#where-this-leaves-your-team] Running your own messaging stack is permanent work: provider API changes, shifting compliance rules, performance tuning, and testing across channels and failure cases never stop. Treating messaging as bought infrastructure converts that recurring cost into a dependency, and keeps your engineers on the product work that differentiates you. Whether that trade is right for your team depends on volume, channels, and how central messaging is to your product. [What Sent Solves](/start/why-sent/use-cases) describes the scenarios where the trade pays off, and [Compare Your Options](/start/why-sent/comparison) works through the build-vs-buy decision in full. **Ready to try?** You don't need to commit to anything: light onboarding gives you API access and pre-built templates with just a verified email and phone number. See [Try Sent](/start/try-sent) for what's included. --- # What Sent Solves (/start/why-sent/use-cases.md) # What Sent Solves [#what-sent-solves] Sent isn't for every app, but once messaging grows beyond simple SMS notifications, the cracks start to show. At scale, you hit problems that adding another provider API can't fix. Those are infrastructure problems, and they are exactly what Sent is built to solve. ## Where Messaging Gets Hard [#where-messaging-gets-hard] Messaging might seem like a simple problem at first, but it quickly becomes complex as you scale. ### Deliverability Guarantees [#deliverability-guarantees] Some messages cannot fail. If they don't land, you break user trust or business operations: **Authentication & Security** - Login codes, 2FA, fraud alerts, password resets. If delivery fails, users are locked out or left vulnerable. These need speed, redundancy, and reliability that a single provider can't guarantee. **Transactional Confirmations** - Order confirmations, payments, shipping updates, account changes. Users depend on them to know something important happened, which is why [tracking message status](/start/guides/message-status-tracking) end to end matters as much as sending. **Critical Alerts** - Outages, security incidents, or time-sensitive events. Sometimes you need to [send on multiple channels at once](/start/guides/sending-messages) to make sure users actually see them. ### Multichannel Needs [#multichannel-needs] As your user base diversifies, "just send SMS" stops working quickly: **Geography** - SMS dominates in the U.S., WhatsApp in Latin America, and that mix keeps shifting. **Demographics** - Younger users may lean on WhatsApp or iMessage. Older users expect SMS. Different devices and habits mean no single channel covers everyone. **Device Capabilities** - Some users have flip phones. Others expect interactive, media-rich messages. You need to adapt per device, not pick one lowest-common-denominator channel. ### Scaling Up [#scaling-up] High-volume messaging introduces problems you can't solve with quick fixes: **Cost Pressure** - At scale, every cent per message matters. Static routing wastes money. [Dynamic routing](/start/concepts/unified-messaging) based on price and delivery performance saves it. **Reliability** - Depending on one provider is a single point of failure. Intelligent multi-provider failover is a must. **Compliance** - Opt-outs, regulations, content checks. At low volume you can handle this manually; at high volume you need automation, from [opt-out handling](/start/guides/opt-out-and-consent) to [regulatory compliance](/start/advanced/compliance-regulations), or you lose time and risk fines. ## When Sent Makes a Difference [#when-sent-makes-a-difference] What **Sent** provides: - **Multi-channel delivery**: One API for [every supported channel](/start/concepts/channels): SMS, WhatsApp, RCS, and future ones. No juggling providers. - **Deliverability guarantees**: If a missed delivery is a business issue, you need fallback and redundancy. - **Global reach at scale**: Regional optimization and compliance built in, instead of cobbling together country-by-country setups. - **Engineering focus**: Keep your team focused on your product, not fighting messaging edge cases. - **RCS rich messaging**: Reach Android users with branded, interactive messages without building a separate integration. Automatic fallback to SMS means no recipient is left out. ### RCS Use Cases [#rcs-use-cases] [RCS](/start/concepts/channels#rcs) unlocks richer interactions for Android users that plain SMS cannot match. **Interactive Campaigns** - Suggestion chips generated from [template buttons](/start/guides/working-with-templates) let you gather quick feedback ("Rate your experience: Good / Poor") or guide users through a flow ("Track Order" / "Contact Support") directly in the message thread. **Branded Transactional Messages** - Delivery confirmations and appointment reminders sent with your company logo and verified checkmark build trust compared to an unknown short code number. Rich cards and scrollable product carousels are part of the RCS standard but are not yet available through Sent. RCS messages currently render as text plus suggestion chips. ## Who Benefits Most [#who-benefits-most] **B2C SaaS** - Apps where messaging drives engagement, security, or operations. **Financial Services** - Banking, payments, and investment platforms where trust depends on reliable, compliant delivery. **E-commerce & Marketplaces** - Order/shipping notifications and customer service updates at scale. **Developer Platforms & ISVs** - Platforms embedding messaging into their own products without wanting to manage provider sprawl. **Emerging Segments** - AI-driven systems that generate huge volumes of context-sensitive messages. - IoT and connected devices that need guaranteed delivery across varying endpoints. - Logistics and supply chain platforms coordinating fast-moving operations. Sent fits best when messaging is core to your business, multi-channel, or at scale. For the cases where a direct provider integration or an in-house build serves you better, [Compare Your Options](/start/why-sent/comparison) works through the full decision. If your scenario already matches the ones above, the [quickstart](/start/quickstart) takes you from account setup to your first delivered message. --- # What is Sent (/start/why-sent/what-is-sent.md) # What is Sent [#what-is-sent] Sent is a **unified messaging API** that lets you send SMS, WhatsApp, and RCS messages through a single integration, without stitching together multiple providers, managing compliance rules per channel, or building your own fallback logic. You send one request, and Sent handles the routing, delivery, failover, and compliance, across every channel and every country you operate in. ## What Sent Does [#what-sent-does] ## The Problems Sent Solves [#the-problems-sent-solves] ### Managing multiple providers is expensive and fragile [#managing-multiple-providers-is-expensive-and-fragile] Most teams start with a single SMS provider. Then they add WhatsApp. Then a second SMS provider for better rates in certain countries. Before long, you're maintaining multiple integrations, dealing with inconsistent APIs, and debugging delivery failures across different dashboards. Sent replaces all of that with one API. One set of credentials. One place to see what's happening. ### Messages that must arrive sometimes don't [#messages-that-must-arrive-sometimes-dont] Authentication codes, payment confirmations, security alerts: these messages have zero tolerance for failure. A single-provider setup has no fallback when that provider has an outage or a carrier issue in a specific region. Sent's routing layer monitors delivery performance in real time and fails over automatically, so you're not the one scrambling when a provider goes down at 2 AM. ### Compliance is a moving target [#compliance-is-a-moving-target] US 10DLC registration, WhatsApp Business Account approvals, country-specific sender ID requirements, opt-out keyword handling: every channel and every market has its own rules, and they change. Sent manages the compliance layer on your behalf. Your team focuses on the product; Sent handles the regulations. ### Scaling messaging is a full-time job [#scaling-messaging-is-a-full-time-job] Rate limits, throughput management, cost optimization across providers, routing logic per country: at low volume this is manageable. At scale, it becomes its own engineering project. Sent handles high-volume messaging with routing optimized across providers, so you're not overpaying or hitting limits. ## What You Get [#what-you-get] - **Unified API**: one endpoint for SMS, WhatsApp, and RCS - **Message templates**: create once, send across all channels - **Contacts**: manage recipients with channel preferences attached - **Sender Profiles**: control the identity your messages come from - **Webhooks**: real-time delivery status and event updates - **Activities log**: full visibility into every message sent - **Dashboard**: manage everything without writing a line of code You can start sending in minutes, with no credit card and no lengthy setup: verify your email and phone number to get API access and pre-built templates. See [Try Sent](/start/try-sent) for exactly what's included. ## How It Fits Into Your Stack [#how-it-fits-into-your-stack] Sent sits between your app and the messaging providers. Your code calls the Sent API; Sent takes care of everything downstream. ``` Your App → Sent API → SMS / WhatsApp / RCS ``` You keep full control over what gets sent and to whom. Sent handles the how and where. --- Ready to go deeper? Explore [what Sent is built for](/start/why-sent/use-cases), [how it compares to alternatives](/start/why-sent/comparison), or jump straight to the [Quickstart](/start/quickstart). --- # Account Activation & KYC Review (/troubleshooting/account-activation.md) # Account Activation & KYC Review [#account-activation--kyc-review] Account activation gates everything else you do on Sent. This guide covers every stage of the process, from initial KYC submission through to channel setup, with solutions for the issues developers encounter most often. The number one cause of activation delays is incomplete information. Before reaching out to support, double-check that all form fields are filled, your website is live, and it includes both a **privacy policy** and a **messaging opt-in disclosure**. Getting these right up front is the fastest way to move through review. ## "Waiting for approval" with no ETA or status updates [#waiting-for-approval-with-no-eta-or-status-updates] {/* vale Google.WordList = NO */} {/* "application" here is the compliance submission reviewed for activation, not a software app. */} **Symptoms:** After submitting your application on the final **Review & Submit** step of the onboarding wizard, the dashboard shows a message like: {/* vale Google.WordList = YES */} > Waiting for approval: Your compliance details are under review. You'll be notified once approved. **What's happening:** - Sent's compliance team reviews every submission manually to satisfy carrier and regulatory requirements. - Typical review time is **1-3 business days**. It can take longer if your submission is incomplete or requires clarification. - If you are targeting US SMS, your business details are also submitted to **The Campaign Registry (TCR)** for 10DLC approval, which adds additional processing time (see [TCR submission pending](#tcr-submission-pending-with-no-visibility) below). **What to do:** 1. Check your email inbox, including spam and promotions folders, for any "Action Required" messages from Sent. These emails request clarification or corrections needed before approval can proceed. 2. Verify that every field in the compliance form is filled out completely. Partial submissions are held until the missing information is provided. 3. Confirm your website is live and accessible. A website that returns a 404 or is password-protected will delay review. 4. If you have been waiting **more than 5 business days** with no communication, email [support@sent.dm](mailto:support@sent.dm) with the email address associated with your Sent account. ## KYC / compliance form confusion: what's required [#kyc--compliance-form-confusion-whats-required] **Symptoms:** You are unsure what information to provide, or your submission was returned for corrections. The compliance form asks for your legal business name, tax ID (EIN in the US), registered business address, a live website URL, a use case description, and the URL where end users opt in to receive messages. For field-by-field guidance, including what to do if you don't have a website yet, see [Compliance Form Questions](/troubleshooting/compliance#compliance-form-questions). **Common rejection reasons:** a missing privacy policy, no visible messaging opt-in disclosure, a website that is not live, or a vague use case description. [Compliance Submission Rejected](/troubleshooting/compliance#compliance-submission-rejected) explains each one and how to resubmit. ## Individual developer vs business entity [#individual-developer-vs-business-entity] **Symptoms:** You are an independent developer or sole trader and are unsure whether you can register without a formal business entity. **Solution:** Sent requires business-level verification for all accounts. This is a regulatory requirement imposed by carriers and cannot be waived. However, you do **not** need to be a registered corporation. - **Sole traders and self-employed individuals** can register. Use your personal name as the business name and provide your tax registration number (SSN or EIN in the US, UTR in the UK, or the equivalent in your jurisdiction). - **Side projects and hobby apps** still require the same business-level details. Carriers enforce these rules uniformly regardless of the scale of your messaging. - If you are unsure which tax ID to use, consult your local tax authority or accountant. Sent cannot provide tax advice. ## What Sent reviews during KYC [#what-sent-reviews-during-kyc] Every submission is checked against five criteria before approval: - **Valid business details**: business name, registered address, and tax ID must be verifiable and match tax-authority records. - **Active website**: reachable, with a clearly linked privacy policy page. - **Clear messaging opt-in mechanism**: your website or app shows how end users consent to receiving messages. - **Messaging use case**: what you send, to whom, and how frequently; used to classify your traffic type with carriers. - **Compliance with local regulations**: your use case must comply with the laws of your target regions (TCPA, GDPR, PECR, CASL, and others); [Compliance & Regulations](/start/advanced/compliance-regulations) summarizes each framework with authoritative sources. Sent does not provide legal advice. If you are unsure whether your messaging use case complies with regulations in your target market, consult a legal professional before submitting your application. ## Cannot use platform features while waiting [#cannot-use-platform-features-while-waiting] **Symptoms:** Dashboard sections such as Contacts, API Keys, Templates, and Channels are locked or greyed out while your account is under review. **What you can do during review:** - Browse the [getting-started guides](/start) and [API reference](/reference/api) to plan your integration. - Explore the [Templates](/start/concepts/templates) section to learn about template structure and draft templates locally. You will not be able to submit them until approved. - Set up your local development environment and prepare your codebase for integration. **What you cannot do during review:** - Generate or view API keys - Create or manage contacts - Submit templates for carrier approval - Send messages (including sandbox/test messages) - Configure webhook endpoints Once approved, you will receive an email notification and all dashboard sections will unlock automatically. ## Post-approval onboarding issues [#post-approval-onboarding-issues] After your account is approved, you set up your sending channels and numbers in the dashboard. The following issues may arise at this stage. ### No phone numbers available [#no-phone-numbers-available] **Symptoms:** The phone number dropdown on the **Choose Your Sender Number** step of the Sender Profile wizard is empty or shows no available numbers for your region. **Solution:** 1. Click the **Refresh** button to reload available inventory. 2. Phone number availability varies by country and region. Some regions may be temporarily out of stock. 3. If no numbers appear after refreshing, contact [support@sent.dm](mailto:support@sent.dm) with your preferred country and region. The team can check inventory and provision a number manually if stock is available. ### "Something went wrong" during Sender Profile setup [#something-went-wrong-during-sender-profile-setup] {/* vale Google.We = NO */} {/* Verbatim dashboard error string; the first person is the product's wording, not the docs'. */} **Symptoms:** The Sender Profile setup step displays: "Something went wrong: We could not complete your onboarding. Please try again." {/* vale Google.We = YES */} **Solution:** 1. Click **Try Again** once. This error is often caused by a transient backend issue. 2. If the error persists after retrying, clear your browser cache and attempt the setup in an incognito/private window. 3. If it still fails, contact [support@sent.dm](mailto:support@sent.dm) with a screenshot of the error. Include the browser and OS you are using. ### Messages sending from a different number than your dedicated one [#messages-sending-from-a-different-number-than-your-dedicated-one] **Symptoms:** After setting up a dedicated phone number, messages are still being sent from another number, such as your organization's. The outbound number is determined by the Sender Profile your API request is authenticated as, not by a request body field. See [Messages Routing to Wrong Sender Number](/troubleshooting/messages-not-delivered#messages-routing-to-wrong-sender-number) for the fix. ### WhatsApp channel requires a Facebook account [#whatsapp-channel-requires-a-facebook-account] **Symptoms:** The WhatsApp channel setup prompts you to connect a Facebook account, which you were not expecting. **Solution:** WhatsApp Business API channels are managed through Meta (Facebook). To set up WhatsApp on Sent, you need: 1. A Facebook account (personal account is fine for initial setup) 2. A Meta Business Account that has completed Meta Business Verification. Create one at [business.facebook.com](https://business.facebook.com) if you don't have one. Meta requires verification before a WhatsApp Business Account can be shared with partners like Sent, so complete it before starting the connection flow. This is a Meta requirement, not a Sent-specific one. The dashboard will guide you through the connection flow step by step; see [Prerequisites for WhatsApp setup](/troubleshooting/whatsapp-setup#prerequisites-for-whatsapp-setup) for the full list. ## TCR submission pending with no visibility [#tcr-submission-pending-with-no-visibility] **Symptoms:** Your account is approved by Sent, but you see a message like: > Your case has been submitted to TCR and Sent is waiting for a response. You have no visibility into the status or timeline. **What's happening:** For US SMS messaging, all businesses must be registered with **The Campaign Registry (TCR)** for 10DLC (10-digit long code) compliance. This is a separate process from Sent's internal KYC review and is handled by an external body. **Timeline:** - TCR review typically takes **3-7 business days** after Sent submits your details. - In some cases, particularly for new brands or unusual use cases, it can take longer. - This process runs in addition to Sent's own review, so total time from signup to sending can be 1-2 weeks for US SMS. **What to do:** - **Nothing.** Sent handles the TCR submission on your behalf. There is no action required from you at this stage. - If TCR rejects the submission, the Sent support team will contact you with details about what needs to be corrected (typically business name mismatches or use case clarification). - If you have been waiting more than **10 business days** since your Sent account was approved and you still cannot send US SMS, contact [support@sent.dm](mailto:support@sent.dm). TCR approval is only required for US SMS messaging via 10DLC numbers. If you are sending messages in other countries or using WhatsApp exclusively, this step does not apply to you. ## API returns 401 Unauthorized [#api-returns-401-unauthorized] **Symptoms:** API calls return `401 Unauthorized` with an "Invalid or missing API key" error. Because your account is still partway through onboarding, the error looks activation-related. **Why this happens:** Onboarding status never causes a `401`. A valid API key authenticates at every stage of the activation process, including while compliance review is still in progress. Until you complete onboarding, the platform caps how many messages you can send, but that cap is enforced as a sending quota with its own error message, never as an authentication failure. A `401` always means the credential on the request failed: - The request carries no API key, in `x-api-key` or as `Authorization: Bearer`. - The key value is wrong: truncated, padded with whitespace, or copied from a different environment. - The key was rotated or deleted, so the value your client sends no longer exists. If your client keeps retrying with a bad key, the API stops returning `401` after 10 consecutive failures and instead returns `429 Too Many Requests` ("Too many failed authentication attempts") until a lockout period expires. **Solution:** 1. Open **Dashboard → API Keys** and compare the key character for character with the value your client sends. Watch for whitespace or truncation introduced by environment-variable handling. 2. Confirm the key is sent in the `x-api-key` request header, or as `Authorization: Bearer `. 3. If the key was recently rotated, update every environment that still holds the old value. 4. If you are receiving `429`, stop the retry loop first, fix the key, and wait for the period in the `Retry-After` response header before retrying. --- ## 403 Forbidden on organization-scoped endpoints [#403-forbidden-on-organization-scoped-endpoints] **Symptoms:** Some API endpoints, such as listing users, return a "You do not have access to this organization or profile" error with status `403 Forbidden`. Other endpoints (such as listing profiles) respond correctly with the same key. **Why this happens:** User-management endpoints check the email address on the account your API key belongs to. That email must either own the target organization or profile, or hold an active user role on it granted by invitation. If it has neither, the endpoint returns `403`. Some actions, such as inviting a user, additionally require the `admin` role. A separate `403` ("Profile API keys cannot use x-profile-id") occurs when a request sends the `x-profile-id` header with a profile-scoped API key. Only organization API keys can act on behalf of profiles. Your account is an organization from the moment it is created. There is no separate upgrade step, and creating a Sender Profile does not change which endpoints your key can access. **Solution:** 1. Confirm the API key belongs to the organization or profile you are targeting. Retrieve the key from **Dashboard → API Keys** while signed in to that account. 2. If a team member needs access, ask the organization owner to invite their email under **Dashboard → Users**. Actions such as inviting users require the member's role to be `admin`. 3. If the failing request sends the `x-profile-id` header, switch to an organization API key, or remove the header when authenticating with a profile key. --- ## Sender Profile creation fails with a "duplicate key" error [#sender-profile-creation-fails-with-a-duplicate-key-error] **Symptoms:** Clicking **Unlock Sender Profiles** or attempting to create a Sender Profile returns an error along the lines of: *"duplicate key violates unique constraint."* **Why this happens:** This is a database-level conflict that can rarely occur during Sender Profile creation. It is not caused by anything in your configuration and requires Sent support to clear. **Solution:** 1. Contact [support@sent.dm](mailto:support@sent.dm) with your account email and the exact error message. 2. Sent support will identify and clear the conflicting record. 3. Once resolved, you will be notified to retry Sender Profile creation. This error blocks only Sender Profile creation. Your API key keeps working while you wait, so you can continue sending messages via an existing sender and working with templates. --- ## Still waiting? [#still-waiting] If you have worked through the preceding steps and your issue is not resolved, contact the Sent support team: - **email:** [support@sent.dm](mailto:support@sent.dm) - **Include:** The email address associated with your Sent account, a description of where you are stuck, and any error messages or screenshots from the dashboard. - **Response time:** The support team typically responds within 1 business day. For general questions about the platform, check the [FAQ](/start/reference-guides/faq) or browse the [getting-started guides](/start). ## Related Guides [#related-guides] - [Login, Signup & OTP Verification](/troubleshooting/authentication): if you're having trouble logging in or verifying your phone number - [Compliance & 10DLC Issues](/troubleshooting/compliance): for details on 10DLC registration, A2P requirements, and compliance form guidance - [WhatsApp Setup](/troubleshooting/whatsapp-setup): if you're setting up WhatsApp as a channel after account approval --- # Login, Signup & OTP Verification (/troubleshooting/authentication.md) # Login, Signup & OTP Verification [#login-signup--otp-verification] Issues with signing up, logging in, or verifying your phone number are among the most commonly reported problems. This guide walks through each scenario with concrete steps to get you unblocked. If you can sign in but an API request comes back as HTTP 403 with the code `AUTH_004`, your role is blocking the request rather than your login: see [Roles and Permissions](/reference/api/roles-and-permissions) for the operations each role can perform. Phone verification and message delivery use different SMS routes. If you cannot receive the OTP code during signup, it does not mean your customers won't receive messages through Sent. ## Quick Diagnostic Checklist [#quick-diagnostic-checklist] Before working through the sections below, run through these checks first. They resolve the majority of login and signup issues: - [ ] **Browser is up to date**: outdated browsers can cause unexpected errors during signup - [ ] **JavaScript is enabled**: the authentication flow requires JavaScript - [ ] **No VPN or proxy active**: VPNs can interfere with phone verification and OTP delivery - [ ] **Cookies and local storage are enabled** (required for session management) - [ ] **Phone number includes correct country code**: select your country from the dropdown, do not type the code manually - [ ] **Phone has SMS capability**: data-only SIMs cannot receive OTP codes - [ ] **Check spam/filtered folders**: both SMS and email OTPs can be filtered - [ ] **Wait at least 60 seconds** before requesting a new OTP, since earlier requests may still be in transit --- ## OTP Not Delivered to Phone Number [#otp-not-delivered-to-phone-number] This is the single most reported authentication issue. You reach the phone verification step at `app.sent.dm/auth/verify-phone`, request an OTP, and the SMS never arrives. ### Why This Happens [#why-this-happens] - **Carrier-level filtering**: Mobile carriers in certain regions aggressively filter automated SMS traffic. This is especially common in Algeria, the UAE, Turkey, Ghana, and parts of West and East Africa. - **SMS route unavailability**: The SMS route to your carrier may be temporarily down or congested. - **Network delay**: In some cases, OTP messages are delayed by several minutes rather than lost entirely. ### What to Do [#what-to-do] 1. **Wait at least 60 seconds**, then tap "Resend code." The first message may still be in transit. 2. **Check your SMS inbox carefully**: some phones place messages from short codes or unknown senders into a separate folder (for example, "Filtered messages" on Samsung devices, or "Transaction" on some Android phones). 3. **Disable any SMS-blocking apps**: apps like Truecaller or carrier-provided spam filters can intercept OTP messages. 4. **Try a different phone number** if you have access to one, such as a secondary SIM or a family member's number temporarily. 5. **Contact support** at [support@sent.dm](mailto:support@sent.dm) with your email address and the phone number you are trying to verify. The team can manually complete phone verification on your account. In regions with heavy carrier filtering such as Algeria, the UAE, Turkey, Ghana, and parts of West and East Africa, this is often the fastest path. --- ## Country Code Not Listed in Phone Verification Dropdown [#country-code-not-listed-in-phone-verification-dropdown] The phone verification step includes a dropdown for selecting your country code. Some users report that their country does not appear in the list. For issues related to phone number availability for *sending* messages (rather than verification), see [Phone Number & Sender ID Issues](/troubleshooting/phone-numbers). ### Countries Reported as Missing [#countries-reported-as-missing] Users have reported difficulty finding country codes for Rwanda (+250), Uganda (+256), Kenya (+254), and others. In most cases the country is present but not immediately visible. ### What to Do [#what-to-do-1] 1. **Use the search field** at the top of the dropdown. Type your country name (for example, "Rwanda") or the numeric code (for example, "250") to filter the list. 2. **Scroll through the full list**: the dropdown is sorted alphabetically and may require scrolling. 3. **If your country is genuinely not listed**, email [support@sent.dm](mailto:support@sent.dm) with your account email and phone number. Sent support can manually verify your phone number. Phone verification and message sending are separate systems. Even if your country code is not available in the verification dropdown, Sent may still support sending messages to that country. Contact [support@sent.dm](mailto:support@sent.dm) to confirm delivery coverage for your target region. --- ## Signup Returns 500 Internal Server Error [#signup-returns-500-internal-server-error] After filling out the signup form and clicking "Sign up," you see one of the following errors: - `Sign-up failed — Server Action was not found` - `500 Internal Server Error` ### Why This Happens [#why-this-happens-1] This is an intermittent server-side issue. It is not caused by your input or account details. ### What to Do [#what-to-do-2] 1. **Clear your browser cache** and cookies for `sent.dm` and `app.sent.dm`. 2. **Try incognito/private browsing mode**: this rules out extensions and cached state as the cause. 3. **Try a different browser**: switch from Chrome to Firefox (or vice versa) to isolate browser-specific issues. 4. **Wait 15 to 30 minutes and retry**: transient server errors typically resolve within this window. 5. **If the error persists for more than a few hours**, contact [support@sent.dm](mailto:support@sent.dm) with the exact error message and a screenshot if possible. --- ## "Invalid email address" Error on Login [#invalid-email-address-error-on-login] You see the message: *"Invalid email address. Please provide a valid email address that can receive messages"* even though you are entering a valid email. ### Why This Happens [#why-this-happens-2] - **email domain blocklist**: Some email domains (particularly disposable email providers) are blocked during signup. - **Unusual characters**: email addresses with special characters (`+`, non-ASCII characters) may not pass validation. - **Browser autofill corruption**: Autofill can silently insert hidden characters or whitespace into the email field. ### What to Do [#what-to-do-3] 1. **Type the email address manually** instead of relying on paste or autofill. Click inside the field, clear it completely, and type each character. 2. **Try a mainstream email provider**: Gmail, Outlook, or Yahoo addresses are universally accepted. 3. **Clear your browser autofill data** for the `sent.dm` domain. 4. **If you previously had an approved account** and now see this error, your account may require re-verification. Contact [support@sent.dm](mailto:support@sent.dm) with your email address and business name. --- ## "Send Limit Reached" Error [#send-limit-reached-error] You see: *"Send Limit Reached. You've reached the maximum number of attempts"* when trying to request a new OTP code. ### Why This Happens [#why-this-happens-3] After too many OTP requests in a short period, the system temporarily blocks further attempts. This is a security measure to prevent abuse of the verification system. ### What to Do [#what-to-do-4] 1. **Wait approximately 1 hour**: the rate limit resets automatically after this period. Do not continue attempting during this time, as it may extend the cooldown. 2. **Contact support** at [support@sent.dm](mailto:support@sent.dm) if you need immediate access. The team can reset your OTP attempt counter manually. --- ## Phone Verification Not Working (General) [#phone-verification-not-working-general] If the phone verification step fails in a way not covered by the preceding sections (the page hangs, the "Verify" button does nothing, or you see an unexpected error), try the following general steps. ### What to Do [#what-to-do-5] 1. **Switch to a different browser.** Chrome and Firefox on desktop tend to have the fewest issues. 2. **Disable your VPN or proxy.** Some VPN exit nodes are flagged by fraud-prevention systems, which can block OTP delivery or cause verification to fail silently. 3. **Confirm your SIM supports SMS.** Data-only SIMs, eSIMs configured for data only, and some VoIP numbers cannot receive SMS-based OTPs. 4. **Check the phone number format.** Enter only the digits after the country code: no spaces, dashes, or parentheses. The country code is selected separately from the dropdown. 5. **Try on a mobile device** if you have been using a desktop browser, or vice versa. --- {/* vale Google.WordList = NO */} {/* Title-case heading: lowercasing "Email" here would break house heading style. */} ## Magic Link or Email Confirmation Not Arriving [#magic-link-or-email-confirmation-not-arriving] {/* vale Google.WordList = YES */} You requested a login link or email confirmation code, but nothing appears in your inbox. {/* TODO(verify): production (dashboard-managed) Supabase otp_expiry. Repo config sent-dm-app-nextjs/supabase/config.toml:184 sets 3600s (1 hour); confirm hosted value with engineering. */} ### What to Do [#what-to-do-6] 1. **Check your spam and junk folders.** Search for emails from `team@sent.dm`. 2. **Add `team@sent.dm` to your contacts or allowlist.** This prevents future emails from being filtered. 3. **Check with your IT department** if you are using a corporate or managed email account. Some organizations block external senders or filter automated messages at the server level. 4. **Be aware of expiration.** OTP codes sent by email expire after 1 hour. If you find an older code, request a fresh one rather than trying to use it. 5. **Request a new code** by returning to the login page and starting the flow again. If you use a corporate email with strict filtering, consider signing up with a personal email address and then updating your account email later, or ask your IT team to allowlist `team@sent.dm`. --- ## Facebook or Meta Account Restriction Blocking Login [#facebook-or-meta-account-restriction-blocking-login] If you signed up or logged in using your Facebook or Meta account and that account is subsequently restricted or suspended by Facebook, you will be unable to access your Sent account. ### What to Do [#what-to-do-7] 1. **Resolve the restriction directly with Facebook.** Sent cannot override Facebook's account restrictions. Visit [facebook.com/help](https://www.facebook.com/help/) to appeal or resolve the issue. 2. **Contact Sent support** at [support@sent.dm](mailto:support@sent.dm) to request a change of login method. The team can unlink your Facebook login and switch your account to email-based authentication, provided you can verify your identity. --- ## Delete or Reset a Previous Account [#delete-or-reset-a-previous-account] If you created an account with the wrong email address, or need to start fresh with a different email, you cannot do this self-service. Account deletion requires manual action from Sent support. ### What to Do [#what-to-do-8] 1. **Send an email to [support@sent.dm](mailto:support@sent.dm)** with the following details: - The email address associated with the account you want to delete - The new email address you want to use going forward - Your business name (for identity verification) 2. Sent support will delete or deactivate the old account and confirm when you can sign up again with the new email. Account deletion is permanent. Any API keys, templates, contacts, and message history associated with the old account will be removed and cannot be recovered. --- ## Still Stuck? [#still-stuck] If none of the preceding solutions resolved your issue: 1. **Gather the following information** before contacting support: - Your email address - The phone number you are trying to verify (with country code) - The exact error message or screenshot - The browser and operating system you are using - The approximate time the issue occurred 2. **Send an email to [support@sent.dm](mailto:support@sent.dm)** with the details from the preceding list. Most authentication issues are resolved within one business day. ## Related Guides [#related-guides] - [Account Activation & KYC Review](/troubleshooting/account-activation): if your account is stuck in the approval or compliance review stage - [Phone Number & Sender ID Issues](/troubleshooting/phone-numbers): if you're having trouble with phone number availability for sending messages - [WhatsApp Setup](/troubleshooting/whatsapp-setup): if your issue is specifically with connecting a WhatsApp Business Account --- # Compliance & 10DLC Issues (/troubleshooting/compliance.md) # Compliance & 10DLC Issues [#compliance--10dlc-issues] Compliance is a prerequisite for sending messages through Sent. If your compliance submission is incomplete, rejected, or missing required information, your messages will not be delivered. This guide covers the most common compliance-related issues and how to resolve them. Compliance requirements exist to protect consumers and are enforced by carriers and regulators. Non-compliant messaging can result in number suspension, fines, or account termination. If you're unsure about requirements for your use case, contact support before sending. --- ## Compliance Checklist [#compliance-checklist] Before submitting your compliance form, make sure you have the following ready. Having everything prepared upfront avoids back-and-forth and speeds up approval. - [ ] **Legal business name**: must match your official registration documents - [ ] **Business address**: the registered address of your business entity - [ ] **EIN or Tax ID**: for US businesses, your Employer Identification Number; for non-US businesses, the equivalent tax registration number - [ ] **Live website URL**: must be publicly accessible at the time of review (not localhost, not behind authentication) - [ ] **Privacy policy URL**: must be live and must mention SMS or messaging communications - [ ] **Opt-in mechanism URL**: a direct link to where end users consent to receive messages from you - [ ] **Use case description**: a clear explanation of what messages you send, who receives them, how they opted in, and how often they receive messages - [ ] **Sample messages**: one or two examples of the messages your app will send - [ ] **Opt-out instructions**: how recipients can stop receiving messages (for example, reply STOP) --- ## 10DLC Errors Blocking SMS Sending [#10dlc-errors-blocking-sms-sending] ### The Problem [#the-problem] You have been approved on the Sent platform, set up your channels, and attempted to send SMS messages to US numbers, but messages fail with a 10DLC-related error. Sent registers your brand and campaign with The Campaign Registry (TCR) on your behalf when you submit your compliance form. For what 10DLC is and how the review works, see [What is 10DLC?](/start/concepts/10dlc); for the registration steps and form requirements, see the [10DLC Registration Guide](/start/advanced/10dlc-registration). ### Why Messages Fail [#why-messages-fail] Messages will fail with a 10DLC error if: - Your compliance submission was incomplete and TCR registration was not completed - Your brand or campaign was rejected by TCR - Your compliance form was approved but the TCR registration is still processing (this can take 3-7 business days) - You are sending messages that do not match your registered campaign use case ### How to Fix It [#how-to-fix-it] 1. Go to **Dashboard → Compliance** and check the status of your submission. 2. Look for any rejection notices, pending items, or action items that require your attention. 3. If your status shows as approved but messages still fail, the TCR registration may still be propagating. Wait 24-48 hours and try again. 4. If you see a specific rejection reason, address the issue and resubmit your compliance form. 5. If the status is unclear or you cannot determine the issue, contact Sent support with your account email and the error message you are receiving. TCR registration typically completes within 3-7 business days after your Sent compliance form is approved. During this window, a send to a US number ends as `FAILED` with reason code `DELIVERY_003`, because the account has no US sender yet. --- ## SMS Test Messages Failing Right After Onboarding [#sms-test-messages-failing-right-after-onboarding] ### The Problem [#the-problem-1] You just completed onboarding, created a template, and tried to send a test SMS to a US number, but the message failed. Everything else looks correct: your account is active, your template is set up, and the API is responding. Yet no SMS arrives. ### Why This Happens [#why-this-happens] Sending SMS to US numbers requires an approved 10DLC brand and campaign registration. This registration is submitted as part of your onboarding compliance form, but approval from The Campaign Registry (TCR) typically takes **3–7 business days** after submission. Until the campaign is approved and a number is bound to it, your account has no US sender. A send to a US number ends as `FAILED` with reason code `DELIVERY_003` before any carrier is involved, in a test environment too. This is not an issue with your account, your template, or your API integration. It is a mandatory hold period imposed by US carriers. ### How to Test While Waiting for Approval [#how-to-test-while-waiting-for-approval] There is no shared US sender to test over. Every US SMS goes out from a number registered to a brand and campaign, so a send to a US number has nowhere to go until yours is approved. Two things work in the meantime: - **Sandbox mode.** Add `"sandbox": true` to `POST /v3/messages`. The API authenticates and validates the request, then returns a simulated `202` with `"status": "QUEUED"` without queuing anything, so it exercises your request shape, authentication, and response handling. See [Sandbox Mode](/reference/api/test-mode). - **A destination you already hold a sender for.** If your account has an active sender in another country, send a test there: the same request, template, and webhook flow apply. [`GET /v3/channels`](/start/guides/managing-channels#read-every-channel-at-once) lists your markets and their status. ### What to Expect in the Dashboard [#what-to-expect-in-the-dashboard] While your 10DLC registration is pending, a send to a US number appears in **Dashboard → Activities** as `FAILED` with reason code `DELIVERY_003`: the account has no sender set up for this destination on this channel. The message never reaches a carrier, so this is not carrier filtering and not a bug in your setup. `GET /v3/channels` shows the US `TEN_DLC` market as `PENDING_REVIEW` until the carriers elect your campaign, and `ACTIVE` once a number on it can send. Once the market is `ACTIVE`, the same API request delivers without any code changes on your side. ### Checking Your Registration Status [#checking-your-registration-status] 1. Go to **Dashboard → Compliance** and check the status of your submission. 2. If the status is **Approved**, your TCR registration is either still propagating (allow 24–48 hours) or there is an issue with your campaign details. Contact support. 3. If the status is **Pending**, your submission is still under review. Typical review time is 3–7 business days. 4. If the status is **Action Required** or **Rejected**, follow the guidance in the dashboard or see [Compliance Submission Rejected](#compliance-submission-rejected) below. Sent never sends US SMS from an unregistered number, so retrying while the registration is pending gains nothing. Hold the sends in your application and release them once the market is `ACTIVE`. --- ## Compliance Form Questions [#compliance-form-questions] ### The Problem [#the-problem-2] The compliance form asks for business-level details that may seem excessive, especially if you are an individual developer or working on a small project. Understanding what is needed and why helps you fill it out correctly the first time. ### Required Information Explained [#required-information-explained] **Legal Business Name** Enter the name your business is registered under, not a product name or DBA. This must match the name associated with your EIN or tax ID. If you are a sole proprietor, use your full legal name. **Business Address** Your registered business address. This is verified against public records, so it must match your official filings. **EIN / Tax ID** For US businesses, this is your 9-digit Employer Identification Number. For businesses outside the US, provide your local tax registration number or business registration number. **Website URL** A publicly accessible website that represents your business. The site must be live and reachable at the time of review. Placeholder pages, under-construction pages, or password-protected sites will result in rejection. **Message / Call-to-Action Field** This field should contain a direct URL to the page where users opt in to receive messages. For example, if users sign up on `https://yourapp.com/signup` and check a box to receive SMS notifications, that URL goes here. **Use Case Description** Clearly explain: - What type of messages you will send (for example, order confirmations, appointment reminders, OTP codes) - Who receives the messages (for example, registered users of your platform) - How recipients opted in (for example, checked a consent box during registration) - Approximate message frequency (for example, 2-3 messages per week per user) **Privacy Policy URL** Must link to a live privacy policy that explicitly mentions SMS or messaging communications, including how users can opt out. ### If You Don't Have a Website Yet [#if-you-dont-have-a-website-yet] Create a simple landing page that includes: 1. Your business name and contact information 2. A privacy policy (templates are available online for common jurisdictions) 3. A description of your messaging service and how users opt in 4. An opt-in mechanism (even a simple checkbox with disclosure text) This is sufficient to pass review. You can update the site later. ### Building on Behalf of Another Business? [#building-on-behalf-of-another-business] If you are a developer building a messaging integration for another business, enter that business's details on the compliance form, not your own. The compliance registration must reflect the entity that end users will receive messages from. --- ## A2P Registration Requirements [#a2p-registration-requirements] ### The Problem [#the-problem-3] You are not sure what registration is required for your messaging use case, or the requirements differ from what you expected. ### Requirements by Channel [#requirements-by-channel] Virtually all messages sent through Sent are A2P (Application-to-Person); [What is 10DLC?](/start/concepts/10dlc) explains the A2P/P2P distinction and why US carriers gate this traffic. **US SMS (10DLC)** - 10DLC registration is mandatory for all A2P SMS to US numbers. Sent registers your brand and campaign with TCR as part of your compliance submission; both must be approved before messages are delivered. See the [10DLC Registration Guide](/start/advanced/10dlc-registration). **International SMS** - Requirements vary by country: some require sender ID pre-registration (for example, India, Philippines), and some restrict content or block international A2P SMS entirely. Sent's compliance review covers foundational requirements; country-specific details are addressed during channel setup. [Compliance & Regulations](/start/advanced/compliance-regulations) summarizes the major frameworks per region. **WhatsApp** - You need a Meta-approved WhatsApp Business Account (WABA), and message templates must be approved by Meta before use. Sent guides you through this during channel configuration; see [WhatsApp Setup](/troubleshooting/whatsapp-setup) if you get stuck. Sent's compliance review covers the foundational requirements for your account. Channel-specific requirements (such as WhatsApp template approval or country-specific sender ID registration) are handled during channel setup and configuration. --- ## Combining Marketing Consent with a Mandatory Agreement [#combining-marketing-consent-with-a-mandatory-agreement] A common design question is whether the marketing messaging opt-in checkbox can be merged with a mandatory terms of service or purchase confirmation checkbox, so that completing an action (booking, purchase, account creation) automatically grants marketing consent. ### Why this approach is risky [#why-this-approach-is-risky] This pattern, sometimes called "bundled consent," is broadly non-compliant and can expose you to regulatory and carrier liability: - **US SMS (TCPA/CTIA):** The CTIA guidelines and TCPA require that consent to receive marketing text messages be obtained separately from unrelated agreements. Tying marketing opt-in to a required step in a purchase or signup flow is considered coercive and can constitute a TCPA violation. - **Meta/WhatsApp:** Meta's messaging guidelines require opt-in language to be presented clearly and distinctly. Consent must not be a required condition for accessing a service that is not itself a messaging service. - **EU/UK (GDPR/PECR):** GDPR explicitly prohibits bundled consent. Marketing consent cannot be a precondition for a non-messaging service. Consent must be freely given, specific, and separately obtained. ### What compliant opt-in looks like [#what-compliant-opt-in-looks-like] Present the marketing consent as a separate, optional, unchecked checkbox with clear language. Positioning it near (but distinct from) a mandatory agreement is acceptable, as long as it can be independently checked or left unchecked without blocking the user's action: {/* vale Sent.Emoji = NO */} {/* The ballot box depicts the unchecked checkbox in this sample consent form; it is the subject matter, not decoration. */} > ☐ Agree to receive marketing messages from [Your Brand]. Message and data rates may apply. Reply STOP to opt out. {/* vale Sent.Emoji = YES */} Users who do not check the box must still be able to complete the purchase or sign up. For US SMS specifically, freely given consent that is not bundled with other agreements is a strict requirement, not a best practice. If your opt-in UI ties marketing consent to a purchase or account creation step, do not launch it for US audiences without legal review. If you are unsure whether your specific opt-in design satisfies the requirements for your target markets, contact [support@sent.dm](mailto:support@sent.dm) before going live. --- ## Compliance Submission Rejected [#compliance-submission-rejected] ### The Problem [#the-problem-4] Your compliance submission was rejected and you received an email explaining the reason. You need to understand what went wrong and how to fix it. ### Common Rejection Reasons [#common-rejection-reasons] **Website not live or not accessible** Your website URL returned an error, was behind authentication, or showed a placeholder page at the time of review. Make sure the site is publicly accessible and fully functional before resubmitting. **Privacy policy missing or incomplete** Your privacy policy either could not be found at the provided URL, or it does not mention SMS or messaging communications. Update your privacy policy to include: - That your service sends SMS or messaging communications - What types of messages are sent - How users can opt out of receiving messages - How user data related to messaging is handled **Opt-in mechanism not clearly visible** The reviewer could not find a clear opt-in mechanism on the URL you provided. Make sure: - The consent checkbox or opt-in prompt is visible without scrolling excessively - The opt-in language is explicit (for example, "I agree to receive SMS notifications from [Business Name]") - The opt-in is not pre-checked: users must actively consent **Business information does not match public records** The business name, address, or tax ID you provided does not match publicly available records. Double-check your information against your official business registration documents. **Use case violates Acceptable Use Policy** Sent prohibits certain categories of messaging, including but not limited to: - Illegal content or services - Deceptive or misleading messages - Phishing or social engineering - Cannabis, CBD, or controlled substance marketing (varies by jurisdiction) - Debt collection harassment - Messages without proper opt-in consent If your use case was flagged in error, contact support with a detailed explanation of your messaging purpose. ### How to Resubmit [#how-to-resubmit] 1. Go to **Dashboard → Compliance**. 2. Review the rejection reason provided in the email or displayed in the dashboard. 3. Fix the identified issues. 4. Update your compliance details in the dashboard. 5. Resubmit the form for review. There is no limit on resubmissions, but repeated submissions without addressing the stated issues may delay review. --- ## Country-Specific Compliance Considerations [#country-specific-compliance-considerations] Messaging regulations vary significantly by country. [Compliance & Regulations](/start/advanced/compliance-regulations) summarizes the major frameworks per region (TCPA, GDPR, PECR, CASL, and others) with links to the authoritative sources, and describes the controls Sent enforces automatically at send time. Sent's compliance review helps ensure you meet baseline platform requirements, but you are ultimately responsible for legal compliance in every jurisdiction where you send messages. Consult legal counsel if you are unsure about the regulations that apply to your use case. ### Carrier-Level Restrictions [#carrier-level-restrictions] Beyond regulatory requirements, individual carriers may impose their own restrictions: - Content filtering that blocks certain keywords or message patterns - Rate limits that vary by carrier and sender reputation - Additional registration requirements for high-volume senders - Restrictions on certain message categories (for example, some carriers block loan or gambling-related content) These restrictions are not always publicly documented and can change without notice. If your messages are being filtered despite regulatory compliance, contact Sent support for guidance. For more on delivery failures caused by carrier filtering, see [Messages Not Delivered](/troubleshooting/messages-not-delivered). --- ## Still Stuck? [#still-stuck] If your compliance issue is not covered here or you need help understanding the requirements for your specific use case: 1. Check **Dashboard → Compliance** for any actionable items or status updates. 2. Review the rejection email (if applicable) for specific details about what needs to be fixed. 3. Contact Sent support at [support@sent.dm](mailto:support@sent.dm) with: - Your account email address - The specific compliance issue or error you are encountering - Any relevant screenshots from the dashboard - Your intended messaging use case and target countries ## Related Guides [#related-guides] - [10DLC Registration Guide](/start/advanced/10dlc-registration): registration steps, campaign types, and the opt-in and autoresponse requirements reviewers check - [Compliance & Regulations](/start/advanced/compliance-regulations): the controls Sent enforces at send time, and per-region regulations with authoritative sources - [Account Activation & KYC Review](/troubleshooting/account-activation): if your account is still under review or your compliance submission is pending - [Messages Not Delivered](/troubleshooting/messages-not-delivered): if your compliance is approved but messages are failing to deliver - [Phone Number & Sender ID Issues](/troubleshooting/phone-numbers): for sender ID registration and number provisioning questions --- # Troubleshooting (/troubleshooting.md) # Troubleshooting [#troubleshooting] Something not working as expected? This section covers the issues customers run into most often, with clear diagnosis steps and solutions for each. Browse by category below, or scan the [Quick Error Reference](#quick-error-reference) table to identify your problem by HTTP status or error code. If you're unable to find a resolution here, include your **request ID**, **timestamp**, and a sanitised code snippet when [contacting support](/start/reference-guides/support). It significantly speeds up diagnosis. ## Browse by Category [#browse-by-category] } /> } /> } /> } /> } /> } /> } /> ## Quick Error Reference [#quick-error-reference] Map an HTTP status or error code directly to a solution: | Status / Code | Meaning | Go to | |---|---|---| | `AUTH_002` | Missing or invalid API key | [Messages Not Delivered](/troubleshooting/messages-not-delivered) | | `401 Unauthorized` | API key not accepted | [Messages Not Delivered](/troubleshooting/messages-not-delivered) | | `403 Forbidden` | Key lacks permission or KYC incomplete | [Account Activation](/troubleshooting/account-activation) | | `422 Unprocessable Entity` | Request body failed validation | [WhatsApp Templates](/troubleshooting/template-issues) | | `429 Too Many Requests` | Rate limit exceeded | [Error Handling Guide](/start/guides/error-handling) | | `500 / 503` | Sent-side error or temporary outage | [Status page](https://status.sent.dm) | | `ERR_ECOSYSTEM_ENGAGEMENT` | Meta anti-spam filter triggered | [Messages Not Delivered](/troubleshooting/messages-not-delivered) | | `TEMPLATE_NOT_APPROVED` | Template pending or rejected | [WhatsApp Templates](/troubleshooting/template-issues) | | `INSUFFICIENT_BALANCE` | Account balance too low to send | [FAQ: Pricing & Billing](/start/reference-guides/faq) | | `INVALID_PHONE_NUMBER` | Number format incorrect | [Phone Numbers](/troubleshooting/phone-numbers) | | `CHANNEL_UNAVAILABLE` | WhatsApp or RCS not available for recipient | [Messages Not Delivered](/troubleshooting/messages-not-delivered) | | RCS always falls back to SMS | RCS Agent not approved or recipient lacks RCS support | [Messages Not Delivered](/troubleshooting/messages-not-delivered) | | `MESSAGE_FILTERED` | Carrier-side content filter triggered | [Messages Not Delivered](/troubleshooting/messages-not-delivered) | | Sign-up failed / Server Action error | Signup form error | [Login & Signup](/troubleshooting/authentication) | | OTP not received | Phone verification code not arriving | [Login & Signup](/troubleshooting/authentication) | ## Diagnostic Checklist [#diagnostic-checklist] Before diving deep, run through these quick checks. They resolve the majority of reported issues: - **KYC is approved**: most features are locked until your account clears compliance review - **API key is present** in the `x-api-key` request header, or as `Authorization: Bearer ` - **API key is active** and has not been rotated or revoked in the dashboard - **Phone numbers use E.164 format** (for example, `+14155552671`, not `14155552671` or `(415) 555-2671`) - **Templates are approved** before sending: WhatsApp templates require external Meta review, while SMS templates need no external approval; check the template status in your dashboard - **Sender Profile ID is included** in API calls if you're using a dedicated number - **Sandbox mode is off** if you expect real message delivery - **Account balance is positive**: messages are not queued when balance is zero ## Not Finding Your Issue? [#not-finding-your-issue] } /> } /> } /> --- # Messages Not Delivered (/troubleshooting/messages-not-delivered.md) # Messages Not Delivered [#messages-not-delivered] Message delivery failures are the most commonly reported issue on Sent. This guide walks through every major failure scenario, from API misconfiguration to carrier-level filtering, with concrete steps to resolve each one. ## Diagnostic Flowchart [#diagnostic-flowchart] Before reading the full guide, use this decision tree to narrow down the problem: B{API returning\nan error?} B -- Yes --> C{Which error code?} C -- AUTH_002 --> D["Invalid or Missing API Key"] C -- "131049 / ecosystem" --> E["ERR_ECOSYSTEM_ENGAGEMENT"] C -- Other --> F["Check Quick Error Reference"] B -- No --> G{Message delivered\nto recipient?} G -- Yes --> H[No issue - delivery confirmed] G -- No --> I{Works from dashboard\nbut not API?} I -- Yes --> J["API vs Dashboard mismatch"] I -- No --> K[Open Dashboard → Activities\nand locate the message] K --> L{Failure reason\nshown?} L -- Yes --> M[Match reason to\na section below] L -- No --> N[Message may still be in transit\nAllow up to 60 seconds] `} /> The **Activities** page in the Sent dashboard is the single best diagnostic tool for delivery issues. Every message (whether sent via API or dashboard) is logged with its delivery status, channel used, error codes, and timestamps. Navigate to **Dashboard → Activities** and filter by recipient or message ID to inspect individual sends. --- ## WhatsApp Messages Fail via API but Work from Dashboard [#whatsapp-messages-fail-via-api-but-work-from-dashboard] This is the most commonly reported delivery issue. You send a WhatsApp message through the API, the call returns a `2xx` success response, but the message ultimately shows as **failed** in your Activities log. Meanwhile, sending the exact same template from the Sent dashboard delivers successfully. ### Why This Happens [#why-this-happens] When the API accepts your request, it means the request was syntactically valid and queued. The actual delivery attempt happens asynchronously, and it can fail for reasons the initial response cannot predict. The dashboard works because it builds the payload for you with the correct structure. ### Common Causes [#common-causes] **1. Missing or incorrect `template` object** The v3 API requires a `template` object with either an `id` (the template's UUID) or a `name` field, never both. Passing the template ID as a flat string or using the wrong field name will cause the message to fail during processing. ```json // Incorrect - flat string { "to": ["+1234567890"], "template": "7ba7b820-9dad-11d1-80b4-00c04fd430c8", "channel": ["whatsapp"] } // Correct - template object with id { "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, "channel": ["whatsapp"] } // Also correct - template object with name { "to": ["+1234567890"], "template": { "name": "order_confirmation" }, "channel": ["whatsapp"] } ``` **2. Channel not specified correctly** The `channel` field is an array, and every entry must be a lowercase channel name: `"channel": ["whatsapp"]`. Values like `"WhatsApp"`, `"WHATSAPP"`, or `"wa"` fail request validation with a `400` response listing the allowed values: `sent`, `sms`, `whatsapp`, `rcs`. **3. Recipient does not have WhatsApp** If the recipient's phone number is not registered with WhatsApp, the message cannot be delivered on that channel. The API will accept the request, but delivery will fail. Check the Activities log for a status indicating the number is not WhatsApp-capable. **4. Template parameter mismatch** If your approved template expects three variables but your API request supplies two (or vice versa), the message will fail. Parameter types also matter: sending a string where the template expects a currency or date-time object will cause a rejection from Meta. ### How to Debug [#how-to-debug] 1. Open **Dashboard → Activities** and find the specific message by recipient number or message ID. 2. Check the **error details**: the Activities log includes the downstream error from Meta or the carrier. 3. Send the same message from the dashboard and compare the payload. The dashboard's outbound payload is visible in the message detail view. 4. Verify your template ID is correct by checking **Dashboard → Templates** and confirming the template status is **Approved**. --- ## WhatsApp ERR_ECOSYSTEM_ENGAGEMENT / Error 131049 [#whatsapp-err_ecosystem_engagement--error-131049] If you see the error code `131049` or the message `ERR_ECOSYSTEM_ENGAGEMENT`, this is a restriction imposed by Meta, not by Sent. ### What It Means [#what-it-means] Meta enforces anti-spam protections on WhatsApp Business messages. Error 131049 typically means one of: - **More than 24 hours have passed** since the customer last replied to you, and you are attempting to send a session (free-form) message instead of a pre-approved template. - **WhatsApp is throttling your messages** because Meta's systems detect patterns that resemble spam: high volume sends to recipients who rarely engage, repeated messages to the same number, or low read/reply rates. ### Solutions [#solutions] **Respect the 24-hour conversation window.** WhatsApp allows free-form session messages only within 24 hours of the customer's last message to you. Outside that window, you must use an approved message template to initiate contact. Note that Sent's own conversation rule is separate and does not extend Meta's: it does not apply to a send pinned to `channel: "whatsapp"` at all, so such a send needs an inbound WhatsApp message from the customer within 24 hours no matter how recently they replied elsewhere. See [Conversation Windows](/start/guides/two-way-conversations#conversation-windows). **Use approved templates to start conversations.** If you need to reach out to a customer who has not messaged you recently, always send a template message. Session messages sent outside the window will be rejected with error 131049. **Reduce message frequency.** If you are sending multiple messages to the same recipients in a short period, Meta may begin blocking delivery. Space out your sends and ensure each message provides clear value to the recipient. **Check for template reclassification.** Meta periodically reviews and reclassifies templates. A template originally approved as **Utility** may be reclassified to **Marketing**, which has stricter sending limits. If you believe your template was reclassified incorrectly: 1. Open [Meta Business Manager](https://business.facebook.com/). 2. Navigate to **WhatsApp Manager → Message Templates**. 3. Find the affected template and submit an appeal for reclassification. Error 131049 is enforced by Meta's infrastructure. Sent cannot override or bypass this restriction. The only path forward is to comply with Meta's messaging policies. --- ## Free-Form SMS or RCS Blocked with CONVERSATION_TEMPLATE_REQUIRED [#free-form-sms-or-rcs-blocked-with-conversation_template_required] A free-form send (`text` instead of `template`) on SMS, RCS, or with `channel` omitted ends as `BLOCKED` with error code `CONVERSATION_TEMPLATE_REQUIRED` when the contact has never replied and no recent template opened a conversation. The code arrives as `reason_code` on `GET /v3/messages/{id}` and on the `message.blocked` webhook. ### What It Means [#what-it-means-1] Sent gates free-form content behind its own conversation rule, not a carrier or Meta one. **If the contact has ever replied to you, on any channel, at any time, free-form stays available indefinitely** and this error cannot occur. The 7-day clock applies only to contacts who have never replied: free-form rides on the last approved template you sent, and lapses 7 days after it. Because the gate runs before routing, nothing is handed to a carrier. The message is recorded as `BLOCKED` rather than `FAILED`, is excluded from your deliverability rate, and fires `message.blocked`. The error message distinguishes the two cases: | Message contains | Meaning | |---|---| | `No open conversation with this contact` | The contact has never replied and no template was ever sent. | | `has never replied, and the template that opened the conversation is more than 7 days old` | A template opened the conversation, the contact never replied, and 7 days passed. | ### Common Causes [#common-causes-1] - **Cold outreach at a low cadence.** The contact has never answered, and your own free-form messages do not extend the 7-day window, so a weekly free-form send eventually falls outside it. - **The template lapsed before the contact engaged.** A template makes free-form available for 7 days; with no reply in that time, free-form needs another template. - **The only inbound was an opt-out keyword.** A `STOP` (or a custom opt-out keyword) does not count as a reply, and neither does the opt-out confirmation Sent sends back. `START` and `HELP` do count. ### Solutions [#solutions-1] 1. **Send an approved template to re-open the conversation.** Free-form is then accepted for 7 days, and indefinitely once the contact replies. 2. **Do not retry the same free-form send.** It is blocked identically until a template or a reply from the contact opens the conversation. 3. **Check whether the contact has ever replied** in Dashboard → Activities. If they have, this is not your error; if they have not, find the newest template you sent, and that timestamp plus 7 days is when it lapsed. Window mechanics in full: [Conversation Windows](/start/guides/two-way-conversations#conversation-windows). Error reference: [CONVERSATION_TEMPLATE_REQUIRED](/reference/api/error-catalog#conversation_template_required-no-open-conversation). --- ## SMS Not Delivered in Specific Countries [#sms-not-delivered-in-specific-countries] SMS delivery relies on carrier agreements that vary by country. A message that delivers within seconds in the US may fail or be silently filtered in another region. ### Common Patterns [#common-patterns] - **Carrier-level filtering**: Countries including Algeria and several countries in the Middle East and Africa apply aggressive content filtering. Messages may be silently dropped without a delivery failure being reported back to Sent. - **Alphanumeric sender ID restrictions**: Some countries do not support alphanumeric sender IDs (for example, "MySaaS" as the sender name). In these countries, the sender ID may be silently converted to a local number or the message may be blocked entirely. - **Registration requirements**: Certain countries require pre-registration of sender IDs or message content before SMS can be delivered. Sending without registration results in filtering. ### Solutions [#solutions-2] 1. **Try a different sender ID type.** If you are using an alphanumeric sender ID, switch to a numeric sender ID (a dedicated phone number) for countries that do not support alphanumeric IDs. 2. **Contact Sent support** for country-specific routing information. Sent support can advise on the best sender type, content guidelines, sender ID coverage, and any registration requirements for your target country. 3. **Monitor delivery rates by country** in the Activities dashboard. A sudden drop in delivery rate for a specific country often indicates a carrier policy change. --- ## Messages Routing to Wrong Sender Number [#messages-routing-to-wrong-sender-number] You configured a Sender Profile with a dedicated long code or toll-free number, but messages are still going out from a different number. ### Cause [#cause] The v3 API does not accept a `sender_profile_id` field: the request body supports only `to`, `channel`, `template`, `text`, and `sandbox`. The outbound number is determined by which Sender Profile your request is **authenticated as**. If your API key belongs to your organization or to a different profile, Sent routes the message with that identity's own senders, so it goes out from the organization's number or the other profile's. ### Solution [#solution] Send the message as the Sender Profile that owns the dedicated number. There are two ways to do this: **Use an API key that belongs to the profile.** API keys are scoped to the profile that is active when you create them. Switch to the target profile with the profile selector, then create or copy a key under **Dashboard → API Keys**. Requests made with this key always send as that profile. **Use your organization API key with the `x-profile-id` header.** Organization keys can act on behalf of any profile in the organization by passing the profile's ID as a request header: ```bash curl -X POST https://api.sent.dm/v3/messages \ -H "x-api-key: YOUR_ORG_API_KEY" \ -H "x-profile-id: 7ba7b820-9dad-11d1-80b4-00c04fd430c8" \ -H "Content-Type: application/json" \ -d '{ "to": ["+1234567890"], "channel": ["sms"], "template": { "name": "order_confirmation" } }' ``` You can find each profile's ID in **Dashboard → Profiles**. Every profile card displays its ID with a copy button. **Sending from the dashboard instead?** Select the correct Sender Profile with the profile selector before sending. The active profile determines which number or sender ID is used for outbound messages. The `x-profile-id` value must be the profile's UUID. The API returns `400` for a malformed ID, `404` if the profile does not belong to your organization, and `403` if you send the header with a profile-scoped key. Only organization API keys can act on behalf of profiles. --- ## Sending SMS Only When WhatsApp Is Connected [#sending-sms-only-when-whatsapp-is-connected] You have connected a WhatsApp Business Account during onboarding, but you want all messages sent exclusively via SMS, either because you have a separate WhatsApp integration elsewhere, or because you do not want Sent's channel selection logic to attempt WhatsApp delivery. ### Why This Happens [#why-this-happens-1] By default, when a WhatsApp Business Account is connected to your Sent account, Sent will attempt WhatsApp delivery for recipients with WhatsApp capability. If your architecture already handles WhatsApp through another system, this can cause duplicate delivery attempts or route messages through a channel you are not expecting. An unverified business in Meta Business Manager doesn't affect routing. Sent skips WhatsApp only when Meta reports that the account or its number can't send messages. ### Solution [#solution-1] Contact Sent support to enable **SMS-only mode** on your account. This is a backend configuration that overrides channel selection and forces all outbound messages to route as SMS, regardless of whether a WABA is connected or what status it shows. Once SMS-only mode is enabled: - Messages are always delivered via SMS, regardless of WABA connection state - You do not need to disconnect your WhatsApp Business Account - WABA verification status has no impact on SMS delivery SMS-only mode is useful if you are using Sent specifically for SMS in markets where your previous provider lacked coverage, while maintaining a separate WhatsApp integration for other use cases. --- ## WhatsApp-to-SMS Failover Not Triggering [#whatsapp-to-sms-failover-not-triggering] You configured WhatsApp as the primary channel with SMS as the fallback, but every message is being sent via SMS: the WhatsApp attempt never seems to happen. ### Common Causes [#common-causes-2] **WhatsApp template not approved.** Failover logic evaluates whether the primary channel can deliver before attempting it. If the specified template is not approved for WhatsApp, Sent skips the WhatsApp attempt entirely and falls through to SMS. **WhatsApp Business Account not connected.** If your WhatsApp Business Account is disconnected or was never fully set up, Sent cannot send on the WhatsApp channel. Verify your connection status under **Dashboard → Channels → WhatsApp**. **Recipient number not recognized as WhatsApp-capable.** Sent performs a channel capability check before attempting delivery. If the recipient's number is not detected as having WhatsApp, the system will immediately fall back to SMS without attempting WhatsApp delivery. ### How to Debug [#how-to-debug-1] Open the message in **Dashboard → Activities** and look for two key fields in the message detail: - `channel_attempted`: shows which channel Sent tried first (should be `whatsapp` if failover is configured correctly). - `fallback_reason`: explains why the system fell back to SMS. Common values include `template_not_approved`, `channel_not_connected`, and `recipient_not_capable`. If `channel_attempted` shows `sms` from the start (rather than `whatsapp`), the failover logic was bypassed, which points to a configuration issue on the WhatsApp side. ### Checklist [#checklist] - Confirm the template is approved for WhatsApp in **Dashboard → Templates**. - Confirm WhatsApp Business Account is connected and active in **Dashboard → Channels**. - Confirm the recipient's number is a valid mobile number (landlines cannot receive WhatsApp messages). - Confirm your API request lets Sent choose the channel. There is no `fallback` field in the v3 API. Omit `channel` or send `"channel": ["sent"]` (auto-detect) so routing can attempt WhatsApp and fall back to SMS. Pinning `"channel": ["whatsapp"]` restricts delivery to WhatsApp only, and listing multiple channels such as `"channel": ["whatsapp", "sms"]` broadcasts a separate message on each channel instead of falling back. --- ## Invalid or Missing API Key (AUTH_002) [#invalid-or-missing-api-key-auth_002] If your API request returns the following error, the API key is either missing, malformed, or no longer valid: ```json { "success": false, "error": { "code": "AUTH_002", "message": "Invalid or missing API key" } } ``` ### Solutions [#solutions-3] **Use a header the API reads.** Sent accepts the key in the `x-api-key` header or as `Authorization: Bearer `. Any other `Authorization` scheme, a missing `Bearer` prefix, or a differently named header counts as no key at all. This is the most common mistake when migrating from other APIs. ```bash # Incorrect: no Bearer scheme, or a scheme the API does not read curl -H "Authorization: YOUR_API_KEY_HERE" https://api.sent.dm/v3/messages curl -H "Authorization: Basic YOUR_API_KEY_HERE" https://api.sent.dm/v3/messages # Correct: either header works curl -H "x-api-key: YOUR_API_KEY_HERE" https://api.sent.dm/v3/messages curl -H "Authorization: Bearer YOUR_API_KEY_HERE" https://api.sent.dm/v3/messages ``` **Copy the key directly from the dashboard.** Navigate to **Dashboard → API Keys** and use the copy button to avoid transcription errors. Ensure there is no trailing whitespace or newline character. These are invisible but will cause authentication to fail. **Check if the key was regenerated.** If someone on your team regenerated the API key, the previous key is immediately invalidated. The Activities log does not record authentication failures, so you will not see the failed request there, only the `AUTH_002` response from the API. **Verify the key matches your environment.** If you have separate keys for production and sandbox, ensure you are using the correct one for the environment you are targeting. --- ## Sandbox Mode: What Gets Delivered and How to Inspect It [#sandbox-mode-what-gets-delivered-and-how-to-inspect-it] When testing your integration in sandbox mode, messages are not actually delivered to recipients and no credit is consumed. Understanding exactly what does happen helps you write reliable tests. ### What sandbox mode does [#what-sandbox-mode-does] - The API processes the request and returns a success response with a real message ID, identical to a live send. - The message and its status appear in **Dashboard → Activities**. - Webhooks fire with status updates, just as they would in production. - No SMS or WhatsApp message is sent to the recipient's device. Pass `"sandbox": true` in your send request to enable it: ```json { "to": ["+1234567890"], "template": { "id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8" }, "channel": ["sms"], "sandbox": true } ``` ### Retrieving template variables (for example, OTP codes) in sandbox [#retrieving-template-variables-for-example-otp-codes-in-sandbox] A common testing scenario is verifying that your OTP or other variable-content template was constructed correctly, without needing to receive a real message. You can do this by calling the get-message-status endpoint with the message ID returned from the send call. The response includes the template variables submitted with that message, so you can confirm the correct code or value was passed. ```bash GET /v3/messages/{message_id} ``` This works in sandbox mode. The message ID in the send response is real and queryable. ### When to switch to live mode [#when-to-switch-to-live-mode] Use sandbox for all logic testing: template variable substitution, webhook handling, status polling, and error path coverage. Switch to live mode only when you need to verify the actual end-to-end recipient experience, for example, confirming that an OTP code renders correctly on a specific device or carrier. Sending real messages in development environments can accumulate significant cost, especially for destinations that carry higher per-message rates. Sandbox mode eliminates this cost without changing your integration code. --- ## RCS Messages Not Delivered [#rcs-messages-not-delivered] If RCS messages are failing or always falling back to SMS, work through this checklist: **RCS sender not approved yet**: RCS requires a one-time approval process with carriers before messages can be sent. If your RCS Agent is still pending, messages that pin RCS only (`"channel": ["rcs"]`) will fail. Check your RCS Agent status in **Dashboard → Channels → RCS**. **Recipient device or carrier does not support RCS**: RCS is only available on Android devices using Google Messages where the carrier supports it. Sent automatically falls back to SMS when RCS is unavailable. To allow this, let Sent choose the channel: omit `channel` or send `"channel": ["sent"]` (auto-detect). Listing multiple channels such as `"channel": ["rcs", "sms"]` does not configure a fallback: it broadcasts a separate message on each channel. **Template not approved for RCS**: Like WhatsApp, RCS templates must be approved before sending. Verify template status in **Dashboard → Templates**. **RCS Agent not set up**: If your account has no launched RCS Agent, RCS messages will fail. Register one from the **RCS** tab on the Channels page or with `POST /v3/channels/rcs`; see [Enable RCS](/start/quickstart/channel-setup#enable-rcs). The `channel_attempted` and `fallback_reason` fields in **Dashboard → Activities** show exactly which channel was tried and why fallback was triggered (useful for diagnosing RCS-specific delivery issues). ## Still Not Resolved? [#still-not-resolved] If none of the preceding scenarios match your issue: 1. **Collect your diagnostic information**: message ID, timestamp, recipient number (redacted if needed), the exact API request payload (with sensitive values replaced), and the full error response. 2. **Check the [Sent status page](https://status.sent.dm)** for any ongoing incidents that could affect delivery. 3. **Contact [developer support](/start/reference-guides/support)** with the information from step 1. Including these details upfront significantly reduces resolution time. ## Related Guides [#related-guides] - [WhatsApp Template Issues](/troubleshooting/template-issues): if messages fail due to template approval, categorization, or parameter problems - [Phone Number & Sender ID Issues](/troubleshooting/phone-numbers): if messages are sending from the wrong number or you need a different sender ID - [Compliance & 10DLC Issues](/troubleshooting/compliance): if SMS delivery is blocked by carrier restrictions or 10DLC registration issues --- # Phone Number & Sender ID Issues (/troubleshooting/phone-numbers.md) # Phone Number & Sender ID Issues [#phone-number--sender-id-issues] This guide covers the most common phone number and sender ID problems reported by Sent users, from number provisioning issues to messages sending from an unexpected number. Phone number availability varies by region and demand. If you need a number for a specific country, contact **support@sent.dm** and we can check availability or suggest alternatives. ## "No phone numbers available" When Choosing a Sender Number [#no-phone-numbers-available-when-choosing-a-sender-number] ### Symptoms [#symptoms] On the **Choose Your Sender Number** step of the Sender Profile wizard (**Dashboard → Profiles**), the phone number dropdown displays: > No phone numbers available. Please refresh to try again. ### Cause [#cause] This typically means one of the following: - **Regional inventory is temporarily depleted.** Sent provisions numbers from carrier partners, and stock for certain area codes or countries can run low during periods of high demand. - **Numbers have not yet been provisioned for your account.** There is a brief delay between account approval and number allocation. This does **not** indicate a problem with your compliance or KYC approval. Number provisioning is a separate step that occurs after your account has been approved. ### Solution [#solution] 1. **Click the "Refresh" button** next to the dropdown. In many cases, numbers become available within seconds as inventory updates. 2. **Wait a few minutes and try again.** If the inventory for your region is temporarily low, new numbers are restocked frequently. 3. **Contact support** at [support@sent.dm](mailto:support@sent.dm) if the issue persists after several attempts. The team can provision numbers for your account manually or suggest an alternative region. ## Specific Country Numbers Not Available [#specific-country-numbers-not-available] ### Symptoms [#symptoms-1] You need a local phone number for a specific country (for example, Nigeria, Canada/Quebec, Russia, Kazakhstan, Spain), but no numbers for that region appear in the dashboard. ### Cause [#cause-1] Sent's phone number inventory depends on carrier partnerships that vary by country. Not every country has local numbers available at all times, and some regions have stricter regulatory requirements that limit number availability. ### Solution [#solution-1] **For WhatsApp messaging:** A US-based number works globally. WhatsApp routes messages based on the recipient's WhatsApp account, not the sender's country code. You do not need a local number to reach international recipients over WhatsApp. **For SMS messaging:** A US number can often be used to send internationally. However, depending on the destination country's regulations, your message may arrive displaying an alphanumeric sender ID rather than your numeric phone number. This is normal carrier behaviour and does not affect deliverability. **Bring your own number:** In some cases, you can port an existing phone number into Sent. Contact support to discuss eligibility and the porting process. For country-specific number availability, reach out to [support@sent.dm](mailto:support@sent.dm) with the country and use case. The team can confirm what is available or recommend the best sending strategy for your target region. ## Alphanumeric Sender ID vs Phone Number [#alphanumeric-sender-id-vs-phone-number] ### Overview [#overview] When sending SMS in many countries outside the United States, you have the option to use an **alphanumeric sender ID** (for example, "MyBrand") instead of a phone number. This is the text that appears as the sender name on the recipient's device. ### Key differences [#key-differences] | Feature | Alphanumeric Sender ID | Dedicated Phone Number | |---|---|---| | **Setup speed** | Generally faster | May require provisioning time | | **Replies** | Recipients cannot reply directly | Supports two-way messaging | | **US/Canada support** | Not supported (numeric sender required) | Fully supported | | **Branding** | Displays your brand name | Displays a phone number | | **Country coverage** | Varies by country regulations | Varies by carrier inventory | ### When to use each [#when-to-use-each] - **Use an alphanumeric sender ID** when you are sending one-way notifications (OTP codes, order confirmations, alerts) and want brand recognition in the sender field. - **Use a dedicated phone number** when you need two-way messaging, are sending to the US or Canada, or want a consistent numeric identity. ### Setup [#setup] Alphanumeric sender IDs are configured during **Sender Profile** setup in the Sent dashboard. Navigate to **Dashboard → Profiles** to create or edit a Sender Profile with your preferred sender ID. Not all countries support alphanumeric sender IDs. The US and Canada require a numeric sender (phone number or short code). Check the destination country's regulations before relying on an alphanumeric sender. ## Messages Sending from the Wrong Number [#messages-sending-from-the-wrong-number] You configured a Sender Profile with a dedicated phone number, but outbound messages arrive from a different number than expected, such as your organization's. This happens when the request is authenticated as the wrong Sender Profile. See [Messages Routing to Wrong Sender Number](/troubleshooting/messages-not-delivered#messages-routing-to-wrong-sender-number) for the cause and the fix for both API and dashboard sends. ## Sender ID Registration for International Markets [#sender-id-registration-for-international-markets] ### Overview [#overview-1] Some countries require sender IDs to be pre-registered before SMS can be delivered. Sending without a registered sender ID in these markets results in messages being silently filtered or blocked at the carrier level. The API will accept your request, but the message will not reach the recipient. ### Markets that require registration [#markets-that-require-registration] Registration requirements vary by country and change as local regulations evolve. As a general guide: - **African markets**: many countries including Rwanda, Ghana, Kenya, Uganda, and Nigeria require sender ID registration. Without registration, alphanumeric sender IDs may be blocked entirely. - **Other markets with strict requirements**: India, the Philippines, and several Southeast Asian countries also require pre-registration. ### Markets where generic alphanumeric sender IDs work without registration [#markets-where-generic-alphanumeric-sender-ids-work-without-registration] Major European markets, including France, Germany, Spain, and the UK, generally support alphanumeric sender IDs without prior registration. If you are expanding into Europe, you can typically start sending immediately using a generic sender ID. ### How to register [#how-to-register] Sent's compliance team handles sender ID registration on your behalf. The process varies by country and typically requires documentation such as your business registration, a description of your messaging use case, and sample message content. To begin registration: 1. Contact [support@sent.dm](mailto:support@sent.dm) and list the countries you need registered. 2. The Sent compliance team will provide the specific documents required for each market. 3. Submit the requested documents. Registration timelines vary: some markets complete in a few days, others can take several weeks depending on local regulators. If you are expanding into multiple markets rapidly, let the compliance team know your priority countries upfront. Registration can be initiated in parallel for multiple markets. Do not rely on unregistered sending in markets that require registration, even temporarily. Carrier-level blocks applied during unregistered sending can sometimes affect subsequent registered traffic. Starting the registration process before you begin sending is strongly recommended. ## Still Having Issues? [#still-having-issues] If none of the preceding solutions resolve your problem: - Include your **account ID**, the **country** you are trying to provision a number for, and any **error messages** you see in the dashboard. - Contact [support@sent.dm](mailto:support@sent.dm) with these details for faster resolution. ## Related Guides [#related-guides] - [Messages Not Delivered](/troubleshooting/messages-not-delivered): if your number is configured but messages are not being delivered - [Compliance & 10DLC Issues](/troubleshooting/compliance): for 10DLC registration and country-specific compliance that affects number usage - [Account Activation & KYC Review](/troubleshooting/account-activation): if you cannot access phone number provisioning because your account is still under review --- # WhatsApp Template Issues (/troubleshooting/template-issues.md) # WhatsApp Template Issues [#whatsapp-template-issues] WhatsApp messages sent through the Sent platform require pre-approved templates. This guide covers the most common issues developers run into when creating, submitting, and using templates, along with solutions for each. WhatsApp templates require Meta approval before they can be used. SMS templates on Sent do not require external approval. If you need to send messages immediately, consider using SMS while your WhatsApp template is under review. ## "Failed to save template" / "Failed to submit template for review" [#failed-to-save-template--failed-to-submit-template-for-review] **Symptoms:** When creating a template in the dashboard and clicking Save or Submit, you see a generic error: > Failed to save template or > Failed to submit template for review No additional detail is provided about what went wrong. **Common causes:** - **WhatsApp Business Account not connected.** Your Meta Business Account must be fully linked to Sent before you can create WhatsApp templates. Go to **Dashboard → Settings** and verify that your Meta Business Account shows as connected. - **Template body exceeds character limits.** WhatsApp enforces a maximum of **1024 characters** for the template body. Headers and footers have their own separate limits. - **Prohibited content or formatting.** Templates that contain content violating Meta's commerce or messaging policies will be rejected at submission time. This includes certain restricted industries, misleading content, or unsupported formatting. - **Application permission issue.** If the error includes the phrase "Application does not have permission for this action," see the [dedicated section below](#application-does-not-have-permission-for-this-action). **Solutions:** 1. Open **Dashboard → Settings** and confirm your WhatsApp Business Account is connected and showing a healthy status. 2. Check your template body length. If you are close to the limit, trim the content or split it across multiple messages. 3. Review your template against [Meta's template guidelines](https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/overview) for prohibited content. 4. Try creating a **text-only template** with no variables, header, or buttons. If this succeeds, add complexity incrementally to isolate what is causing the failure. 5. If the error mentions "permission," see the next section. ## "Application does not have permission for this action" [#application-does-not-have-permission-for-this-action] **Symptoms:** When submitting a template for review, you receive: > Failed to submit template for review: Application does not have permission for this action **What's happening:** The Meta Business Account integration with Sent does not have the required permissions to manage templates on your behalf. This typically happens when permissions were not fully granted during the initial WhatsApp Business Account connection flow, or when Meta has revoked permissions due to a policy change. **Solutions:** 1. Go to **Dashboard → Settings** and disconnect your WhatsApp Business Account. 2. Reconnect the account by going through the Facebook OAuth flow again. During the connection process, ensure you **grant all requested permissions** when prompted. Do not skip or decline any permission scopes. 3. After reconnecting, try submitting your template again. 4. If the issue persists after disconnecting and reconnecting, contact [support@sent.dm](mailto:support@sent.dm). Sent support may need to re-authorize the integration, or there may be a configuration issue with your Meta Business Account that requires manual intervention. When reconnecting your WhatsApp Business Account, make sure you are logged into the correct Facebook account that owns or administers the Meta Business Account. Connecting with a different Facebook account can result in permission errors. ## Template stuck in PENDING approval [#template-stuck-in-pending-approval] **Symptoms:** You submitted a template for review, and it has been in "Pending" status for an extended period with no updates. **What's happening:** WhatsApp templates go through Meta's review process before they can be used to send messages. This is a Meta-side process that Sent does not control. **Typical timeline:** - Most templates are reviewed within **24-48 hours**. - During peak periods or for templates in certain categories, reviews can take longer. - Templates with media (images, videos, documents) may take slightly longer than text-only templates. **What to do:** 1. **If pending for less than 48 hours:** Wait. This is within the normal review window. 2. **If pending for more than 48 hours:** - Log into [Meta Business Manager](https://business.facebook.com/) directly and navigate to your WhatsApp account's message templates. Meta sometimes provides additional context or action items there that are not surfaced in the Sent dashboard. - Contact [support@sent.dm](mailto:support@sent.dm) and ask Sent support to check the template status. Include your template name and the approximate date you submitted it. 3. **If you need to send messages now:** Use an existing approved SMS template. SMS templates on Sent do not require external approval and can be used immediately after creation. ## Template categorized incorrectly by Meta [#template-categorized-incorrectly-by-meta] **Symptoms:** You submitted a template as **Utility** (transactional), but Meta re-categorized it as **Marketing**. Alternatively, you expected one category but received another after approval. **Why this matters:** - **Marketing templates** are subject to stricter delivery rules, including per-user frequency caps. If a recipient has received too many marketing messages recently, your message may not be delivered. - **Utility templates** (order confirmations, shipping updates, OTP codes, account alerts) have more lenient delivery rules because they contain information the recipient is expecting. - **Authentication templates** (OTP codes, verification) have the highest delivery priority. **What to do:** 1. Review your template content. Meta categorizes templates based on the language and intent of the content, not the category you select during creation. Common triggers for marketing categorization include: - Promotional language ("Get 20% off," "Limited time offer," "Shop now") - Upselling or cross-selling content - General announcements not tied to a specific user action 2. **Appeal through Meta Business Manager.** Log into [Meta Business Manager](https://business.facebook.com/), navigate to your template, and submit a category appeal if you believe the categorization is incorrect. 3. **Contact Sent support.** The team can also submit an appeal on your behalf. Send an email to [support@sent.dm](mailto:support@sent.dm) with the template name and your reasoning for why it should be categorized differently. **To avoid miscategorization in the first place:** - Do not include any promotional language in utility or authentication templates. - Keep the content focused on the specific transaction or event that triggered the message (for example, "Your order #12345 has shipped" rather than "Your order has shipped. Check out new arrivals"). - Avoid including links to product pages, promotional landing pages, or anything not directly related to the transaction. ## Template variables / parameters mismatch [#template-variables--parameters-mismatch] **Symptoms:** Your template is approved and visible in the dashboard, but sends fail with a 400 error that reports a missing or invalid variable. **What's happening:** Sent templates use **named variables** such as `{{customerName}}` or `{{orderNumber}}`. When you send a message using a template, you provide a `parameters` **object** whose keys match the variable names defined in the template. (A template body can also write the same variable in the canonical `{{0:variable}}` form, which is what the dashboard builder produces; either way you address it by `name` in `parameters`. See [variable placeholder forms](/reference/api/template-definition#variable-object).) The rule: every variable name defined in the template must be present in the `parameters` object. A missing name causes a 400 error (`VALIDATION_004`) listing which names are missing. Extra keys are ignored, never rejected. **Common mistakes:** - **Missing variable names.** Every variable defined in any section of the template (header, body, buttons) must appear as a key in `parameters`. Order does not matter. - **Passing an array instead of an object.** `parameters` is an object keyed by variable name. A positional array like `['Alex', 'ORD-98765']` fails request validation before the message is accepted. - **Invalid parameter values.** Values cannot contain newlines, tabs, or five or more consecutive spaces. Sent rejects these with a 400 error (`VALIDATION_008`) at send time, mirroring WhatsApp's own constraint on parameter text. **Example:** If your approved template body is: ``` Hi {{customerName}}, your order {{orderNumber}} has been shipped and will arrive by {{deliveryDate}}. ``` Your API call should include: ```typescript await client.messages.send({ to: ['+14155552671'], template: { id: '7ba7b820-9dad-11d1-80b4-00c04fd430c8', parameters: { customerName: 'Alex', orderNumber: 'ORD-98765', deliveryDate: 'March 25' } } }); ``` **Debugging tips:** 1. Open the template in the dashboard and note every variable name across all sections (header, body, buttons). Each name must appear as a key in your `parameters` object. 2. Read the 400 response body: the error details list each missing variable by name. 3. Test with hardcoded string values first before using dynamic data from your app. To avoid these issues in future templates, follow the [template best practices](/start/guides/working-with-templates#template-best-practices) in the templates guide. ## Still need help? [#still-need-help] If you have worked through the preceding steps and your template issue is not resolved, contact the Sent support team: - **email:** [support@sent.dm](mailto:support@sent.dm) - **Include:** Your template name, the error message you are seeing (exact text or screenshot), and whether this is a new template or one that was previously working. - **Response time:** The support team typically responds within 1 business day. ## Related Guides [#related-guides] - [Messages Not Delivered](/troubleshooting/messages-not-delivered): if your template is approved but messages still fail to deliver - [WhatsApp Setup](/troubleshooting/whatsapp-setup): if you're unable to create templates because your WhatsApp Business Account is not connected - [Compliance & 10DLC Issues](/troubleshooting/compliance): for SMS-specific compliance and A2P registration requirements --- # Troubleshoot WhatsApp Delivery Failures by Error Code (/troubleshooting/whatsapp-delivery-errors.md) # Troubleshoot WhatsApp Delivery Failures by Error Code [#troubleshoot-whatsapp-delivery-failures-by-error-code] This guide shows you how to diagnose WhatsApp messages that fail after the API accepted them, and how to resolve each of the per-message error codes that WhatsApp sends produce. It assumes your WhatsApp channel is already connected and sending; for connection and onboarding problems, see [WhatsApp Onboarding & Business Account Connection](/troubleshooting/whatsapp-setup). ## Rule Out a Synchronous API Error First [#rule-out-a-synchronous-api-error-first] A rejected API call and a failed delivery are different problems: - **Synchronous API errors** come back in the HTTP response. The call returns `4xx` with an envelope code such as `AUTH_002` or `VALIDATION_002`. Fix the request itself; refer to the [error handling reference](/reference/api/errors) for the envelope format and the full code list. - **Asynchronous delivery failures** happen after `POST /v3/messages` responds `202 Accepted`. Each message is processed and finalized on its own, so a message can fail minutes after a successful API call. These failures carry the `ERR_*` codes covered in this guide, which never appear in the HTTP response. If your API call returned `2xx` but the message shows as failed, you are debugging an asynchronous delivery failure. Continue below. ## Locate the Failure [#locate-the-failure] A failed delivery surfaces in four places: - `GET /v3/messages/{id}`: the `status` field reads `FAILED`, and `channel` shows the channel of the most recent attempt. - `GET /v3/messages/{id}/activities`: the lifecycle log ends in a `FAILED` activity. - The [`message.failed` webhook event](/start/webhooks/event-types) pushes the failure to your endpoint as it happens. - **Dashboard → Activities** shows the same timeline for each message. ```bash curl https://api.sent.dm/v3/messages/8ba7b830-9dad-11d1-80b4-00c04fd430c8/activities \ -H "x-api-key: YOUR_API_KEY" ``` ```json { "success": true, "data": { "message_id": "8ba7b830-9dad-11d1-80b4-00c04fd430c8", "activities": [ { "status": "FAILED", "description": "Message updated to FAILED", "from": "+15551234567", "timestamp": "2026-07-24T15:00:20Z", "price": null, "active_contact_price": null } ] } } ``` Activity descriptions and webhook payloads report the `FAILED` status but do not currently include the `ERR_*` code itself. To get the exact code for a specific message, [contact support](/start/reference-guides/support) with the message ID. Each section below also describes the behavior you can observe (for example, an automatic SMS re-send) so you can narrow down the code without it. ## Match the Code to a Fix [#match-the-code-to-a-fix] | Error code | Raised by | Meta error | Falls back to SMS | Meaning | |------------|-----------|------------|-------------------|---------| | [`ERR_MESSAGE_UNDELIVERABLE`](#err_message_undeliverable) | Meta | 131026 | Yes, automatic | Meta accepted the message, then reported it undeliverable | | [`ERR_TEMPLATE_PARAMS_INVALID`](#err_template_params_invalid) | Sent or Meta | 100 | No | Template variables missing, malformed, or rejected by Meta | | [`ERR_TEMPLATE_NAME_INVALID`](#err_template_name_invalid) | Meta | - | No | No template with that name exists for the language sent | | [`ERR_RECIPIENT_NOT_REGISTERED`](#err_recipient_not_registered) | Meta | 133016 | Yes, automatic | The recipient's number is not on WhatsApp | | [`ERR_PROVIDER_ERROR`](#err_provider_error) | Meta or carrier | - | No | Unclassified provider error | | [`ERR_ECOSYSTEM_ENGAGEMENT`](#err_ecosystem_engagement) | Meta | 131049 | Yes, automatic | Meta anti-spam restriction | ## ERR_MESSAGE_UNDELIVERABLE [#err_message_undeliverable] Meta accepted the message (the send call succeeded and returned a WhatsApp message ID), then reported it undeliverable in a later delivery status callback. Sent maps Meta's undeliverable failure, WhatsApp error 131026, to this code. It is a recipient-side failure: the recipient cannot currently receive WhatsApp messages from your number. Sent handles it automatically: 1. The WhatsApp attempt is recorded as `FAILED` and a `message.failed` webhook fires with `"channel": "whatsapp"`. 2. WhatsApp is paused for that recipient for 30 days: routing skips WhatsApp for them until the pause expires. 3. The same message is re-sent through SMS routing. Fresh lifecycle events arrive for the same `message_id` with `"channel": "sms"`, and the message's `channel` field changes to `sms`. You do not need to fix anything per message: watch for the SMS attempt's outcome (`message.delivered` with `"channel": "sms"`). If sends to a recipient repeatedly end here, treat that number as unreachable on WhatsApp and message them over SMS. The 30-day WhatsApp pause expires on its own. ## ERR_TEMPLATE_PARAMS_INVALID [#err_template_params_invalid] The variables submitted with the send do not satisfy the template. Both Sent and Meta raise this code: - **Sent's send pipeline** blocks the message when a required template variable is missing, a value contains new-line or tab characters or more than 4 consecutive spaces (Meta's parameter text rules), or a value fails the variable's validation pattern. - **Meta** rejects the dispatch with error 100 (invalid parameter) when the payload does not match the approved template, for example the wrong variable count, or a plain string where the template expects a currency or date-time object. The message stays `FAILED`; there is no SMS fallback and no automatic retry. To resolve: 1. Open the template in **Dashboard → Templates** and compare its placeholders against the variables in your request: supply every placeholder, and remove extras. 2. Strip new-lines, tabs, and long runs of spaces from variable values. 3. Send a corrected message. If the template itself is the problem (rejected, miscategorized, or stuck in review), see [WhatsApp Template Issues](/troubleshooting/template-issues). ## ERR_TEMPLATE_NAME_INVALID [#err_template_name_invalid] Meta rejected the send because no template with that name exists on the WhatsApp Business Account for the language sent. Meta's error message reads `template name does not exist in the translation`. To resolve: 1. Confirm the template exists and shows **Approved** in **Dashboard → Templates**. 2. If you manage templates directly in Meta's WhatsApp Manager, confirm the template was not renamed or deleted there, and that it exists in the language you are sending. 3. Send a corrected message. The failed message stays `FAILED`; there is no SMS fallback and no automatic retry. ## ERR_RECIPIENT_NOT_REGISTERED [#err_recipient_not_registered] The recipient's phone number is not registered on WhatsApp. Sent maps Meta error 133016, and provider messages stating the number is not a WhatsApp user, to this code. For a genuine unregistered recipient, Sent reacts the same way as for [`ERR_MESSAGE_UNDELIVERABLE`](#err_message_undeliverable): WhatsApp is paused for that recipient for 30 days and the message is re-sent through SMS routing under the same `message_id`. No action is needed beyond confirming the SMS attempt delivered. If your own WhatsApp number is not fully connected to a WhatsApp Business Account, Meta can report every send with this code even though the problem is on your side, not the recipient's. If all of your WhatsApp sends fail this way, check the connection under **Dashboard → Channels → WhatsApp** and work through [WhatsApp Onboarding & Business Account Connection](/troubleshooting/whatsapp-setup) before assuming your recipients lack WhatsApp. ## ERR_PROVIDER_ERROR [#err_provider_error] The catch-all code: the provider returned an error that Sent could not map to any specific code. It appears on WhatsApp and on SMS carriers alike. Unclassified failures deliberately do not trigger an automatic re-send, so the message stays `FAILED`. To resolve: 1. Check the [Sent status page](https://status.sent.dm) for an ongoing incident. 2. [Contact support](/start/reference-guides/support) with the message ID to get the raw provider response. 3. If the cause was transient, send the message again. ## ERR_ECOSYSTEM_ENGAGEMENT [#err_ecosystem_engagement] Meta's anti-spam restriction, WhatsApp error 131049: Meta declined to deliver the message because its systems flagged the send as spam-like. Sent treats it as a recipient-side failure, so the message is automatically re-sent through SMS routing and WhatsApp is paused for that recipient for 30 days. For the causes and prevention steps (the 24-hour conversation window, template reclassification, send frequency), see [ERR_ECOSYSTEM_ENGAGEMENT in Messages Not Delivered](/troubleshooting/messages-not-delivered#whatsapp-err_ecosystem_engagement--error-131049). ## When Failures Fall Back to SMS [#when-failures-fall-back-to-sms] Two separate mechanisms can move a WhatsApp send to SMS: - **After Meta accepts, on a recipient-side failure.** `ERR_MESSAGE_UNDELIVERABLE`, `ERR_RECIPIENT_NOT_REGISTERED`, and `ERR_ECOSYSTEM_ENGAGEMENT` trigger an automatic re-send of the same message over SMS, plus the 30-day per-recipient WhatsApp pause. You observe a `message.failed` event with `"channel": "whatsapp"` followed by new lifecycle events for the same `message_id` with `"channel": "sms"`. - **At send time, before Meta accepts.** If the WhatsApp send call itself fails and your routing allows fallback, Sent immediately tries the next eligible route in the same send. See [WhatsApp-to-SMS failover](/troubleshooting/messages-not-delivered#whatsapp-to-sms-failover-not-triggering) for debugging that path. Template and unclassified errors (`ERR_TEMPLATE_PARAMS_INVALID`, `ERR_TEMPLATE_NAME_INVALID`, `ERR_PROVIDER_ERROR`) never fall back: the message stays `FAILED`, and you must fix the cause and send a new message. ## Verify the Resolution [#verify-the-resolution] After applying a fix, send the message again and confirm delivery: - `GET /v3/messages/{id}` returns `"status": "DELIVERED"`, or a `message.delivered` webhook arrives. - For the automatic-fallback codes, confirm the SMS attempt delivered: the terminal event carries `"channel": "sms"`. ## Related [#related] - [Messages Not Delivered](/troubleshooting/messages-not-delivered): API-vs-dashboard mismatches, country-specific SMS filtering, and sender routing issues - [WhatsApp Template Issues](/troubleshooting/template-issues): template approval, categorization, and rejection problems - [Error Handling](/reference/api/errors): the API error envelope, HTTP status codes, and the full send-time `ERR_*` code table - [Message Status Tracking](/start/guides/message-status-tracking): tracking delivery status by webhook, polling, and dashboard # WhatsApp Onboarding & Business Account Connection (/troubleshooting/whatsapp-setup.md) # WhatsApp Onboarding & Business Account Connection [#whatsapp-onboarding--business-account-connection] Setting up WhatsApp as a messaging channel on Sent requires connecting a Meta (Facebook) Business Account and a WhatsApp Business Account. Because this process involves multiple systems (Sent, Meta Business Manager, and WhatsApp), there are several points where things can go wrong. This guide covers the most common issues and how to resolve them. If your channel is already connected and individual messages fail after you send them, see [Troubleshoot WhatsApp Delivery Failures by Error Code](/troubleshooting/whatsapp-delivery-errors) instead. WhatsApp Business API access is managed by Meta. Many WhatsApp connection issues originate from Meta's side, not Sent's. If you're having trouble connecting, start by verifying your Meta Business Account status at [business.facebook.com](https://business.facebook.com). ## Prerequisites for WhatsApp setup [#prerequisites-for-whatsapp-setup] Before starting the WhatsApp onboarding flow in the Sent dashboard, confirm that you have the following: - **Meta Business Account (verified)**: Created and verified at [business.facebook.com](https://business.facebook.com). Verification includes submitting your business documents to Meta and having them approved. - **Facebook personal account**: Required to manage the Meta Business Account. This is the account you will use to log in during the connection flow. - **Phone number not already linked to another WhatsApp Business Account**: A phone number can only be associated with one WhatsApp Business Account at a time. If your number is currently linked elsewhere, you must remove it first. - **Sent account with KYC approved**: Your Sent account must have passed compliance review before you can configure channels. See [Account Activation & KYC Review](/troubleshooting/account-activation) if your account is still under review. If any of these prerequisites are not met, the onboarding flow will fail at various stages. Address them before proceeding. ## "The information could not be verified" connection error [#the-information-could-not-be-verified-connection-error] **Symptoms:** During step 2 of the WhatsApp onboarding flow, a Facebook popup opens for connecting your WhatsApp Business Account. After selecting your WA account and confirming authorization, you see: > The information could not be verified. Please repeat the verification process or cancel the registration. Failed to share the WhatsApp Business Account with partners. **Common causes:** - Your Meta Business Account has not completed Meta's own business verification process. - Two-factor authentication on your Facebook account is interfering with the OAuth flow. - Your browser is blocking popups or third-party cookies required by the Facebook login window. - You are using a browser with known compatibility issues with Facebook OAuth (Safari in particular). **Solutions:** 1. **Verify your Meta Business Account.** Log in to [Meta Business Manager](https://business.facebook.com) and navigate to **Settings → Business Info → Business Verification**. If verification is not complete, follow Meta's instructions to submit the required documents. This process can take several days on Meta's side. 2. **Disable popup blockers temporarily.** The connection flow opens a Facebook popup window. If your browser blocks it, the authorization cannot complete. Allow popups from `sent.dm` and `facebook.com` for the duration of the setup. 3. **Use Chrome instead of Safari.** Safari has known issues with Facebook's OAuth flow due to its Intelligent Tracking Prevention (ITP) feature, which blocks third-party cookies. Chrome is the recommended browser for this step. 4. **Clear Facebook session cookies.** If you have multiple Facebook accounts or recently changed your password, stale session data can cause verification failures. Clear cookies for `facebook.com` and `business.facebook.com`, then log in again before retrying. 5. **Complete Meta Business Verification first.** If you created a new Meta Business Account specifically for Sent, it may not yet be verified. Meta requires business verification before you can share your WhatsApp Business Account with third-party partners like Sent. This is a Meta requirement and cannot be bypassed. Meta Business Verification is separate from Sent's KYC process. You need to complete both: Sent's KYC for your Sent account, and Meta's Business Verification for your Meta Business Account. ## "This phone number is already used and linked to a WhatsApp account" [#this-phone-number-is-already-used-and-linked-to-a-whatsapp-account] **Symptoms:** During WhatsApp channel setup, you receive an error indicating that the phone number you are trying to use is already linked to another WhatsApp Business Account. **Why this happens:** A phone number can only be connected to **one** WhatsApp Business Account at a time. This is a Meta platform limitation. If the number was previously registered with a different WhatsApp Business Account (whether through another provider, a previous Sent account, or the standard WhatsApp Business app), it must be removed from that account before it can be linked to a new one. **Solutions:** 1. **Remove the number from the previous WhatsApp Business Account.** Log in to [Meta Business Manager](https://business.facebook.com), navigate to the WhatsApp Business Account that currently holds the number, and remove it. After removal, wait a few minutes before retrying the connection in Sent. 2. **If you don't have access to the previous account:** Contact [Meta Business Support](https://www.facebook.com/business/help) to request that the number be released. You will need to verify ownership of the number. This process may take several days. 3. **Use a different phone number.** If releasing the number is not feasible or time-sensitive, consider using a different phone number for your WhatsApp channel on Sent. If you were previously using the number with the standard WhatsApp Business app (not the API), you must delete the WhatsApp Business app account for that number before it can be used with the WhatsApp Business API through Sent. ## Meta verification code sent to Sent-provisioned number [#meta-verification-code-sent-to-sent-provisioned-number] **Symptoms:** During the WhatsApp onboarding flow, Meta sends a 6-digit verification code via SMS to the phone number that was provisioned by Sent. You do not have physical access to this number and cannot receive the SMS. **Why this happens:** Meta requires phone number verification as part of the WhatsApp Business API setup. When Sent provisions a number for you, the verification step is handled automatically by Sent's integration with the carrier. **What to do:** 1. **You do not need to manually enter a verification code.** Sent handles the automated verification of provisioned numbers as part of the integration flow. If the system is working correctly, the code is received and submitted automatically. 2. **If you see a prompt asking for the code,** you may have navigated to Meta's verification page directly rather than going through the Sent dashboard. Go back to the Sent dashboard and follow the WhatsApp onboarding flow from there. The dashboard orchestrates the verification process end-to-end. 3. **If the automated verification does not complete** after several minutes, contact [support@sent.dm](mailto:support@sent.dm) with: - The phone number that was provisioned - The step in the onboarding flow where you are stuck - Any error messages displayed in the dashboard Do not attempt to verify the number manually through Meta Business Manager, as this can interfere with Sent's automated process. ## Country or number became unavailable after registration [#country-or-number-became-unavailable-after-registration] **Symptoms:** The country or phone number you originally selected during WhatsApp setup is no longer available. The country may have been removed from the available list, or no numbers are shown for that region. **Why this happens:** Phone number availability depends on carrier partnerships and regional regulations. Countries and number ranges can be added or removed over time due to: - Changes in carrier agreements - Regulatory requirements in specific regions - Temporary inventory shortages **Solutions:** 1. **Contact support for alternatives.** Send an email to [support@sent.dm](mailto:support@sent.dm) with your original number or country selection and the team can check whether alternative numbers are available or if the region is expected to return. 2. **Consider using a US number.** US phone numbers for WhatsApp work globally regardless of your business location or your recipients' locations. WhatsApp messages are delivered over the internet, so the number's country code does not affect deliverability. A US number is often the most reliable option if your preferred region is unavailable. ## Facebook account required for WhatsApp setup [#facebook-account-required-for-whatsapp-setup] **Symptoms:** You are prompted to connect a Facebook account during WhatsApp channel setup and were not expecting this requirement. **Why a Facebook account is required:** The WhatsApp Business API is part of Meta's platform. All WhatsApp Business API access is managed through Meta Business Manager, which requires a Facebook account. This is a Meta requirement, not a Sent limitation. **What you need:** | Account | Purpose | Where to create | |---|---|---| | **Facebook personal account** | Used to log in to Meta Business Manager and manage business assets | [facebook.com](https://www.facebook.com) | | **Meta Business Account** | Container for your business assets including WhatsApp | [business.facebook.com](https://business.facebook.com) | | **WhatsApp Business Account** | Created during the Sent onboarding flow or in Meta Business Manager | Created automatically during setup | **If you don't have a Meta Business Account:** 1. Go to [business.facebook.com](https://business.facebook.com) and click **Create Account**. 2. Follow Meta's setup wizard to provide your business name, your name, and your business email. 3. Complete Meta's Business Verification process (required for WhatsApp Business API access). 4. Return to the Sent dashboard and start the WhatsApp onboarding flow. The Sent onboarding wizard guides you through connecting these accounts step by step. If you already have a Meta Business Account, the flow will detect it and prompt you to select it during authorization. ## Country not available in Meta payment or address forms [#country-not-available-in-meta-payment-or-address-forms] **Symptoms:** When setting up billing or entering address details in Meta Business Manager as part of WABA setup, your country does not appear in the dropdown. Meta recommends adding a payment method to speed up WABA approval, but the form cannot be completed without the correct country selection. **Why this happens:** This is an inconsistency in Meta's platform. A country may appear in some Meta form fields (such as the VAT number entry field) but be absent from others (such as the billing address country selector). The omission is on Meta's side and is not related to your Sent account or WABA configuration. **Impact:** Without a payment method on file, Meta may take longer to approve your WABA. However, the missing country does **not** block the WABA connection itself. You can complete onboarding on Sent using a provisionally assigned phone number and add payment details later. **Solutions:** 1. **Proceed without a payment method.** Complete the WABA setup flow in the Sent dashboard as normal. A provisional number will be assigned. You can update the number and revisit payment setup once Meta resolves the issue on their end. 2. **Submit a support ticket to Meta.** Go to [Meta Business Help](https://business.facebook.com/help) and report that your country is missing from the payment setup dropdown. Reference the inconsistency (for example, country appears in VAT fields but not billing address) in your report. 3. **Check other Meta Business Manager accounts.** If you manage multiple Meta Business assets, the country dropdown behavior can differ between them. You may find a path to add billing details through an account or asset where the country does appear. A provisionally assigned number can be changed later. If you need a local number for your region once WABA is approved, contact [support@sent.dm](mailto:support@sent.dm) and the team can update it. ## "Log in with Meta" button is greyed out or pop-up does not open [#log-in-with-meta-button-is-greyed-out-or-pop-up-does-not-open] **Symptoms:** On the WhatsApp Integration step of onboarding, the **Log in with Meta** button is greyed out and cannot be clicked, or clicking it does nothing: the Meta authorization window never appears. **Why this happens:** The **Log in with Meta** button loads external scripts from `facebook.com` before it becomes active. Browser extensions that block ads, trackers, or third-party scripts (such as uBlock Origin, Privacy Badger, or similar tools) can silently prevent these scripts from loading, leaving the button permanently greyed out. The same extensions can also allow the button to activate but then block the Facebook authorization pop-up from opening. **Solutions:** 1. **Try a different browser without extensions.** Any browser profile without ad-blocking or privacy extensions installed will typically work. This is the fastest way to confirm whether an extension is the cause. 2. **Use an incognito or private window.** Most browsers turn off extensions in private mode by default. If the button becomes active in incognito, an extension in your normal session is the cause. 3. **Turn off your extensions temporarily.** If you prefer to stay in your regular browser, turn off ad blockers and privacy extensions one at a time until the button activates, then re-enable them after completing setup. This issue is caused entirely by the browser environment and is not related to your Sent account or Meta configuration. Once the button loads correctly in a compatible browser, the rest of the connection flow proceeds normally. ## Missing administrator permissions for WABA connection [#missing-administrator-permissions-for-waba-connection] **Symptoms:** During the WABA connection flow, Meta displays a message indicating that your account does not have the required permissions to create or modify WhatsApp Business accounts. You cannot proceed past this step. **Why this happens:** Connecting a WhatsApp Business Account to Sent requires Meta Business Manager administrator permissions. If the person completing the setup is not an administrator on the Meta Business Account (or if the account was set up with limited roles), Meta blocks the authorization step. **Solutions:** 1. **Have a Meta Business Account administrator complete the connection.** Log in to [Meta Business Manager](https://business.facebook.com), navigate to **Settings → People**, and verify that the account being used to connect has administrator access. If not, ask an administrator to complete the WABA connection step in the Sent dashboard. 2. **Grant administrator permissions to your account.** If you need to complete the setup yourself, have an existing administrator grant you administrator access in Meta Business Manager, then retry the connection flow. 3. **Use a different Sent account login if needed.** Another person on your team can log in to Sent and complete the WhatsApp connection step as long as they have administrator access to the Meta Business Account. The admin requirement is enforced by Meta, not Sent. Sent cannot bypass or work around this permission check. The account used to authorize the connection must have admin rights on the Meta Business Account. ## General troubleshooting steps [#general-troubleshooting-steps] If you are experiencing a WhatsApp connection issue not covered in the preceding sections, try these steps in order: 1. **Check Meta Business Manager status.** Log in to [business.facebook.com](https://business.facebook.com) and verify that your Meta Business Account is active and verified. Look for any alerts or pending actions. 2. **Use Chrome in incognito mode.** This eliminates issues caused by cached data, conflicting extensions, or stale sessions. 3. **Ensure only one Facebook account is logged in.** Multiple Facebook sessions can cause the OAuth flow to authenticate with the wrong account. Log out of all Facebook accounts and log in with only the one associated with your Meta Business Account. 4. **Retry the onboarding flow from the Sent dashboard.** Navigate to the WhatsApp channel setup in your Sent dashboard and restart the connection process. Do not attempt to configure WhatsApp directly through Meta Business Manager. 5. **Check Meta's status page.** Occasionally, Meta's APIs experience outages that affect WhatsApp Business API operations. Check [metastatus.com](https://metastatus.com) for any ongoing incidents. ## Still need help? [#still-need-help] If you have worked through the preceding steps and your WhatsApp setup is not completing, contact the Sent support team: - **email:** [support@sent.dm](mailto:support@sent.dm) - **Include:** The email address on your Sent account, the step in the onboarding flow where you are stuck, any error messages (screenshots are helpful), and the browser you are using. - **Response time:** The support team typically responds within 1 business day. For other onboarding issues not related to WhatsApp, see [Account Activation & KYC Review](/troubleshooting/account-activation) or the [FAQ](/start/reference-guides/faq). ## Related Guides [#related-guides] - [WhatsApp Template Issues](/troubleshooting/template-issues): once WhatsApp is connected, troubleshoot template creation, approval, and sending - [Troubleshoot WhatsApp Delivery Failures by Error Code](/troubleshooting/whatsapp-delivery-errors): match each `ERR_*` code to a fix when connected messages fail on send - [Messages Not Delivered](/troubleshooting/messages-not-delivered): diagnose delivery failures after your channels are configured - [Phone Number & Sender ID Issues](/troubleshooting/phone-numbers): if you need a different number or are having trouble with sender routing ---