Skip to main content
Redeem a reward for the currently logged-in customer. Deducts points from their balance and generates a Shopify discount code.

Usage

MageSDK.redeemReward('reward_abc').then(function(resp) {
  if (resp.success) {
    console.log('Discount code:', resp.data.discountCode);
  } else {
    console.log('Error:', resp.error);
  }
});

Parameters

rewardId
string
required
The ID of the reward to redeem. You can get reward IDs from getShopRewards.

Response

success
boolean
Whether the redemption was successful.
data.discountCode
string
The generated Shopify discount code.
data.reward
object
Details of the redeemed reward.

Errors

ErrorCause
"Customer not found"Customer is not logged in or not enrolled
"Insufficient points"Customer does not have enough points
"Reward not found"The reward ID is invalid

Example: Redeem button

<button id="redeem-btn" data-reward-id="reward_abc">
  Redeem 500 points for \u00a35 off
</button>

<script>
  document.getElementById('redeem-btn').addEventListener('click', function() {
    var rewardId = this.getAttribute('data-reward-id');
    MageSDK.redeemReward(rewardId).then(function(resp) {
      if (resp.success) {
        alert('Your discount code: ' + resp.data.discountCode);
      } else {
        alert('Error: ' + resp.error);
      }
    });
  });
</script>