Skip to content

Store, Products, Referral

The remaining namespaces on window.OpenShop: store settings, product data, referral attribution, and a thin escape hatch for endpoints the API surface above does not cover.

OpenShop.store.get(): Promise<StoreOverview>

Resolves with the overview of the store this domain belongs to. The bundle requests it during init and keeps the result in memory, so by the time your code runs this usually resolves from what is already there.

StoreOverview is a curated shape — a store’s name, its identifiers, and its two logos. It is not a settings object:

openshop.d.ts
interface StoreOverview {
name: string;
slug: string;
domain: string;
wideLogoUrl: string;
squareLogoUrl: string;
}
FieldWhat it is
nameThe store’s display name.
slugThe store’s slug.
domainThe domain this store resolves from.
wideLogoUrlURL of the wide (horizontal) logo.
squareLogoUrlURL of the square logo.
app.js
const store = await OpenShop.store.get();
document.title = `${store.name} — Shop`;
document.querySelector('.site-logo').src = store.wideLogoUrl;
OpenShop.products.card(slug: string): Promise<ProductCard>
OpenShop.products.cards(slugs: string[]): Promise<ProductCard[]>
OpenShop.products.details(slug: string): Promise<ProductDetails>
OpenShop.products.collections(): Promise<Collection[]>
OpenShop.products.paged(query: PagedQuery): Promise<PagedProducts>
MethodWhat it returns
card(slug)The compact card view of one product — what os-single-product renders.
cards(slugs)The card view of up to 50 products in one request, in the order asked. See cards(slugs).
details(slug)The full detail view of one product — what os-product-details renders.
collections()Every collection in the store.
paged(query)A page of products, for building your own grid or search.
app.js
const product = await OpenShop.products.card('awesome-cream');
await OpenShop.cart.add({ productId: product.id });

These are the same calls the product components make, so what you get back matches what the components on the page are showing.

Fetches several cards in one request, such as a rep’s favorites. The referral resolves after the page loads and can change later, so handle both the current value and the event:

app.js
async function showFavorites(referral) {
const slugs = referral?.branding?.favorites.map((favorite) => favorite.slug) ?? [];
const cards = await OpenShop.products.cards(slugs);
// render the cards
}
if (OpenShop.referral.current !== undefined) showFavorites(OpenShop.referral.current);
OpenShop.on('referral:change', showFavorites);
  • Order is kept. Cards come back in the order of slugs.
  • Missing products are left out, not errors. A slug that matches nothing this shopper may buy — unknown, inactive, or limited by purchase eligibility — is dropped, so the result can be shorter than slugs.
  • Up to 50 slugs. More rejects with an OpenShopError whose code is 'INVALID_INPUT' and status is 0, without a request. cards([]) resolves [], also without a request.
  • It shares the card cache. The cards it fetches are the ones card(slug) and os-single-product reuse, so cards rendered afterwards for the same slugs do not fetch again.

Failures reject with an OpenShopError carrying the HTTP status and a code derived from it — a product that does not exist rejects with code: 'NOT_FOUND' and status: 404. These calls do not read the API’s own err code out of the body, so branch on status here; status: 0 still means the request never got an answer. cart.add() and api.* are where the backend’s own codes come through.

The returned shapes are declared in openshop.d.ts; the full field-by-field reference lives in the API docs.

OpenShop.referral.current: Referral | null | undefined

The attribution Open Shop resolved for this visit — who the shopper is shopping with.

openshop.d.ts
interface Referral {
handle: string | null;
firstName: string;
lastName: string;
displayName?: string;
accountType: string | null;
accountTypeCode: string | null;
entitlements: StorefrontEntitlement[];
branding: RepBranding | null;
source: 'HOST' | 'QUERY_PARAM' | 'COOKIE' | 'CUSTOMER';
}
interface StorefrontEntitlement {
code: string;
name: string;
}
interface RepBranding {
photoUrl: string | null;
paragraph: string | null;
favorites: RepFavorite[];
}
interface RepFavorite {
productId: number;
slug: string;
}
FieldWhat it is
handleThe enroller’s referral handle. null only for a CUSTOMER attribution whose enroller has no handle: the name is known, but there is nothing to put in a link.
firstNameThe enroller’s given name, for display.
lastNameThe enroller’s family name, for display.
displayNameThe name the enroller sells under: their company, or their name when none is set. Absent from a server that predates it.
accountTypeThe enroller’s account type name. null when the store does not recognise their type.
accountTypeCodeThe account type’s code, which survives a rename of the type. null with accountType.
entitlementsThe enroller’s storefront entitlements, sorted by name. Always an array; empty when they hold none.
brandingThe enroller’s live rep-site section. null when there is nothing to show.
sourceHow this enroller was resolved. See the values below.

