0

List Workspace

by
Published 4 days ago

List the contents (notebooks, folders, files) of a workspace directory. Use "/" for the root.

Script databricks Verified

The script

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

3
/**
4
 * List Workspace
5
 * List the contents (notebooks, folders, files) of a workspace directory. Use "/" for the root.
6
 */
7
export async function main(auth: RT.Databricks, path: string) {
8
  const base = auth.workspace_url.replace(/\/$/, "")
9
  const url = new URL(`${base}/api/2.0/workspace/list`)
10
  url.searchParams.append("path", path)
11

12
  const response = await fetch(url, {
13
    method: "GET",
14
    headers: {
15
      Authorization: `Bearer ${auth.token}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26