0

Update record using external 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 record using external id
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  module_api_name: string,
12
  external_field_value: string,
13
  body: {
14
    data?: {
15
      id?: string;
16
      Created_By?: { name: string; id: string; email?: string };
17
      Created_Time?: string;
18
      Modified_By?: { name: string; id: string; email?: string };
19
      Modified_Time?: string;
20
      Tag?: {
21
        name: string;
22
        color_code:
23
          | "#57B1FD"
24
          | "#879BFC"
25
          | "#658BA8"
26
          | "#FD87BD"
27
          | "#969696"
28
          | "#F48435"
29
          | "#1DB9B4"
30
          | "#E7A826"
31
          | "#63C57E"
32
          | "#F17574"
33
          | "#D297EE"
34
          | "#A8C026"
35
          | "#B88562";
36
        created_time: string;
37
        modified_time: string;
38
        modified_by: { name: string; id: string; email?: string };
39
        created_by: { name: string; id: string; email?: string };
40
        id: string;
41
      }[];
42
      name?: string;
43
    }[];
44
    trigger?: string[];
45
    process?: string[];
46
    duplicate_check_fields?: string[];
47
    wf_trigger?: string;
48
    lar_id?: string;
49
  },
50
  X_EXTERNAL?: string,
51
) {
52
  const url = new URL(
53
    `https://zohoapis.com/crm/v8/${module_api_name}/${external_field_value}`,
54
  );
55

56
  const response = await fetch(url, {
57
    method: "PUT",
58
    headers: {
59
      ...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}),
60
      "Content-Type": "application/json",
61
      Authorization: "Zoho-oauthtoken " + auth.token,
62
    },
63
    body: JSON.stringify(body),
64
  });
65
  if (!response.ok) {
66
    const text = await response.text();
67
    throw new Error(`${response.status} ${text}`);
68
  }
69
  return await response.json();
70
}
71