0

Update credit note refund

by
Published Oct 17, 2025

Update the refunded 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
 * Update credit note refund
7
 * Update the refunded transaction.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  creditnote_id: string,
12
  creditnote_refund_id: string,
13
  organization_id: string | undefined,
14
  body: {
15
    date?: string;
16
    refund_mode?: string;
17
    reference_number?: string;
18
    amount?: number;
19
    exchange_rate?: string;
20
    from_account_id?: string;
21
    description?: string;
22
  },
23
) {
24
  const url = new URL(
25
    `https://www.zohoapis.com/inventory/v1/creditnotes/${creditnote_id}/refunds/${creditnote_refund_id}`,
26
  );
27
  for (const [k, v] of [["organization_id", organization_id]]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "PUT",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: "Zoho-oauthtoken " + auth.token,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46