1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Retrieve a survey |
9 | * Retrieve a survey |
10 | */ |
11 | export async function main(auth: Gorgias, id: string) { |
12 | const url = new URL( |
13 | `https://${auth.domain}.gorgias.com/api/satisfaction-surveys/${id}/`, |
14 | ); |
15 |
|
16 | const response = await fetch(url, { |
17 | method: "GET", |
18 | headers: { |
19 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
20 | }, |
21 | body: undefined, |
22 | }); |
23 | if (!response.ok) { |
24 | const text = await response.text(); |
25 | throw new Error(`${response.status} ${text}`); |
26 | } |
27 | return await response.json(); |
28 | } |
29 |
|