1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update pipelines |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | layout_id: string, |
12 | body: { |
13 | pipeline: { |
14 | display_value: string; |
15 | default: false | true; |
16 | maps: { |
17 | display_value: string; |
18 | sequence_number: number; |
19 | forecast_category: { name: string; id: string }; |
20 | _delete?: false | true; |
21 | actual_value: string; |
22 | id: string; |
23 | colour_code?: string; |
24 | forecast_type: string; |
25 | }[]; |
26 | actual_value: string; |
27 | id: string; |
28 | child_available?: false | true; |
29 | parent?: {}; |
30 | }[]; |
31 | }, |
32 | ) { |
33 | const url = new URL(`https://zohoapis.com/crm/v8/settings/pipeline`); |
34 | for (const [k, v] of [["layout_id", layout_id]]) { |
35 | if (v !== undefined && v !== "" && k !== undefined) { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "PUT", |
41 | headers: { |
42 | "Content-Type": "application/json", |
43 | Authorization: "Zoho-oauthtoken " + auth.token, |
44 | }, |
45 | body: JSON.stringify(body), |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|