Generate customer referral URL
(Re)registers the short referral link for the logged-in customer. The link is normally created automatically when the customer joins the program, so most integrations never need to call this.
No request body and no customer ID parameter. The customer is taken from the Shopify session that the
App Proxy attaches to the request (logged_in_customer_id) — a customer ID can’t be passed in.
The response body is empty. To read the link itself, call GET /apps/loyalty/cp/api/customer-loyalty
and use the referralLink field.
Example (JavaScript running on the storefront while the customer is logged in):
await fetch('/apps/loyalty/cp/api/add-customer-referral-url', {
method: 'POST',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
const { referralLink } = await (await fetch('/apps/loyalty/cp/api/customer-loyalty')).json();
Server-side / headless: use the Admin API instead —
GET /api/external/customer-loyalty?customerId={id} with the X-API-Key header returns the same referralLink.
curl --request POST \
--url https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-urlimport requests
url = "https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url';
const options = {method: 'POST'};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyResponse
Referral link registered. The response body is empty.
curl --request POST \
--url https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-urlimport requests
url = "https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url';
const options = {method: 'POST'};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://{storeDomain}/apps/loyalty/cp/api/add-customer-referral-url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body