0

Export Workspace Object

by
Published 4 days ago

Export a notebook or file from the workspace. The returned content is base64-encoded under .content; decode it client-side.

Script databricks Verified

The script

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

3
/**
4
 * Export Workspace Object
5
 * Export a notebook or file from the workspace. The returned content is base64-encoded under .content; decode it client-side.
6
 */
7
export async function main(
8
  auth: RT.Databricks,
9
  path: string,
10
  format: "SOURCE" | "HTML" | "JUPYTER" | "DBC" | "AUTO" = "SOURCE"
11
) {
12
  const base = auth.workspace_url.replace(/\/$/, "")
13
  const url = new URL(`${base}/api/2.0/workspace/export`)
14
  url.searchParams.append("path", path)
15
  url.searchParams.append("format", format)
16

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

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

29
  return await response.json()
30
}
31