Transport for Attio's v2 API.

Per-call credentials. Every API-calling function in this package takes an optional trailing opts Map, resolved by resolve: opts first, then the attio.api.key context variable, then the defaults. Nothing from opts is written to ctx, so one run can act for many workspaces and parallel flows don't share credentials. An api-key present but blank or null is an error, never a fallback to context.

  • api-key: the access token for this call
  • base-url: another API root, such as a proxy. It needs an api-key in the same opts: attio.api.key is never sent to a per-call URL.

Context Vars

Optional
  • attio.api.key

Functions

blank-credential

fn (opts: Map, names: Vec): Str?

The first of names that opts has but with a blank or null value, else null. Such a key is an error, never a fallback to context: a tenant whose key is missing must not run on the project's credentials.

Example

::attio::api/blank-credential({api-key: " "}, ["api-key"])  // "api-key"
::attio::api/blank-credential({}, ["api-key"])  // null

build-request

fn (method: Str, path: Str, body: Any, resolved: Map): ::hot::http/HttpRequest

The outgoing HttpRequest from resolved settings (see resolve). A "" body sends no Content-Type. Pure; exposed for testing.

Example

req ::attio::api/build-request("GET", "/self", "", {api-key: "key-a", base-url: "https://api.attio.com/v2"})
req.url  // "https://api.attio.com/v2/self"
req.headers  // {Authorization: "Bearer key-a"}

json

fn (method: Str, path: Str): Any
fn (method: Str, path: Str, body: Any): Any
fn (method: Str, path: Str, body: Any, api-key: Str): Any
fn (method: Str, path: Str, body: Any, opts: Map): Any

Make an authenticated Attio request and unwrap: the decoded JSON body on 2xx (Attio wraps payloads in data), or an Err carrying HttpError.

Example

me ::attio::api/json("GET", "/self", "", {api-key: "tenant-b-token"})

resolve

fn (opts: Map): Map

Credentials and settings for one call (see resolve-from). opts values are never written to ctx. A credential from opts is masked in the run's call records.

Example

::attio::api/resolve({api-key: "tenant-b-token"}).base-url  // "https://api.attio.com/v2"
Context Vars: attio.api.key

resolve-from

fn (opts: Map, ctx-values: Map): Map

The one resolver, pure: {api-key, base-url} for a call from opts first, then ctx-values (a Map of context variables), then defaults. An Err when no API key is set, when api-key is in opts but blank or null (that never falls back to context), or when opts has base-url without api-key. Exposed for testing; resolve feeds it the context.

Example

::attio::api/resolve-from({api-key: "key-a"}, {"attio.api.key": "key-b"})  // {api-key: "key-a", base-url: "https://api.attio.com/v2"}
::attio::api/resolve-from({}, {"attio.api.key": "key-b"}).api-key  // "key-b"
is-err(::attio::api/resolve-from({api-key: ""}, {"attio.api.key": "key-b"}))  // true

Types

HttpError

HttpError type {
    status: Int,
    headers: Map,
    body: Any
}