0

ListGiftCardActivities

by
Published Oct 17, 2025

Lists gift card activities. By default, you get gift card activities for all gift cards in the seller's account. You can optionally specify query parameters to filter the list. For example, you can get a list of gift card activities for a gift card, for all gift cards in a specific region, or for activities within a time window.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListGiftCardActivities
7
 * Lists gift card activities. By default, you get gift card activities for all
8
gift cards in the seller's account. You can optionally specify query parameters to
9
filter the list. For example, you can get a list of gift card activities for a gift card,
10
for all gift cards in a specific region, or for activities within a time window.
11
 */
12
export async function main(
13
  auth: Square,
14
  gift_card_id: string | undefined,
15
  type: string | undefined,
16
  location_id: string | undefined,
17
  begin_time: string | undefined,
18
  end_time: string | undefined,
19
  limit: string | undefined,
20
  cursor: string | undefined,
21
  sort_order: string | undefined,
22
) {
23
  const url = new URL(`https://connect.squareup.com/v2/gift-cards/activities`);
24
  for (const [k, v] of [
25
    ["gift_card_id", gift_card_id],
26
    ["type", type],
27
    ["location_id", location_id],
28
    ["begin_time", begin_time],
29
    ["end_time", end_time],
30
    ["limit", limit],
31
    ["cursor", cursor],
32
    ["sort_order", sort_order],
33
  ]) {
34
    if (v !== undefined && v !== "" && k !== undefined) {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51