0

Add tags

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