0

List Jobs

by
Published 4 days ago

List jobs defined in the workspace. Filter by name and paginate with page_token (next_page_token is in the response).

Script databricks Verified

The script

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

3
/**
4
 * List Jobs
5
 * List jobs defined in the workspace. Filter by name and paginate with page_token (next_page_token is in the response).
6
 */
7
export async function main(
8
  auth: RT.Databricks,
9
  name: string | undefined,
10
  limit: number | undefined,
11
  expand_tasks: boolean | undefined,
12
  page_token: string | undefined
13
) {
14
  const base = auth.workspace_url.replace(/\/$/, "")
15
  const url = new URL(`${base}/api/2.2/jobs/list`)
16
  if (name !== undefined && name !== "") url.searchParams.append("name", name)
17
  if (limit !== undefined) url.searchParams.append("limit", String(limit))
18
  if (expand_tasks !== undefined)
19
    url.searchParams.append("expand_tasks", String(expand_tasks))
20
  if (page_token !== undefined && page_token !== "")
21
    url.searchParams.append("page_token", page_token)
22

23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      Authorization: `Bearer ${auth.token}`,
27
      Accept: "application/json",
28
    },
29
  })
30

31
  if (!response.ok) {
32
    throw new Error(`${response.status} ${await response.text()}`)
33
  }
34

35
  return await response.json()
36
}
37