0

Get folder information

by
Published Oct 17, 2025

Retrieves details for a folder, including the first 100 entries in the folder. Passing `sort`, `direction`, `offset`, and `limit` parameters in query allows you to manage the list of returned [folder items](r://folder--full#param-item-collection). To fetch more items within the folder, use the [Get items in a folder](e://get-folders-id-items) endpoint.

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 folder information
7
 * Retrieves details for a folder, including the first 100 entries
8
in the folder.
9

10
Passing `sort`, `direction`, `offset`, and `limit`
11
parameters in query allows you to manage the
12
list of returned
13
[folder items](r://folder--full#param-item-collection).
14

15
To fetch more items within the folder, use the
16
[Get items in a folder](e://get-folders-id-items) endpoint.
17
 */
18
export async function main(
19
  auth: Box,
20
  folder_id: string,
21
  fields: string | undefined,
22
  sort: "id" | "name" | "date" | "size" | undefined,
23
  direction: "ASC" | "DESC" | undefined,
24
  offset: string | undefined,
25
  limit: string | undefined,
26
  if_none_match: string,
27
  boxapi: string,
28
) {
29
  const url = new URL(`https://api.box.com/2.0/folders/${folder_id}`);
30
  for (const [k, v] of [
31
    ["fields", fields],
32
    ["sort", sort],
33
    ["direction", direction],
34
    ["offset", offset],
35
    ["limit", limit],
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
      "if-none-match": if_none_match,
45
      boxapi: boxapi,
46
      Authorization: "Bearer " + auth.token,
47
    },
48
    body: undefined,
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56