//native
/**
* List Catalogs
* List the catalogs in the Unity Catalog metastore the workspace is attached to. Paginate with page_token.
*/
export async function main(
auth: RT.Databricks,
max_results: number | undefined,
page_token: string | undefined
) {
const base = auth.workspace_url.replace(/\/$/, "")
const url = new URL(`${base}/api/2.1/unity-catalog/catalogs`)
if (max_results !== undefined)
url.searchParams.append("max_results", String(max_results))
if (page_token !== undefined && page_token !== "")
url.searchParams.append("page_token", page_token)
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 days ago