API Reference

All endpoints are served by the Next.js app. Desktop and mobile clients communicate exclusively through these routes — no direct Supabase access.

Base URLhttp://<your-server>:3000

Calls

Manage call records stored in the database.

GET/api/callsList all calls

Returns a paginated list of call records. Supports optional query params: ?limit, ?status (answered | missed | rejected), ?agent_id.

ParamInDescription
limitqueryMax records to return (default 50)
statusqueryFilter by call status
agent_idqueryFilter by agent
POST/api/callsInsert a new call

Creates a new call record. Called by the desktop app when a call event is received from the mobile gateway.

ParamInDescription
caller_numberbodyIncoming phone number
gateway_idbodyID of the originating gateway
agent_idbodyAgent that handled the call
statusbodyInitial call status
GET/api/calls/statsDashboard statistics

Returns aggregated call stats: total calls, answered/missed/rejected counts, and average call duration. Used by the dashboard page.

GET/api/calls/[id]Get a single call

Fetches the full record for one call by its UUID.

ParamInDescription
idpathCall UUID
PATCH/api/calls/[id]Update a call

Updates mutable fields on a call — typically status, answered_at, ended_at, or duration. Called by the desktop app during and after a call.

ParamInDescription
idpathCall UUID
statusbodyNew status value
answered_atbodyISO timestamp when answered
ended_atbodyISO timestamp when ended
durationbodyDuration in seconds

Agents

Manage the agents (operators) who answer calls via the desktop app.

GET/api/agentsList all agents

Returns all agents with their linked gateway info and call statistics (total, answered, missed).

POST/api/agentsCreate an agent

Creates a new agent record. A random pairing_secret is generated automatically for QR-based gateway registration.

ParamInDescription
namebodyAgent display name
emailbodyAgent email (used for sign-in)
GET/api/agents/[id]Agent detail

Returns a single agent with full stats and the 10 most recent calls.

ParamInDescription
idpathAgent UUID
PATCH/api/agents/[id]Update an agent

Updates agent fields: name, email, or status (active | inactive).

ParamInDescription
idpathAgent UUID
namebodyNew display name
emailbodyNew email address
statusbodyactive | inactive
GET/api/agents/[id]/pairing-secretGet pairing data for QR

Returns the pairing_secret for the given agent. The desktop QR screen calls this to build the QR payload that the mobile app scans.

ParamInDescription
idpathAgent UUID
POST/api/agents/signinAgent sign-in

Looks up an agent by email. Returns the agent record on match. No password required — email-only authentication for the desktop app.

ParamInDescription
emailbodyAgent email address

Gateways

Manage mobile phone gateways (Android phones that forward SIM calls).

POST/api/gateways/registerRegister a gateway

Called by the mobile app after scanning the QR code. Verifies the pairing_secret, then upserts a gateway record tied to the agent. Returns a gateway_token the mobile app stores for subsequent requests. Re-scanning the QR after reinstall works cleanly (upsert by phone_number).

ParamInDescription
agent_idbodyAgent to pair with
pairing_secretbodySecret from QR payload
phone_numberbodySIM phone number auto-detected on device
GET/api/gateways/[id]Get a gateway

Returns the gateway record (status, phone_number, last_seen, linked agent).

ParamInDescription
idpathGateway UUID
PATCH/api/gateways/[id]Update a gateway

Updates gateway fields such as ws_url (WebSocket address) or status (online | offline). Called by the desktop app when its IP or port changes.

ParamInDescription
idpathGateway UUID
ws_urlbodyNew WebSocket URL
statusbodyonline | offline