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