0

Create metadata instance on folder

by
Published Oct 17, 2025

Applies an instance of a metadata template to a folder. In most cases only values that are present in the metadata template will be accepted, except for the `global.properties` template which accepts any key-value pair. To display the metadata template in the Box web app the enterprise needs to be configured to enable **Cascading Folder Level Metadata** for the user in the admin console.

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 instance on folder
7
 * Applies an instance of a metadata template to a folder.
8

9
In most cases only values that are present in the metadata template
10
will be accepted, except for the `global.properties` template which accepts
11
any key-value pair.
12

13
To display the metadata template in the Box web app the enterprise needs to be
14
configured to enable **Cascading Folder Level Metadata** for the user in the
15
admin console.
16
 */
17
export async function main(
18
  auth: Box,
19
  folder_id: string,
20
  scope: "global" | "enterprise",
21
  template_key: string,
22
  body: {},
23
) {
24
  const url = new URL(
25
    `https://api.box.com/2.0/folders/${folder_id}/metadata/${scope}/${template_key}`,
26
  );
27

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