0

Add classification to folder

by
Published Oct 17, 2025

Adds a classification to a folder by specifying the label of the classification to add. This API can also be called by including the enterprise ID in the URL explicitly, for example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Add classification to folder
7
 * Adds a classification to a folder by specifying the label of the
8
classification to add.
9

10
This API can also be called by including the enterprise ID in the
11
URL explicitly, for example
12
`/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`.
13
 */
14
export async function main(
15
  auth: Box,
16
  folder_id: string,
17
  body: { Box__Security__Classification__Key?: string },
18
) {
19
  const url = new URL(
20
    `https://api.box.com/2.0/folders/${folder_id}/metadata/enterprise/securityClassification-6VMVochwUWo`,
21
  );
22

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