0

List contents of a folder

by
Published Oct 17, 2025

Set `folder_id` to 'root' to list root level contents. Sort order: Folders sorted by name, followed by Clusters sorted by name. Can be used by the following roles assigned at the organization, folder or cluster scope: - ORG_ADMIN - CLUSTER_ADMIN - CLUSTER_OPERATOR_WRITER - CLUSTER_DEVELOPER - FOLDER_ADMIN - FOLDER_MOVER

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 contents of a folder
7
 * Set `folder_id` to 'root' to list root level contents.  Sort order: Folders sorted by name, followed by Clusters sorted by name.
8

9
Can be used by the following roles assigned at the organization, folder or cluster scope:
10
- ORG_ADMIN
11
- CLUSTER_ADMIN
12
- CLUSTER_OPERATOR_WRITER
13
- CLUSTER_DEVELOPER
14
- FOLDER_ADMIN
15
- FOLDER_MOVER
16

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