DataResource API
Updated 2026-11-13
A DataResource holds data an app can use. A Protocol defines the format and operations. A Data Port is a connection declared by the app's Schema. A Binding connects an Instance's Port to a Resource. A Grant defines who may read, write, or connect.
Use a Data Port from an app
Make relative requests from the hosted app's origin. The user needs an app session and access to the Instance.
| Method and path | Purpose |
|---|---|
GET /__ato/data-ports | Read the Schema and its requirements, including each Port's Protocol, access ceiling, declared Operations, and current Binding. |
GET /__ato/data-ports/:port/candidates?access=read | List eligible Resources. Use access=write for editing. Pass next_cursor as after for the next page. |
POST /__ato/data-ports/:port/connect | Connect the Resource selected by the user. Send resource_id, access (read or write), and expected_epoch (the candidate's access_epoch). |
POST /__ato/data-ports/:port/invoke | Run a declared Operation. Send operation, arguments, and idempotency_key. Include expected_binding_id to pin the call to a particular Binding. |
DELETE /__ato/data-ports/:port/connection | Disconnect the current Binding. To check that it has not changed, send its binding_epoch as expected_epoch in JSON. |
A Port with scope: "user" can have a separate Binding for each user of the same Instance. In Task Board, tasks connects to the user's personal data and shared_tasks connects to a collaborative Resource. Each collaborator needs access to the Instance and permission to connect to and operate on the Resource. Operations recheck permissions, so revoking a Grant stops access based on that Grant even after connection.
Invoke an Operation
In Task Board, after connecting shared_tasks, fetch the shared board as shown below. The Operation declaration defines the shape of arguments.
const response = await fetch("/__ato/data-ports/shared_tasks/invoke", {
method: "POST",
credentials: "same-origin",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
operation: "todo_shared_board",
arguments: {},
idempotency_key: crypto.randomUUID(),
}),
});
const body = await response.json();
if (!response.ok) throw new Error(body.error);
const board = body.result;
A read Operation (Observation) returns persisted: false. A committed write (Evolution) returns persisted: true. If a connection failure leaves the outcome of a write unknown, retry with the same input and idempotency_key on the same Binding. Use a new key for each new write.
An operation-only Port can run the Operations declared by the Schema and allowed by the Resource's permissions. An operation-scoped Grant does not allow direct document reads, replacements, or exports through the management API. If a Resource's pinned implementation digest differs from the registered Operation, the call fails with 409 protocol_definition_changed.
Management API
These paths are relative to /v1/data-resources on the API origin. They require an ato.run session and a trusted first-party origin (the API itself or the official ato.run client).
| Method and path | Purpose |
|---|---|
GET / / POST / | List and create Resources for the account. Page through the list with after and next_cursor. For standard creation, provide display_name and optionally document and protocol. |
GET /:resourceId | Read the current document, revision, generation, actor_fence, and access. |
GET /:resourceId/details / GET /:resourceId/export | Read management metadata such as access_epoch, or download a ZIP of an exportable Resource. |
POST /:resourceId/operations | Replace the whole document. Send changes: { kind: "replace", value: … } and operation_id with the last read's actor_fence, revision, generation, and access. The request fields are expected_revision and expected_generation. |
POST /:resourceId/grants | Set a user or Instance Grant. Send subject_kind, subject_id, the four capability flags (can_read, can_write, can_connect, can_manage), and expected_epoch. Include operations to limit the Grant to Operations. |
DELETE /:resourceId/grants/:grantId | Revoke a Grant. Send expected_epoch in JSON. |
GET /instances/:instanceId/requirements | Inspect the Instance's Ports and Bindings. |
GET /instances/:instanceId/ports/:port/candidates / POST /instances/:instanceId/ports/:port/bindings | List eligible Resources or connect one. The management API uses read or read_write. To connect, send resource_id, schema_id, access, and expected_epoch. |
An Instance Grant requires explicit audience confirmation with audience_confirmation: "SHARE_WITH_INSTANCE". For both setting and revoking a Grant, send the Resource's current access_epoch as expected_epoch.
On 409 data_revision_or_authority_conflict, fetch the latest document, check whether the edit still applies, and submit it as a new operation. A 404 data_resource_unavailable can indicate that access has been lost. Check the current Binding, Grant, and the Port's declared Operations.