API conventions
The path a request takes through the backend, route shape, validation, pagination and cursors, the error shape, file uploads, and how the app calls the API.
The backend is a JSON REST API. A route checks its input and calls one service; the service runs the queries, scoped to the caller’s workspace, and raises a domain error when something is wrong.
The app calls /api/…. In development the Vite server, and in production the reverse proxy, removes /api before the request reaches the backend, which has no prefix of its own.
Routes
- Each area has its own path, and nested resources sit under their parent:
/customers/:id/contacts,/campaigns/:campaignId/runs. - Ids are opaque strings and are not format-checked. An id from another workspace gets the same
404as one that does not exist. - A
POSTanswers201by default. Actions that create nothing answer200,204when there is no body, or202when the work is queued. - Webhooks and tracking links do their own checks; see Channels.
Validation
- A field the route does not declare is removed before the route sees it, and no error is raised.
- A request that fails validation gets
400with the codevalidationand the messages indetails. - Route parameters are not checked. An unexpected value reaches the database query.
- A JSON body may be at most 100 KB.
- Two inputs are checked by their service, because their shape depends on another field: a template’s content, by template type, and an audience rule, when it is first used.
Pagination
List routes share one set of query parameters:
| Parameter | Default | Meaning |
|---|---|---|
page | 1 | Page number. Ignored when cursor is set. |
limit | 10 | Rows per page, kept between 1 and 100 |
cursor | None | The nextCursor of the previous page |
search | None | Repeatable field:value. Several fields are combined with OR, each a case-insensitive contains. |
sort | Route default | Repeatable -field (descending) or field (ascending) |
Repeat a key for several values: ?search=name:ann&search=jobTitle:cto&sort=-createdAt. The bracket form sort[]= is ignored. Each route lists the fields it lets callers search and sort on, and drops any other. A search field can reach into a relation, such as the company name of a person or the name of one of their tags.
{
"data": [ ... ],
"pagination": {
"total": 128,
"limit": 10,
"nextPage": 2,
"nextCursor": "eyJjcmVhdGVkQXQiOnsiX190IjoiRGF0ZSIsInYiOiIuLi4ifSwiaWQiOiIuLi4ifQ.n0aB..."
}
}The backend fetches one row more than the limit to know whether a next page exists. nextPage is set only when paging by number. nextCursor holds the last row’s values for every sort field plus its id as a tie-breaker, signed by the server so a client cannot forge one. Dates inside a cursor keep their type, so comparisons stay right across time zones. total is counted with the cursor’s condition, so when paging by cursor it is the number of rows left from that point.
A cursor that fails its signature check answers 500 internal_error, because the check raises an unexpected error instead of a domain error.
Some routes page differently:
| Route | Paging |
|---|---|
GET /inbox | Its own unsigned cursor of last activity time and person; a bad one gives 400 |
GET /inbox/:threadKey | The cursor is the id of the oldest message on the previous page |
GET /templates | Merges the workspace’s templates with the shipped ones and pages the list in memory |
GET /deals/kanban | 100 deals per stage, no paging |
| Members, workspaces, invites, the audiences for the Reports filter | Plain lists |
Errors
{
"http_status": 404,
"code": "customer_not_found",
"message": "Customer 'ck2x...' not found"
}| Cause | code | Extra |
|---|---|---|
| A domain error | Its own code, such as invalid_credentials or pool_empty | None |
| Failed validation | validation | details, the validator messages |
| Any other HTTP error (an unknown route, a file over the limit) | http_error | None |
| Anything else | internal_error, status 500 | The message is generic; the stack goes to the log |
Codes are snake_case and stable. The app branches on the code and shows the message, preferring the first entry in details. A new error is declared once in its module, with a status, a code and a message.
The channel webhooks are outside this error handling. They answer 200 { ok: true }, or 401 { ok: false } when their signature check fails.
File uploads
Uploads are multipart/form-data. A file is held in memory until the route stores it.
| Upload | Files | Size per file | Types |
|---|---|---|---|
| Knowledge documents | 10 by default | 25 MB by default | Any; unsupported types fail while the document is read |
| CSV import | 10 by default | 25 MB by default | CSV |
| Email image | 1 | 5 MB, fixed | JPEG, PNG, GIF, WebP, SVG |
A file over the limit gets 413. A message sent from the Inbox attaches Knowledge documents by id, at most 3.
Responses
- Records come back as JSON with camelCase fields and related records nested. Secrets are masked first.
- Dates are ISO 8601 strings. Deal amounts are decimals and arrive as strings.
- Downloads (the people export, an import’s error file, a Knowledge file) set a file name for the browser.
- The live Inbox stream is server-sent events; see Backend.
Rate limits and API docs
There is no general rate limit, sign-in included. The Ask agent and lead research started by hand limit themselves. A few list routes describe their paging parameters with OpenAPI annotations, and no OpenAPI document is served.
How the app calls the API
The app uses one HTTP client for the API:
- Its base address is set when the app is built, and is
/apiin the example settings. - Each request carries the access token from the browser’s local storage.
- On a
401it runs one shared refresh, stores the new pair and retries the request once. A failed refresh clears both tokens and sends the browser to sign-in. - Sign-in and sign-up use a separate plain client, because a wrong password is also a
401and must not start the refresh path.
Each feature of the app keeps its own API calls and query hooks, and some reshape the response there; the finished state of a Knowledge document, for example, is renamed to Ready. The app side is on Frontend.