1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Create a widget |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | body: { |
14 | context?: "ticket" | "user"; |
15 | deactivated_datetime?: string; |
16 | integration_id?: number; |
17 | order?: number; |
18 | template: {}; |
19 | type: |
20 | | "custom" |
21 | | "http" |
22 | | "magento2" |
23 | | "recharge" |
24 | | "shopify" |
25 | | "smile" |
26 | | "smooch_inside" |
27 | | "yotpo" |
28 | | "klaviyo" |
29 | | "stripe"; |
30 | }, |
31 | ) { |
32 | const url = new URL(`https://${auth.domain}.gorgias.com/api/widgets`); |
33 |
|
34 | const response = await fetch(url, { |
35 | method: "POST", |
36 | headers: { |
37 | "Content-Type": "application/json", |
38 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
39 | }, |
40 | body: JSON.stringify(body), |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|