Sync REST API (server to server)
Read and write your workspace's data from your own server over HTTP: rows, environments, tokens, bulk writes, the live stream, limits, and mirroring.
The Sync REST API reads and writes your workspace's data from your own
server: a backend that mirrors its database into Oalo, a job that imports
orders every night, a service that reads members' bookings. It is plain HTTP and
JSON under https://<workspace>.oalo.ai/api/sync/v1.
It is not for apps on a phone or in a browser. Those use the sync SDK
(sync-api-reference.md), which signs in as the member and keeps a local copy.
A Sync API token reads and writes every member's rows, so it must never be
shipped inside an app.
What a write does
Every write lands in your workspace's data at once and syncs to every connected app on that environment, the same as an edit in the dashboard. The rows show up in the Data browser, in reports, and in bots that use that model.
Two environments
Each workspace has two copies of every model:
- dev, a sandbox for trying things;
- prod (live), which your live apps read.
Pick one with ?env=dev or ?env=prod on any call. The API defaults to
prod, so pass env=dev while you experiment. When dev looks right, promote the
model (POST /api/data/v1/models/<name>/promote, or oalo data promote <name>):
it copies dev rows to prod, replacing prod rows that have the same id.
Dev and prod says which copy bots, tests and loops use.
Tokens
Create a token in the dashboard's Sync API page or with
oalo tokens create --name <what> --scope <scope>. It is shown once. Send it as
Authorization: Bearer oalo_sync_....
| Scope | Allows |
|---|---|
read | read every model |
write | read and write every model, define models, promote |
read:<model> | read one model |
write:<model> | read and write one model |
read_manifest | list models and fields, no rows |
events | send events that start workflows (POST /api/events/v1) |
workflows | call workflows (POST /api/workflows/v1/<name>/run) |
chat | sign the chat widget in as your app's user (POST /api/chat/v1/sessions) |
env:dev, env:prod | reach only that env's data (add it to the others) |
write defines models and promotes them only on a token that isn't locked to
one env: a server app's own OALO_SYNC_TOKEN can't. An unknown scope is
refused.
Give each integration the narrowest scope it needs: a shop mirror needs
write:shop_orders, not write. Tokens can expire and be revoked
(oalo tokens revoke <id>). See tokens-and-credentials.md.
Rows
{
"id": "ord_1042",
"document": { "total": 59.9, "email": "ana@example.com", "status": "paid" },
"owner_id": null,
"availability": "free",
"product_id": null,
"seqnum": 88213,
"last_modified_ms": 1762440000000,
"deleted_at": null
}
idis yours to choose. Use the source system's own key, so sending a row again updates it instead of adding a copy.documentholds the fields. When you write, you can send the fields flat ({"id": "ord_1042", "total": 59.9}) or as{"id", "document": {...}}.owner_idis the app user who owns the row, for models where each member sees only their own rows. Leave it empty for shared content.availabilityisfree,premiumorproduct. Withproduct,product_idnames what a member must have bought to see the full row.seqnumincreases with every change. It is the cursor for reading changes.- Deletes are soft:
deleted_atis set and the row leaves synced apps.
Endpoints
| Method | Path | Scope | What |
|---|---|---|---|
| GET | /manifest | read | your models and their fields |
| GET | /_routes | read | this list, with params, headers and limits |
| GET | /:model | read | a page of rows: since, limit (default 500, max 5000), include_deleted, order |
| GET | /:model/:id | read | one row |
| GET | /:model/stream | read | live stream of writes (server-sent events) |
| POST | /:model | write | create one row (optional Idempotency-Key header) |
| POST | /:model/bulk | write | up to 1,000 upserts and deletes in one call |
| PUT | /:model/:id | write | replace a row that exists (404 if it doesn't) |
| PATCH | /:model/:id | write | merge fields into a row's document |
| DELETE | /:model/:id | write | soft-delete a row |
products and orders are Commerce's own tables and are not reachable here
(see commerce.md), so name your models something else.
Defining models is the Data API, on the same token with write scope:
GET /api/data/v1/models lists them, POST /api/data/v1/models creates one
({"name", "fields": [{"name", "type"}], "owner_field"?}), and
POST /api/data/v1/models/:name/promote copies dev to prod. The full contract
is the OpenAPI spec at https://<workspace>.oalo.ai/api/docs.
Reading changes
Read pages in order with since. Start at since=0; each reply has
next_since and has_more. Keep calling with since=<next_since> while
has_more is true. Save next_since, and next time ask only for what changed:
curl -s "https://acme.oalo.ai/api/sync/v1/shop_orders?env=prod&since=0&limit=500" \
-H "Authorization: Bearer $OALO_SYNC_TOKEN"
Add include_deleted=true to see deletes too, which a mirror needs.
The live stream
GET /:model/stream?since=<seqnum> sends the rows after since as row
events (data: the row), then each write as it happens, named by its operation:
insert, update, delete, or upsert (bulk writes and sources). A write
event's data wraps the row: {"table", "operation", "row_id", "data": <row>, "env", "timestamp", "source"}. Comment lines keep the connection open.
Reconnect with since set to the last seqnum you saw. The stream carries
writes made through this API and sources. When its token is revoked or
expires, the stream sends one invalid_token event and closes; reconnecting
with that token gets 401.
Bulk writes
POST /api/sync/v1/shop_orders/bulk?env=dev
{ "operations": [
{ "op": "upsert", "row": { "id": "ord_1042", "total": 59.9, "status": "paid" } },
{ "op": "delete", "id": "ord_0999" }
] }
Each operation succeeds or fails on its own. The reply lists them:
{"results": [{"op", "id", "ok", "seqnum"?, "error"?}], "all_ok"}. Retry only
the ones with ok: false. An upsert replaces the row's document; to change
one field, use PATCH.
Safe retries and concurrent edits
Idempotency-Key: <your id>on a create makes a retry return the first result instead of creating a second row (kept for 24 hours). Upserts by id are safe to repeat without it.If-Unmodified-Since-Ms: <last_modified_ms>onPUTorPATCHfails with412if someone changed the row since you read it.
Limits and errors
Per token, per minute: 600 reads, 120 writes (a bulk call counts as one write,
so up to 120,000 rows a minute), 60 manifest reads. Every reply carries
x-ratelimit-limit, x-ratelimit-remaining and x-ratelimit-reset (Unix
seconds). Over the limit you get 429; wait until x-ratelimit-reset.
Errors are JSON, usually {"error": {"code", "message"}} or {"error": "..."}:
| Status | Meaning |
|---|---|
| 400 | bad request: unknown env, empty or oversized bulk, bad body |
| 401 | missing, expired or revoked token |
| 403 | the token lacks the scope (the message names it, e.g. write:shop_orders) |
| 404 | no such model or row |
| 409 | a create with an id that exists |
| 412 | If-Unmodified-Since-Ms failed |
| 422 | the Data API refused a model definition (name, field, type) |
| 429 | rate limited |
Mirroring data from another system
Your data can stay where it lives (your own database, a shop, a CRM). Send Oalo the parts you want to see, report on, or use in bots.
- Define a model for it once: in the dashboard, with
oalo data models create orders_mirror --field total:float --field email, orPOST /api/data/v1/models. - Make a token limited to it:
oalo tokens create --name shop-mirror --scope write:orders_mirror. Put it in your server's secrets. - Send rows, keyed by your own ids, one of these ways:
- Write-through: when your app saves a record, also send it to Oalo. Data in Oalo is current to the second.
- Scheduled batch: every few minutes, send what changed since the last
run through
bulk. Simplest to run. - One-off import:
oalo data push orders_mirror orders.csv --id-field order_nofor a file. It batches, waits out the rate limit, and reports rows that failed.
Node, a scheduled batch:
const res = await fetch(`https://acme.oalo.ai/api/sync/v1/orders_mirror/bulk?env=prod`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.OALO_SYNC_TOKEN}`, "Content-Type": "application/json" },
body: JSON.stringify({
operations: changed.map((o) => ({ op: "upsert", row: { id: String(o.id), total: o.total, email: o.email } })),
}),
});
const { results } = await res.json();
const failed = results.filter((r) => !r.ok); // retry these
Python, write-through (a one-row bulk call, because it creates the row or updates
it; PUT only updates a row that exists):
import os, requests
def mirror(order):
r = requests.post(
"https://acme.oalo.ai/api/sync/v1/orders_mirror/bulk?env=prod",
headers={"Authorization": f"Bearer {os.environ['OALO_SYNC_TOKEN']}"},
json={"operations": [{"op": "upsert", "row": {"id": str(order["id"]), "total": order["total"], "email": order["email"]}}]},
timeout=10,
)
r.raise_for_status()
if not r.json()["all_ok"]:
raise RuntimeError(r.json()["results"])
Send up to 1,000 rows per bulk call. To have these writes start workflows,
turn on row events for the model (oalo data events orders_mirror created updated):
each write then fires data.orders_mirror.created or .updated. See
App events. To hear about Oalo's own events (bookings, orders,
forms) on your server, add an event webhook in the dashboard.
From the terminal
The oalo CLI wraps this API: oalo data models, list, get, push,
delete, watch, promote and routes, and oalo tokens. Writes say which
environment they use, and writing to prod needs --env prod. oalo help data
has the details.
How to define your own data tables in Oalo, import a CSV, stage and promote data, and push data in from another system through the Data API.
The six kinds of credential in Oalo, what each one is for, how to create it, and which ones are safe to put in an app.
The mental model behind Oalo's offline-first data sync, its core concepts, and how the TypeScript and Dart client libraries are layered.
The consumer-facing TypeScript and Dart client API for wiring Oalo sync into your app.
How the sync client keeps reading and writing over HTTP when the WebSocket drops, and what you must poll while degraded.
Sign up, install the CLI, and deploy your repo in a few minutes.