0

Add tags to multiple records

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
 * Add tags to multiple records
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  module_api_name: string,
12
  over_write: string | undefined,
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
    over_write: false | true;
37
    ids: string[];
38
  },
39
) {
40
  const url = new URL(
41
    `https://zohoapis.com/crm/v8/${module_api_name}/actions/add_tags`,
42
  );
43
  for (const [k, v] of [["over_write", over_write]]) {
44
    if (v !== undefined && v !== "" && k !== undefined) {
45
      url.searchParams.append(k, v);
46
    }
47
  }
48
  const response = await fetch(url, {
49
    method: "POST",
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