0

List service accounts for an organization

by
Published Oct 17, 2025

Sort order: Service account name Can be used by the following roles assigned at the organization scope: - ORG_ADMIN - CLUSTER_ADMIN

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * List service accounts for an organization
7
 * Sort order: Service account name
8

9
Can be used by the following roles assigned at the organization scope:
10
- ORG_ADMIN
11
- CLUSTER_ADMIN
12

13
 */
14
export async function main(
15
  auth: Cockroachdb,
16
  pagination_page: string | undefined,
17
  pagination_limit: string | undefined,
18
  pagination_as_of_time: string | undefined,
19
  pagination_sort_order: "ASC" | "DESC" | undefined,
20
) {
21
  const url = new URL(`https://cockroachlabs.cloud/api/v1/service-accounts`);
22
  for (const [k, v] of [
23
    ["pagination.page", pagination_page],
24
    ["pagination.limit", pagination_limit],
25
    ["pagination.as_of_time", pagination_as_of_time],
26
    ["pagination.sort_order", pagination_sort_order],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45