0

List retention policy assignments

by
Published Oct 17, 2025

Returns a list of all retention policy assignments associated with a specified retention policy.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * List retention policy assignments
7
 * Returns a list of all retention policy assignments associated with a specified
8
retention policy.
9
 */
10
export async function main(
11
  auth: Box,
12
  retention_policy_id: string,
13
  type: "folder" | "enterprise" | "metadata_template" | undefined,
14
  fields: string | undefined,
15
  marker: string | undefined,
16
  limit: string | undefined,
17
) {
18
  const url = new URL(
19
    `https://api.box.com/2.0/retention_policies/${retention_policy_id}/assignments`,
20
  );
21
  for (const [k, v] of [
22
    ["type", type],
23
    ["fields", fields],
24
    ["marker", marker],
25
    ["limit", limit],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
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