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_....

ScopeAllows
readread every model
writeread and write every model, define models, promote
read:<model>read one model
write:<model>read and write one model
read_manifestlist models and fields, no rows
eventssend events that start workflows (POST /api/events/v1)
workflowscall workflows (POST /api/workflows/v1/<name>/run)
chatsign the chat widget in as your app's user (POST /api/chat/v1/sessions)
env:dev, env:prodreach 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
}
  • id is yours to choose. Use the source system's own key, so sending a row again updates it instead of adding a copy.
  • document holds the fields. When you write, you can send the fields flat ({"id": "ord_1042", "total": 59.9}) or as {"id", "document": {...}}.
  • owner_id is the app user who owns the row, for models where each member sees only their own rows. Leave it empty for shared content.
  • availability is free, premium or product. With product, product_id names what a member must have bought to see the full row.
  • seqnum increases with every change. It is the cursor for reading changes.
  • Deletes are soft: deleted_at is set and the row leaves synced apps.

Endpoints

MethodPathScopeWhat
GET/manifestreadyour models and their fields
GET/_routesreadthis list, with params, headers and limits
GET/:modelreada page of rows: since, limit (default 500, max 5000), include_deleted, order
GET/:model/:idreadone row
GET/:model/streamreadlive stream of writes (server-sent events)
POST/:modelwritecreate one row (optional Idempotency-Key header)
POST/:model/bulkwriteup to 1,000 upserts and deletes in one call
PUT/:model/:idwritereplace a row that exists (404 if it doesn't)
PATCH/:model/:idwritemerge fields into a row's document
DELETE/:model/:idwritesoft-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> on PUT or PATCH fails with 412 if 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": "..."}:

StatusMeaning
400bad request: unknown env, empty or oversized bulk, bad body
401missing, expired or revoked token
403the token lacks the scope (the message names it, e.g. write:shop_orders)
404no such model or row
409a create with an id that exists
412If-Unmodified-Since-Ms failed
422the Data API refused a model definition (name, field, type)
429rate 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.

  1. Define a model for it once: in the dashboard, with oalo data models create orders_mirror --field total:float --field email, or POST /api/data/v1/models.
  2. Make a token limited to it: oalo tokens create --name shop-mirror --scope write:orders_mirror. Put it in your server's secrets.
  3. 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_no for 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.

Related
Try it on your own Base

Sign up, install the CLI, and deploy your repo in a few minutes.

bring your repo