0

Update a shortcut

by
Published Oct 17, 2025

Updates a shortcut by 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 a shortcut
7
 * Updates a shortcut by ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    name?: string;
14
    parent?: string;
15
    draft?: { text?: string; template?: string };
16
    payload?: {};
17
    accessTeams?: string[];
18
    accessUsers?: string[];
19
    conversation?: {
20
      tags?: { operator?: "append" | "replace" | "remove"; value?: string[] };
21
      name?: { operator?: "replace" | "remove"; value?: string };
22
      status?: { operator?: "replace" | "remove"; value?: "open" | "done" };
23
      subStatus?: { operator?: "replace" | "remove"; value?: string };
24
      snooze?: { operator?: "replace"; value?: string };
25
      queue?: { operator?: "replace"; value?: {} };
26
      assignedUsers?: {
27
        operator?: "append" | "replace" | "remove";
28
        value?: unknown[];
29
      };
30
      assignedTeams?: {
31
        operator?: "append" | "replace" | "remove";
32
        value?: unknown[];
33
      };
34
      custom?: {};
35
    };
36
    deleted?: false | true;
37
  },
38
) {
39
  const url = new URL(`https://api.kustomerapp.com/v1/shortcuts/${id}`);
40

41
  const response = await fetch(url, {
42
    method: "PUT",
43
    headers: {
44
      "Content-Type": "application/json",
45
      Authorization: "Bearer " + auth.apiKey,
46
    },
47
    body: JSON.stringify(body),
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55