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

# redeemFlexibleToSubscription

> Redeem a flexible reward and apply the discount to a subscription.

Redeem an amount of a flexible reward and apply the discount to one of the customer's subscriptions, instead of returning a code for checkout. The reward's purchase type must be **Subscription** or **Both**.

## Usage

```javascript theme={null}
MageSDK.redeemFlexibleToSubscription('reward_abc', 500, '7d993128-2570-4386-97a8-a04e074fc7ff')
  .then(function(resp) {
    if (resp.success) {
      console.log(resp.data.discountAmount + ' off the next order');
    } else {
      console.log('Error:', resp.error);
    }
  });
```

## Parameters

**rewardId** `string` *required*

The ID of a flexible reward (one whose `redemptionMode` is `"flexible"`). Get reward IDs from [`getShopRewards`](/js-sdk/rewards/get-shop-rewards).

**amount** `number` *required*

The amount to spend, in the shop's loyalty unit (points, or minor currency units in store-credit mode). Must fall within the reward's `flexibleConfig.minPoints` and `flexibleConfig.maxPoints`.

**subscriptionId** `string` *required*

The `id` of one of the customer's subscriptions, from [`getSubscriptions`](/js-sdk/subscriptions/get-subscriptions).

## Response

**success** `boolean`

Whether the discount was applied.

**data.customerReward** `object`

The created reward record, with `id` and `discountCode`.

**data.discountAmount** `number`

The discount value, in major currency units.

**data.pointsRedeemed** `number`

The amount deducted from the customer's balance.

**data.updatedPoints** `number`

The customer's remaining balance.

**data.subscriptionId** `string`

The subscription the discount was applied to.

> [!NOTE]
>
> How many orders the discount applies to follows the reward's own settings. If applying fails, the customer's balance is not charged.

## Errors

| Error | Cause |
| - | - |
| `"Customer not found"` | Customer is not logged in or not enrolled |
| `"Insufficient points"` | Customer does not have enough balance |
| `"Minimum redemption is ... points"` / `"Maximum redemption is ... points"` | `amount` is outside the reward's limits |
| `"This reward cannot be applied to subscriptions"` | The reward's purchase type is One-time |
| `"That subscription is no longer active."` | The subscription is paused or cancelled |
| `"That subscription is not available for this account."` | The subscription belongs to another customer |
| `"No subscription integration is connected for this shop"` | No subscription app is connected in Mage |

## Sample response

```json theme={null}
{
  "success": true,
  "data": {
    "customerReward": { "id": "cr_def456", "discountCode": "MAGE-FLEX-ABC" },
    "discountAmount": 5,
    "pointsRedeemed": 500,
    "updatedPoints": 76,
    "subscriptionId": "7d993128-2570-4386-97a8-a04e074fc7ff",
    "provider": "skio"
  }
}
```


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