StorefrontClient
Your own storefront on a shop's catalog, carts and shopper accounts, through the Storefront API. Checkout, payment and orders stay on Store Hugs: a cart ends in a link to the shop's own checkout page.
Get started
-
Turn it on. In the Store Hugs panel, open Shop Settings → Integration API and set your site's address, which checkout links back to.
-
Make a key.
- A publishable key (
pk_live_…) lists your site's origins, such ashttps://www.example.com, and works only from browsers on them. It reaches no more than a shopper could, so it may ship in your pages. - A secret key (
sk_live_…) works only from your server, and is shown once. Pass the shopper's IP asshopperIp, so limits count each shopper rather than your server.
- A publishable key (
-
Install the SDK:
npm install @storehugs/integration -
Make a client:
import { StorefrontClient } from '@storehugs/integration'; // In the browser, with a publishable key: const storefront = new StorefrontClient({ host: 'acme.storehugs.com', key: 'pk_live_…', }); // On your server, with a secret key: const serverStorefront = new StorefrontClient({ host: 'shop.example.com', key: process.env.STOREHUGS_SECRET_KEY!, shopperIp: request.headers.get('x-forwarded-for') ?? undefined, locale: 'ar', }); -
Sell: list products, fill a cart, and open its checkout link.
const { data: products } = await storefront.products.list({ perPage: 12 }); const cart = await storefront.createCart(); const session = storefront.cart(cart.cartToken); await session.addItem(products[0].id, 2); const { checkoutUrl } = await session.checkout({ returnPath: '/thanks' }); window.location.assign(checkoutUrl);Keep
cart.cartToken(in a cookie or local storage) to come back to the cart.
Options
| Option | Type | |
|---|---|---|
host |
string |
Required. The shop's {slug}.storehugs.com host or its custom domain. https:// is added when missing. |
key |
string |
Required. A publishable or secret key. |
shopperIp |
string |
With a secret key: the shopper your server calls for. |
accessToken |
string |
A signed-in shopper's access token (see sign-in). |
locale |
string |
The language of names and descriptions, one of the shop's; the shop's default otherwise. |
fetch |
FetchLike |
Your own fetch (see custom fetch). |
maxRetries |
number |
Retries after 429, 503 and network errors. Default 2. |
inProgressTimeoutMs |
number |
How long to wait while a retried write still runs. Default 30000. |
Models and methods
Each page describes every method in full: its parameters, the fields it sends and gets back, its refusals and an example.
Shop and pagesThe shop's details and its content pages.
ProductsThe published catalog: search, filter and read a product.
ClassificationsThe shop's classifications (Category, Brand…) and their terms.
Carts and checkoutMake and fill a cart, estimate shipping and hand it to checkout.
Shopper sign-inShoppers sign in on the shop's page; your site gets their tokens.
CustomerThe signed-in shopper's profile and sign-out.
Customer ordersThe signed-in shopper's orders.
AddressesThe signed-in shopper's address book.
WishlistThe signed-in shopper's wishlist.