0

Categorize as expense

by
Published Oct 17, 2025

Categorize an Uncategorized transaction as 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
 * Categorize as expense
7
 * Categorize an Uncategorized transaction as expense.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  transaction_id: string,
12
  organization_id: string | undefined,
13
  doc: string | undefined,
14
  totalFiles: string | undefined,
15
  document_ids: string | undefined,
16
  body: {
17
    account_id?: string;
18
    paid_through_account_id?: string;
19
    date?: string;
20
    tax_id?: string;
21
    amount?: number;
22
    project_id?: string;
23
    tax_exemption_code?: string;
24
    tax_exemption_id?: string;
25
    is_inclusive_tax?: false | true;
26
    is_billable?: false | true;
27
    reference_number?: string;
28
    description?: string;
29
    customer_id?: string;
30
    zp_project_id?: number;
31
    zp_project_name?: string;
32
    zp_client_id?: number;
33
    vendor_id?: string;
34
    vehicle_id?: string;
35
    mileage_unit?: string;
36
    mileage_rate?: number;
37
    can_reclaim_vat_on_mileage?: false | true;
38
    fuel_type?: string;
39
    engine_capacity_range?: string;
40
    employee_id?: number;
41
    mileage_type?: string;
42
    expense_type?: string;
43
    distance?: number;
44
    start_reading?: string;
45
    end_reading?: string;
46
    currency_id?: string;
47
    custom_fields?: { index?: number; value?: string }[];
48
    tags?: { tag_id?: number; tag_option_id?: number }[];
49
    documents?: { file_name?: {}; document_id?: {} }[];
50
    exchange_rate?: number;
51
    recurring_expense_id?: number;
52
    vat_treatment?: string;
53
    tax_treatment?: string;
54
    acquisition_vat_id?: string;
55
    reverse_charge_vat_id?: string;
56
    is_update_customer?: false | true;
57
    product_type?: string;
58
    taxes?: { tax_name?: string; tax_amount?: number; tax_id?: string }[];
59
    reason?: string;
60
    line_items?: {
61
      line_item_id?: number;
62
      account_id?: string;
63
      description?: string;
64
      amount?: number;
65
      tax_id?: string;
66
      item_order?: number;
67
      product_type?: string;
68
      acquisition_vat_id?: string;
69
      reverse_charge_vat_id?: string;
70
      tax_exemption_code?: string;
71
      tax_exemption_id?: string;
72
      tags?: { tag_id?: number; tag_option_id?: number }[];
73
    }[];
74
    zcrm_potential_id?: number;
75
  },
76
) {
77
  const url = new URL(
78
    `https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/categorize/expenses`,
79
  );
80
  for (const [k, v] of [
81
    ["organization_id", organization_id],
82
    ["doc", doc],
83
    ["totalFiles", totalFiles],
84
    ["document_ids", document_ids],
85
  ]) {
86
    if (v !== undefined && v !== "" && k !== undefined) {
87
      url.searchParams.append(k, v);
88
    }
89
  }
90
  const response = await fetch(url, {
91
    method: "POST",
92
    headers: {
93
      "Content-Type": "application/json",
94
      Authorization: "Zoho-oauthtoken " + auth.token,
95
    },
96
    body: JSON.stringify(body),
97
  });
98
  if (!response.ok) {
99
    const text = await response.text();
100
    throw new Error(`${response.status} ${text}`);
101
  }
102
  return await response.json();
103
}
104