0

Create a tax

by
Published Oct 17, 2025

Create a tax which can be associated with an item.

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 a tax
7
 * Create a tax which can be associated with an item.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    tax_name?: string;
14
    tax_percentage?: number;
15
    tax_type?: string;
16
    tax_factor?: string;
17
    tax_specific_type?: string;
18
    tax_authority_name?: string;
19
    tax_authority_id?: string;
20
    country_code?: string;
21
    purchase_tax_expense_account_id?: number;
22
    is_value_added?: false | true;
23
    update_draft_invoice?: false | true;
24
    update_draft_so?: false | true;
25
    is_editable?: false | true;
26
  },
27
) {
28
  const url = new URL(`https://www.zohoapis.com/inventory/v1/settings/taxes`);
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: "POST",
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