0

Update a customer

by
Published Oct 17, 2025

Update details of an existing customer.

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 customer
7
 * Update details of an existing customer.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  customer_id: string,
12
  X_com_zoho_subscriptions_organizationid: string,
13
  body: {
14
    display_name: string;
15
    salutation?: string;
16
    first_name?: string;
17
    last_name?: string;
18
    email: string;
19
    tags?: { tag_id?: number; tag_option_id?: number }[];
20
    company_name?: string;
21
    phone?: string;
22
    mobile?: string;
23
    billing_address?: {
24
      attention?: string;
25
      street?: string;
26
      city?: string;
27
      state?: string;
28
      zip?: string;
29
      country?: string;
30
      state_code?: string;
31
      fax?: string;
32
    };
33
    shipping_address?: {
34
      attention?: string;
35
      street?: string;
36
      city?: string;
37
      state?: string;
38
      zip?: string;
39
      country?: string;
40
      state_code?: string;
41
      fax?: string;
42
    };
43
    fax?: string;
44
    currency_code?: string;
45
    twitter?: string;
46
    facebook?: string;
47
    skype?: string;
48
    is_portal_enabled?: false | true;
49
    gst_no?: string;
50
    gst_treatment?: string;
51
    place_of_contact?: string;
52
    vat_treatment?: string;
53
    vat_reg_no?: string;
54
    is_taxable?: string;
55
    tax_id?: string;
56
    tax_authority_id: string;
57
    tax_authority_name: string;
58
    tax_exemption_id?: string;
59
    tax_exemption_code?: string;
60
    default_templates?: {
61
      invoice_template_id?: string;
62
      creditnote_template_id?: string;
63
    };
64
    tax_reg_no?: string;
65
    tds_tax_id?: string;
66
    tax_treatment?: string;
67
    tax_regime?: string;
68
    is_tds_registered?: false | true;
69
    custom_fields?: {
70
      index?: number;
71
      value?: string;
72
      label?: string;
73
      data_type?: string;
74
    }[];
75
  },
76
) {
77
  const url = new URL(
78
    `https://www.zohoapis.com/billing/v1/customers/${customer_id}`,
79
  );
80

81
  const response = await fetch(url, {
82
    method: "PUT",
83
    headers: {
84
      "X-com-zoho-subscriptions-organizationid":
85
        X_com_zoho_subscriptions_organizationid,
86
      "Content-Type": "application/json",
87
      Authorization: "Zoho-oauthtoken " + auth.token,
88
    },
89
    body: JSON.stringify(body),
90
  });
91
  if (!response.ok) {
92
    const text = await response.text();
93
    throw new Error(`${response.status} ${text}`);
94
  }
95
  return await response.json();
96
}
97