//native
type Box = {
token: string;
};
/**
* Update folder
* Updates a folder. This can be also be used to move the folder,
create shared links, update collaborations, and more.
*/
export async function main(
auth: Box,
folder_id: string,
fields: string | undefined,
if_match: string,
body: {
name?: string;
description?: string;
sync_state?: "synced" | "not_synced" | "partially_synced";
can_non_owners_invite?: false | true;
parent?: { id?: string; user_id?: string } & {};
shared_link?: {
access?: "open" | "company" | "collaborators";
password?: string;
vanity_name?: string;
unshared_at?: string;
permissions?: { can_download?: false | true };
} & {};
folder_upload_email?: { access?: "open" | "collaborators" } & {};
tags?: string[];
is_collaboration_restricted_to_enterprise?: false | true;
collections?: { id?: string; type?: string }[];
can_non_owners_view_collaborators?: false | true;
},
) {
const url = new URL(`https://api.box.com/2.0/folders/${folder_id}`);
for (const [k, v] of [["fields", fields]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"if-match": if_match,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago