0

CreateLoyaltyPromotion

by
Published Oct 17, 2025

Creates a loyalty promotion for a [loyalty program]($m/LoyaltyProgram). A loyalty promotion enables buyers to earn points in addition to those earned from the base loyalty program. This endpoint sets the loyalty promotion to the `ACTIVE` or `SCHEDULED` status, depending on the `available_time` setting. A loyalty program can have a maximum of 10 loyalty promotions with an `ACTIVE` or `SCHEDULED` status.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * CreateLoyaltyPromotion
7
 * Creates a loyalty promotion for a [loyalty program]($m/LoyaltyProgram). A loyalty promotion
8
enables buyers to earn points in addition to those earned from the base loyalty program.
9

10
This endpoint sets the loyalty promotion to the `ACTIVE` or `SCHEDULED` status, depending on the
11
`available_time` setting. A loyalty program can have a maximum of 10 loyalty promotions with an
12
`ACTIVE` or `SCHEDULED` status.
13
 */
14
export async function main(
15
  auth: Square,
16
  program_id: string,
17
  body: {
18
    loyalty_promotion: {
19
      id?: string;
20
      name: string;
21
      incentive: {
22
        type: "POINTS_MULTIPLIER" | "POINTS_ADDITION";
23
        points_multiplier_data?: {
24
          points_multiplier?: number;
25
          multiplier?: string;
26
        };
27
        points_addition_data?: { points_addition: number };
28
      };
29
      available_time: {
30
        start_date?: string;
31
        end_date?: string;
32
        time_periods: string[];
33
      };
34
      trigger_limit?: { times: number; interval?: "ALL_TIME" | "DAY" };
35
      status?: "ACTIVE" | "ENDED" | "CANCELED" | "SCHEDULED";
36
      created_at?: string;
37
      canceled_at?: string;
38
      updated_at?: string;
39
      loyalty_program_id?: string;
40
      minimum_spend_amount_money?: {
41
        amount?: number;
42
        currency?:
43
          | "UNKNOWN_CURRENCY"
44
          | "AED"
45
          | "AFN"
46
          | "ALL"
47
          | "AMD"
48
          | "ANG"
49
          | "AOA"
50
          | "ARS"
51
          | "AUD"
52
          | "AWG"
53
          | "AZN"
54
          | "BAM"
55
          | "BBD"
56
          | "BDT"
57
          | "BGN"
58
          | "BHD"
59
          | "BIF"
60
          | "BMD"
61
          | "BND"
62
          | "BOB"
63
          | "BOV"
64
          | "BRL"
65
          | "BSD"
66
          | "BTN"
67
          | "BWP"
68
          | "BYR"
69
          | "BZD"
70
          | "CAD"
71
          | "CDF"
72
          | "CHE"
73
          | "CHF"
74
          | "CHW"
75
          | "CLF"
76
          | "CLP"
77
          | "CNY"
78
          | "COP"
79
          | "COU"
80
          | "CRC"
81
          | "CUC"
82
          | "CUP"
83
          | "CVE"
84
          | "CZK"
85
          | "DJF"
86
          | "DKK"
87
          | "DOP"
88
          | "DZD"
89
          | "EGP"
90
          | "ERN"
91
          | "ETB"
92
          | "EUR"
93
          | "FJD"
94
          | "FKP"
95
          | "GBP"
96
          | "GEL"
97
          | "GHS"
98
          | "GIP"
99
          | "GMD"
100
          | "GNF"
101
          | "GTQ"
102
          | "GYD"
103
          | "HKD"
104
          | "HNL"
105
          | "HRK"
106
          | "HTG"
107
          | "HUF"
108
          | "IDR"
109
          | "ILS"
110
          | "INR"
111
          | "IQD"
112
          | "IRR"
113
          | "ISK"
114
          | "JMD"
115
          | "JOD"
116
          | "JPY"
117
          | "KES"
118
          | "KGS"
119
          | "KHR"
120
          | "KMF"
121
          | "KPW"
122
          | "KRW"
123
          | "KWD"
124
          | "KYD"
125
          | "KZT"
126
          | "LAK"
127
          | "LBP"
128
          | "LKR"
129
          | "LRD"
130
          | "LSL"
131
          | "LTL"
132
          | "LVL"
133
          | "LYD"
134
          | "MAD"
135
          | "MDL"
136
          | "MGA"
137
          | "MKD"
138
          | "MMK"
139
          | "MNT"
140
          | "MOP"
141
          | "MRO"
142
          | "MUR"
143
          | "MVR"
144
          | "MWK"
145
          | "MXN"
146
          | "MXV"
147
          | "MYR"
148
          | "MZN"
149
          | "NAD"
150
          | "NGN"
151
          | "NIO"
152
          | "NOK"
153
          | "NPR"
154
          | "NZD"
155
          | "OMR"
156
          | "PAB"
157
          | "PEN"
158
          | "PGK"
159
          | "PHP"
160
          | "PKR"
161
          | "PLN"
162
          | "PYG"
163
          | "QAR"
164
          | "RON"
165
          | "RSD"
166
          | "RUB"
167
          | "RWF"
168
          | "SAR"
169
          | "SBD"
170
          | "SCR"
171
          | "SDG"
172
          | "SEK"
173
          | "SGD"
174
          | "SHP"
175
          | "SLL"
176
          | "SLE"
177
          | "SOS"
178
          | "SRD"
179
          | "SSP"
180
          | "STD"
181
          | "SVC"
182
          | "SYP"
183
          | "SZL"
184
          | "THB"
185
          | "TJS"
186
          | "TMT"
187
          | "TND"
188
          | "TOP"
189
          | "TRY"
190
          | "TTD"
191
          | "TWD"
192
          | "TZS"
193
          | "UAH"
194
          | "UGX"
195
          | "USD"
196
          | "USN"
197
          | "USS"
198
          | "UYI"
199
          | "UYU"
200
          | "UZS"
201
          | "VEF"
202
          | "VND"
203
          | "VUV"
204
          | "WST"
205
          | "XAF"
206
          | "XAG"
207
          | "XAU"
208
          | "XBA"
209
          | "XBB"
210
          | "XBC"
211
          | "XBD"
212
          | "XCD"
213
          | "XDR"
214
          | "XOF"
215
          | "XPD"
216
          | "XPF"
217
          | "XPT"
218
          | "XTS"
219
          | "XXX"
220
          | "YER"
221
          | "ZAR"
222
          | "ZMK"
223
          | "ZMW"
224
          | "BTC"
225
          | "XUS";
226
      };
227
      qualifying_item_variation_ids?: string[];
228
      qualifying_category_ids?: string[];
229
    };
230
    idempotency_key: string;
231
  },
232
) {
233
  const url = new URL(
234
    `https://connect.squareup.com/v2/loyalty/programs/${program_id}/promotions`,
235
  );
236

237
  const response = await fetch(url, {
238
    method: "POST",
239
    headers: {
240
      "Content-Type": "application/json",
241
      Authorization: "Bearer " + auth.token,
242
    },
243
    body: JSON.stringify(body),
244
  });
245
  if (!response.ok) {
246
    const text = await response.text();
247
    throw new Error(`${response.status} ${text}`);
248
  }
249
  return await response.json();
250
}
251