0

List Catalogs

by
Published 4 days ago

List the catalogs in the Unity Catalog metastore the workspace is attached to. Paginate with page_token.

Script databricks Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * List Catalogs
5
 * List the catalogs in the Unity Catalog metastore the workspace is attached to. Paginate with page_token.
6
 */
7
export async function main(
8
  auth: RT.Databricks,
9
  max_results: number | undefined,
10
  page_token: string | undefined
11
) {
12
  const base = auth.workspace_url.replace(/\/$/, "")
13
  const url = new URL(`${base}/api/2.1/unity-catalog/catalogs`)
14
  if (max_results !== undefined)
15
    url.searchParams.append("max_results", String(max_results))
16
  if (page_token !== undefined && page_token !== "")
17
    url.searchParams.append("page_token", page_token)
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: `Bearer ${auth.token}`,
23
      Accept: "application/json",
24
    },
25
  })
26

27
  if (!response.ok) {
28
    throw new Error(`${response.status} ${await response.text()}`)
29
  }
30

31
  return await response.json()
32
}
33