1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Update a view |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | id: string, |
14 | body: { |
15 | category?: string; |
16 | deactivated_datetime?: string; |
17 | decoration?: { emoji?: string }; |
18 | display_order?: number; |
19 | fields?: |
20 | | "details" |
21 | | "tags" |
22 | | "customer" |
23 | | "last_message" |
24 | | "name" |
25 | | "email" |
26 | | "created" |
27 | | "updated" |
28 | | "assignee" |
29 | | "assignee_team" |
30 | | "channel" |
31 | | "closed" |
32 | | "language" |
33 | | "last_received_message" |
34 | | "integrations" |
35 | | "snooze" |
36 | | "status" |
37 | | "subject"[]; |
38 | filters?: string; |
39 | filters_ast?: {}; |
40 | name?: string; |
41 | order_by?: string; |
42 | order_dir?: "asc" | "desc"; |
43 | shared_with_teams?: number[]; |
44 | shared_with_users?: number[]; |
45 | slug?: string; |
46 | type?: "ticket-list"; |
47 | visibility?: "public" | "shared" | "private"; |
48 | }, |
49 | ) { |
50 | const url = new URL(`https://${auth.domain}.gorgias.com/api/views/${id}/`); |
51 |
|
52 | const response = await fetch(url, { |
53 | method: "PUT", |
54 | headers: { |
55 | "Content-Type": "application/json", |
56 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
57 | }, |
58 | body: JSON.stringify(body), |
59 | }); |
60 | if (!response.ok) { |
61 | const text = await response.text(); |
62 | throw new Error(`${response.status} ${text}`); |
63 | } |
64 | return await response.json(); |
65 | } |
66 |
|