0

Update an account

by
Published Oct 17, 2025

Updates the account information.

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 an account
7
 * Updates the account information.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  account_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    account_name?: string;
15
    account_code?: string;
16
    account_type?: string;
17
    currency_id?: string;
18
    description?: string;
19
    show_on_dashboard?: false | true;
20
    can_show_in_ze?: false | true;
21
    include_in_vat_return?: false | true;
22
    custom_fields?: { customfield_id?: string; value?: string }[];
23
    parent_account_id?: string;
24
  },
25
) {
26
  const url = new URL(
27
    `https://www.zohoapis.com/books/v3/chartofaccounts/${account_id}`,
28
  );
29
  for (const [k, v] of [["organization_id", organization_id]]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "PUT",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Zoho-oauthtoken " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48