0

SearchInvoices

by
Published Oct 17, 2025

Searches for invoices from a location specified in the filter. You can optionally specify customers in the filter for whom to retrieve invoices. In the current implementation, you can only specify one location and optionally one customer. The response is paginated. If truncated, the response includes a `cursor` that you use in a subsequent request to retrieve the next set of invoices.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * SearchInvoices
7
 * Searches for invoices from a location specified in 
8
the filter. You can optionally specify customers in the filter for whom to 
9
retrieve invoices. In the current implementation, you can only specify one location and 
10
optionally one customer.
11

12
The response is paginated. If truncated, the response includes a `cursor` 
13
that you use in a subsequent request to retrieve the next set of invoices.
14
 */
15
export async function main(
16
  auth: Square,
17
  body: {
18
    query: {
19
      filter: { location_ids: string[]; customer_ids?: string[] };
20
      sort?: { field: "INVOICE_SORT_DATE"; order?: "DESC" | "ASC" };
21
    };
22
    limit?: number;
23
    cursor?: string;
24
  },
25
) {
26
  const url = new URL(`https://connect.squareup.com/v2/invoices/search`);
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42