0
run flow by path
One script reply has been approved by the moderators Verified
Created by admin 198 days ago Viewed 88 times
0
Submitted by admin Typescript (fetch-only)
Verified 198 days ago
1
/**
2
 * run flow by path
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  path: string,
8
  scheduled_for: string | undefined,
9
  scheduled_in_secs: string | undefined,
10
  parent_job: string | undefined,
11
  job_id: string | undefined,
12
  include_header: string | undefined,
13
  invisible_to_owner: string | undefined,
14
  body: { [k: string]: unknown }
15
) {
16
  const url = new URL(`${BASE_URL}/api/w/${workspace}/jobs/run/f/${path}`);
17
  for (const [k, v] of [
18
    ["scheduled_for", scheduled_for],
19
    ["scheduled_in_secs", scheduled_in_secs],
20
    ["parent_job", parent_job],
21
    ["job_id", job_id],
22
    ["include_header", include_header],
23
    ["invisible_to_owner", invisible_to_owner],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + WM_TOKEN,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.text();
42
}
43