1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update an vendor payment using a custom field's unique value |
7 | * A custom field will have unique values if it's configured to not accept duplicate values. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | X_Unique_Identifier_Key: string, |
13 | X_Unique_Identifier_Value: string, |
14 | body: { |
15 | vendor_id?: string; |
16 | bills?: { |
17 | bill_payment_id?: string; |
18 | bill_id?: string; |
19 | amount_applied?: number; |
20 | tax_amount_withheld?: number; |
21 | }[]; |
22 | date?: string; |
23 | exchange_rate?: number; |
24 | amount: number; |
25 | paid_through_account_id?: string; |
26 | payment_mode?: string; |
27 | description?: string; |
28 | reference_number?: string; |
29 | is_paid_via_print_check?: false | true; |
30 | check_details?: string[]; |
31 | location_id?: string; |
32 | custom_fields?: { index?: number; value?: string }[]; |
33 | }, |
34 | X_Upsert?: string, |
35 | ) { |
36 | const url = new URL(`https://www.zohoapis.com/books/v3/vendorpayments`); |
37 | for (const [k, v] of [["organization_id", organization_id]]) { |
38 | if (v !== undefined && v !== "" && k !== undefined) { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "PUT", |
44 | headers: { |
45 | "X-Unique-Identifier-Key": X_Unique_Identifier_Key, |
46 | "X-Unique-Identifier-Value": X_Unique_Identifier_Value, |
47 | ...(X_Upsert ? { "X-Upsert": X_Upsert } : {}), |
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 |
|