SubblySubbly
Log inGet started
  • Get started
  • Developer resources
Subbly.js SDK reference
Docs
Information
    CookiesAmounts and datesCurrencyExpand parametersErrors
Setup
    Start the SDKSet the currencySet the languageVersionConfiguration
Addresses
    List the addressesAdd an addressDelete an address
Authentication
    Authentication stateCheck the authenticationLog in with a passwordRegister a customerCheck if an email is registeredSend a one-time passwordLog in with a one-time passwordLog in with single sign-onLog outGet the access token
Bundles
    List the bundlesLoad a bundleLoad the bundle itemsLoad the bundle groupsQuote a bundle
Cart
    Create a cartLoad a cartUpdate the cartAdd an itemUpdate an itemRemove an itemGet the start datesGet the gifting datesGet the shipping methodsGet the pick-up pointsAttach the customer
Checkout
    Purchase the cart
Countries
    List the countries
Customers
    Get the customer profileUpdate the customerGet the referral link
Funnels
    Get a pre-purchase offerAccept a pre-purchase offerSkip a pre-purchase offerReset the pre-purchase offersGet a mid-purchase offerAccept a mid-purchase offerSkip a mid-purchase offerGet a post-purchase offerAccept a post-purchase offerSkip a post-purchase offer
Leads
    Capture a lead
Metafields
    List the metafields
Payment intents
    Get a payment intentConfirm a payment intent
Pick-up info
    List the pick-up infosAdd a pick-up infoDelete a pick-up info
Products
    List the productsLoad a productLoad a variantLoad a plan
Shop
    Load the shop
Stock notifications
    Get a back-in-stock alert
Subscriptions
    List the subscriptionsLoad a subscriptionUpdate a subscriptionUpdate the survey preferencesUpdate the bundleLoad a subscription itemUpdate a subscription itemUpdate an item bundleUpdate the item survey preferences
Surveys
    Load a survey
Wallet
    List the payment methodsStart a payment setupAdd a payment methodStart a 3-D Secure setup

Subbly.js SDK

Subbly.js is Subbly's browser-side JavaScript library. It calls the Storefront API for you, holds one cart per page, and keeps the cart ID and the customer access token in browser cookies. Subbly.init resolves with an SDK instance; every method in this reference is a method of that instance.

The SDK emits no events: it has no emitter and dispatches no DOM events. The events you may have seen in Subbly belong to the cart widget, a separate product.

Load

Start the SDK
import Subbly from '@subbly/sdk' const subbly = await Subbly.init({ apiKey: 'API_KEY' })

The package also ships a browser bundle, https://cdn.jsdelivr.net/npm/@subbly/sdk, that defines the global Subbly. It is the class, not an instance, so you still call Subbly.init(config).

Cookies

The SDK writes two cookies, each for 365 days on path=/:

  • subbly_cart_id — the cart, written by Subbly.init when you pass loadCart, and by subbly.cart.create.
  • subbly_access_token — the customer access token, written by the authentication methods and emptied by subbly.auth.logout.

Both are plain cookies. The SDK sets no Secure, HttpOnly or SameSite attribute, so any script on the host can read them.

Amounts and dates

Amounts are whole numbers in the minor unit of the currency: 1250 in a USD cart means $12.50. Dates and timestamps are strings.

Currency

The product, bundle and survey methods take an optional headers object as their last argument. Set x-currency on it to price that one response in another currency. When you leave it out, the SDK sends the currency you set with subbly.setCurrency; when you set neither, it sends no currency header.

The subscription methods also take headers, but the SDK adds no currency to them.

setCurrency does not change the cart. The cart has its own currencyCode; change it with subbly.cart.update({ currencyCode }). When Subbly.init loads a cart, it calls setCurrency with the cart currency for you.

Price one product in another currency
subbly.setCurrency('USD') const product = await subbly.products.load(123) const inEuros = await subbly.products.load(123, {}, { 'x-currency': 'EUR' })

Expand parameters

Most methods that return a cart or a subscription take an optional params object with an expand list. Each entry names a relation the API should fill in. A relation you do not name comes back null, so ask for what you need to render.

The cart methods accept coupon, gift_card, items.product, items.product.parent, items.product.parent.pricings, items.bundle.items.product, items.bundle.items.product.parent, items.metadata, shipping_method, shipping_address, payment_method, billing_address, metadata and shipping_carrier. The funnel accepts that return a cart take the same list.

The subscription methods accept product, product.parent, bundle.items.product, bundle.items.product.parent, metadata, addons, discounts and cancellations.

The funnel fetches accept parent, which loads the parent product of each offered variant or plan.

Load a cart with its items and coupon
await subbly.cart.load(cartId, { expand: ['items.product', 'items.product.parent', 'coupon'] })

Errors

A failed request rejects with a plain object, not an Error. So error instanceof Error is false and error.message may be missing. Read error.code instead.

Handle an error
try { await subbly.cart.addItem({ productId: 3301 }) } catch (error) { if (error.code === 'out_of_stock') { // tell the customer } }

The codes are:

codeWhat happened
not_foundThe record does not exist.
bad_requestThe request or the payload is invalid.
out_of_stockA product or a survey answer ran out.
payment_requires_actionThe card needs 3-D Secure. The object also carries paymentIntentId.
user_email_is_not_uniqueThe email already has an account.
unauthenticatedThere is no valid access token.

When the response has no body, the rejection is a real Error carrying the HTTP status text instead. Handle both shapes.

Two rejections are plain Error objects instead, with no code:

  • Error('Missing required apiKey config') — Subbly.init with no argument, or with an empty or missing apiKey. init is async, so it rejects.
  • Error('Cart ID is required') — subbly.cart.load with no ID given and none held.

To install, configure and update the library, see the Subbly.js SDK article.

Last modified on September 15, 2026
Javascript
Javascript
Javascript
Javascript