Edits history of script submission #22648 for ' Export Workspace Object (databricks)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Export Workspace Object
     * Export a notebook or file from the workspace. The returned content is base64-encoded under .content; decode it client-side.
     */
    export async function main(
      auth: RT.Databricks,
      path: string,
      format: "SOURCE" | "HTML" | "JUPYTER" | "DBC" | "AUTO" = "SOURCE"
    ) {
      const base = auth.workspace_url.replace(/\/$/, "")
      const url = new URL(`${base}/api/2.0/workspace/export`)
      url.searchParams.append("path", path)
      url.searchParams.append("format", format)
    
      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