For the complete documentation index, see llms.txt. This page is also available as Markdown.

Headless API

@lightspeed/ecom-headless is a typed TypeScript client for accessing Ecwid store data. It wraps two official Ecwid APIs into a single package with type safety, automatic authentication, and a consistent developer experience.

API Surface

The package provides typed wrappers for two distinct Ecwid APIs:

REST API Client
Storefront JS API

Runs in

Browser + Node.js

Browser only

What it does

Fetch products, categories, store profile, reviews

Cart management, customer data, page navigation, event callbacks

How it works

Typed fetch wrapper with auto Bearer token

Promise wrappers around callback-based window.Ecwid methods

Both sides share a single initialization call.

Installation

npm install @lightspeed/ecom-headless

Setup

Before using any API function, initialize the client with a public token:

import { initStorefrontApi } from '@lightspeed/ecom-headless'

await initStorefrontApi({
  publicToken: 'YOUR_PUBLIC_TOKEN',
  storeId: 12345,
})

If you omit storeId, it is auto-detected from window.Ecwid. This only works in a browser after the Ecwid storefront widget has loaded. In Node.js, or if initialization runs before window.Ecwid is available, you must pass storeId explicitly.

ApiConfig

Property
Type
Required
Description

publicToken

string

Yes

Public access token for the store API

storeId

number

No

Store ID. If omitted, it is auto-detected from window.Ecwid in a browser context after the storefront widget loads; required in Node.js and before window.Ecwid is available

baseURL

string

No

API base URL. Defaults to https://app.ecwid.com/api/v3/

getApiConfig

After initialization, you can retrieve the resolved config:

Throws an error if called before initStorefrontApi().

Entry Points

The package provides four entry points for tree-shaking:

Import Path
What It Provides

@lightspeed/ecom-headless

Everything — REST functions, storefront methods, Cart/Customer namespaces, constants, types

@lightspeed/ecom-headless/api

REST API functions only

@lightspeed/ecom-headless/storefront

Storefront JS API wrappers only

@lightspeed/ecom-headless/types

TypeScript types only (empty at runtime)

Last updated

Was this helpful?