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

# getReferralLink

> Get the customer's referral link and sharing options.

Retrieve the referral link for the currently logged-in customer, along with social sharing configuration.

## Usage

```javascript theme={null}
MageSDK.getReferralLink().then(function(resp) {
  if (resp.success && resp.data.enabled) {
    console.log('Referral URL:', resp.data.referralUrl);
    console.log('Referral code:', resp.data.referralCode);
  }
});
```

## Response

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

<ResponseField name="data.enabled" type="boolean">
  Whether the referral program is enabled for this shop.
</ResponseField>

<ResponseField name="data.referralCode" type="string">
  The customer's unique referral code.
</ResponseField>

<ResponseField name="data.referralUrl" type="string">
  Full referral URL that can be shared.
</ResponseField>

<ResponseField name="data.stats" type="object">
  Quick referral statistics.

  <Expandable title="Stats properties">
    <ResponseField name="totalReferred" type="number">
      Total number of people referred.
    </ResponseField>

    <ResponseField name="completedReferrals" type="number">
      Number of completed referrals.
    </ResponseField>

    <ResponseField name="pendingReferrals" type="number">
      Number of pending referrals.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="data.socialSharing" type="object">
  Social sharing configuration set by the merchant.

  <Expandable title="Social sharing properties">
    <ResponseField name="twitter" type="boolean">
      Whether Twitter/X sharing is enabled.
    </ResponseField>

    <ResponseField name="twitterMessage" type="string">
      Pre-filled message for Twitter/X shares.
    </ResponseField>

    <ResponseField name="facebook" type="boolean">
      Whether Facebook sharing is enabled.
    </ResponseField>

    <ResponseField name="email" type="boolean">
      Whether email sharing is enabled.
    </ResponseField>

    <ResponseField name="whatsapp" type="boolean">
      Whether WhatsApp sharing is enabled.
    </ResponseField>

    <ResponseField name="whatsappMessage" type="string">
      Pre-filled message for WhatsApp shares.
    </ResponseField>
  </Expandable>
</ResponseField>

## Sample response

```json theme={null}
{
  "success": true,
  "data": {
    "enabled": true,
    "referralCode": "ABC123",
    "referralUrl": "https://mystore.com?referral_code=ABC123",
    "stats": {
      "totalReferred": 5,
      "completedReferrals": 2,
      "pendingReferrals": 2
    },
    "socialSharing": {
      "twitter": true,
      "twitterMessage": "Check out this store!",
      "facebook": true,
      "email": true,
      "whatsapp": true,
      "whatsappMessage": "Check out this store!"
    }
  }
}
```

## Example: Share buttons

```html theme={null}
<div id="referral-share"></div>

<script>
  MageSDK.getReferralLink().then(function(resp) {
    if (!resp.success || !resp.data.enabled) return;

    var container = document.getElementById('referral-share');
    var url = encodeURIComponent(resp.data.referralUrl);
    var sharing = resp.data.socialSharing;

    if (sharing.twitter) {
      var msg = encodeURIComponent(sharing.twitterMessage);
      container.innerHTML += '<a href="https://twitter.com/intent/tweet?text=' + msg + '&url=' + url + '" target="_blank">Share on Twitter</a> ';
    }

    if (sharing.whatsapp) {
      var msg = encodeURIComponent(sharing.whatsappMessage + ' ' + resp.data.referralUrl);
      container.innerHTML += '<a href="https://wa.me/?text=' + msg + '" target="_blank">Share on WhatsApp</a> ';
    }
  });
</script>
```
