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

**success** `boolean`

Whether the request was successful.

**data.enabled** `boolean`

Whether the referral program is enabled for this shop.

**data.referralCode** `string`

The customer's unique referral code.

**data.referralUrl** `string`

Full referral URL that can be shared.

**data.stats** `object`

Quick referral statistics.

**Stats properties**

**totalReferred** `number`

Total number of people referred.

**completedReferrals** `number`

Number of completed referrals.

**pendingReferrals** `number`

Number of pending referrals.

**data.socialSharing** `object`

Social sharing configuration set by the merchant.

**Social sharing properties**

**twitter** `boolean`

Whether Twitter/X sharing is enabled.

**twitterMessage** `string`

Pre-filled message for Twitter/X shares.

**facebook** `boolean`

Whether Facebook sharing is enabled.

**email** `boolean`

Whether email sharing is enabled.

**whatsapp** `boolean`

Whether WhatsApp sharing is enabled.

**whatsappMessage** `string`

Pre-filled message for WhatsApp shares.

**sms** `boolean`

Whether SMS sharing is enabled.

**smsMessage** `string | null`

Pre-filled message for SMS shares.

## 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!",
      "sms": false,
      "smsMessage": null
    }
  }
}
```

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


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