0

Create task

by
Published Oct 17, 2025

Creates a single task on a file. This task is not assigned to any user and will need to be assigned separately.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Create task
7
 * Creates a single task on a file. This task is not assigned to any user and
8
will need to be assigned separately.
9
 */
10
export async function main(
11
  auth: Box,
12
  body: {
13
    item: { id?: string; type?: "file" };
14
    action?: "review" | "complete";
15
    message?: string;
16
    due_at?: string;
17
    completion_rule?: "all_assignees" | "any_assignee";
18
  },
19
) {
20
  const url = new URL(`https://api.box.com/2.0/tasks`);
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36