0

AdjustLoyaltyPoints

by
Published Oct 17, 2025

Adds points to or subtracts points from a buyer's account. Use this endpoint only when you need to manually adjust points. Otherwise, in your application flow, you call [AccumulateLoyaltyPoints]($e/Loyalty/AccumulateLoyaltyPoints) to add points when a buyer pays for the purchase.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * AdjustLoyaltyPoints
7
 * Adds points to or subtracts points from a buyer's account.
8

9
Use this endpoint only when you need to manually adjust points. Otherwise, in your application flow, you call
10
[AccumulateLoyaltyPoints]($e/Loyalty/AccumulateLoyaltyPoints)
11
to add points when a buyer pays for the purchase.
12
 */
13
export async function main(
14
  auth: Square,
15
  account_id: string,
16
  body: {
17
    idempotency_key: string;
18
    adjust_points: {
19
      loyalty_program_id?: string;
20
      points: number;
21
      reason?: string;
22
    };
23
    allow_negative_balance?: false | true;
24
  },
25
) {
26
  const url = new URL(
27
    `https://connect.squareup.com/v2/loyalty/accounts/${account_id}/adjust`,
28
  );
29

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