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

# getProductEarningValue

> Get the points or store credit a product earns, with and without the active bonus campaign.

Returns the points or store credit the current customer earns on a product. Use it for product page messages like "Earn 500 points with this purchase".

* **Bonus campaigns:** when a bonus campaign is boosting the product, it also returns what the customer would normally earn, for messages like "Usually 250 points".

## Usage

```javascript theme={null}
const resp = await MageSDK.getProductEarningValue({
  productId: {{ product.id }},
  variantId: {{ product.selected_or_first_available_variant.id }},
  price: {{ product.selected_or_first_available_variant.price }}
});

if (resp.success) {
  console.log(resp.data.formatted);        // "500" or "$140.00"
  console.log(resp.data.regularFormatted); // "250" or "$70.00"
}
```

### Parameters

<ParamField body="productId" type="number | string" required>
  The product ID.
</ParamField>

<ParamField body="variantId" type="number | string" required>
  The selected variant ID.
</ParamField>

<ParamField body="price" type="number">
  The selected variant's price in cents, as Liquid's `{{ variant.price }}` outputs it. Optional, but makes the call faster.
</ParamField>

<ParamField body="quantity" type="number" default="1">
  The quantity to calculate for.
</ParamField>

### Example

```javascript theme={null}
const resp = await MageSDK.getProductEarningValue({ productId, variantId, price });
if (!resp.success) return;

const { formatted, regularFormatted, bonusApplied, loyaltyMode } = resp.data;
const unit = loyaltyMode === 'store_credit' ? 'in store credit' : 'points';

earnEl.textContent = `Earn ${formatted} ${unit} with this purchase`;
usuallyEl.textContent = bonusApplied ? `Usually ${regularFormatted}` : '';
```

Call it again when the customer changes variant or quantity.

## Response

<ResponseField name="data.value" type="number">
  What the customer earns, including any bonus. Points in points mode (`500`), or the store credit amount in store credit mode (`140` for \$140.00).
</ResponseField>

<ResponseField name="data.formatted" type="string">
  `value` ready to display: `"500"` or `"$140.00"`.
</ResponseField>

<ResponseField name="data.regularValue" type="number">
  What the customer would normally earn, without the bonus. Equal to `value` when no bonus applies.
</ResponseField>

<ResponseField name="data.regularFormatted" type="string">
  `regularValue` ready to display.
</ResponseField>

<ResponseField name="data.bonusApplied" type="boolean">
  `true` when a bonus campaign is increasing what this customer earns on this product. Use it to decide whether to show bonus messaging.
</ResponseField>

<ResponseField name="data.loyaltyMode" type="string">
  `"points"` or `"store_credit"`. Use it to choose your wording.
</ResponseField>

<ResponseField name="error" type="string">
  Error message when `success` is `false`. Hide your message in that case.
</ResponseField>

<ResponseExample>
  ```json Points theme={null}
  {
    "success": true,
    "data": {
      "value": 250,
      "formatted": "250",
      "regularValue": 250,
      "regularFormatted": "250",
      "bonusApplied": false,
      "loyaltyMode": "points"
    }
  }
  ```

  ```json Store credit theme={null}
  {
    "success": true,
    "data": {
      "value": 70,
      "formatted": "$70.00",
      "regularValue": 70,
      "regularFormatted": "$70.00",
      "bonusApplied": false,
      "loyaltyMode": "store_credit"
    }
  }
  ```

  ```json Bonus campaign (Points) theme={null}
  {
    "success": true,
    "data": {
      "value": 500,
      "formatted": "500",
      "regularValue": 250,
      "regularFormatted": "250",
      "bonusApplied": true,
      "loyaltyMode": "points"
    }
  }
  ```

  ```json Bonus campaign (Store credit) theme={null}
  {
    "success": true,
    "data": {
      "value": 140,
      "formatted": "$140.00",
      "regularValue": 70,
      "regularFormatted": "$70.00",
      "bonusApplied": true,
      "loyaltyMode": "store_credit"
    }
  }
  ```
</ResponseExample>


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