Client

RoamClient is the async HTTP client for the Roam Research API.

Creating a client

use roam_sdk::RoamClient;

let client = RoamClient::new("graph-name", "api-token");

The client is Clone — you can share it across async tasks.

Methods

pull

Fetch an entity by ID or lookup reference using a pull expressionarrow-up-right.

pub async fn pull(
    &self,
    eid: serde_json::Value,
    selector: &str,
) -> Result<PullResponse>

Parameters:

  • eid — entity identifier. Either a direct eid or a lookup ref as an EDN string:

    • json!("[:block/uid \"02-21-2026\"]") — lookup by block UID

    • json!("[:node/title \"My Page\"]") — lookup by page title

  • selector — EDN pull expression selecting which attributes to return

Returns: PullResponse { result: serde_json::Value }

Example:

query

Run a Datalog queryarrow-up-right against the graph.

Parameters:

  • query — Datalog query string with :find and :where clauses

  • args — arguments for :in clause bindings (pass vec![] if none)

Returns: QueryResponse { result: Vec<Vec<serde_json::Value>> }

Each inner Vec is one result row, with values matching the :find variables.

Example:

write

Execute a write operation (create, update, delete, or move a block).

Parameters:

  • action — a WriteAction variant describing the mutation

Example:

See Types for all WriteAction variants.

write_batch

Execute multiple write operations in sequence. Each action is sent as an individual API request, stopping on the first error.

Parameters:

  • actions — a list of WriteAction variants to execute atomically

Example:

Sends each action as a separate API request in order. Stops and returns the error if any request fails.

Authentication

The client sends the API token as a Bearer token in the X-Authorization header on every request. All communication goes over HTTPS via rustls (no OpenSSL needed).

Base URL

Requests go to https://api.roamresearch.com/api/graph/{graph_name}/:

Endpoint
Method

/pull

pull()

/q

query()

/write

write()

Last updated

Was this helpful?