Events and sync
Stream a file's change events, and get a ticket to sync the CRDT document directly.
Change events (SSE or WebSocket) and the headless CRDT sync ticket (HAPI-05)
Change events of one file, as Server-Sent Events or (with a WebSocket upgrade) JSON text messages
GET/api/v1/files/{fileId}/events
SSE: id: <event id>, event: <type>, data: <Event JSON>, a keep-alive comment every 15 s. WebSocket: one Event per text message. Resume with Last-Event-ID (or since): the events after it from this server's in-memory ring (512 per file), or one resync event when it is gone. A stream that falls 256 events behind is closed with code 4008 (SSE: a final close event {code, reason}); a user token's stream closes with 4001 when the token expires, and with 4003 when the host revokes the user. Events carry ids only, never content.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
fileIdrequired | path | string | The host's file id 1 to 1024 characters. |
Last-Event-ID | header | string | Resume after this event id At most 64 characters. |
since | query | string | Same as Last-Event-ID (the header wins) At most 64 characters. |
types | query | string | Comma-separated event types to receive (default all) |
Responses
101Switching Protocols: Switched to a WebSocket (Upgrade: websocket); each text message is an Event
Body application/json
| Field | Type | Description |
|---|---|---|
idrequired | string | ev_<ulid>; pass the last one back as Last-Event-ID to resume (also the webhook Idempotency-Key) |
typerequired | string | One of edited, commented, mentioned, member.joined, member.left, session.closed, restored, saved, live.embedded, live.removed, automation.ran, automation.failed, resync. |
fileIdrequired | string | - |
atrequired | integer | Unix milliseconds |
datarequired | object | edited {blockIds, removedBlockIds, databaseIds?, boardIds?, by, truncated?, untracked?}; commented {threadId, blockId?, added, by}; mentioned {mentioned, by, blockId?, threadId?}; member.joined {userId, role}; member.left {userId}; session.closed {reason: host|idle}; restored {restoreId, from, by}; saved {version}; live.embedded / live.removed {blockId, type: liveBlock|blockRef, liveFileId, by}; automation.ran {ruleId, runId, trigger, result: done|skipped|stopped, changes, by: "automation:<ruleId>"}; automation.failed {ruleId, runId, trigger, code, httpStatus?}; resync {reason} |
Example
{
"at": 1795550974787,
"data": {
"added": 1,
"blockId": "b_01m87jv4rtkdxymn93jwtx35sk",
"by": [
"u_42"
],
"threadId": "t_01m87jv4sqj5z6jz5q2n5zdtdw"
},
"fileId": "doc_1",
"id": "ev_01m87jv4t3ggvh8n6d6nh38xc0",
"type": "commented"
}200OK: An event stream; each data: line is an Event
Headers
| Header | Description |
|---|---|
RateLimit-Policy | Token buckets that apply: "subject";q=<burst>;w=<seconds to refill>, and "file-writes" on writes |
RateLimit | The bucket closest to empty: "<name>";r=<remaining>;t=<seconds until full> |
Body text/event-stream
string
Example
id: ev_01m87jv4t3ggvh8n6d6nh38xc0
event: commented
data: {"at":1795550974787,"data":{"added":1,"blockId":"b_01m87jv4rtkdxymn93jwtx35sk","by":["u_42"],"threadId":"t_01m87jv4sqj5z6jz5q2n5zdtdw"},"fileId":"doc_1","id":"ev_01m87jv4t3ggvh8n6d6nh38xc0","type":"commented"}
400Bad Request: BAD_INPUT, PATCH_INVALID, CURSOR_INVALID, IDEMPOTENCY_KEY_INVALID, …
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:bad-input",
"title": "Bad Request",
"status": 400,
"detail": "rows[0].values must be an object",
"code": "BAD_INPUT"
}Codes: BAD_INPUT.
401Unauthorized: UNAUTHENTICATED, TOKEN_INVALID, TOKEN_EXPIRED
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:unauthenticated",
"title": "Unauthorized",
"status": 401,
"detail": "missing or wrong credentials",
"code": "UNAUTHENTICATED"
}Codes: UNAUTHENTICATED, TOKEN_INVALID, TOKEN_EXPIRED.
403Forbidden: ROLE_FORBIDDEN, SCOPE_REQUIRED, FILES_REQUIRED
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:scope-required",
"title": "Forbidden",
"status": 403,
"detail": "SCOPE_REQUIRED: comment_add needs canvas:comment",
"code": "SCOPE_REQUIRED"
}Codes: SCOPE_REQUIRED, ROLE_FORBIDDEN, FILES_REQUIRED.
404Not Found: API_OFF, BLOCK_NOT_FOUND, NOT_FOUND, …
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:api-off",
"title": "Not Found",
"status": 404,
"detail": "the API is not enabled for this host ([host.flags] api_v1)",
"code": "API_OFF"
}Codes: API_OFF.
429Too Many Requests: RATE_LIMITED, with Retry-After, RateLimit-Policy and RateLimit
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:rate-limited",
"title": "Too Many Requests",
"status": 429,
"detail": "too many requests (subject limit); retry later",
"code": "RATE_LIMITED"
}Codes: RATE_LIMITED, TOO_MANY_STREAMS.
503Service Unavailable: UNAVAILABLE, ROOM_UNAVAILABLE, with Retry-After
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:unavailable",
"title": "Service Unavailable",
"status": 503,
"detail": "the idempotency store is unavailable; retry",
"code": "UNAVAILABLE"
}Codes: UNAVAILABLE.
Errors
| Status | Code | When |
|---|---|---|
| 400 | BAD_INPUT | The request is not what the operation takes: the body is not a JSON object, a field is missing or has the wrong type, an op, mode, format or event type is unknown, or fileId is longer than 1,024 bytes. detail says which. |
| 429 | TOO_MANY_STREAMS | A server holds at most 100 event streams per file. Close one, or share one stream between your workers. |
Also, like every operation on a file: API_OFF, UNAUTHENTICATED, TOKEN_INVALID, TOKEN_EXPIRED, SCOPE_REQUIRED, ROLE_FORBIDDEN, FILES_REQUIRED, RATE_LIMITED, UNAVAILABLE, INTERNAL.
A ticket for the room WebSocket, so a Yjs-native client syncs the CRDT directly
POST/api/v1/files/{fileId}/sync-token
Answers a session ticket with the caller's effective role (min(scope, host role)). Connect to url (y-websocket protocol) within 60 s; the session ends at expiresAt. Takes no Idempotency-Key: the answer is a credential and is never stored. Cache-Control: no-store.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
fileIdrequired | path | string | The host's file id 1 to 1024 characters. |
Responses
200OK
Headers
| Header | Description |
|---|---|
RateLimit-Policy | Token buckets that apply: "subject";q=<burst>;w=<seconds to refill>, and "file-writes" on writes |
RateLimit | The bucket closest to empty: "<name>";r=<remaining>;t=<seconds until full> |
Body application/json
| Field | Type | Description |
|---|---|---|
ticketrequired | string | - |
roomrequired | string | - |
rolerequired | string | One of view, comment, edit. |
urlrequired | string | WebSocket path to connect to (y-websocket protocol): /v1/collab/{room}?ticket=… |
expiresAtrequired | integer | Unix seconds; the socket closes then (15 min at most, never after the token's exp) |
connectWithinSecsrequired | integer | - |
Example
{
"connectWithinSecs": 60,
"expiresAt": 1795551874,
"role": "edit",
"room": "r_2whbv4nncveupmqu35cywoidfe",
"ticket": "01M87JV4T23GYQ773ZF1WN91VA",
"url": "/v1/collab/r_2whbv4nncveupmqu35cywoidfe?ticket=01M87JV4T23GYQ773ZF1WN91VA"
}401Unauthorized: UNAUTHENTICATED, TOKEN_INVALID, TOKEN_EXPIRED
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:unauthenticated",
"title": "Unauthorized",
"status": 401,
"detail": "missing or wrong credentials",
"code": "UNAUTHENTICATED"
}Codes: UNAUTHENTICATED, TOKEN_INVALID, TOKEN_EXPIRED.
403Forbidden: ROLE_FORBIDDEN, SCOPE_REQUIRED, FILES_REQUIRED
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:scope-required",
"title": "Forbidden",
"status": 403,
"detail": "SCOPE_REQUIRED: comment_add needs canvas:comment",
"code": "SCOPE_REQUIRED"
}Codes: SCOPE_REQUIRED, ROLE_FORBIDDEN, FILES_REQUIRED.
404Not Found: API_OFF, BLOCK_NOT_FOUND, NOT_FOUND, …
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:api-off",
"title": "Not Found",
"status": 404,
"detail": "the API is not enabled for this host ([host.flags] api_v1)",
"code": "API_OFF"
}Codes: API_OFF.
429Too Many Requests: RATE_LIMITED, with Retry-After, RateLimit-Policy and RateLimit
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:rate-limited",
"title": "Too Many Requests",
"status": 429,
"detail": "too many requests (subject limit); retry later",
"code": "RATE_LIMITED"
}Codes: RATE_LIMITED.
503Service Unavailable: UNAVAILABLE, ROOM_UNAVAILABLE, with Retry-After
Body application/problem+json
| Field | Type | Description |
|---|---|---|
typerequired | string | Format uri-reference. |
titlerequired | string | - |
statusrequired | integer | - |
detail | string | - |
coderequired | string | Machine code (BLOCK_NOT_FOUND, STALE_BLOCK, ROLE_FORBIDDEN, …) |
fresh | any | STALE_BLOCK: the current state to retry against |
Other members may appear; ignore the ones you do not know.
Example
{
"type": "urn:opencanvas:problem:unavailable",
"title": "Service Unavailable",
"status": 503,
"detail": "the idempotency store is unavailable; retry",
"code": "UNAVAILABLE"
}Codes: UNAVAILABLE.
Errors
Also, like every operation on a file: API_OFF, UNAUTHENTICATED, TOKEN_INVALID, TOKEN_EXPIRED, SCOPE_REQUIRED, ROLE_FORBIDDEN, FILES_REQUIRED, RATE_LIMITED, UNAVAILABLE, INTERNAL.
Last changed .