# Keeping in sync

Most integrations keep a copy of some Omono data, for example in a data
warehouse, a reporting tool or a CRM. This guide shows you how to build
that copy, keep it up to date, and remove the records that are deleted in
Omono. Omono doesn't send webhooks, so your integration finds changes by
asking for them, as this guide explains.

Keeping in sync takes three steps:

1. **Load everything once.** Note where Omono's list of deleted records
   currently ends, then read every record.
2. **Poll for changes.** Every few minutes, and not more often than every
   2 minutes, ask each list for the records
   that have changed since your last poll.
3. **Remove deleted records.** Read the events list, `GET /events`, to find
   the records that were deleted in Omono.

The sections below explain each step in turn, and the
[Mirror your data in another system](/docs/recipes/mirror-data) recipe
puts all three together.

## Load everything the first time

1. Call `GET /events?limit=1` and save the `latestSequence` from the
   response. This is where you'll start reading deleted records, so any
   record deleted while your load runs is still caught.
2. Read every record in each list you want to copy, starting from the
   beginning of time:

   ```http
   GET /api/v1/<list>?updated_since=1970-01-01T00:00:00.000Z&sort=updated&limit=200
   ```

   Add `archived=any` on the lists that take it. Page through the results
   and upsert each record by its `id`, in the same way as a
   [poll for changes](/docs/syncing#incremental-sync).

3. Save the highest `updated` value you saw in each list. From then on,
   poll for changes as usual, starting from that value minus 60 seconds. If
   a list was empty, keep `1970-01-01T00:00:00.000Z` as its mark until a
   record arrives.

> **Warning:** Always take your mark from the `updated` values of records
> you received with `sort=updated`. Never take it from your own clock, or
> from a list in its default order, because you would miss records that
> changed while your load was running.

## Poll for changes

You can poll these lists for changes, with `updated_since` together with
`sort=updated`: companies, quotes, sales orders, dispatches, invoices,
credit notes, purchase orders, deliveries, stock items, tasks and
documents.

Each time you poll one of them:

1. Call `GET /<list>?updated_since=<mark>&sort=updated`, where `<mark>` is
   the time you saved after your last poll. On `/companies`, `/stock-items`
   and `/documents`, also send `archived=any`, so that archived records come
   too. The quote, sales order, dispatch, invoice, purchase order,
   delivery, credit note and task lists always return every record, so
   they don't need it.
2. Page through the results and upsert each record by its `id`. That is,
   update your copy of the record if you have one, and add it if you don't.
3. Save the highest `updated` value you saw. Next time, set `updated_since`
   to that value minus 60 seconds.

For example, if the highest `updated` you saw on companies was
`2026-09-18T10:15:30.123Z`, your next poll of companies is:

```http
GET /api/v1/companies?updated_since=2026-09-18T10:14:30.123Z&sort=updated&archived=any&limit=200
```

The 60-second overlap matters. A change can become visible a few seconds
after the time in its `updated` field, so if you started exactly at your
last mark, you could miss it. Because of the overlap, you'll see some
records twice, so always upsert, and never insert a record without checking
for your copy first.

> **Warning:** Never filter a poll for changes on a field that can change,
> such as a sales order's `status` or a stock item's `canSell`. A record
> that changes so that it no longer matches the filter drops out of every
> later poll, and your copy keeps its old values for good. Poll the whole
> list, and filter your own copy instead. This is also why you send
> `archived=any`. A filter on a field that never changes, such as a sales
> order's `companyId`, is safe.

A record can also come back with no change that you can see, because Omono
updated one of its fields that the API doesn't show. For example, when you
add a stock item to an assembly's `bom`, or take it out, the stock item's
`updated` time changes too. Compare it with your
copy before you act on it, for example before you send a notification about
it.

Addresses belong to a company, and they don't accept `updated_since`.
Instead, any change to an address also changes the company's `updated`
time. So when a company comes back in your poll, read its addresses again
through it, with `include`, as
[Include related records](/docs/reading#include) describes. For example, a
CRM keeps its addresses in step by polling
`GET /companies?updated_since=<mark>&sort=updated&archived=any&include=addresses`.

Contacts belong to a company too, but you can poll all of them directly
with [List contacts](/docs#tag/contacts/GET/contacts), as
`GET /contacts?updated_since=<mark>&sort=updated&archived=any`. A change to
a contact also changes its company's `updated` time, so polling the
companies with `include=contacts` still works.

Dispatches and deliveries work the same way: a change to a dispatch also
changes its sales order's `updated` time, and a change to a delivery its
purchase order's, and you can poll all of them directly with
[List all dispatches](/docs#tag/dispatches/GET/dispatches) and
[List all deliveries](/docs#tag/deliveries/GET/deliveries).

Sales order line items are different. You can read all of them with
[List all sales order lines](/docs#tag/sales-orders/GET/sales-order-lines),
which suits reports, but don't keep a copy of your orders from it. A line
item that staff remove is gone from that list, and `GET /events` doesn't
report it: only its order's `updated` time changes. So keep line items in
step through the sales orders: poll
`GET /sales-orders?updated_since=<mark>&sort=updated&include=lineItems`,
and replace your copy of each order's line items with the ones it returns.

### Reference lists

The reference lists, such as tax rates, currencies, users and workflow
statuses, work differently. Their records have no `updated` time, they
don't take `updated_since` or `sort`, and they never appear in
`GET /events`. To keep a copy of one, read the whole list, with
`archived=any` on the lists that take it, and replace your copy with what
you receive. The lists change rarely, so refresh them every hour or once
a day rather than on every poll, which keeps you well inside your daily
request limit. Start your polls and refreshes at a random second, not on
the hour, as [Spread your polls over time](/docs/limits#spread-polls)
explains.

## Find deleted records

A record that's deleted in Omono no longer comes back in a poll, so on its
own your poll would keep it in your copy forever. `GET /events` lists these
deleted records for you. Each event looks like this:

```json
{
  "id": "Zq8mTbN4xWc2RkPfJ",
  "sequence": 1042,
  "resource": "sales_order_line_items",
  "resourceId": "aK3nMh2PqXwYbTzWc",
  "parentId": "bT7pQx4RmN2sWvZyK",
  "op": "deleted",
  "at": "2026-09-18T10:15:30.123Z"
}
```

`resource` is the kind of record that was deleted, such as `companies` or
`sales_order_line_items`, and `resourceId` is its ID. `parentId` is the ID
of the record it belonged to, such as the sales order for a sales order line
item, or `null` for a record that doesn't belong to another one. `op` says
what happened to the record, and `at` is the time it happened.

Today, `deleted` is the only `op`. Act only on events whose `op` is
`deleted`, and skip any other value. If Omono adds another kind of event,
such as `updated`, you'll get it only if you ask for it with the `op`
filter, so the events you get without that filter won't change.

To read the events:

1. Call `GET /events?since=<sequence>`, where `<sequence>` is the one you
   saved last time. If you only want some kinds of record, add `resource=`
   with a comma-separated list, for example
   `resource=companies,contacts`.
2. For each event whose `op` is `deleted`, delete your copy of the record
   that its `resource` and `resourceId` name.
3. Save the `nextSince` value from the response as your new sequence. Do
   this even when the page is empty, because `nextSince` also moves past
   events your key can't see.
4. While `hasMore` is `true`, call again straight away.

While `hasMore` is `true`, you can also send the response's `nextCursor` as
`cursor` instead of `nextSince` as `since`, in the same way as on any other
list. Send one or the other, never both. On the last page `nextCursor` is
`null`, so always save `nextSince` for your next poll. If Omono refuses a
cursor with a `422` error, poll again with `since` set to the `nextSince`
of the page that returned the cursor, which holds the same position.

Events are kept for 30 days. If your saved sequence is older than that, or
comes from before a sandbox reset or a restore, the request fails with a
`410` error and the code `events-expired`. It fails the same way if the
events after your sequence are removed for age while the request runs. The
response includes a `latestSequence`. When that happens, do the
[initial load](/docs/syncing#initial-load) again, then continue reading events from that
`latestSequence`.

### Tasks are the exception

Omono also writes a `tasks` event when someone makes a task private,
because the API can't see private tasks. If the task is made public again,
it comes back with the same ID. So when you get a `tasks` event, call
`GET /tasks/{id}` first. If you get a `404`, delete your copy. If you get a
`200`, upsert the task instead. Today, tasks are the only records that can
come back after an event.

### Archiving isn't deleting

Archiving a record doesn't create an event. If you poll with
`archived=any`, archiving or unarchiving a record reaches you as an
ordinary update, with its `archived` field changed.

Deleting a document is the same: Omono archives the document rather than
removing it, so it reaches you as an update with `archived` set to `true`.
A `documents` event is written only when Omono removes a document for
good, which happens when the quote, sales order, credit note or purchase
order it's attached to is deleted.

## Keep your copy accurate

- **Replace line items as a whole.** Each time you read a quote, sales
  order, credit note, purchase order, dispatch or delivery, replace all of
  its `lineItems` in your copy with the ones you received. Don't merge them
  line by line, because Omono can remove dispatch and delivery lines without
  writing a delete event.
- **Expect new line IDs on a new quote revision.** Staff can make a new
  revision of a quote in Omono, for example when the customer asks for a
  change. The API shows one revision of each quote: the won revision of a
  won quote, and the latest revision of any other quote. When staff make a
  new revision, every line gets a new ID, and the old lines disappear
  without delete events.
- **Read live fields again before you act on them.** A few fields are
  worked out each time you read the record, so they can change without
  changing its `updated` time. A dispatch's `legalTransitions`, and the
  `blockedBy` list in each of them, change when someone creates or closes
  a task that blocks shipping, or changes the customer. Keep them in your
  copy if you like, but read the order again just before you move a
  dispatch. A read of a sales order with `include=dispatches` always
  returns the whole order, even when you send `If-None-Match`, so you
  always get the live values.
- **Read notes from the notes list.** Adding a note, in Omono or through
  the API, doesn't change its record's `updated` time, so polling the
  record's list with `updated_since` doesn't find a new note. To keep a copy
  of a record's notes, read the record's notes list, such as
  [`GET /quotes/{id}/notes`](/docs#tag/notes/GET/quotes/{id}/notes), with
  `created_gte` set to the `created` time of the newest note you have, as
  [Read a record's notes](/docs/reading#notes) explains.
- **Ignore what you don't recognise.** New fields, and new values in lists
  such as statuses, can be added at any time, so your integration shouldn't
  fail when it meets one. Don't build logic on a list of today's values:
  for example, to leave out cancelled orders, skip the ones whose status is
  `cancelled`, rather than keeping only today's other statuses. The
  [compatibility policy](/docs/compatibility) explains what can change.

## Check your copy now and then

Events are how you learn about deletes, but in rare cases a delete can be
missing from `GET /events`, for example when Omono fails to record its
event. So now and then, for example once a week, check that your copy
holds no record that Omono no longer has:

1. Read every record in each list you copy, as in the
   [initial load](/docs/syncing#initial-load), with `archived=any` on the lists that
   take it, and note the `id` of each one.
2. Remove from your copy any record whose `id` didn't come back.

This costs about as many requests as the initial load, so run it outside
your busiest hours. Records that belong to another record, such as
contacts or line items, come back with their parent through `include`.

## Good to know

- Event sequence numbers have gaps, because you only see events for
  resources your key's scopes can read. Use the event `id` to spot an event
  you've already handled.
- A delete can take about 10 seconds to appear in `GET /events`, because
  Omono holds back events that are less than 10 seconds old. One request
  also checks at most 1,000 events, so a page can end early, or even be
  empty, while `hasMore` is `true`.
- Any read or write scope lets a key read the events list. A write scope
  includes reading, so a key with only `sales:write` sees the same events
  as a key with `sales:read`. A key with only `reference:read` or
  `pricing:read` can't read any kind of record that has events, so it
  always gets an empty list, with `latestSequence` and `nextSince` set to
  the `since` you sent, or 0.
- When an admin changes a key's scopes, your `since` and `nextCursor`
  stay valid, and the next page uses the key's new scopes. If the key can
  now read a kind of record it couldn't before, deletes of those records
  from before your `since` don't come back. Load those lists in full once,
  as in the [initial load](/docs/syncing#initial-load), then carry on from your saved
  mark. If the key can no longer read a kind of record, its deletes stop
  appearing.
- A change to a line item's cost or margin in Omono changes the line
  item's `updated` and its quote's or sales order's `updated`. On a sales
  order it also changes the `updated` of every dispatch of the order, and
  so of its invoices, because Omono works out their totals and costs
  again. So `updated_since` finds these changes. A sync to Xero changes
  the `updated` of the invoice, credit note or delivery it updates.
- Some fields depend on your key or your organisation, not on the record,
  so they can appear or change without changing the record's `updated`,
  and a read with `If-None-Match` can still answer `304`. When an admin
  adds `stock:read` to a key, the costs and margins
  [appear](/docs/reading#costs) on records you read from then on; when it's
  removed, they're left out. When your organisation connects to Xero or
  disconnects, `xero` changes on every invoice, credit note and delivery.
  After such a change, load the affected lists in full once, as in the
  [initial load](/docs/syncing#initial-load), without `If-None-Match`.
- A task that's made private also disappears from `GET /tasks`, as
  [Tasks are the exception](/docs/syncing#tasks-are-the-exception) explains.
- A sync can run into a deploy of a new version of Omono, when the API is
  unavailable for a few minutes. Keep retrying, as
  [Planned maintenance](/docs/errors#planned-maintenance) explains, then
  carry on from your saved mark.
