0

ListPayouts

by
Published Oct 17, 2025

Retrieves a list of all payouts for the default location. You can filter payouts by location ID, status, time range, and order them in ascending or descending order. To call this endpoint, set `PAYOUTS_READ` for the OAuth scope.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListPayouts
7
 * Retrieves a list of all payouts for the default location.
8
You can filter payouts by location ID, status, time range, and order them in ascending or descending order.
9
To call this endpoint, set `PAYOUTS_READ` for the OAuth scope.
10
 */
11
export async function main(
12
  auth: Square,
13
  location_id: string | undefined,
14
  status: "SENT" | "FAILED" | "PAID" | undefined,
15
  begin_time: string | undefined,
16
  end_time: string | undefined,
17
  sort_order: "DESC" | "ASC" | undefined,
18
  cursor: string | undefined,
19
  limit: string | undefined,
20
) {
21
  const url = new URL(`https://connect.squareup.com/v2/payouts`);
22
  for (const [k, v] of [
23
    ["location_id", location_id],
24
    ["status", status],
25
    ["begin_time", begin_time],
26
    ["end_time", end_time],
27
    ["sort_order", sort_order],
28
    ["cursor", cursor],
29
    ["limit", limit],
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