source tells you which attribution path won:

sourceThe shopper…
HOSTarrived on an enroller’s subdomain.
QUERY_PARAMlanded on a page URL that carried ?referral=.
COOKIEwas remembered from an earlier visit.
CUSTOMERis signed in, and this is the enroller on their own account.

undefined means attribution has not resolved yet; null means it resolved to nobody. The os-referral-tracker component is what resolves it, so keep that component on the page.

A store can switch any entitlement to Show on storefront (Settings › Entitlements in the Open Shop admin). entitlements lists the ones the enroller currently holds, as { code, name }. Entitlements that are not switched on, and grants that have ended, never appear here.

Value for a rep holding two storefront entitlements
[
{ code: 'BOATS', name: 'Boats' },
{ code: 'CARS', name: 'Cars' }
];
  • code is the stable identifier from the admin, always uppercase. Branch on it, because the name can be renamed.
  • name is the label staff gave it, for display.

The same list is on OpenShop.customer.current.enroller.entitlements for a signed-in shopper, describing the enroller on their own account.

For no-code use, the bundle also writes the codes to <html data-os-referral-entitlements> and accepts data-os-show="referral-entitlement:<CODE>". Storefront entitlements walks through a full setup.

Reps on the account types a store enables can publish a section for the home page of their site: one landscape photo, a paragraph of up to 500 characters, and their favorite products. The store turns rep sites on and may review each one. branding is the version that is live right now.

Value for a rep with a published section
{
photoUrl: 'https://media.example.com/rep-photo.jpg?w=1600',
paragraph: 'Hi, I am Jane.\nI have been selling boats on the lake for ten years.',
favorites: [
{ productId: 412, slug: 'pontoon-cover' },
{ productId: 87, slug: 'dock-lines' }
]
}
  • photoUrl is an https URL already sized for display, or null when the rep added no photo.
  • paragraph is plain text, or null when the rep wrote none. Its line breaks are the rep’s own, so render it with white-space: pre-line, and set it as text, never as HTML.
  • favorites lists products in the rep’s order. It can include products this shopper cannot buy; products.cards() leaves those out.

The rep’s name is not part of branding. Use the referral’s displayName.

branding is null whenever there is nothing to show: the store has rep sites off, the rep switched theirs off or never published one, the store hid it, or the server predates it. The same value is on OpenShop.customer.current.enroller.branding for a signed-in shopper.

os-rep-spotlight renders the whole section for you. To lay it out yourself without a script, use the data-os-src and data-os-text bindings.

Fires when the tracker resolves attribution, changes it, or clears it, and when a later resolution (a page load, a sign-in) carries different entitlements or branding. Nothing is pushed to an open page: a rep switching their section off or the store hiding it reaches the shopper on their next page load. The detail is Referral | null, entitlements and branding included, and it is mirrored on document as os:referral:change.

app.js
OpenShop.on('referral:change', (referral) => {
const label = document.querySelector('.shopping-with');
label.hidden = referral === null;
if (referral) label.textContent = `Shopping with ${referral.firstName}`;
});
Theme by entitlement
OpenShop.on('referral:change', (referral) => {
const codes = referral?.entitlements.map((entitlement) => entitlement.code) ?? [];
document.querySelector('.dealer-badge').hidden = !codes.includes('BOATS');
});

There is no setter. Which enroller wins, and whether a shopper picked one by hand, is decided inside Open Shop and is not something site code can override.

The data-os-show="referral" and data-os-text="referral.firstName" attributes cover the display case without a script.

OpenShop.api.get<T>(path: string): Promise<T>
OpenShop.api.post<T>(path: string, body?: unknown): Promise<T>

An escape hatch for endpoints the namespaces above do not wrap. Both are thin:

  • Same-origin only. The path must start with a single /. Absolute URLs and protocol-relative // paths are refused with code: 'INVALID_PATH'.
  • JSON in, JSON out. A body is serialised for you. A response that is not JSON rejects with code: 'INVALID_RESPONSE'.
  • The { data } envelope is unwrapped, so you get the payload directly.
  • No headers are added. The browser sends the session cookies; nothing else is needed.
  • Non-2xx rejects with an OpenShopError carrying the API’s own error code.
app.js
const result = await OpenShop.api.get('/api/v1/some/endpoint');