The official, auto-generated TypeScript client for Sentry's public REST API.
npm install @sentry/apiPass baseUrl and an auth header to each call:
import { listYourOrganizations } from "@sentry/api";
const { data, error } = await listYourOrganizations({
baseUrl: "https://sentry.io",
headers: { Authorization: `Bearer ${process.env.SENTRY_AUTH_TOKEN}` },
});
if (error) throw error;
console.log(data);Auth tokens and base URLs (including self-hosted and region URLs) are documented at https://docs.sentry.io/api/auth/.
Sentry uses cursor-based pagination via Link headers. Every operation in the SDK that accepts a cursor query parameter has three auto-generated typed wrappers:
fetchPage_<operation>(options, cursor?)— fetch a single page; returns{ data, nextCursor?, prevCursor? }.paginateAll_<operation>(options, paginateOptions?)— eagerly fetch all pages, returning the concatenated array. Bounded bymaxPages(default 50) for safety. Available only for endpoints whose 200 response isArray<...>.paginateUpTo_<operation>(options, paginateOptions)— fetch up to a hardlimitof items; suppressesnextCursorwhen the last page is trimmed (so callers resuming pagination won't skip records). Available only for endpoints whose 200 response isArray<...>.
The wrappers manage cursor for you — passing one in query is a type error. Every wrapper's query is also widened with an optional per_page?: number field, since Sentry's pagination framework accepts per_page on every cursor-paginated route at runtime even when the spec omits it.
import { fetchPage_listAnOrganization_sIssues } from "@sentry/api";
const { data, nextCursor } = await fetchPage_listAnOrganization_sIssues({
baseUrl: "https://sentry.io",
headers: { Authorization: `Bearer ${process.env.SENTRY_AUTH_TOKEN}` },
path: { organization_id_or_slug: "my-org" },
query: { collapse: ["stats"], limit: 25 },
});import { paginateAll_listAnOrganization_sProjects } from "@sentry/api";
const projects = await paginateAll_listAnOrganization_sProjects({
baseUrl: "https://sentry.io",
headers: { Authorization: `Bearer ${process.env.SENTRY_AUTH_TOKEN}` },
path: { organization_id_or_slug: "my-org" },
});import { paginateUpTo_listAnOrganization_sIssues } from "@sentry/api";
const { data, nextCursor } = await paginateUpTo_listAnOrganization_sIssues(
{
baseUrl: "https://sentry.io",
headers: { Authorization: `Bearer ${process.env.SENTRY_AUTH_TOKEN}` },
path: { organization_id_or_slug: "my-org" },
query: { limit: 100 },
},
{
limit: 250,
onPage: (fetched, target) => console.log(`fetched ${fetched}/${target}`),
},
);By default, paginateUpTo drops nextCursor if the last fetched page had to be trimmed to fit limit — returning a cursor that points past the trimmed items would cause callers resuming pagination to skip records. For endpoints with no server-side per_page control (e.g. /issues/{id}/events/), pass keepCursorOnOvershoot: true to preserve the cursor; the trimmed-tail items remain reachable via the same cursor on the next call.
nextCursor is also dropped if paginateUpTo reaches maxPages (default 50) before fulfilling limit — raise maxPages to continue paginating.
The same low-level helpers used by the generated wrappers are also exported for advanced use cases:
parseSentryLinkHeader(header)—{ nextCursor?, prevCursor? }unwrapResult(sdkResult, context)— throw-on-error data unwrapunwrapPaginatedResult(sdkResult, context)— same but with cursorsfetchPage,paginateAll,paginateUpTo— generic versions taking a fetcher thunk
The OpenAPI schema is synced from getsentry/sentry. Schema fixes belong there; build/tooling changes belong here.
FSL-1.1-Apache-2.0. See LICENSE.md.