0

Create metadata cascade policy

by
Published Oct 17, 2025

Creates a new metadata cascade policy that applies a given metadata template to a given folder and automatically cascades it down to any files within that folder. In order for the policy to be applied a metadata instance must first be applied to the folder the policy is to be applied to.

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 cascade policy
7
 * Creates a new metadata cascade policy that applies a given
8
metadata template to a given folder and automatically
9
cascades it down to any files within that folder.
10

11
In order for the policy to be applied a metadata instance must first
12
be applied to the folder the policy is to be applied to.
13
 */
14
export async function main(
15
  auth: Box,
16
  body: {
17
    folder_id: string;
18
    scope: "global" | "enterprise";
19
    templateKey: string;
20
  },
21
) {
22
  const url = new URL(`https://api.box.com/2.0/metadata_cascade_policies`);
23

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