0

ListTransactions

by
Published Oct 17, 2025

Lists transactions for a particular location. Transactions include payment information from sales and exchanges and refund information from returns and exchanges. Max results per [page](https://developer.squareup.com/docs/working-with-apis/pagination): 50

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListTransactions
7
 * Lists transactions for a particular location.
8

9
Transactions include payment information from sales and exchanges and refund
10
information from returns and exchanges.
11

12
Max results per [page](https://developer.squareup.com/docs/working-with-apis/pagination): 50
13
 */
14
export async function main(
15
  auth: Square,
16
  location_id: string,
17
  begin_time: string | undefined,
18
  end_time: string | undefined,
19
  sort_order: "DESC" | "ASC" | undefined,
20
  cursor: string | undefined,
21
) {
22
  const url = new URL(
23
    `https://connect.squareup.com/v2/locations/${location_id}/transactions`,
24
  );
25
  for (const [k, v] of [
26
    ["begin_time", begin_time],
27
    ["end_time", end_time],
28
    ["sort_order", sort_order],
29
    ["cursor", cursor],
30
  ]) {
31
    if (v !== undefined && v !== "" && k !== undefined) {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48