1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update KView |
7 | * Updates a KView. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | resource: string, |
12 | id: string, |
13 | body: { |
14 | template?: string; |
15 | context?: "expanded-timeline" | "smartbar-details" | "smartbar-card"; |
16 | meta?: {}; |
17 | enabled?: false | true; |
18 | advanced?: false | true; |
19 | layout?: unknown[]; |
20 | components?: {}; |
21 | }, |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.kustomerapp.com/v1/kviews/${resource}/${id}`, |
25 | ); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "PUT", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: "Bearer " + auth.apiKey, |
32 | }, |
33 | body: JSON.stringify(body), |
34 | }); |
35 | if (!response.ok) { |
36 | const text = await response.text(); |
37 | throw new Error(`${response.status} ${text}`); |
38 | } |
39 | return await response.json(); |
40 | } |
41 |
|