1 | |
2 | type Box = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List items in folder |
7 | * Retrieves a page of items in a folder. These items can be files, |
8 | folders, and web links. |
9 |
|
10 | To request more information about the folder itself, like its size, |
11 | use the [Get a folder](#get-folders-id) endpoint instead. |
12 | */ |
13 | export async function main( |
14 | auth: Box, |
15 | folder_id: string, |
16 | fields: string | undefined, |
17 | usemarker: string | undefined, |
18 | marker: string | undefined, |
19 | offset: string | undefined, |
20 | limit: string | undefined, |
21 | sort: "id" | "name" | "date" | "size" | undefined, |
22 | direction: "ASC" | "DESC" | undefined, |
23 | boxapi: string, |
24 | ) { |
25 | const url = new URL(`https://api.box.com/2.0/folders/${folder_id}/items`); |
26 | for (const [k, v] of [ |
27 | ["fields", fields], |
28 | ["usemarker", usemarker], |
29 | ["marker", marker], |
30 | ["offset", offset], |
31 | ["limit", limit], |
32 | ["sort", sort], |
33 | ["direction", direction], |
34 | ]) { |
35 | if (v !== undefined && v !== "" && k !== undefined) { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | boxapi: boxapi, |
43 | Authorization: "Bearer " + auth.token, |
44 | }, |
45 | body: undefined, |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|