0

Create a shortcut

by
Published Oct 17, 2025

Creates a new shortcut.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Create a shortcut
7
 * Creates a new shortcut.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  body: {
12
    name: string;
13
    parent?: string;
14
    draft?: { text?: string; template?: string };
15
    payload?: {};
16
    accessTeams?: string[];
17
    accessUsers?: string[];
18
    conversation?: {
19
      tags?: { operator?: "append" | "replace" | "remove"; value?: string[] };
20
      name?: { operator?: "replace" | "remove"; value?: string };
21
      status?: { operator?: "replace" | "remove"; value?: "open" | "done" };
22
      subStatus?: { operator?: "replace" | "remove"; value?: string };
23
      snooze?: { operator?: "replace"; value?: string };
24
      queue?: { operator?: "replace"; value?: {} };
25
      assignedUsers?: {
26
        operator?: "append" | "replace" | "remove";
27
        value?: unknown[];
28
      };
29
      assignedTeams?: {
30
        operator?: "append" | "replace" | "remove";
31
        value?: unknown[];
32
      };
33
      custom?: {};
34
    };
35
  },
36
) {
37
  const url = new URL(`https://api.kustomerapp.com/v1/shortcuts`);
38

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