1 | |
2 | type Box = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List workflows |
7 | * Returns list of workflows that act on a given `folder ID`, and |
8 | have a flow with a trigger type of `WORKFLOW_MANUAL_START`. |
9 |
|
10 | You application must be authorized to use the `Manage Box Relay` application |
11 | scope within the developer console in to use this endpoint. |
12 | */ |
13 | export async function main( |
14 | auth: Box, |
15 | folder_id: string | undefined, |
16 | trigger_type: string | undefined, |
17 | limit: string | undefined, |
18 | marker: string | undefined, |
19 | ) { |
20 | const url = new URL(`https://api.box.com/2.0/workflows`); |
21 | for (const [k, v] of [ |
22 | ["folder_id", folder_id], |
23 | ["trigger_type", trigger_type], |
24 | ["limit", limit], |
25 | ["marker", marker], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: "Bearer " + auth.token, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|