0

Create a rule

by
Published Oct 17, 2025

Create a rule and apply it on deposit/withdrawal for bank accounts and on refund/charges for credit card accounts.

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 rule
7
 * Create a rule and apply it on deposit/withdrawal for bank accounts and on refund/charges for credit card accounts.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    rule_name: string;
14
    target_account_id: number;
15
    apply_to: string;
16
    criteria_type: string;
17
    criterion: { field?: string; comparator?: string; value?: string }[];
18
    record_as: string;
19
    account_id?: number;
20
    customer_id?: number;
21
    tax_id?: string;
22
    reference_number?: string;
23
    vat_treatment?: string;
24
    tax_treatment?: string;
25
    is_reverse_charge_applied?: false | true;
26
    product_type?: string;
27
    tax_authority_id?: string;
28
    tax_exemption_id?: string;
29
  },
30
) {
31
  const url = new URL(`https://www.zohoapis.com/books/v3/bankaccounts/rules`);
32
  for (const [k, v] of [["organization_id", organization_id]]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Zoho-oauthtoken " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51