//native
type Box = {
token: string;
};
/**
* Transfer owned folders
* Move all of the items (files, folders and workflows) owned by a user into
another user's account
Only the root folder (`0`) can be transferred.
*/
export async function main(
auth: Box,
user_id: string,
fields: string | undefined,
notify: string | undefined,
body: { owned_by: { id: string } },
) {
const url = new URL(`https://api.box.com/2.0/users/${user_id}/folders/0`);
for (const [k, v] of [
["fields", fields],
["notify", notify],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"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