0

List invoices

by
Published Oct 17, 2025

List all invoices with pagination.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * List invoices
7
 * List all invoices with pagination.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  invoice_number: string | undefined,
13
  item_name: string | undefined,
14
  item_id: string | undefined,
15
  item_description: string | undefined,
16
  reference_number: string | undefined,
17
  customer_name: string | undefined,
18
  recurring_invoice_id: string | undefined,
19
  email: string | undefined,
20
  total: string | undefined,
21
  balance: string | undefined,
22
  custom_field: string | undefined,
23
  date: string | undefined,
24
  due_date: string | undefined,
25
  status: string | undefined,
26
  customer_id: string | undefined,
27
  filter_by: string | undefined,
28
  search_text: string | undefined,
29
  sort_column: string | undefined,
30
) {
31
  const url = new URL(`https://www.zohoapis.com/inventory/v1/invoices`);
32
  for (const [k, v] of [
33
    ["organization_id", organization_id],
34
    ["invoice_number", invoice_number],
35
    ["item_name", item_name],
36
    ["item_id", item_id],
37
    ["item_description", item_description],
38
    ["reference_number", reference_number],
39
    ["customer_name", customer_name],
40
    ["recurring_invoice_id", recurring_invoice_id],
41
    ["email", email],
42
    ["total", total],
43
    ["balance", balance],
44
    ["custom_field", custom_field],
45
    ["date", date],
46
    ["due_date", due_date],
47
    ["status", status],
48
    ["customer_id", customer_id],
49
    ["filter_by", filter_by],
50
    ["search_text", search_text],
51
    ["sort_column", sort_column],
52
  ]) {
53
    if (v !== undefined && v !== "" && k !== undefined) {
54
      url.searchParams.append(k, v);
55
    }
56
  }
57
  const response = await fetch(url, {
58
    method: "GET",
59
    headers: {
60
      Authorization: "Zoho-oauthtoken " + auth.token,
61
    },
62
    body: undefined,
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70