0

List trashed items

by
Published Oct 17, 2025

Retrieves the files and folders that have been moved to the trash. Any attribute in the full files or folders objects can be passed in with the `fields` parameter to retrieve those specific attributes that are not returned by default. This endpoint defaults to use offset-based pagination, yet also supports marker-based pagination using the `marker` parameter.

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 trashed items
7
 * Retrieves the files and folders that have been moved
8
to the trash.
9

10
Any attribute in the full files or folders objects can be passed
11
in with the `fields` parameter to retrieve those specific
12
attributes that are not returned by default.
13

14
This endpoint defaults to use offset-based pagination, yet also supports
15
marker-based pagination using the `marker` parameter.
16
 */
17
export async function main(
18
  auth: Box,
19
  fields: string | undefined,
20
  limit: string | undefined,
21
  offset: string | undefined,
22
  usemarker: string | undefined,
23
  marker: string | undefined,
24
  direction: "ASC" | "DESC" | undefined,
25
  sort: "name" | "date" | "size" | undefined,
26
) {
27
  const url = new URL(`https://api.box.com/2.0/folders/trash/items`);
28
  for (const [k, v] of [
29
    ["fields", fields],
30
    ["limit", limit],
31
    ["offset", offset],
32
    ["usemarker", usemarker],
33
    ["marker", marker],
34
    ["direction", direction],
35
    ["sort", sort],
36
  ]) {
37
    if (v !== undefined && v !== "" && k !== undefined) {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "GET",
43
    headers: {
44
      Authorization: "Bearer " + auth.token,
45
    },
46
    body: undefined,
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54