Building Integrations
Build an app any Dispatch customer can connect: sign in their agents with Dispatch, act as them through the API, and add buttons to their chat widget. No approval needed.
Overview
Data access
The customer approves your app with Connect to Dispatch and picks its brands.
Sign in with Dispatch
Standard OAuth 2.0 / OpenID Connect tells you which agent is using your app.
Act
Claim tickets, reply as the agent, react to webhooks, add chat buttons.
Signing in proves who someone is. It grants nothing on its own: everything your app can read or change comes from the access the customer approved.
Connect a customer
Register your app once with your own Dispatch account. Keep the clientId and the clientSecret, which is shown only once.
curl -X POST https://api.dispatchtickets.com/v1/integration-apps \
-H "Authorization: Bearer $YOUR_DISPATCH_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"name": "My Integration",
"redirectUris": ["https://example.com/dispatch/connected"],
"homepageUrl": "https://example.com",
"logoUrl": "https://example.com/logo.png"
}'Then give each customer a Connect to Dispatch button. Their admin signs in, ticks the brands your app may reach and approves. Dispatch sends them back to your redirect with a one-time code, which your server swaps for tokens.
import { DispatchTickets, connectUrl, exchangeCode } from "@dispatchtickets/sdk";
// 1. Your "Connect to Dispatch" button links here
const link = connectUrl({ clientId, redirectUri, state });
// 2. On your redirect: ?code=...&state=... (check the state)
const tokens = await exchangeCode({ clientId, clientSecret, code, redirectUri });
// 3. Use the access token like an API key, scoped to the approved brands
const dispatch = new DispatchTickets({ apiKey: tokens.access_token });
const { brands } = await dispatch.integrations.me();Access tokens last an hour. Refresh tokens are single use: store the new one each time. The token reaches tickets, comments, attachments, agents, presence, webhooks and chat buttons on the approved brands. Other endpoints return 403, and you can change only the webhooks and chat buttons you created. The customer can change brands or disconnect in Dispatch at any time. After that your token gets a 401, and the webhooks and chat buttons you created are switched off.
Register a sign-in client
Registration is open. Register once per integration and keep the client_id and client_secret. An app with no server side sets token_endpoint_auth_method to none and uses PKCE.
curl -X POST https://clerk.dispatchtickets.com/oauth/register \
-H 'Content-Type: application/json' \
-d '{
"client_name": "My Integration",
"redirect_uris": ["https://example.com/auth/dispatch/callback"],
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"],
"token_endpoint_auth_method": "client_secret_basic",
"scope": "openid profile email"
}'Endpoints are published at https://clerk.dispatchtickets.com/.well-known/oauth-authorization-server. Ask for openid profile email only.
Sign an agent in
Use the authorization code flow with PKCE (S256): send the agent to /oauth/authorize, exchange the code at /oauth/token, then call /oauth/userinfo. Its sub is the agent's Dispatch sign-in id.
Map to the customer's agents
GET /v1/brands/:brandId/agents lists who can handle that brand's tickets. Match on clerkUserId. Check it every time the agent acts, not just at sign-in: someone removed from the team drops out immediately.
// 1. Who signed in (access token from the OAuth code exchange)
const me = await fetch("https://clerk.dispatchtickets.com/oauth/userinfo", {
headers: { Authorization: `Bearer ${accessToken}` },
}).then((r) => r.json());
// 2. Are they an agent on this brand? (the customer's access token)
const { data: agents } = await fetch(
`https://api.dispatchtickets.com/v1/brands/${brandId}/agents`,
{ headers: { Authorization: `Bearer ${tokens.access_token}` } },
).then((r) => r.json());
const agent = agents.find((a) => a.clerkUserId === me.sub);
if (!agent) throw new Error("Not an agent on this brand");
// agent.id is what assigneeId and a comment's authorId takeAct as the agent
Take a ticket without racing a colleague
PATCH /v1/brands/:brandId/tickets/:ticketId
{ "assigneeId": "usr_...", "ifUnassigned": true }
// 200: theirs (the usual assignment email goes out)
// 409: { "error": "already_assigned", "assigneeId": "usr_..." }Reply as them
authorId must be an agent on the brand (otherwise 403). On a live chat the reply reaches the visitor's widget straight away.
POST /v1/brands/:brandId/tickets/:ticketId/comments
{
"body": "Here's the call link: https://...",
"authorType": "AGENT",
"authorId": "usr_...",
"authorName": "Kal"
}React to events
Subscribe to webhooks. presence.updated (who is available, including when someone goes offline) is opt-in: subscribe to it by name, because * doesn't include it.
Add a button to the customer's chat widget
POST /v1/brands/:brandId/chat/actions with { label, url } adds a button to the customer's chat widget, with no code on their site. When a visitor presses it, Dispatch POSTs a signed chat.action to your URL (verify it like a webhook). The message in your JSON reply appears in the widget. You have 5 seconds.
What to trust
| Value | Use it for | Not for |
|---|---|---|
sub from userinfo | Who signed in | Anything about brands or access |
id from /agents | Assigning and authoring as the agent | - |
| Email address | Display | Matching people across systems |