1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Categorize as customer payment |
7 | * Categorize an uncategorized transaction as Customer Payment. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | transaction_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | customer_id?: string; |
15 | retainerinvoice_id?: number; |
16 | invoices?: { |
17 | invoice_payment_id?: number; |
18 | invoice_id?: number; |
19 | amount_applied?: number; |
20 | tax_amount_withheld?: number; |
21 | discount_amount?: number; |
22 | }[]; |
23 | payment_mode?: string; |
24 | description?: string; |
25 | reference_number?: string; |
26 | exchange_rate?: number; |
27 | amount?: number; |
28 | bank_charges?: number; |
29 | account_id?: string; |
30 | custom_fields?: { index?: number; value?: string }[]; |
31 | documents?: { file_name?: {}; document_id?: {} }[]; |
32 | date?: string; |
33 | template_id?: number; |
34 | contact_persons?: string[]; |
35 | }, |
36 | ) { |
37 | const url = new URL( |
38 | `https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/categorize/customerpayments`, |
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: "POST", |
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 |
|