0
list schedules with last 20 jobs
One script reply has been approved by the moderators Verified
Created by admin 502 days ago Viewed 9660 times
0
Submitted by admin Typescript (fetch-only)
Verified 502 days ago
1
/**
2
 * list schedules with last 20 jobs
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  page: string | undefined,
8
  per_page: string | undefined
9
) {
10
  const url = new URL(
11
    `${BASE_URL}/api/w/${workspace}/schedules/list_with_jobs`
12
  );
13
  for (const [k, v] of [
14
    ["page", page],
15
    ["per_page", per_page],
16
  ]) {
17
    if (v !== undefined && v !== "") {
18
      url.searchParams.append(k, v);
19
    }
20
  }
21
  const response = await fetch(url, {
22
    method: "GET",
23
    headers: {
24
      Authorization: "Bearer " + WM_TOKEN,
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34