1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Transfer pipelines |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | layout_id: string, |
12 | body: { |
13 | transfer_pipeline: { |
14 | pipeline: { from: string; to: string }; |
15 | stages: { from: string; to: string }[]; |
16 | }[]; |
17 | }, |
18 | ) { |
19 | const url = new URL( |
20 | `https://zohoapis.com/crm/v8/settings/pipeline/actions/transfer`, |
21 | ); |
22 | for (const [k, v] of [["layout_id", layout_id]]) { |
23 | if (v !== undefined && v !== "" && k !== undefined) { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: "Zoho-oauthtoken " + auth.token, |
32 | }, |
33 | body: JSON.stringify(body), |
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 |
|