---
title: "Generate customer referral URL"
method: POST
path: "/loyalty/cp/api/add-customer-referral-url"
tags: ["Referrals"]
---

# Generate customer referral URL

`POST /loyalty/cp/api/add-customer-referral-url`

## Request

- Base URL: `https://your-store.myshopify.com/apps`
- URL: `https://your-store.myshopify.com/apps/loyalty/cp/api/add-customer-referral-url`
- Auth: none declared

(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):
```javascript
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`.

## Response `200`

Referral link registered. The response body is empty.

## Other responses

- `401`: Customer not authenticated
- `500`: Error generating referral URL

---

[API](https://skmtc.dev/appstle/apis/storefront-apis.md) - [All operations](https://skmtc.dev/appstle/apis/storefront-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/appstle/apis/storefront-apis/revisions/9f59d178ff71?raw)
