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