1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create customer archive search |
7 | * Searches across all customer data with criteria based on a limited number of attributes on standard objects, including Message, Conversation, and Company objects, and on custom objects. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | body: { |
12 | queryContext?: string; |
13 | includeDeleted?: false | true; |
14 | timeZone?: string; |
15 | and?: |
16 | | {} |
17 | | { |
18 | conversation_id?: {}; |
19 | conversation_created_at?: {}; |
20 | conversation_updated_at?: {}; |
21 | conversation_customer_id?: {}; |
22 | conversation_any_text?: {}; |
23 | conversation_deleted?: {}; |
24 | customer_id?: {}; |
25 | customer_companyId?: {}; |
26 | customer_created_at?: {}; |
27 | customer_updated_at?: {}; |
28 | customer_deleted?: {}; |
29 | customer_any_text_new?: {}; |
30 | message_id?: {}; |
31 | message_created_at?: {}; |
32 | message_updated_at?: {}; |
33 | message_conversation_id?: {}; |
34 | message_any_text?: {}; |
35 | kobject_id?: {}; |
36 | kobject_created_at?: {}; |
37 | kobject_updated_at?: {}; |
38 | kobject_customer_id?: {}; |
39 | kobject_company_id?: {}; |
40 | kobject_any_text?: {}; |
41 | "^kobject_.*_id$"?: {}; |
42 | "^kobject_.*_created_at$"?: {}; |
43 | "^kobject_.*_updated_at$"?: {}; |
44 | "^kobject_.*_customer_id$"?: {}; |
45 | "^kobject_.*_company_id$"?: {}; |
46 | "^kobject_.*_any_text$"?: {}; |
47 | company_created_at?: {}; |
48 | company_updated_at?: {}; |
49 | }[]; |
50 | or?: |
51 | | {} |
52 | | { |
53 | conversation_id?: {}; |
54 | conversation_created_at?: {}; |
55 | conversation_updated_at?: {}; |
56 | conversation_customer_id?: {}; |
57 | conversation_any_text?: {}; |
58 | conversation_deleted?: {}; |
59 | customer_id?: {}; |
60 | customer_companyId?: {}; |
61 | customer_created_at?: {}; |
62 | customer_updated_at?: {}; |
63 | customer_deleted?: {}; |
64 | customer_any_text_new?: {}; |
65 | message_id?: {}; |
66 | message_created_at?: {}; |
67 | message_updated_at?: {}; |
68 | message_conversation_id?: {}; |
69 | message_any_text?: {}; |
70 | kobject_id?: {}; |
71 | kobject_created_at?: {}; |
72 | kobject_updated_at?: {}; |
73 | kobject_customer_id?: {}; |
74 | kobject_company_id?: {}; |
75 | kobject_any_text?: {}; |
76 | "^kobject_.*_id$"?: {}; |
77 | "^kobject_.*_created_at$"?: {}; |
78 | "^kobject_.*_updated_at$"?: {}; |
79 | "^kobject_.*_customer_id$"?: {}; |
80 | "^kobject_.*_company_id$"?: {}; |
81 | "^kobject_.*_any_text$"?: {}; |
82 | company_created_at?: {}; |
83 | company_updated_at?: {}; |
84 | }[]; |
85 | not?: |
86 | | {} |
87 | | { |
88 | conversation_id?: {}; |
89 | conversation_created_at?: {}; |
90 | conversation_updated_at?: {}; |
91 | conversation_customer_id?: {}; |
92 | conversation_any_text?: {}; |
93 | conversation_deleted?: {}; |
94 | customer_id?: {}; |
95 | customer_companyId?: {}; |
96 | customer_created_at?: {}; |
97 | customer_updated_at?: {}; |
98 | customer_deleted?: {}; |
99 | customer_any_text_new?: {}; |
100 | message_id?: {}; |
101 | message_created_at?: {}; |
102 | message_updated_at?: {}; |
103 | message_conversation_id?: {}; |
104 | message_any_text?: {}; |
105 | kobject_id?: {}; |
106 | kobject_created_at?: {}; |
107 | kobject_updated_at?: {}; |
108 | kobject_customer_id?: {}; |
109 | kobject_company_id?: {}; |
110 | kobject_any_text?: {}; |
111 | "^kobject_.*_id$"?: {}; |
112 | "^kobject_.*_created_at$"?: {}; |
113 | "^kobject_.*_updated_at$"?: {}; |
114 | "^kobject_.*_customer_id$"?: {}; |
115 | "^kobject_.*_company_id$"?: {}; |
116 | "^kobject_.*_any_text$"?: {}; |
117 | company_created_at?: {}; |
118 | company_updated_at?: {}; |
119 | }[]; |
120 | sort?: {} | {}[]; |
121 | }, |
122 | ) { |
123 | const url = new URL( |
124 | `https://api.kustomerapp.com/v1/customers/archive/search`, |
125 | ); |
126 |
|
127 | const response = await fetch(url, { |
128 | method: "POST", |
129 | headers: { |
130 | "Content-Type": "application/json", |
131 | Authorization: "Bearer " + auth.apiKey, |
132 | }, |
133 | body: JSON.stringify(body), |
134 | }); |
135 | if (!response.ok) { |
136 | const text = await response.text(); |
137 | throw new Error(`${response.status} ${text}`); |
138 | } |
139 | return await response.json(); |
140 | } |
141 |
|