0

Get file information

by
Published Oct 17, 2025

Retrieves the details about a file.

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 file information
7
 * Retrieves the details about a file.
8
 */
9
export async function main(
10
  auth: Box,
11
  file_id: string,
12
  fields: string | undefined,
13
  if_none_match: string,
14
  boxapi: string,
15
  x_rep_hints: string,
16
) {
17
  const url = new URL(`https://api.box.com/2.0/files/${file_id}`);
18
  for (const [k, v] of [["fields", fields]]) {
19
    if (v !== undefined && v !== "" && k !== undefined) {
20
      url.searchParams.append(k, v);
21
    }
22
  }
23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      "if-none-match": if_none_match,
27
      boxapi: boxapi,
28
      "x-rep-hints": x_rep_hints,
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39