0

SearchLoyaltyRewards

by
Published Oct 17, 2025

Searches for loyalty rewards. This endpoint accepts a request with no query filters and returns results for all loyalty accounts. If you include a `query` object, `loyalty_account_id` is required and `status` is optional. If you know a reward ID, use the [RetrieveLoyaltyReward]($e/Loyalty/RetrieveLoyaltyReward) endpoint. Search results are sorted by `updated_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
 * SearchLoyaltyRewards
7
 * Searches for loyalty rewards. This endpoint accepts a request with no query filters and returns results for all loyalty accounts.
8
If you include a `query` object, `loyalty_account_id` is required and `status` is  optional.
9

10
If you know a reward ID, use the
11
[RetrieveLoyaltyReward]($e/Loyalty/RetrieveLoyaltyReward) endpoint.
12

13
Search results are sorted by `updated_at` in descending order.
14
 */
15
export async function main(
16
  auth: Square,
17
  body: {
18
    query?: {
19
      loyalty_account_id: string;
20
      status?: "ISSUED" | "REDEEMED" | "DELETED";
21
    };
22
    limit?: number;
23
    cursor?: string;
24
  },
25
) {
26
  const url = new URL(`https://connect.squareup.com/v2/loyalty/rewards/search`);
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42