0

ListCashDrawerShifts

by
Published Oct 17, 2025

Provides the details for all of the cash drawer shifts for a location in a date range.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListCashDrawerShifts
7
 * Provides the details for all of the cash drawer shifts for a location
8
in a date range.
9
 */
10
export async function main(
11
  auth: Square,
12
  location_id: string | undefined,
13
  sort_order: "DESC" | "ASC" | undefined,
14
  begin_time: string | undefined,
15
  end_time: string | undefined,
16
  limit: string | undefined,
17
  cursor: string | undefined,
18
) {
19
  const url = new URL(`https://connect.squareup.com/v2/cash-drawers/shifts`);
20
  for (const [k, v] of [
21
    ["location_id", location_id],
22
    ["sort_order", sort_order],
23
    ["begin_time", begin_time],
24
    ["end_time", end_time],
25
    ["limit", limit],
26
    ["cursor", cursor],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45