1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get deleted records |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | module_api_name: string, |
12 | _type: string | undefined, |
13 | page: string | undefined, |
14 | per_page: string | undefined, |
15 | If_Modified_Since?: string, |
16 | ) { |
17 | const url = new URL(`https://zohoapis.com/crm/v8/${module_api_name}/deleted`); |
18 | for (const [k, v] of [ |
19 | ["type", _type], |
20 | ["page", page], |
21 | ["per_page", per_page], |
22 | ]) { |
23 | if (v !== undefined && v !== "" && k !== undefined) { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "GET", |
29 | headers: { |
30 | ...(If_Modified_Since ? { "If-Modified-Since": If_Modified_Since } : {}), |
31 | Authorization: "Zoho-oauthtoken " + auth.token, |
32 | }, |
33 | body: undefined, |
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 |
|