0

Create an account

by
Published Oct 17, 2025

Creates an account with the given account type.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Create an account
7
 * Creates an account with the given account type.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    account_name?: string;
14
    account_code?: string;
15
    account_type?: string;
16
    currency_id?: string;
17
    description?: string;
18
    show_on_dashboard?: false | true;
19
    can_show_in_ze?: false | true;
20
    include_in_vat_return?: false | true;
21
    custom_fields?: { customfield_id?: string; value?: string }[];
22
    parent_account_id?: string;
23
  },
24
) {
25
  const url = new URL(`https://www.zohoapis.com/books/v3/chartofaccounts`);
26
  for (const [k, v] of [["organization_id", organization_id]]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Zoho-oauthtoken " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45