0

Categorize an uncategorized transaction

by
Published Oct 17, 2025

Categorize an uncategorized transaction by creating a new transaction.

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 an uncategorized transaction
7
 * Categorize an uncategorized transaction by creating a new transaction.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  transaction_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    from_account_id?: string;
15
    to_account_id?: string;
16
    transaction_type: string;
17
    amount?: number;
18
    date?: string;
19
    reference_number?: string;
20
    payment_mode?: string;
21
    exchange_rate?: number;
22
    description?: string;
23
    customer_id?: string;
24
    tags?: { tag_id?: number; tag_option_id?: number }[];
25
    documents?: { file_name?: {}; document_id?: {} }[];
26
    currency_id?: string;
27
    tax_id?: string;
28
    to_account_tags?: { tag_id?: number; tag_option_id?: number }[];
29
    from_account_tags?: { tag_id?: number; tag_option_id?: number }[];
30
    is_inclusive_tax?: false | true;
31
    bank_charges?: number;
32
    user_id?: number;
33
    tax_authority_id?: string;
34
    tax_exemption_id?: string;
35
    custom_fields?: {
36
      custom_field_id?: number;
37
      index?: number;
38
      label?: string;
39
      value?: string;
40
    }[];
41
    line_items?: {
42
      line_id?: number;
43
      account_id?: string;
44
      account_name?: string;
45
      description?: string;
46
      tax_amount?: number;
47
      tax_id?: string;
48
      tax_name?: string;
49
      tax_type?: string;
50
      tax_percentage?: number;
51
      item_total?: number;
52
      item_total_inclusive_of_tax?: number;
53
      item_order?: number;
54
      tags?: { tag_id?: number; tag_option_id?: number }[];
55
    }[];
56
  },
57
) {
58
  const url = new URL(
59
    `https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/categorize`,
60
  );
61
  for (const [k, v] of [["organization_id", organization_id]]) {
62
    if (v !== undefined && v !== "" && k !== undefined) {
63
      url.searchParams.append(k, v);
64
    }
65
  }
66
  const response = await fetch(url, {
67
    method: "POST",
68
    headers: {
69
      "Content-Type": "application/json",
70
      Authorization: "Zoho-oauthtoken " + auth.token,
71
    },
72
    body: JSON.stringify(body),
73
  });
74
  if (!response.ok) {
75
    const text = await response.text();
76
    throw new Error(`${response.status} ${text}`);
77
  }
78
  return await response.json();
79
}
80