Sentry API plumbing shared by every ::sentry::* module: base URL selection (SaaS, region, or self-hosted), authentication, readable errors, query strings, and Link-header cursor pagination. Use json, get-page, and collect-all directly for endpoints the curated modules don't cover.

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

  • token: the auth token for this call
  • org: the organization slug for this call
  • base-url: a self-hosted instance or explicit host. It needs a token in the same opts: sentry.token is never sent to a per-call URL.
  • region: us or de, to call https://{region}.sentry.io. When sentry.base.url is set it needs a token too, since that context token belongs to another instance.

Context Vars

Optional
  • sentry.token
  • sentry.org
  • sentry.base.url
  • sentry.region

Values

DEFAULT_MAX_ITEMS

DEFAULT_MAX_ITEMS: Int 1000

Functions

base-url

fn (): Str

The API root: instance-url() plus /api/0.

Example

root ::sentry::api/base-url()
`${root}/organizations/my-org/`

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

settings {token: "TOKEN", base-url: "https://sentry.io/api/0"}
req ::sentry::api/build-request("PUT", "/organizations/my-org/issues/4501/", {status: "resolved"}, settings)
req.url  // "https://sentry.io/api/0/organizations/my-org/issues/4501/"
req.body  // "{\"status\":\"resolved\"}"

collect-all

fn (path: Str, params: Map): Vec
fn (path: Str, params: Map, max: Int): Vec
fn (path: Str, params: Map, opts: Map): Vec
fn (path: Str, params: Map, max: Int, opts: Map): Vec

Every item of a list endpoint at path (with params), following cursors up to max items (default 1000).

Example

repos ::sentry::api/collect-all("/organizations/my-org/repos/", {per_page: 100})
length(repos)

// Stop after 250 items
::sentry::api/collect-all("/organizations/my-org/repos/", {per_page: 100}, 250)

collect-pages

fn (fetch: Fn, params: Map, max: Int): Vec

Walk a cursor-paginated list: call fetch(params) (returning a Page) and follow next_cursor until the last page or max items. Pages are fetched serially.

Example

fetch (params) { ::sentry::api/org-page("/repos/", params) }
repos ::sentry::api/collect-pages(fetch, {per_page: 100}, 500)
length(repos)

error-message

fn (status: Int, body: Any): Str

One readable line from a failed response: detail, else field errors (version: This field is required.), else the text body, else HTTP <status>.

Example

::sentry::api/error-message(404, {detail: "Not found"})  // "Not found"
::sentry::api/error-message(400, {version: ["This field is required."]})  // "version: This field is required."
::sentry::api/error-message(502, "")  // "HTTP 502"

get-page

fn (path: Str, params: Map): Page
fn (path: Str, params: Map, opts: Map): Page

GET one page of a list endpoint: path plus params (including cursor) as the query string. Returns a Page.

Example

page ::sentry::api/get-page("/organizations/my-org/repos/", {})
page.items

instance-url

fn (): Str
fn (base-url: Str?, region: Str?): Str

The Sentry host to call: sentry.base.url when set (self-hosted, or an explicit region host), else https://{sentry.region}.sentry.io when sentry.region is set (us, de), else https://sentry.io. The 2-arity form takes the values explicitly (null for unset).

Example

::sentry::api/instance-url(null, "DE")  // "https://de.sentry.io"
::sentry::api/instance-url("https://sentry.acme.test/", null)  // "https://sentry.acme.test"

json

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

Like request, but return the decoded JSON body (null for 204).

Example

org ::sentry::api/json("GET", "/organizations/my-org/", "")
org.name
fn (headers: Map, relation: Str): Str?

The cursor of the relation entry ("next" or "previous") when it has results="true", else null.

Example

headers {link: `<https://sentry.io/api/0/projects/?cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"`}
::sentry::api/link-cursor(headers, "next")  // "0:100:0"
::sentry::api/link-cursor(headers, "previous")  // null

next-cursor

fn (headers: Map): Str?

The cursor for the next page from a response's headers, or null on the last page.

Example

::sentry::api/next-cursor({link: `<https://sentry.io/api/0/projects/?cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"`})  // "0:100:0"
::sentry::api/next-cursor({link: `<https://sentry.io/api/0/projects/?cursor=0:100:0>; rel="next"; results="false"; cursor="0:100:0"`})  // null

org

fn (): Str
fn (opts: Map): Str

The org in opts, else the sentry.org organization slug, or an Err carrying ConfigError when it is unset. An org in opts that is blank or null is an Err too.

Example

::sentry::api/org({org: "my-org"})  // "my-org"

org-json

