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