Integrate Loyalty with a custom or headless store

Run Yotpo Loyalty & Referrals on a store built on a custom or unsupported platform. Send customers, orders and refunds from your server, set up reward codes, and show points in your own UI.

Use this guide when your store runs on a custom-built platform, or on one without a Yotpo Loyalty integration. Every step runs on your server and uses your GUID and API key (see Authentication). Never call the API from the browser.

📘

Before you start

  • Set up your earning campaigns and redemption options in the Loyalty admin.
  • Test on a separate store first. See Testing your integration.

Step 1: Send customers

Send customers with Create/Update Customer Records when they create an account or their details change. Use your platform's customer ID as id; the other endpoints take the same value as customer_id.

  • Set opted_in to true when a customer joins the program.
  • Send tags if campaigns include or exclude customers by tag.
  • Sending customers is also what rewards account creation.

Step 2: Load coupon codes for your rewards

Without a platform integration, Loyalty can't create discount codes in your store. Create the codes in your platform instead, then load them into each coupon redemption option, either in the Loyalty admin or with Upload Coupon Codes. Each time a customer redeems that option, they get the next unused code.

Create a separate set of codes for each reward, such as $5 off and $10 off. Upload enough to cover your expected redemptions, and add more before they run out.

Step 3: Send orders

After each purchase, send the order from your server with Create Order. Points are awarded asynchronously against your active campaigns.

  • What earns points: points are based on total_amount_cents. Send the total with or without shipping and taxes, depending on what you want customers to earn on.
  • Product rules: include items if any campaign is limited to certain products or collections.
  • Customer rules: include the customer object, always with tags, if campaigns include or exclude customers by tag. Sending customer without tags can clear the customer's stored tags, so a rule that excludes customers by tag would no longer exclude them.
  • Discounts: send the codes used on the order in coupon_code.

Customers can redeem points in two ways:

  • Explicitly: redeem with Create Redemption and show the customer the coupon code. Points are deducted right away.
  • At checkout: redeem with delay_points_deduction: true and apply the code to the cart for the customer. Points are deducted only when the code is used, so a customer who changes their mind or abandons the cart keeps their points. The points aren't held in the meantime: if the code is used after the customer spent them, the balance can go negative.

Orders are processed only when their status matches the order statuses set in your Loyalty admin (if none are set, every order is processed). To award points only once an order ships, for example, set that status in the admin and send the order again when it ships: a send that doesn't match isn't processed, and the matching one is. Once an order is processed, a resend doesn't change it.

Step 4: Send refunds

When an order is refunded, send it with Create Refund, using the order_id you sent in step 3 and your own refund id. Refunds are deduplicated by id, so retries are safe. The points the refund amount earned are deducted. Include items if campaigns depend on specific products.

Step 5: Show points and rewards in your storefront

Fetch the data on your server and render it in your own UI:

Next steps


Did this page help you?