Skip to content

Ruza Drive / Guides

Change feed

Keep a tool in sync with a Ruza drive: initial snapshot, cursor, changes applied in order, recovery after a 410 error.

How it works

GET /changes tells everything that happens to the drive: creations, changes, moves, trashing, permanent deletions. Every answer returns an opaque cursor; the next request sends it back and gets what follows. A backup or sync tool never has to walk the whole drive again.

The feed covers the whole account: a key restricted to a folder cannot call it (403 folder_restricted). It needs the drive.files:read permission.

First synchronisation

Without a cursor, the feed starts with a snapshot of the live tree, in pages: every entry comes as upserted. While has_more is true, call again with the cursor received. When has_more turns false, your copy is complete: keep that last cursor, it marks where to resume.

get/changes
curl "https://api.ruzagency.com/drive/v1/changes" \
  -H "Authorization: Bearer rza_YOUR_KEY"
{
  "changes": [
    {
      "seq": 4211,
      "change": "upserted",
      "entry_id": "5f0c8a4e-2d71-4b7e-9a3c-1e2f3a4b5c6d",
      "entry": {
        "id": "5f0c8a4e-2d71-4b7e-9a3c-1e2f3a4b5c6d",
        "parent_id": "b7d24c19-3a5e-4f60-8b21-9c0d1e2f3a4b",
        "kind": "file",
        "name": "Invoice-2026-03.pdf",
        "size": 184320,
        "mtime": "2026-03-02T09:14:00Z",
        "revision": 3,
        "trashed": false
      }
    }
  ],
  "cursor": "c.41f9c2a7d3e85b60",
  "has_more": false
}

Applying changes

  • upserted: the entry exists; create or update it from entry (name, parent folder, size, date, revision; for a file, version_id and content_hash).
  • trashed: the entry went to the trash, with everything inside if it is a folder.
  • purged: the entry is permanently deleted; entry is absent.

Apply changes in seq order. A move is an upserted whose parent_id changed, a rename an upserted whose name changed. revision grows with every change: ignore a state older than the one you hold.

Then poll the feed at your own pace, every minute for instance. An answer without changes is light, but counts as one request in the rate limits.

Starting from now

GET /changes/cursor returns a cursor at the head of the journal, without a snapshot: to react to what happens from now on without copying what exists.

get/changes/cursor
curl "https://api.ruzagency.com/drive/v1/changes/cursor" \
  -H "Authorization: Bearer rza_YOUR_KEY"
{
  "cursor": "c.41f9c2a7d3e85b60"
}

Starting again after a 410

The journal does not go back forever. Two 410 answers ask to start again without a cursor:

  • resync_required: your cursor is older than the journal. Take a new snapshot and compare it with your copy.
  • restored: the drive's catalogue was restored from a backup. Take a new snapshot, and delete nothing on your side that the server lacks: the server may be the one that lost something.

Complete example

A complete sync loop, the key read from an environment variable. loadCursor, saveCursor and apply are yours to write.

const BASE = "https://api.ruzagency.com/drive/v1";
const headers = { Authorization: `Bearer ${process.env.RUZA_API_KEY}` };
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// Your side: where the cursor is kept, and what a change does to your copy.
let cursor = await loadCursor(); // null the first time

for (;;) {
  const url = new URL(`${BASE}/changes`);
  if (cursor) url.searchParams.set("cursor", cursor);
  const response = await fetch(url, { headers });
  if (response.status === 410) {
    cursor = null; // resync_required or restored: start again with a snapshot
    continue;
  }
  if (response.status === 429) {
    await sleep(Number(response.headers.get("Retry-After") ?? "5") * 1000);
    continue;
  }
  if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);

  const page = await response.json();
  for (const change of page.changes) await apply(change); // in order
  cursor = page.cursor;
  await saveCursor(cursor);
  if (!page.has_more) await sleep(60_000); // up to date: look again in a minute
}
Next guideErrors