> ## Documentation Index
> Fetch the complete documentation index at: https://developers.mageloyalty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# redeemReward

> Redeem a reward for the logged-in customer.

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

## Usage

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

## Parameters

<ParamField body="rewardId" type="string" required>
  The ID of the reward to redeem. You can get reward IDs from [`getShopRewards`](/js-sdk/rewards/get-shop-rewards).
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Whether the redemption was successful.
</ResponseField>

<ResponseField name="data.discountCode" type="string">
  The generated Shopify discount code.
</ResponseField>

<ResponseField name="data.reward" type="object">
  Details of the redeemed reward.

  <Expandable title="Reward properties">
    <ResponseField name="name" type="string">
      Name of the reward.
    </ResponseField>

    <ResponseField name="discountType" type="string">
      Type of discount applied.
    </ResponseField>
  </Expandable>
</ResponseField>

## Errors

| Error                   | Cause                                     |
| ----------------------- | ----------------------------------------- |
| `"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

```html theme={null}
<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>
```
