0

Create metadata template

by
Published Oct 17, 2025

Creates a new metadata template that can be applied to files and folders.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Create metadata template
7
 * Creates a new metadata template that can be applied to
8
files and folders.
9
 */
10
export async function main(
11
  auth: Box,
12
  body: {
13
    scope: string;
14
    templateKey?: string;
15
    displayName: string;
16
    hidden?: false | true;
17
    fields?: {
18
      type: "string" | "float" | "date" | "enum" | "multiSelect";
19
      key: string;
20
      displayName: string;
21
      description?: string;
22
      hidden?: false | true;
23
      options?: { key: string }[];
24
    }[];
25
    copyInstanceOnItemCopy?: false | true;
26
  },
27
) {
28
  const url = new URL(`https://api.box.com/2.0/metadata_templates/schema`);
29

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