0

Update a vendor payment

by
Published Oct 17, 2025

Update an existing vendor payment. You can also modify the amount applied to the bills.

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 vendor payment
7
 * Update an existing vendor payment. You can also modify the amount applied to the bills.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  payment_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    vendor_id?: string;
15
    bills?: {
16
      bill_payment_id?: string;
17
      bill_id?: string;
18
      amount_applied?: number;
19
      tax_amount_withheld?: number;
20
    }[];
21
    date?: string;
22
    exchange_rate?: number;
23
    amount: number;
24
    paid_through_account_id?: string;
25
    payment_mode?: string;
26
    description?: string;
27
    reference_number?: string;
28
    is_paid_via_print_check?: false | true;
29
    check_details?: string[];
30
    location_id?: string;
31
    custom_fields?: { index?: number; value?: string }[];
32
  },
33
) {
34
  const url = new URL(
35
    `https://www.zohoapis.com/books/v3/vendorpayments/${payment_id}`,
36
  );
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
      "Content-Type": "application/json",
46
      Authorization: "Zoho-oauthtoken " + auth.token,
47
    },
48
    body: JSON.stringify(body),
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56