Applies to: Loyalty API
Learn how to enroll a buyer in a loyalty program so they can accumulate and redeem points.
To enroll a buyer in a loyalty program, you create a loyalty account and provide the program ID and buyer's phone number. You can obtain the buyer's phone number from your application flow. For this walkthrough, you provide a test phone number that uses the format +1<valid-area-code>555<any-four-digits>
and works in the Square Sandbox.
Did you know?
Check out the Sandbox 101: Loyalty API video, which shows how to set up a loyalty program in the Sandbox, create a loyalty account, and then add and redeem loyalty points using steps that are similar to this walkthrough.
Call RetrieveLoyaltyProgram using the
main
keyword to retrieve the loyalty program in the seller's account.Replace
{ACCESS_TOKEN}
with your Sandbox access token.Retrieve loyalty program
Copy the program ID from the response.
Call CreateLoyaltyAccount to create a loyalty account.
- Replace
{ACCESS_TOKEN}
with your Sandbox access token and{UNIQUE_KEY}
with a unique string. A unique idempotency key guarantees that Square processes a request only once. - Replace the example value for
program_id
with the actual program ID.
Note that the
mapping
field references the buyer by phone number.Create loyalty account
After receiving the request, Square does the following:
- Checks the seller's Customer Directory to determine whether it contains a customer profile with the same phone number. If not, Square creates a customer profile using the buyer's phone number.
- Creates an account in the specified loyalty program.
The following is an example response:
{ "loyalty_account":{ "id":"716cefbc-3d71-4d7c-bdc8-9c78fexample", "mapping": { "id":"6377d589-3f09-4f00-a0e8-56d70example", "phone_number":"+14255551111", "created_at":"2020-01-30T00:11:58Z" }, "program_id":"ba293138-8fbd-425d-860b-18ab3example", "balance":0, "lifetime_points":0, "customer_id":"REK96J96AS5AN2Y8Z4Hexample", "created_at":"2020-01-30T00:11:58Z", "updated_at":"2020-01-30T00:11:58Z" } }- Replace
Copy the ID of the new loyalty account from the response. Make sure to copy the
id
for the loyalty account, not for the mapping.The response also includes other account information, such as the
customer_id
of the associated customer profile. Note that bothbalance
andlifetime_points
are 0 because the buyer hasn't yet accrued any loyalty points.Now that you have the account ID, you can use it to access the loyalty account. For example, you can call RetrieveLoyaltyAccount.
Retrieve loyalty account