1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Update a macro |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | id: string, |
14 | body: { |
15 | external_id?: string; |
16 | name?: string; |
17 | intent?: |
18 | | "discount/request" |
19 | | "exchange/request" |
20 | | "exchange/status" |
21 | | "feedback" |
22 | | "order/damaged" |
23 | | "order/cancel" |
24 | | "order/change" |
25 | | "order/wrong" |
26 | | "other/no_reply" |
27 | | "other/question" |
28 | | "other/thanks" |
29 | | "product/recommendation" |
30 | | "product/question" |
31 | | "refund/request" |
32 | | "refund/status" |
33 | | "return/request" |
34 | | "return/status" |
35 | | "shipping/change" |
36 | | "shipping/delivery-issue" |
37 | | "shipping/policy" |
38 | | "shipping/status" |
39 | | "stock/request" |
40 | | "subscription/cancel" |
41 | | "subscription/change"; |
42 | language?: string; |
43 | actions?: { |
44 | description?: string; |
45 | arguments: {}; |
46 | type?: "system" | "user"; |
47 | name: string; |
48 | title: string; |
49 | }[]; |
50 | }, |
51 | ) { |
52 | const url = new URL(`https://${auth.domain}.gorgias.com/api/macros/${id}/`); |
53 |
|
54 | const response = await fetch(url, { |
55 | method: "PUT", |
56 | headers: { |
57 | "Content-Type": "application/json", |
58 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
59 | }, |
60 | body: JSON.stringify(body), |
61 | }); |
62 | if (!response.ok) { |
63 | const text = await response.text(); |
64 | throw new Error(`${response.status} ${text}`); |
65 | } |
66 | return await response.json(); |
67 | } |
68 |
|