0

SearchLoyaltyEvents

by
Published Oct 17, 2025

Searches for loyalty events. A Square loyalty program maintains a ledger of events that occur during the lifetime of a buyer's loyalty account. Each change in the point balance (for example, points earned, points redeemed, and points expired) is recorded in the ledger. Using this endpoint, you can search the ledger for events. Search results are sorted by `created_at` in descending order.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * SearchLoyaltyEvents
7
 * Searches for loyalty events.
8

9
A Square loyalty program maintains a ledger of events that occur during the lifetime of a
10
buyer's loyalty account. Each change in the point balance
11
(for example, points earned, points redeemed, and points expired) is
12
recorded in the ledger. Using this endpoint, you can search the ledger for events.
13

14
Search results are sorted by `created_at` in descending order.
15
 */
16
export async function main(
17
  auth: Square,
18
  body: {
19
    query?: {
20
      filter?: {
21
        loyalty_account_filter?: { loyalty_account_id: string };
22
        type_filter?: {
23
          types:
24
            | "ACCUMULATE_POINTS"
25
            | "CREATE_REWARD"
26
            | "REDEEM_REWARD"
27
            | "DELETE_REWARD"
28
            | "ADJUST_POINTS"
29
            | "EXPIRE_POINTS"
30
            | "OTHER"
31
            | "ACCUMULATE_PROMOTION_POINTS"[];
32
        };
33
        date_time_filter?: {
34
          created_at: { start_at?: string; end_at?: string };
35
        };
36
        location_filter?: { location_ids: string[] };
37
        order_filter?: { order_id: string };
38
      };
39
    };
40
    limit?: number;
41
    cursor?: string;
42
  },
43
) {
44
  const url = new URL(`https://connect.squareup.com/v2/loyalty/events/search`);
45

46
  const response = await fetch(url, {
47
    method: "POST",
48
    headers: {
49
      "Content-Type": "application/json",
50
      Authorization: "Bearer " + auth.token,
51
    },
52
    body: JSON.stringify(body),
53
  });
54
  if (!response.ok) {
55
    const text = await response.text();
56
    throw new Error(`${response.status} ${text}`);
57
  }
58
  return await response.json();
59
}
60