> ## 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 fixed-cost reward for the logged-in customer.

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

> [!NOTE]
>
> This method is for `fixed` rewards. For `flexible` rewards (where the customer chooses an amount) use [redeemFlexible](https://developers.mageloyalty.com/js-sdk/rewards/redeem-flexible.md). On store-credit shops fixed-cost redemption is disabled, so `redeemFlexible` is the only redemption path. See [Loyalty modes](https://developers.mageloyalty.com/js-sdk/loyalty-modes.md).

## 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

**rewardId** `string` *required*

The ID of the reward to redeem. You can get reward IDs from [`getShopRewards`](https://developers.mageloyalty.com/js-sdk/rewards/get-shop-rewards).

## Response

**success** `boolean`

Whether the redemption was successful.

**data.discountCode** `string`

The generated Shopify discount code.

**data.reward** `object`

A summary of the redeemed reward.

**Reward properties**

**name** `string`

Name of the reward.

**discountType** `string | null`

Type of discount applied, or `null`.

**data.customerReward** `object`

The full customer reward record that was created, including `id`, `status`, `expiresAt`, and the discount code. Same shape as an entry from [`getCustomerRewards`](https://developers.mageloyalty.com/js-sdk/rewards/get-customer-rewards).

## Errors

| Error | Cause |
| - | - |
| `"Customer not found"` | Customer is not logged in or not enrolled |
| `"Insufficient points"` | Customer does not have enough balance |
| `"Reward not found"` | The reward ID is invalid |
| `"This reward cannot be redeemed in store credit mode"` | The shop runs on store credit. Use [redeemFlexible](https://developers.mageloyalty.com/js-sdk/rewards/redeem-flexible.md) |

## Example: Redeem button

```html theme={null}
<button id="redeem-btn" data-reward-id="reward_abc">
  Redeem 500 points for £5 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>
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.