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