//native
type Smartsheet = {
token: string;
baseUrl: string;
};
/**
* Delete Multiple Favorites
* Deletes all favorites with the same type for the user.
*/
export async function main(
auth: Smartsheet,
favoriteType:
| "folder"
| "report"
| "sheet"
| "sight"
| "template"
| "workspace",
objectIds: string | undefined,
x_smar_sc_actor_id?: string,
) {
const url = new URL(`${auth.baseUrl}/favorites/${favoriteType}`);
for (const [k, v] of [["objectIds", objectIds]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
headers: {
...(x_smar_sc_actor_id
? { "x-smar-sc-actor-id": x_smar_sc_actor_id }
: {}),
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