graphlife Docs graphlife.app

Integration API

Listing and paging

Three tools read a graph without a search term or a node to start from.

Tool The key's scope must hold Answers
list_nodes list_nodes every node the key can see, in id order, a page at a time
list_edges list_edges every relationship whose two ends the key can see
get_nodes node what node answers, for up to 100 ids in one call

list_nodes and list_edges are in no default set of tools. A key holds them only when they were named in its scope when it was minted, or added later by editing the key. Without them the call answers 403 forbidden. A key that lists can copy out everything it can see; that is what granting it means.

Pages#

POST /v1/live/list_nodes
{"kind": "event", "limit": 200}
{"result": {"nodes": [{"id": "...", "kind": "event", "label": "...",
                       "groups": ["..."], "subtype": "meeting",
                       "props": {}, "createdAt": "..."}],
            "nextCursor": "c1....", "hasMore": true,
            "syncToken": "s1.41.ab12cd34ef56"}}

Page on hasMore and nextCursor only, never on how many rows came back. A page may be short, or empty, with hasMore: true: one call reads at most 10,000 rows, and a filter that matches few of them ends the call before the page is full. Send nextCursor back as cursor, with the same filters, until hasMore is false. On the last page nextCursor is null.

import json, urllib.request

BASE = "https://graphlife.example.com"
KEY = "glk_..."

def call(tool, **args):
    req = urllib.request.Request(
        f"{BASE}/v1/live/{tool}", data=json.dumps(args).encode(), method="POST",
        headers={"authorization": f"Bearer {KEY}",
                 "content-type": "application/json"})
    with urllib.request.urlopen(req) as resp:
        return json.load(resp)["result"]

nodes, cursor, sync_token = [], None, None
while True:
    page = call("list_nodes", kind="event", limit=200,
                **({"cursor": cursor} if cursor else {}))
    sync_token = sync_token or page["syncToken"]   # keep the FIRST page's
    nodes.extend(page["nodes"])
    if not page["hasMore"]:
        break
    cursor = page["nextCursor"]
  • limit defaults to 100. It is capped at the key's own node limit, and at 1,000.
  • The cursor is opaque. It is good for one graph, one tool and one set of filters; anything else answers 400 bad_cursor. If the server's signing secret is changed, cursors stop working: start the listing again.
  • Rows come in id order. A node added during a listing is listed if its id sorts after the page being read. Nothing is listed twice.

Filters#

Tool Filter Meaning
list_nodes kind one kind of node
group a group id the key holds, else 403 group_out_of_scope
subtype needs the node tool
where {"status": "open", "floor": 3}: an exact match on up to 5 top-level attributes, by type (true is not 1). Needs the node tool
props false leaves attributes and dates out of each row
list_edges type, node (either end), src, dst, ids (at most 100)
predicate, where need the node tool
both changedSince a sync token; see below
both limit, cursor, graph graph only when the credential reaches more than one

subtype, predicate and where match on content. Without the node tool they answer 403 forbidden; on an attribute the key's scope redacts they answer 400 bad_args; and they never match a node or edge the key only knows exists.

What a row shows#

The key sees the node Row
in full id, kind, label, groups (those of the node's groups the key holds). With the node tool also subtype, props, validFrom, validTo, createdAt
as existing only id, kind, a masked label, withheld: true
not at all absent

An edge is listed only when neither end is hidden. With an end the key only knows exists it is id, src, dst, type and withheld: true. With both ends in full it adds the dates and, for a key holding node, props and the predicate of a related_to edge.

get_nodes#

POST /v1/live/get_nodes
{"ids": ["a1", "a2", "nope"]}
{"result": {"nodes": [{"id": "a1", "...": "..."}, {"id": "a2", "...": "..."}],
            "missing": ["nope"]}}

One to 100 ids (fewer if the key's own node limit is lower). nodes is in the order you asked; missing holds the ids that do not exist or that the key may not see (the two are not told apart).

Listing only what changed#

Every page carries a syncToken: where the graph's change log stood when the call was made. Keep the one from the first page of a full listing. Later, {"changedSince": "<token>"} lists only what was created or changed since, paged the same way, and its first page gives the next token.

  • list_nodes with changedSince returns the nodes created, changed, regrouped or restored since.
  • list_edges with changedSince returns the edges created, changed or restored since. Deleting or restoring a node removes or returns its edges without listing each one: list that node's edges again with node.
  • Deleted nodes and edges are not listed. Deletions come from the change feed.
  • 409 resync_required means the token can no longer be followed: list again from the start. It is the answer when the key's reach changed (a group gained or lost, a tool added), when the graph was unpublished and published again or moved into an organisation, when the change log has been pruned past the token (30 days by default), when the whole graph was replaced at once after the token, and when more than 20,000 ids changed (error.reason is too_many_changes).

A sync token is opaque. It names a position the server handed out to your scope; a token you build or alter yourself is treated as one that cannot be followed.