Skip to main content

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.

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

Usage

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.
data.socialSharing
object
Social sharing configuration set by the merchant.

Sample response

{
  "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

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