# REST API conventions

> For AI agents: the index of these docs is at https://shippified.net/docs/llms.txt (every page it lists has a Markdown version like this one).

Base URL, request and response rules, errors, pagination, rate limits, IDs and dates that apply to every endpoint.

These rules apply to every endpoint under `https://shippified.net/api`. Read this page once; the resource pages assume it.

## Base URL

```text
https://shippified.net/api
```

Paths in these docs include the `/api` prefix: `GET /api/orders` means `https://shippified.net/api/orders`. Every request except the [public endpoints](#public-endpoints) needs an `Authorization: Bearer` header; see [Authentication](https://shippified.net/docs/authentication).

## Requests

- **Methods.** `GET`, `POST`, `PATCH` and `DELETE`. There is no `PUT`.
- **JSON bodies.** Send `Content-Type: application/json`. The server parses the body as JSON either way.
- **Invalid JSON isn't rejected up front.** A body that doesn't parse is kept as a raw string, so the endpoint sees its fields as missing and usually answers `400` with a field-specific message such as `itemSummary is required`.
- **2 MiB body limit.** A larger body gets `413 {"error": "Request body too large (limit 2 MiB)."}`. For moderately oversized uploads the server reads and discards the rest first, so your client sees the `413` instead of a broken connection. Very large uploads get the `413` and a closed connection.
- **Unknown fields are ignored.** Each endpoint reads only the fields it documents. Keys named `__proto__`, `prototype` or `constructor` are stripped at any depth.
- **Filters and paging** go in the query string: `?status=shipped&limit=100`.

## Responses

Every JSON response has `Content-Type: application/json; charset=utf-8`. Most endpoints return the resource itself; a few wrap it, such as `POST /api/orders` → `{ "order": …, "merged": … }`. Each resource page shows the exact shape.

Fields without a value are **left out**, not sent as `null`. An order with no tracking number simply has no `trackingNumber` key.

## Errors

Every error has the same shape:

```json
{ "error": "Human-readable message" }
```

Some add machine-readable fields next to `error`:

| Extra fields | Returned by | Meaning |
| --- | --- | --- |
| `reason: "plan_limit_reached"`, `cap`, `used` | `POST /api/orders` and `POST /api/email/import` (429), Discord intake (202 with `rejected: true`) | The free plan's monthly order limit is used up. |
| `blockedSender` | `POST /api/email/import` (403) | The email's real sender isn't in the source's allowed senders. Absent when the email has no sender at all. |
| `reason: "email_unverified"` | `POST /api/billing/checkout` (403) | Verify the account email before upgrading. |
| `code` | `POST /api/auth/atlas-login` | A short code for the sign-in failure. |

:::hint{style="success"}
Branch on the status code (and `reason` where present), not on the wording of `error`. Messages are written for people and can change.
:::

### Status codes

| Code | Used for |
| --- | --- |
| `200 OK` | Reads, updates, deletes (`{"ok": true}`) and actions. |
| `201 Created` | A resource was created: orders, API keys, webhook subscriptions, bots, email sources, custom templates, recurring costs, shares. |
| `202 Accepted` | Intake that processes a message (Discord intake, `POST /api/email/import`) and the background mailbox rebuild. |
| `204 No Content` | CORS preflight (`OPTIONS`) responses. No body. |
| `400 Bad Request` | Missing or invalid input: `itemSummary is required`, a bad `receivedAt` or `eventType`, an invalid regex in a template, a webhook URL that points at a private address, `sinceDays must be 1–365.`. |
| `401 Unauthorized` | Missing, invalid, revoked or expired credentials, or an API key on an endpoint that needs a signed-in session. |
| `403 Forbidden` | An API key's scope doesn't allow the request (a **Read-only** key on anything but `GET`, or any key creating or revoking API keys; see [Authentication](https://shippified.net/docs/authentication)), an email sender blocked by the allow-list, or upgrading before the email is verified. Resources from other accounts return `404`, not `403`. |
| `404 Not Found` | The resource doesn't exist or belongs to another account. Unknown `/api` routes return `{"error": "Not found"}`. |
| `409 Conflict` | Username taken, email already registered, or a mailbox rebuild already running. |
| `413 Content Too Large` | Body over 2 MiB. |
| `422 Unprocessable Content` | `POST /api/email/import`: the message couldn't be read as an email order. |
| `429 Too Many Requests` | A rate limit, a resource cap (25 API keys, 25 webhook subscriptions), or the monthly plan limit on a create. |
| `500 Internal Server Error` | Unhandled error. The body is still `{"error": "<message>"}`. |
| `502 Bad Gateway` | An upstream service (the sign-in service, Discord) couldn't be reached. |
| `503 Service Unavailable` | A feature isn't configured on this deployment (for example Google sign-in, billing, or webhook-secret encryption), or `/api/healthz` found storage unhealthy. |

## Pagination

Collections that can grow large use offset pagination and one envelope.

| Query parameter | Default | Bounds | Notes |
| --- | --- | --- | --- |
| `limit` | `50` | 1 to 200 | Above 200 is capped at 200. `0`, negative or non-numeric values fall back to 50 (negative becomes 1). |
| `offset` | `0` | 0 or more | Items to skip. Non-numeric values become 0. |

```json
{
  "items": [ … ],
  "total": 342,
  "limit": 50,
  "offset": 100,
  "hasMore": true
}
```

| Field | Meaning |
| --- | --- |
| `items` | This page. |
| `total` | All matches after filters, before paging. |
| `limit`, `offset` | The values the server actually used, after clamping. |
| `hasMore` | `true` when `offset + items.length < total`. |

Endpoints that use this envelope:

| Endpoint | Order |
| --- | --- |
| `GET /api/orders` | `receivedAt`, newest first |
| `GET /api/webhook-subscriptions` | `createdAt`, newest first |
| `GET /api/bots` | Not guaranteed |
| `GET /api/email-sources` | Not guaranteed |
| `GET /api/subscriptions` | Not guaranteed |

### Walk every page

:::tabs
::tab{title="curl + jq"}
```bash
offset=0
while :; do
  page=$(curl -s "https://shippified.net/api/orders?limit=200&offset=$offset" \
    -H "Authorization: Bearer $SHIPPIFIED_API_KEY")
  echo "$page" | jq -c '.items[]'
  [ "$(echo "$page" | jq -r .hasMore)" = "true" ] || break
  offset=$((offset + 200))
done
```
::
::tab{title="TypeScript SDK"}
```typescript
// Pages with limit=200 until hasMore is false.
const all = await shippified.listOrders();

// Or page yourself:
let offset = 0;
for (;;) {
  const page = await shippified.orders.list({ limit: 200, offset });
  for (const order of page.items) handle(order);
  if (!page.hasMore) break;
  offset += page.limit;
}
```
::
:::

:::hint{style="warning"}
Pages are cut from a list sorted newest first. If orders arrive while you page, items shift and you can see some twice. Deduplicate by `id`.
:::

A few small lists aren't paginated and use their own wrapper:

| Endpoint | Shape | Limit |
| --- | --- | --- |
| `GET /api/account/api-keys` | `{ items }` | At most 25 keys exist. |
| `GET /api/templates/custom` | `{ items }` | None. Newest first, which is also the order templates are tried in. |
| `GET /api/shares` | `{ shares }` | None. |
| `GET /api/webhook-logs` | `{ logs }` | `?limit=` 1 to 500, default 100. Newest first. |
| `GET /api/bots/:id/logs` | `{ logs }` | `?limit=` 1 to 500, default 200. Newest first. |
| `GET /api/inbox` | `{ items, total }` | `?limit=` 1 to 500, default 200. Optional `?sourceId=`. |

## Rate limits and caps

Only the endpoints below are rate-limited. Each limit is a sliding 60-second window counted in the server's memory.

| Scope | Limit | Over the limit |
| --- | --- | --- |
| Sign-in endpoints: `POST /api/auth/register`, `/login`, `/forgot-password`, `/reset-password`, `/atlas-login`, `/discord/widget-verify` | 10 a minute per client IP, shared | `429` with `Retry-After: 60` |
| Discord intake, per client IP across all bots | 60 a minute | `429`, `Retry-After: 60`, `{"error": "Webhook ingest rate exceeded (60/min per IP)"}` |
| Discord intake, per bot URL | 60 a minute | `429`, `Retry-After: 60`, `{"error": "Webhook ingest rate exceeded for this bot (60/min)"}` |
| Embed copier submission URL, per workspace | 30 a minute | `429 {"error": "Too many submissions — slow down."}` |

The client IP is the first address in `X-Forwarded-For`, or the connection's address when that header is absent.

Resource caps:

| Resource | Cap | When exceeded |
| --- | --- | --- |
| API keys per account | 25 | `429` |
| Webhook subscriptions per account | 25 | `429` |
| New orders a month on the free plan | 100, counted by when each order was created, from the 1st of the month in your account's timezone. Deleted orders still count. Applies only when billing is switched on for the deployment. | `429` on `POST /api/orders` and `POST /api/email/import`; `202` with `rejected: true` on Discord intake |

The plan limit counts only **new** orders. Messages that merge into an existing order (shipping and delivery emails, for example) are never blocked, and mailbox rebuilds don't use extra quota. See [Orders → Monthly limit](https://shippified.net/docs/orders#monthly-limit). `GET /api/billing/usage` returns `plan`, `used`, `cap` (`null` means unlimited), `resetsAt` and `billingEnabled`.

## Duplicates and retries

There's no `Idempotency-Key` header. Duplicates are prevented by the data instead:

| Path | Rule |
| --- | --- |
| `POST /api/orders` | An `orderNumber` that matches an existing order merges into it (`merged: true`). Without an `orderNumber`, every call creates a new order. |
| Email (import, polling, forwarding) | Deduplicated by `Message-ID`, or a SHA-256 of the raw message when there's none. `POST /api/email/import` answers `200` with `duplicate: true` for a repeat. Polling and forwarding also skip the messages of an order you deleted; importing by hand brings it back. |
| Discord intake | **Not deduplicated.** Discord payloads carry no message ID, and two identical checkouts can be two real orders. Posts with the same order number still merge. |

:::hint{style="warning"}
Before retrying a failed `POST /api/orders`, make sure the body has an `orderNumber`, so a retry merges instead of duplicating. Or search first with `GET /api/orders?q=<order number>`.
:::

## IDs

IDs are opaque strings with a type prefix. Don't parse them or rely on their length.

| Resource | Prefix | Example |
| --- | --- | --- |
| Order | `ord_` | `ord_mpvu9uim_aeh5t` |
| User | `usr_` | `usr_4f1c2a9b7e0d3c11` |
| API key | `key_` | `key_m1x2y3z4_a1b2c3` |
| Bot | `bot_` | `bot_m1x2y3z4` |
| Email source | `email_` | `email_m1x2y3z4` |
| Custom template | `tmpl_` | `tmpl_m1x2y3z4` |
| Recurring cost | `sub_` | `sub_m1x2y3z4` |
| Webhook subscription | `whsub_` | `whsub_m1x2y3z4_k9d2q` |
| Webhook event | `evt_` | `evt_m1x2y3z4_0a1b2c3d` |
| Intake log entry | `log_` | `log_m1x2y3z4_x7k2p` |

Secrets look similar but aren't IDs: API keys start with `sk_` and webhook signing secrets with `whsec_`.

## Dates and money

| Kind | Format | Example | Fields |
| --- | --- | --- | --- |
| Timestamp | ISO 8601, UTC, milliseconds | `2026-09-24T15:02:11.482Z` | `receivedAt`, `updatedAt`, `createdAt`, `lastUsedAt`, `lastFiredAt` |
| Calendar date | `YYYY-MM-DD` | `2026-09-27` | `estimatedDelivery`, `actualDelivery`, the `from`/`to` order filters |
| Money | Integer cents | `49999` = $499.99 | `costCents`, `salePriceCents`, recurring-cost `costCents` |
| Display money | Text as it appeared in the message | `"$499.99"` | Order `total`, `price` |

:::hint{style="warning"}
`total` and `price` are strings copied from the source message. Do arithmetic only on the `…Cents` fields.
:::

## CORS

JSON responses carry:

```http
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PATCH,DELETE,OPTIONS
Access-Control-Allow-Headers: authorization,content-type
```

`OPTIONS` to any path gets `204` with no body. Authentication uses the `Authorization` header, not cookies.

:::hint{style="danger"}
CORS lets a browser call the API, but never put an API key in a web page: even a **Read-only** key can read the whole workspace. Call Shippified from your own backend.
:::

## Public endpoints

These need no token:

| Endpoint | Returns |
| --- | --- |
| `GET /api/healthz` | `{ ok, uptimeMs, version, node, persistence, counts }`. `503` when storage is unhealthy. Never cached. |
| `GET /api/openapi.json` | The OpenAPI 3.1 spec. |
| `GET /api` | An interactive API reference page (HTML). |
| `GET /api/landing-stats` | `{ generatedAt, totalValueCents, ordersTracked, platformsSupported }` across the whole platform. |
| `GET /api/profile/:usernameOrUserId` | A public profile. `404 {"error": "Profile not found"}` when it's private, unless you're the owner. |
| `GET /api/auth/providers` | Which sign-in methods the deployment has switched on. |
| `POST /api/webhooks/discord/:handle/:slug` | Discord intake. The URL is the credential. See [Getting orders in](https://shippified.net/docs/intake). |

## Endpoint map

Everything else needs a token. The resource pages cover the first group in depth; the rest are summarised here and fully specified in the [API reference](https://shippified.net/docs/overview#api-reference).

| Area | Endpoints | Documented in |
| --- | --- | --- |
| Orders and tracking | `/api/orders…`, `/api/carrier-status` | [Orders](https://shippified.net/docs/orders) |
| Bots, email sources, import, logs, inbox | `/api/bots…`, `/api/email-sources…`, `/api/email/import`, `/api/webhook-logs`, `/api/inbox…` | [Getting orders in](https://shippified.net/docs/intake) |
| Templates | `/api/templates…` | [Templates API](https://shippified.net/docs/templates-api) |
| Outbound webhooks | `/api/webhook-subscriptions…` | [Webhooks](https://shippified.net/docs/webhooks) |
| API keys, export, deletion | `/api/account/api-keys…`, `/api/account/export`, `DELETE /api/account` | [Authentication](https://shippified.net/docs/authentication) |
| Workspace snapshot | `GET /api/state` | [Below](#workspace-snapshot) |
| Recurring costs | `GET/POST /api/subscriptions`, `GET/PATCH/DELETE /api/subscriptions/:id`. See [Recurring costs](#recurring-costs). | [Subscriptions reference](https://shippified.net/docs/ref-subscriptions) |
| Insights | `GET /api/profitability?range=month\|quarter\|year\|all`, `GET /api/calendar?month=YYYY-MM`, `GET /api/leaderboard?timeframe=week\|month\|all`. Days are grouped in your account's timezone; see [Days and timezones](#days-and-timezones). | [Insights reference](https://shippified.net/docs/ref-insights) |
| Share cards | `GET/POST /api/shares`, `DELETE /api/shares/:slug`. In `GET /api/shares`, a card created without Stats (`include.stats: false`) has no `totalSpendCents`, `deliveredCount`, `fulfillmentPct` or `biggestDay` in its `snapshot`; the order count stays. | [Shares reference](https://shippified.net/docs/ref-shares) |
| Workspace settings | `POST /api/settings` (`outputWebhook`, `updatesWebhook`, `forwardOn`) | [Settings reference](https://shippified.net/docs/ref-settings) |
| Account profile | `POST /api/account/username`, `/display-name`, `/visibility`, `/public-stats`, `/timezone`; `GET /api/account/username/available?u=` | [Account reference](https://shippified.net/docs/ref-account) |
| Billing | `GET /api/billing/usage`, `POST /api/billing/checkout`, `POST /api/billing/portal` | [Billing reference](https://shippified.net/docs/ref-billing) |
| Embed copier | `GET /api/embed-copier/config`, `POST /api/embed-copier/rotate`, `/api/embed-samples…` | [Embed Copier reference](https://shippified.net/docs/ref-embed-copier) |
| Discord bot | `GET /api/discord/install`, `PATCH /api/discord/settings`, `POST /api/discord/digest` | [Discord reference](https://shippified.net/docs/ref-discord) |

## Recurring costs

`POST /api/subscriptions` and `PATCH /api/subscriptions/:id` take `name`, `costCents`, `frequency` (`weekly`, `monthly`, `quarterly` or `yearly`), `startDate`, `endDate` and `active`. `PATCH` changes only the fields you send.

| Field | Rule | `400` message |
| --- | --- | --- |
| `name` | Trimmed, up to 80 characters. On `PATCH` it can't be empty (create falls back to `Unnamed subscription`). | `` `name` can't be empty. `` |
| `costCents` | Rounded. On `PATCH`, must be 0 or more (create turns anything invalid into 0). | `` `costCents` must be a number of cents, 0 or more. `` |
| `frequency` | On `PATCH`, one of the four values (create falls back to `monthly`). | `` `frequency` must be one of weekly, monthly, quarterly, yearly. `` |
| `startDate` | A real `YYYY-MM-DD` date. Defaults to today (UTC) on create. | `` `startDate` must be a date like 2026-01-31. `` |
| `endDate` | A real `YYYY-MM-DD` date, on or after `startDate`. The subscription stops renewing on that date. `""` or `null` clears it. | `` `endDate` must be a date like 2026-01-31, or empty to clear it. `` or `` `endDate` can't be before `startDate`. `` |
| `active` | `true` (renewing, the default) or `false` (paused). | `` `active` must be true or false. `` |

Setting `active: false` without an end date sets `endDate` to today (or to `startDate`, if that's later). A paused or ended subscription keeps counting in profit history and the calendar up to its `endDate`; deleting it removes it from history too. Setting `active` back to `true` on the API only flips the flag; the dashboard's resume instead starts a new subscription from today with the same details and leaves the stopped one in history.

## Days and timezones

Calendar days, **Biggest day** and share-card stats are grouped by your account's timezone (**Settings → Profile → Timezone**, `POST /api/account/timezone`; default UTC), so an order placed at 9 pm in New York lands on that day. `GET /api/calendar` returns `{ month, timezone, generatedAt, events }`; without `?month=` it uses the current month in that timezone, and every event `date` is a `YYYY-MM-DD` day in it. Stored timestamps stay in UTC.

## Workspace snapshot

`GET /api/state` returns the whole workspace in one response: `user`, `settings`, `bots` (each with `stats` and `recentOrders`), `emailSources`, every order, `analytics`, `templates` (built-in and custom) and `subscriptions`. The dashboard uses it. Integrations should prefer the paginated endpoints: this response grows with the workspace.

## Troubleshooting

:::expandable{title="Every request returns 401"}
The header must be exactly `Authorization: Bearer <token>`, with the full key including `sk_`. Check the key is still listed under **Settings → Developer**. See [Authentication](https://shippified.net/docs/authentication#when-authentication-fails).
:::

:::expandable{title="My POST fields are ignored or I get \"…is required\""}
Check the body is valid JSON and sent with `Content-Type: application/json`. Invalid JSON arrives as a plain string, so every field looks missing. Field names are case-sensitive (`itemSummary`, not `item_summary`).
:::

:::expandable{title="A status filter returns everything"}
`GET /api/orders` ignores a `status` value it doesn't recognise instead of failing. Use one of `ordered`, `shipped`, `delivered`, `canceled`, `issue`.
:::

:::expandable{title="I get 404 for an ID I can see in the dashboard"}
The token belongs to a different account than the one you're signed in to. Every read is scoped to the token's account, and other accounts' resources return `404`.
:::

:::cards
::card{title="Authentication" href="./authentication"} Tokens, keys and their limits.
::card{title="Orders" href="./orders"} The core resource.
::card{title="Webhooks" href="./webhooks"} Stop polling; get events pushed to you.
:::

---

## For AI agents

- This page for a human reader: https://shippified.net/docs/rest-api
- The whole space as one Markdown file: https://shippified.net/docs/llms-full.txt
- Live search + fetch over MCP: https://shippified.net/docs/_api/public/orgs/5b8789b1-481a-41f5-8e5a-5f30d11f5151/spaces/ae0c5af4-cc84-4899-9078-2faf8e7a6fc5/mcp
  - Install (Claude CLI): `claude mcp add api-docs --transport http https://shippified.net/docs/_api/public/orgs/5b8789b1-481a-41f5-8e5a-5f30d11f5151/spaces/ae0c5af4-cc84-4899-9078-2faf8e7a6fc5/mcp`

This Markdown is the same content the page renders — safe to quote and to ground answers in.
