0

Add items to a pending invoice

by
Published Oct 17, 2025

Editing a pending invoice to add usage charges.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Add items to a pending invoice
7
 * Editing a pending invoice to add usage charges.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  invoice_id: string,
12
  X_com_zoho_subscriptions_organizationid: string,
13
  body: {
14
    invoice_items?: {
15
      code?: {};
16
      product_id?: {};
17
      name?: {};
18
      description?: {};
19
      price?: number;
20
      quantity?: number;
21
      tax_id?: {};
22
      tax_exemption_id?: {};
23
    }[];
24
  },
25
) {
26
  const url = new URL(
27
    `https://www.zohoapis.com/billing/v1/invoices/${invoice_id}/lineitems`,
28
  );
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "X-com-zoho-subscriptions-organizationid":
34
        X_com_zoho_subscriptions_organizationid,
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