# headless-loyalty-page-client

> Source: https://devdocs.joy.so/joy-headless-api/sdk-reference/sdk/headless-loyalty-page-client/ · Last updated: 2026-11-24

## Interfaces

### HeadlessLoyaltyPageClientOptions

Options for [createHeadlessLoyaltyPageClient](#createheadlessloyaltypageclient).

#### Properties

##### apiUrl

```ts
apiUrl: string;
```

Base URL of the Headless API, e.g. `https://api.joy.so/app/api/v1/headless`.

##### fetch?

```ts
fetch?: {
  (input, init?): Promise<Response>;
  (input, init?): Promise<Response>;
  (input, init?): Promise<Response>;
};
```

Override fetch (tests, or a runtime with no global `fetch`). Defaults to `globalThis.fetch`.

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                   |
| --------- | ---------------------- |
| `input`   | `RequestInfo` \| `URL` |
| `init?`   | `RequestInit`          |

###### Returns

`Promise`<`Response`>

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                   |
| --------- | ---------------------- |
| `input`   | `RequestInfo` \| `URL` |
| `init?`   | `RequestInit`          |

###### Returns

`Promise`<`Response`>

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                           |
| --------- | ------------------------------ |
| `input`   | `string` \| `Request` \| `URL` |
| `init?`   | `RequestInit`                  |

###### Returns

`Promise`<`Response`>

##### locale?

```ts
locale?: string;
```

The shopper's locale (e.g. `fr`), sent as `?locale=` on the home read so
its `primaryTranslation` is served in that language. Omit for the shop's
primary language.

##### openUrl?

```ts
openUrl?: (url) => unknown;
```

Opens `url` in a new tab and returns the opened handle (falsy when the
browser blocked it) — what `handleEarningProgram` uses for social,
survey and visit-page programs. Defaults to the browser's global `open`
when there is one.

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `url`     | `string` |

###### Returns

`unknown`

##### shop

```ts
shop: string;
```

The shop's myshopify domain (e.g. `my-store.myshopify.com`). Sent as
`?shop=` on the public (`auth:false`) routes that cannot read the shop
from a customer JWT.

#### Methods

##### getToken()

```ts
getToken(): 
  | string
  | Promise<string | null | undefined>
  | null
  | undefined;
```

Returns the current customer JWT, or `null`/`undefined` for a guest.
Called before every authenticated request — no caching here.

###### Returns

\| `string`
\| `Promise`<`string` | `null` | `undefined`>
\| `null`
\| `undefined`

## Functions

### createHeadlessLoyaltyPageClient()

```ts
function createHeadlessLoyaltyPageClient(options): LoyaltyPageDataClient;
```

Create a [LoyaltyPageDataClient](https://devdocs.joy.so/joy-headless-api/sdk-reference/sdk/loyalty-page-contracts/#loyaltypagedataclient) over the `/headless/*` routes.

[LoyaltyPageDataClient.accountInvite](https://devdocs.joy.so/joy-headless-api/sdk-reference/sdk/loyalty-page-contracts/#accountinvite) rejects immediately: no
`/headless/*` route exists for `POST /popup/accountInvite` (opt-in
`linkAccounts` section only). [LoyaltyPageDataClient.get](https://devdocs.joy.so/joy-headless-api/sdk-reference/sdk/loyalty-page-contracts/#get)/
[LoyaltyPageDataClient.post](https://devdocs.joy.so/joy-headless-api/sdk-reference/sdk/loyalty-page-contracts/#post) refuse a path outside their explicit map
rather than forwarding it — never an open proxy onto `/headless/*`.

#### Parameters

| Parameter | Type                                                                    |
| --------- | ----------------------------------------------------------------------- |
| `options` | [`HeadlessLoyaltyPageClientOptions`](#headlessloyaltypageclientoptions) |

#### Returns

[`LoyaltyPageDataClient`](https://devdocs.joy.so/joy-headless-api/sdk-reference/sdk/loyalty-page-contracts/#loyaltypagedataclient)
