0

Get trashed folder

by
Published Oct 17, 2025

Retrieves a folder that has been moved to the trash. Please note that only if the folder itself has been moved to the trash can it be retrieved with this API call. If instead one of its parent folders was moved to the trash, only that folder can be inspected using the [`GET /folders/:id/trash`](e://get_folders_id_trash) API. To list all items that have been moved to the trash, please use the [`GET /folders/trash/items`](e://get-folders-trash-items/) API.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Get trashed folder
7
 * Retrieves a folder that has been moved to the trash.
8

9
Please note that only if the folder itself has been moved to the
10
trash can it be retrieved with this API call. If instead one of
11
its parent folders was moved to the trash, only that folder
12
can be inspected using the
13
[`GET /folders/:id/trash`](e://get_folders_id_trash) API.
14

15
To list all items that have been moved to the trash, please
16
use the [`GET /folders/trash/items`](e://get-folders-trash-items/)
17
API.
18
 */
19
export async function main(
20
  auth: Box,
21
  folder_id: string,
22
  fields: string | undefined,
23
) {
24
  const url = new URL(`https://api.box.com/2.0/folders/${folder_id}/trash`);
25
  for (const [k, v] of [["fields", fields]]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43