1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update tag |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | id: string, |
12 | _module: string, |
13 | body: { |
14 | tags?: { |
15 | name: string; |
16 | color_code: |
17 | | "#57B1FD" |
18 | | "#879BFC" |
19 | | "#658BA8" |
20 | | "#FD87BD" |
21 | | "#969696" |
22 | | "#F48435" |
23 | | "#1DB9B4" |
24 | | "#E7A826" |
25 | | "#63C57E" |
26 | | "#F17574" |
27 | | "#D297EE" |
28 | | "#A8C026" |
29 | | "#B88562"; |
30 | created_time: string; |
31 | modified_time: string; |
32 | modified_by: { name: string; id: string; email?: string }; |
33 | created_by: { name: string; id: string; email?: string }; |
34 | id: string; |
35 | }[]; |
36 | }, |
37 | ) { |
38 | const url = new URL(`https://zohoapis.com/crm/v8/settings/tags/${id}`); |
39 | for (const [k, v] of [["module", _module]]) { |
40 | if (v !== undefined && v !== "" && k !== undefined) { |
41 | url.searchParams.append(k, v); |
42 | } |
43 | } |
44 | const response = await fetch(url, { |
45 | method: "PUT", |
46 | headers: { |
47 | "Content-Type": "application/json", |
48 | Authorization: "Zoho-oauthtoken " + auth.token, |
49 | }, |
50 | body: JSON.stringify(body), |
51 | }); |
52 | if (!response.ok) { |
53 | const text = await response.text(); |
54 | throw new Error(`${response.status} ${text}`); |
55 | } |
56 | return await response.json(); |
57 | } |
58 |
|