//native
type Box = {
token: string;
};
/**
* Create task
* Creates a single task on a file. This task is not assigned to any user and
will need to be assigned separately.
*/
export async function main(
auth: Box,
body: {
item: { id?: string; type?: "file" };
action?: "review" | "complete";
message?: string;
due_at?: string;
completion_rule?: "all_assignees" | "any_assignee";
},
) {
const url = new URL(`https://api.box.com/2.0/tasks`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago