0

Update search by ID

by
Published Oct 17, 2025

Updates the definition of an existing saved search by its ID.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update search by ID
7
 * Updates the definition of an existing saved search by its ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    name?: string;
14
    data?: {
15
      queryContext?: string;
16
      and?: {} | {}[];
17
      or?: {} | {}[];
18
      not?: {} | {}[];
19
      sort?: {} | {}[];
20
      fields?: {}[];
21
    };
22
    icon?: string;
23
    badgeColor?: string;
24
    showBadge?: false | true;
25
    position?: number;
26
    routing?: { concurrencyLimit: number; timeout: number };
27
    deleted?: false | true;
28
    defaultVisibility?: "all" | "search" | "autopilot" | "none";
29
    userVisibilities?: {
30
      id?: string;
31
      visibility?: "all" | "search" | "autopilot" | "none";
32
    }[];
33
    teamVisibilities?: {
34
      id?: string;
35
      visibility?: "all" | "search" | "autopilot" | "none";
36
    }[];
37
    private?: false | true;
38
    accessTeams?: string[];
39
    accessUsers?: string[];
40
    externalId?: string;
41
    timeZone?: string;
42
    folderId?: string;
43
  },
44
) {
45
  const url = new URL(
46
    `https://api.kustomerapp.com/v1/customers/searches/${id}`,
47
  );
48

49
  const response = await fetch(url, {
50
    method: "PUT",
51
    headers: {
52
      "Content-Type": "application/json",
53
      Authorization: "Bearer " + auth.apiKey,
54
    },
55
    body: JSON.stringify(body),
56
  });
57
  if (!response.ok) {
58
    const text = await response.text();
59
    throw new Error(`${response.status} ${text}`);
60
  }
61
  return await response.json();
62
}
63