1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Search for resources |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | body: { |
14 | size?: number; |
15 | type: |
16 | | "agent" |
17 | | "customer" |
18 | | "customer_profile" |
19 | | "customer_channel" |
20 | | "customer_channel_email" |
21 | | "customer_channel_phone" |
22 | | "customers_by_phone" |
23 | | "integration" |
24 | | "team" |
25 | | "tag"; |
26 | query?: string; |
27 | }, |
28 | ) { |
29 | const url = new URL(`https://${auth.domain}.gorgias.com/api/search`); |
30 |
|
31 | const response = await fetch(url, { |
32 | method: "POST", |
33 | headers: { |
34 | "Content-Type": "application/json", |
35 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
36 | }, |
37 | body: JSON.stringify(body), |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|