0

Update folder

by
Published Oct 17, 2025

Updates a folder. This can be also be used to move the folder, create shared links, update collaborations, and more.

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 folder
7
 * Updates a folder. This can be also be used to move the folder,
8
create shared links, update collaborations, and more.
9
 */
10
export async function main(
11
  auth: Box,
12
  folder_id: string,
13
  fields: string | undefined,
14
  if_match: string,
15
  body: {
16
    name?: string;
17
    description?: string;
18
    sync_state?: "synced" | "not_synced" | "partially_synced";
19
    can_non_owners_invite?: false | true;
20
    parent?: { id?: string; user_id?: string } & {};
21
    shared_link?: {
22
      access?: "open" | "company" | "collaborators";
23
      password?: string;
24
      vanity_name?: string;
25
      unshared_at?: string;
26
      permissions?: { can_download?: false | true };
27
    } & {};
28
    folder_upload_email?: { access?: "open" | "collaborators" } & {};
29
    tags?: string[];
30
    is_collaboration_restricted_to_enterprise?: false | true;
31
    collections?: { id?: string; type?: string }[];
32
    can_non_owners_view_collaborators?: false | true;
33
  },
34
) {
35
  const url = new URL(`https://api.box.com/2.0/folders/${folder_id}`);
36
  for (const [k, v] of [["fields", fields]]) {
37
    if (v !== undefined && v !== "" && k !== undefined) {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "PUT",
43
    headers: {
44
      "if-match": if_match,
45
      "Content-Type": "application/json",
46
      Authorization: "Bearer " + auth.token,
47
    },
48
    body: JSON.stringify(body),
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56