0

Starts workflow based on request body

by
Published Oct 17, 2025

Initiates a flow with a trigger type of `WORKFLOW_MANUAL_START`. You application must be authorized to use the `Manage Box Relay` application scope within the developer console.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Starts workflow based on request body
7
 * Initiates a flow with a trigger type of `WORKFLOW_MANUAL_START`.
8

9
You application must be authorized to use the `Manage Box Relay` application
10
scope within the developer console.
11
 */
12
export async function main(
13
  auth: Box,
14
  workflow_id: string,
15
  body: {
16
    type?: "workflow_parameters";
17
    flow: { type?: string; id?: string };
18
    files: { type?: "file"; id?: string }[];
19
    folder: { type?: "folder"; id?: string };
20
    outcomes?: {
21
      id: string;
22
      collaborators?: {
23
        type: "variable";
24
        variable_type: "user_list";
25
        variable_value: { type: "user"; id: string }[];
26
      } & {};
27
      completion_rule?: {
28
        type: "variable";
29
        variable_type: "task_completion_rule";
30
        variable_value: "all_assignees" | "any_assignees";
31
      } & {};
32
      file_collaborator_role?: {
33
        type: "variable";
34
        variable_type: "collaborator_role";
35
        variable_value:
36
          | ("editor" & {})
37
          | ("viewer" & {})
38
          | ("previewer" & {})
39
          | ("uploader" & {})
40
          | ("previewer uploader" & {})
41
          | ("viewer uploader" & {})
42
          | ("co-owner" & {});
43
      } & {};
44
      task_collaborators?: {
45
        type: "variable";
46
        variable_type: "user_list";
47
        variable_value: { type: "user"; id: string }[];
48
      } & {};
49
      role?: {
50
        type: "variable";
51
        variable_type: "collaborator_role";
52
        variable_value:
53
          | ("editor" & {})
54
          | ("viewer" & {})
55
          | ("previewer" & {})
56
          | ("uploader" & {})
57
          | ("previewer uploader" & {})
58
          | ("viewer uploader" & {})
59
          | ("co-owner" & {});
60
      } & {};
61
    }[];
62
  },
63
) {
64
  const url = new URL(`https://api.box.com/2.0/workflows/${workflow_id}/start`);
65

66
  const response = await fetch(url, {
67
    method: "POST",
68
    headers: {
69
      "Content-Type": "application/json",
70
      Authorization: "Bearer " + auth.token,
71
    },
72
    body: JSON.stringify(body),
73
  });
74
  if (!response.ok) {
75
    const text = await response.text();
76
    throw new Error(`${response.status} ${text}`);
77
  }
78
  return await response.json();
79
}
80