//native
type Box = {
token: string;
};
/**
* Restore web link
* Restores a web link that has been moved to the trash.
An optional new parent ID can be provided to restore the web link to in case
the original folder has been deleted.
*/
export async function main(
auth: Box,
web_link_id: string,
fields: string | undefined,
body: { name?: string; parent?: { id?: string } & {} },
) {
const url = new URL(`https://api.box.com/2.0/web_links/${web_link_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: "POST",
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