0

Delete Multiple Favorites

Published Oct 17, 2025

Deletes all favorites with the same type for the user.

Script smartsheet Verified

The script

Submitted by hugo697 Bun
Verified 397 days ago
1
//native
2
type Smartsheet = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Delete Multiple Favorites
8
 * Deletes all favorites with the same type for the user.
9
 */
10
export async function main(
11
  auth: Smartsheet,
12
  favoriteType:
13
    | "folder"
14
    | "report"
15
    | "sheet"
16
    | "sight"
17
    | "template"
18
    | "workspace",
19
  objectIds: string | undefined,
20
  x_smar_sc_actor_id?: string,
21
) {
22
  const url = new URL(`${auth.baseUrl}/favorites/${favoriteType}`);
23
  for (const [k, v] of [["objectIds", objectIds]]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "DELETE",
30
    headers: {
31
      ...(x_smar_sc_actor_id
32
        ? { "x-smar-sc-actor-id": x_smar_sc_actor_id }
33
        : {}),
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44