1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update variable by api name |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | api_name: string, |
12 | group: string | undefined, |
13 | body: { |
14 | variables: { |
15 | api_name: string; |
16 | name: string; |
17 | description: string; |
18 | source: string; |
19 | id: string; |
20 | type: |
21 | | "date" |
22 | | "website" |
23 | | "double" |
24 | | "textarea" |
25 | | "integer" |
26 | | "percent" |
27 | | "long" |
28 | | "datetime" |
29 | | "phone" |
30 | | "checkbox" |
31 | | "currency" |
32 | | "text" |
33 | | "email"; |
34 | variable_group: { id: string; api_name: string; name: string }; |
35 | read_only: false | true; |
36 | value: {}; |
37 | }[]; |
38 | }, |
39 | ) { |
40 | const url = new URL( |
41 | `https://zohoapis.com/crm/v8/settings/variables/${api_name}`, |
42 | ); |
43 | for (const [k, v] of [["group", group]]) { |
44 | if (v !== undefined && v !== "" && k !== undefined) { |
45 | url.searchParams.append(k, v); |
46 | } |
47 | } |
48 | const response = await fetch(url, { |
49 | method: "PUT", |
50 | headers: { |
51 | "Content-Type": "application/json", |
52 | Authorization: "Zoho-oauthtoken " + auth.token, |
53 | }, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|