0

Update a contact

by
Published Oct 17, 2025

Update an existing contact. To delete a contact person remove it from the contact_persons list.

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 a contact
7
 * Update an existing contact. To delete a contact person remove it from the contact_persons list.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  contact_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    contact_name: string;
15
    company_name?: string;
16
    payment_terms?: number;
17
    currency_id?: string;
18
    contact_type?: string;
19
    website?: string;
20
    custom_fields?: { value?: string; index?: number; label?: string }[];
21
    opening_balances?: {
22
      location_id?: string;
23
      exchange_rate?: number;
24
      opening_balance_amount?: number;
25
    }[];
26
    billing_address?: {
27
      attention?: string;
28
      address?: string;
29
      street2?: string;
30
      city?: string;
31
      state?: string;
32
      zip?: string;
33
      country?: string;
34
    };
35
    shipping_address?: {
36
      attention?: string;
37
      address?: string;
38
      street2?: string;
39
      city?: string;
40
      state?: string;
41
      zip?: string;
42
      country?: string;
43
    };
44
    contact_persons?: {
45
      salutation?: string;
46
      first_name?: string;
47
      last_name?: string;
48
      email?: string;
49
      phone?: string;
50
      mobile?: string;
51
      is_primary_contact?: false | true;
52
    }[];
53
    default_templates?: {
54
      invoice_template_id?: string;
55
      invoice_template_name?: string;
56
      estimate_template_id?: string;
57
      estimate_template_name?: string;
58
      creditnote_template_id?: string;
59
      creditnote_template_name?: string;
60
      invoice_email_template_id?: string;
61
      invoice_email_template_name?: string;
62
      estimate_email_template_id?: string;
63
      estimate_email_template_name?: string;
64
      creditnote_email_template_id?: string;
65
      creditnote_email_template_name?: string;
66
    };
67
    language_code?: string;
68
    notes?: string;
69
    vat_reg_no?: string;
70
    tax_reg_no?: string;
71
    country_code?: string;
72
    tax_treatment?: string;
73
    tax_regime?: string;
74
    legal_name?: string;
75
    is_tds_registered?: false | true;
76
    vat_treatment?: string;
77
    avatax_exempt_no?: string;
78
    avatax_use_code?: string;
79
    tax_exemption_id?: string;
80
    tax_authority_id?: string;
81
    tax_id?: false | true;
82
    is_taxable?: false | true;
83
    facebook?: string;
84
    twitter?: string;
85
    place_of_contact?: string;
86
    gst_no?: string;
87
    gst_treatment?: string;
88
    tax_authority_name?: string;
89
    tax_exemption_code?: string;
90
  },
91
) {
92
  const url = new URL(
93
    `https://www.zohoapis.com/inventory/v1/contacts/${contact_id}`,
94
  );
95
  for (const [k, v] of [["organization_id", organization_id]]) {
96
    if (v !== undefined && v !== "" && k !== undefined) {
97
      url.searchParams.append(k, v);
98
    }
99
  }
100
  const response = await fetch(url, {
101
    method: "PUT",
102
    headers: {
103
      "Content-Type": "application/json",
104
      Authorization: "Zoho-oauthtoken " + auth.token,
105
    },
106
    body: JSON.stringify(body),
107
  });
108
  if (!response.ok) {
109
    const text = await response.text();
110
    throw new Error(`${response.status} ${text}`);
111
  }
112
  return await response.json();
113
}
114