0

Update variable by id

by
Published Oct 17, 2025
Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Update variable by id
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  id: 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(`https://zohoapis.com/crm/v8/settings/variables/${id}`);
41
  for (const [k, v] of [["group", group]]) {
42
    if (v !== undefined && v !== "" && k !== undefined) {
43
      url.searchParams.append(k, v);
44
    }
45
  }
46
  const response = await fetch(url, {
47
    method: "PUT",
48
    headers: {
49
      "Content-Type": "application/json",
50
      Authorization: "Zoho-oauthtoken " + auth.token,
51
    },
52
    body: JSON.stringify(body),
53
  });
54
  if (!response.ok) {
55
    const text = await response.text();
56
    throw new Error(`${response.status} ${text}`);
57
  }
58
  return await response.json();
59
}
60