0

Create a macro

by
Published Oct 17, 2025
Script gorgias Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gorgias = {
3
  username: string;
4
  apiKey: string;
5
  domain: string;
6
};
7
/**
8
 * Create a macro
9
 *
10
 */
11
export async function main(
12
  auth: Gorgias,
13
  body: {
14
    external_id?: string;
15
    name: string;
16
    intent?:
17
      | "discount/request"
18
      | "exchange/request"
19
      | "exchange/status"
20
      | "feedback"
21
      | "order/damaged"
22
      | "order/cancel"
23
      | "order/change"
24
      | "order/wrong"
25
      | "other/no_reply"
26
      | "other/question"
27
      | "other/thanks"
28
      | "product/recommendation"
29
      | "product/question"
30
      | "refund/request"
31
      | "refund/status"
32
      | "return/request"
33
      | "return/status"
34
      | "shipping/change"
35
      | "shipping/delivery-issue"
36
      | "shipping/policy"
37
      | "shipping/status"
38
      | "stock/request"
39
      | "subscription/cancel"
40
      | "subscription/change";
41
    language?: string;
42
    actions?: {
43
      description?: string;
44
      arguments: {};
45
      type?: "system" | "user";
46
      name: string;
47
      title: string;
48
    }[];
49
  },
50
) {
51
  const url = new URL(`https://${auth.domain}.gorgias.com/api/macros`);
52

53
  const response = await fetch(url, {
54
    method: "POST",
55
    headers: {
56
      "Content-Type": "application/json",
57
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
58
    },
59
    body: JSON.stringify(body),
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67