0

Update collaboration

by
Published Oct 17, 2025

Updates a collaboration. Can be used to change the owner of an item, or to accept collaboration invites.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Update collaboration
7
 * Updates a collaboration.
8
Can be used to change the owner of an item, or to
9
accept collaboration invites.
10
 */
11
export async function main(
12
  auth: Box,
13
  collaboration_id: string,
14
  body: {
15
    role:
16
      | "editor"
17
      | "viewer"
18
      | "previewer"
19
      | "uploader"
20
      | "previewer uploader"
21
      | "viewer uploader"
22
      | "co-owner"
23
      | "owner";
24
    status?: "pending" | "accepted" | "rejected";
25
    expires_at?: string;
26
    can_view_path?: false | true;
27
  },
28
) {
29
  const url = new URL(
30
    `https://api.box.com/2.0/collaborations/${collaboration_id}`,
31
  );
32

33
  const response = await fetch(url, {
34
    method: "PUT",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47