0

Assign retention policy

by
Published Oct 17, 2025

Assigns a retention policy to an item.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Assign retention policy
7
 * Assigns a retention policy to an item.
8
 */
9
export async function main(
10
  auth: Box,
11
  body: {
12
    policy_id: string;
13
    assign_to: {
14
      type: "enterprise" | "folder" | "metadata_template";
15
      id?: string;
16
    };
17
    filter_fields?: { field?: string; value?: string }[];
18
    start_date_field?: string;
19
  },
20
) {
21
  const url = new URL(`https://api.box.com/2.0/retention_policy_assignments`);
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