1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Update a survey |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | id: string, |
14 | body: { |
15 | body_text?: string; |
16 | created_datetime?: string; |
17 | customer_id?: number; |
18 | meta?: {}; |
19 | score?: number; |
20 | scored_datetime?: string; |
21 | sent_datetime?: string; |
22 | should_send_datetime?: string; |
23 | ticket_id?: number; |
24 | }, |
25 | ) { |
26 | const url = new URL( |
27 | `https://${auth.domain}.gorgias.com/api/satisfaction-surveys/${id}/`, |
28 | ); |
29 |
|
30 | const response = await fetch(url, { |
31 | method: "PUT", |
32 | headers: { |
33 | "Content-Type": "application/json", |
34 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
35 | }, |
36 | body: JSON.stringify(body), |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|