Integration API
The change feed
GET /v1/graphs/{id}/changes?order=asc is every change to a graph after a
sync token, oldest first, with nothing skipped. It takes a session, or a key
holding changes.
| Parameter | Meaning |
|---|---|
order |
must be asc. Without it the route is the app's own history view, which is not for integrations |
since |
a sync token: a listing's syncToken, or a previous page's next |
limit |
1 to 500, default 100 |
wait |
0 to 25 seconds: when there is nothing to read, hold the request until the next change |
{"events": [{"seq": 41, "type": "node.updated", "id": "...", "revision": 17,
"at": 1790000000, "via": "key", "own": false},
{"seq": 42, "type": "edge.created", "id": "...", "src": "...",
"dst": "...", "revision": 18, "at": 1790000004, "via": "app",
"own": false}],
"next": "s1.57.ab12cd34ef56", "hasMore": false, "reset": false}
typeisnode.oredge.followed bycreated,updated,deletedorrestored, or it isgraph.reset. An edge event also hassrcanddst.viaiskey,app(a signed-in person) orsystem(a background job or a device sending the whole graph).ownis true for a change the calling key made itself.- An event carries ids only: no label, no attribute. Fetch what changed with
get_nodes, orlist_edgeswithids. - Read on from
nextwhilehasMoreis true. A page can be empty and still movenext: the changes in it were not yours to see. - Without
sincethe answer is empty, withnextat the current position. The feed never replays history to a first-time reader.
How to follow a graph#
- List it (
list_nodes, andlist_edgesif you keep relationships). Keep thesyncTokenof the first page. - Read the feed from that token. Store
nextafter each page you have applied. - Treat
node.createdandnode.updatedalike: fetch the node and store it.node.updatedcan be the first event you see for a node, because it moved into your groups. - When a node event names an id you do not hold yet, also list its edges
with
list_edges {"node": "<id>"}. The edges it brings into your reach were created before you could see both ends, and no edge event announces them. Do the same afternode.deletedandnode.restored: a node takes its edges with it and brings them back, without an event for each. - Treat
node.deletedfor an id you do not hold as nothing. - On
reset: true, list again from the start and carry on from the newsyncToken(or thenextof the reset answer). - Delivery is at least once and in order. Tell events apart by
seq.
token = sync_token # from the first page of the listing
while True:
page = get(f"/v1/graphs/{GRAPH}/changes?order=asc&since={token}&wait=25")
if page["reset"]:
relist() # step 1 again
token = page["next"]
continue
for event in page["events"]:
apply(event)
token = page["next"] # persist it once the page is applied
Reset#
reset is true in two cases, and both mean "list again":
- The token cannot be followed. The answer has no events and
nextis the current position. This happens when your reach changed (a group gained or lost, a tool added to the key), when the change log was pruned past the token, when the graph was unpublished and published again or moved into an organisation, and for a token the server did not hand to your scope. - The page holds a
graph.resetevent: the whole graph was replaced at once (a first publish, or a publish too large to list change by change).
What you are shown#
Visibility is decided when you read, on your scope as it is then.
- A node's event, when you read the node in full now.
- A node that has left your reach (moved out of your groups, or removed) is
shown once more as
node.deleted. A node that was never in your reach is not shown at all. - An edge's event, when you read both its ends in full.
- A key that sees nodes as existing only (
level: listed) receives no node events. - Links the server derives from a node's text are never in the feed; the node's own event covers them.
After a wait, the server checks the caller again. A key revoked or expired
while it waited is told so (403 revoked, 401 key_expired) and is not
handed events.