0

List legal hold policy assignments

by
Published Oct 17, 2025

Retrieves a list of items a legal hold policy has been assigned 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
 * List legal hold policy assignments
7
 * Retrieves a list of items a legal hold policy has been assigned to.
8
 */
9
export async function main(
10
  auth: Box,
11
  policy_id: string | undefined,
12
  assign_to_type: "file" | "file_version" | "folder" | "user" | undefined,
13
  assign_to_id: string | undefined,
14
  marker: string | undefined,
15
  limit: string | undefined,
16
  fields: string | undefined,
17
) {
18
  const url = new URL(`https://api.box.com/2.0/legal_hold_policy_assignments`);
19
  for (const [k, v] of [
20
    ["policy_id", policy_id],
21
    ["assign_to_type", assign_to_type],
22
    ["assign_to_id", assign_to_id],
23
    ["marker", marker],
24
    ["limit", limit],
25
    ["fields", fields],
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