1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create Saved Search |
7 | * Creates a saved search. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | body: { |
12 | name: string; |
13 | data: { |
14 | queryContext?: string; |
15 | and?: {} | {}[]; |
16 | or?: {} | {}[]; |
17 | not?: {} | {}[]; |
18 | sort?: {} | {}[]; |
19 | fields?: {}[]; |
20 | }; |
21 | icon?: string; |
22 | badgeColor?: string; |
23 | showBadge?: false | true; |
24 | position?: number; |
25 | routing?: { concurrencyLimit: number; timeout: number }; |
26 | defaultVisibility?: "all" | "search" | "autopilot" | "none"; |
27 | userVisibilities?: { |
28 | id?: string; |
29 | visibility?: "all" | "search" | "autopilot" | "none"; |
30 | }[]; |
31 | teamVisibilities?: { |
32 | id?: string; |
33 | visibility?: "all" | "search" | "autopilot" | "none"; |
34 | }[]; |
35 | private?: false | true; |
36 | accessTeams?: string[]; |
37 | accessUsers?: string[]; |
38 | externalId?: string; |
39 | timeZone?: string; |
40 | folderId?: string; |
41 | }, |
42 | ) { |
43 | const url = new URL(`https://api.kustomerapp.com/v1/customers/searches`); |
44 |
|
45 | const response = await fetch(url, { |
46 | method: "POST", |
47 | headers: { |
48 | "Content-Type": "application/json", |
49 | Authorization: "Bearer " + auth.apiKey, |
50 | }, |
51 | body: JSON.stringify(body), |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.json(); |
58 | } |
59 |
|