0

Update a rule

by
Published Oct 17, 2025

Make changes to the rule, add or modify it and update.

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