//native
type Box = {
token: string;
};
/**
* Get folder information
* 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.
*/
export async function main(
auth: Box,
folder_id: string,
fields: string | undefined,
sort: "id" | "name" | "date" | "size" | undefined,
direction: "ASC" | "DESC" | undefined,
offset: string | undefined,
limit: string | undefined,
if_none_match: string,
boxapi: string,
) {
const url = new URL(`https://api.box.com/2.0/folders/${folder_id}`);
for (const [k, v] of [
["fields", fields],
["sort", sort],
["direction", direction],
["offset", offset],
["limit", limit],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"if-none-match": if_none_match,
boxapi: boxapi,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago