0

Update a recurring expense

by
Published Oct 17, 2025

Update a recurring expense.

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 recurring expense
7
 * Update a recurring expense.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  recurring_expense_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    account_id: string;
15
    recurrence_name: string;
16
    start_date: string;
17
    end_date?: string;
18
    recurrence_frequency: string;
19
    repeat_every: string;
20
    gst_no?: string;
21
    source_of_supply?: string;
22
    destination_of_supply?: string;
23
    place_of_supply?: string;
24
    reverse_charge_tax_id?: string;
25
    location_id?: string;
26
    line_items?: {
27
      line_item_id?: string;
28
      account_id?: string;
29
      description?: string;
30
      amount?: number;
31
      tax_id?: string;
32
      item_order?: string;
33
      product_type?: string;
34
      acquisition_vat_id?: string;
35
      reverse_charge_vat_id?: string;
36
      reverse_charge_tax_id?: string;
37
      tax_exemption_code?: string;
38
      tax_exemption_id?: string;
39
    }[];
40
    amount: number;
41
    vat_treatment?: string;
42
    tax_treatment?: string;
43
    product_type?: string;
44
    acquisition_vat_id?: string;
45
    reverse_charge_vat_id?: string;
46
    tax_id?: string;
47
    is_inclusive_tax?: false | true;
48
    is_billable?: false | true;
49
    customer_id?: string;
50
    project_id?: string;
51
    currency_id?: string;
52
    exchange_rate?: number;
53
    custom_fields?: { customfield_id?: number; value?: string }[];
54
  },
55
) {
56
  const url = new URL(
57
    `https://www.zohoapis.com/books/v3/recurringexpenses/${recurring_expense_id}`,
58
  );
59
  for (const [k, v] of [["organization_id", organization_id]]) {
60
    if (v !== undefined && v !== "" && k !== undefined) {
61
      url.searchParams.append(k, v);
62
    }
63
  }
64
  const response = await fetch(url, {
65
    method: "PUT",
66
    headers: {
67
      "Content-Type": "application/json",
68
      Authorization: "Zoho-oauthtoken " + auth.token,
69
    },
70
    body: JSON.stringify(body),
71
  });
72
  if (!response.ok) {
73
    const text = await response.text();
74
    throw new Error(`${response.status} ${text}`);
75
  }
76
  return await response.json();
77
}
78