fn (method: Str, suffix: Str): Any
fn (method: Str, suffix: Str, body: Any): Any
fn (method: Str, suffix: Str, body: Any, opts: Map): Any

json against an organization-scoped path (suffix follows /organizations/{org}).

Example

repos ::sentry::api/org-json("GET", "/repos/")
map(repos, %.name)

// Another organization for this call
::sentry::api/org-json("GET", "/repos/", "", {token: ::hot::ctx/get("tenant-b.sentry.token"), org: "tenant-b"})

org-page

fn (suffix: Str, params: Map): Page
fn (suffix: Str, params: Map, opts: Map): Page

get-page against an organization-scoped path.

Example

page ::sentry::api/org-page("/repos/", {per_page: 50})
page.items
page.next_cursor

org-path

fn (suffix: Str): Str
fn (suffix: Str, opts: Map): Str

/organizations/{org} plus suffix, or an Err when the organization is unset (see org).

Example

::sentry::api/org-path("/issues/", {org: "my-org"})  // "/organizations/my-org/issues/"
fn (header: Str?): Vec

Parse a Sentry Link header into entries {url, rel, results, cursor}. Sentry sends a previous and a next entry on every list response: <https://…&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0".

Example

link `<https://sentry.io/api/0/projects/?cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"`
first(::sentry::api/parse-link-header(link)).cursor  // "0:100:0"
::sentry::api/parse-link-header(null)  // []

query

fn (params: Map): Str

Build a ?a=1&b=2 suffix from a Map, dropping null values ("" when nothing is left). Vec values repeat the key — Sentry's form for project, environment, and id filters.

Example

::sentry::api/query({project: ["1", "2"], cursor: null})  // "?project=1&project=2"
::sentry::api/query({})  // ""

request

fn (method: Str, path: Str, body: Any): ::hot::http/HttpResponse
fn (method: Str, path: Str, body: Any, token: Str?): ::hot::http/HttpResponse
fn (method: Str, path: Str, body: Any, opts: Map): ::hot::http/HttpResponse

Send an authenticated request to {base-url}{path} with a JSON body ("" for none). Returns the HttpResponse on 2xx, or an Err carrying HttpError / ConfigError. Keeps headers, so callers can read pagination and rate-limit headers.

Example

response ::sentry::api/request("GET", "/organizations/my-org/repos/", "")
response.headers
response.body

// Per-call credentials
::sentry::api/request("GET", "/organizations/tenant-b/repos/", "", {token: ::hot::ctx/get("tenant-b.sentry.token"), org: "tenant-b"})

resolve

fn (opts: Map): Map

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

Example

::sentry::api/resolve({token: "sntrys_tenant_b", region: "de"}).base-url  // "https://de.sentry.io/api/0"
Context Vars: sentry.token, sentry.org, sentry.base.url, sentry.region

resolve-from

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

The one resolver, pure: {token, org, base-url} for a call from opts first, then ctx-values (a Map of context variables), then defaults. base-url is the API root. An Err carrying ConfigError when no token is set, when token or org is in opts but blank or null (that never falls back to context), when opts has base-url without token, or when its region is malformed or would send a self-hosted sentry.token to sentry.io. org may stay null: organization-scoped calls check it. Exposed for testing; resolve feeds it the context.

Example

settings ::sentry::api/resolve-from({region: "de"}, {"sentry.token": "TOKEN", "sentry.org": "my-org"})
settings.base-url  // "https://de.sentry.io/api/0"
settings.org  // "my-org"

seg

fn (value: Any): Str

URL-encode one path segment (issue ids, release versions, project slugs).

Example

::sentry::api/seg("my api")  // "my%20api"

to-page

fn (response: ::hot::http/HttpResponse): Page

Turn a list response into a Page (items plus Link-header cursors).

Example

response ::hot::http/HttpResponse({
  status: 200,
  headers: {link: `<https://sentry.io/api/0/projects/?cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"`},
  body: [{id: "1"}]
})
page ::sentry::api/to-page(response)
page.items  // [{id: "1"}]
page.next_cursor  // "0:100:0"

Types

ConfigError

ConfigError type {
    message: Str
}

Missing configuration (no token or organization). Returned as an Err before any request is sent.

HttpError

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

A non-2xx Sentry response. message is Sentry's detail (or its field errors joined into one line), else the text body, else HTTP <status>.

Page

Page type {
    items: Vec,
    next_cursor: Str?,
    prev_cursor: Str?,
    headers: Map
}

One page of a list endpoint. items is the page; next_cursor is the cursor for the following page, or null on the last page (Sentry's results="false"). Pass it back as cursor to continue.