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:
interface StoreOverview { name: string; slug: string; domain: string; wideLogoUrl: string; squareLogoUrl: string;}| Field | What it is |
|---|---|
name | The store’s display name. |
slug | The store’s slug. |
domain | The domain this store resolves from. |
wideLogoUrl | URL of the wide (horizontal) logo. |
squareLogoUrl | URL of the square logo. |
const store = await OpenShop.store.get();document.title = `${store.name} — Shop`;document.querySelector('.site-logo').src = store.wideLogoUrl;products
Section titled “products”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>| Method | What 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. |
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.
cards(slugs)
Section titled “cards(slugs)”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:
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
OpenShopErrorwhosecodeis'INVALID_INPUT'andstatusis0, without a request.cards([])resolves[], also without a request. - It shares the card cache. The cards it fetches are the ones
card(slug)andos-single-productreuse, 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.
referral
Section titled “referral”OpenShop.referral.current: Referral | null | undefinedThe attribution Open Shop resolved for this visit — who the shopper is shopping with.
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;}| Field | What it is |
|---|---|
handle | The 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. |
firstName | The enroller’s given name, for display. |
lastName | The enroller’s family name, for display. |
displayName | The name the enroller sells under: their company, or their name when none is set. Absent from a server that predates it. |
accountType | The enroller’s account type name. null when the store does not recognise their type. |
accountTypeCode | The account type’s code, which survives a rename of the type. null with accountType. |
entitlements | The enroller’s storefront entitlements, sorted by name. Always an array; empty when they hold none. |
branding | The enroller’s live rep-site section. null when there is nothing to show. |
source | How this enroller was resolved. See the values below. |
source tells you which attribution path won:
source | The shopper… |
|---|---|
HOST | arrived on an enroller’s subdomain. |
QUERY_PARAM | landed on a page URL that carried ?referral=. |
COOKIE | was remembered from an earlier visit. |
CUSTOMER | is 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.
entitlements
Section titled “entitlements”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.
[ { code: 'BOATS', name: 'Boats' }, { code: 'CARS', name: 'Cars' }];codeis the stable identifier from the admin, always uppercase. Branch on it, because the name can be renamed.nameis 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.
branding
Section titled “branding”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.
{ 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' } ]}photoUrlis anhttpsURL already sized for display, ornullwhen the rep added no photo.paragraphis plain text, ornullwhen the rep wrote none. Its line breaks are the rep’s own, so render it withwhite-space: pre-line, and set it as text, never as HTML.favoriteslists 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.
referral:change
Section titled “referral:change”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.
OpenShop.on('referral:change', (referral) => { const label = document.querySelector('.shopping-with'); label.hidden = referral === null; if (referral) label.textContent = `Shopping with ${referral.firstName}`;});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
pathmust start with a single/. Absolute URLs and protocol-relative//paths are refused withcode: 'INVALID_PATH'. - JSON in, JSON out. A
bodyis serialised for you. A response that is not JSON rejects withcode: '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
OpenShopErrorcarrying the API’s own error code.
const result = await OpenShop.api.get('/api/v1/some/endpoint');