0

Add initial classifications

by
Published Oct 17, 2025

When an enterprise does not yet have any classifications, this API call initializes the classification template with an initial set of classifications. If an enterprise already has a classification, the template will already exist and instead an API call should be made to add additional classifications.

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 initial classifications
7
 * When an enterprise does not yet have any classifications, this API call
8
initializes the classification template with an initial set of
9
classifications.
10

11
If an enterprise already has a classification, the template will already
12
exist and instead an API call should be made to add additional
13
classifications.
14
 */
15
export async function main(
16
  auth: Box,
17
  body: {
18
    scope: "enterprise";
19
    templateKey: "securityClassification-6VMVochwUWo";
20
    displayName: "Classification";
21
    hidden?: false | true;
22
    copyInstanceOnItemCopy?: false | true;
23
    fields: {
24
      type: "enum";
25
      key: "Box__Security__Classification__Key";
26
      displayName: "Classification";
27
      hidden?: false | true;
28
      options: {
29
        key: string;
30
        staticConfig?: {
31
          classification?: {
32
            classificationDefinition?: string;
33
            colorID?: number;
34
          };
35
        };
36
      }[];
37
    }[];
38
  },
39
) {
40
  const url = new URL(
41
    `https://api.box.com/2.0/metadata_templates/schema#classifications`,
42
  );
43

44
  const response = await fetch(url, {
45
    method: "POST",
46
    headers: {
47
      "Content-Type": "application/json",
48
      Authorization: "Bearer " + auth.token,
49
    },
50
    body: JSON.stringify(body),
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.json();
57
}
58