1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create bulk write job |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | body: { |
12 | character_encoding?: string; |
13 | operation?: "upsert" | "insert" | "update"; |
14 | callback?: { url?: string; method?: "post" }; |
15 | resource?: { |
16 | status?: "COMPLETED" | "ADDED" | "FAILED" | "IN PROGRESS" | "SKIPPED"; |
17 | type?: "data"; |
18 | module?: { |
19 | api_name: string; |
20 | id: string; |
21 | module_name?: string; |
22 | module?: string; |
23 | }; |
24 | code?: string; |
25 | file_id?: string; |
26 | file_names?: string[]; |
27 | ignore_empty?: false | true; |
28 | find_by?: string; |
29 | field_mappings?: { |
30 | api_name?: string; |
31 | index?: number; |
32 | format?: string; |
33 | find_by?: string; |
34 | default_value?: { name?: string; module?: string; value?: {} }; |
35 | module?: string; |
36 | parent_column_index?: number; |
37 | }[]; |
38 | file?: { |
39 | status?: "COMPLETED" | "ADDED" | "FAILED" | "IN PROGRESS" | "SKIPPED"; |
40 | name?: string; |
41 | added_count?: number; |
42 | skipped_count?: number; |
43 | updated_count?: number; |
44 | total_count?: number; |
45 | }; |
46 | }[]; |
47 | ignore_empty?: false | true; |
48 | }, |
49 | ) { |
50 | const url = new URL(`https://zohoapis.com/crm/bulk/v8/write`); |
51 |
|
52 | const response = await fetch(url, { |
53 | method: "POST", |
54 | headers: { |
55 | "Content-Type": "application/json", |
56 | Authorization: "Zoho-oauthtoken " + auth.token, |
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 |
|