Mulberry SDK reference

Contracts for the browser SDK — window.mulberry namespaces, methods, and the offer object

This is the contract reference for the Mulberry browser SDK exposed at window.mulberry. Use it to look up exact signatures, parameters, return values, and the shape of the offer object. For end-to-end walkthroughs, see Initialize the SDK and Add a warranty to an order — those guides link here for the details.

🚧

Pass the price unchanged — don't convert it

getWarrantyOffer forwards price to Mulberry's offer API exactly as you pass it (components/shared/API/index.js:119). Use the decimal price your platform already gives you — for example Shopify's product JSON variant.price — and pass it through unchanged. Don't multiply it to cents or otherwise transform it.

Prerequisites

Before any namespace below is usable:

  • The SDK script is loaded: <script src="https://app.getmulberry.com/plugin/static/js/mulberry.js"></script>
  • You have called mulberry.core.init({ publicToken }) and awaited mulberry.core.initCompleted. modal, inline, and learnMore await this internally; button and faq don't, but they read core.settings / core.offers, which are only populated once init resolves — so always await init first.
  • You have your public token. See Get your credentials.

Namespaces

window.mulberry exposes these partner-facing namespaces:

NamespaceWhat it does
coreInitialize the SDK and fetch offers. The entry point for everything else.
modalRender offers in a modal dialog.
inlineRender offers inline within a container element on the page.
buttonRender a single add-to-cart-style button that opens the offer modal.
faqOpen the standalone "what's covered" FAQ overlay for an offer.
learnMoreWire up "Learn more" triggers that open the FAQ overlay.
📘

Other namespaces are internal

The SDK also exposes subscription, enrollment, cartManager, checkout, analytics, helpers, and cta. These power Mulberry Unlimited and managed integrations and are not part of the supported partner surface — don't call them directly.


core

The entry point. Initializes the SDK against your account, fetches offers, and gates rendering by location.

core.init(props)

Initializes the SDK. Resolves core.settings, core.validLocation, and the core.initCompleted promise. Call this once, as early as possible, and await it before fetching offers.

await mulberry.core.init({ publicToken: 'YOUR_PUBLIC_TOKEN' })
await mulberry.core.initCompleted

Parameters (single object):

NameTypeRequiredDescription
publicTokenstringYesYour account's public token. Sent as a bearer token on every SDK request.
langstringNoLanguage code for offer copy and overlays. Defaults to 'en'.
isStagingbooleanNoDefaults to false. Affects subscription-preview filtering.
api_endpointstringNoOverrides the API base URL. Leave unset in production.

Returns: Promise resolving to the raw warranty settings. You normally await core.initCompleted rather than this return value.

Instance properties set after init:

PropertyDescription
core.initCompletedPromise<true> that resolves once init finishes. Await it before calling getWarrantyOffer or any render namespace.
core.settingsThe account/branding settings object. Pass this as settings to modal.init / inline.init.
core.validLocationboolean. false when the visitor's location is outside the supported region (geo gate). Render namespaces no-op when this is false.

core.getWarrantyOffer(product)

Fetches the warranty offers available for a product. Await core.initCompleted first.

const offers = await mulberry.core.getWarrantyOffer({
  id: 'OSLO-XYZ',
  title: 'Oslo Chaise in Velvet',
  price: '2999.00', // your platform's price, passed through unchanged
  detail: shopifyProductJson,
})

Parameters (single product object):

NameTypeRequiredDescription
idstringYesYour identifier for the product (or variant).
titlestringYesProduct title, used in offer copy.
pricestring | numberYesThe product's price, passed through to Mulberry unchanged — use your platform's value (a decimal amount); don't convert it.
detailobjectNoThe full platform product node (e.g. Shopify's AJAX product JSON). When it includes variants, the SDK resolves the variant SKU automatically.
external_variant_idstringNoThe variant to match within detail.variants. Falls back to id, then to the first variant.

Returns: Promise<offer[]> — an array of offer objects. Resolves to [] when Mulberry has no coverage for the product. Resolves to null when core.validLocation is false (an error is logged to the console).

👍

Send warranty_offer_id at checkout

When the customer selects an offer, the only field you send to your cart, checkout, or registration call is offer.warranty_offer_id. See Add a warranty to an order.

core.getCoverageDetails(programId)

Fetches coverage details for a coverage program by id. Used by the learnMore namespace; call it directly only if you render your own "what's covered" UI.

NameTypeRequiredDescription
programIdstringYesThe coverage program id.

Returns: Promise resolving to the coverage data object.


modal

Renders offers in a modal dialog overlaid on the page. Returns an instance you keep a reference to.

modal.init(config)

const instance = mulberry.modal.init({
  offers,
  settings: mulberry.core.settings,
  onWarrantySelect: (offer) => {
    addWarrantyToCart(offer.warranty_offer_id)
    mulberry.modal.close()
  },
  onWarrantyDecline: () => mulberry.modal.close(),
})
instance.open()

Parameters (single config object):

NameTypeRequiredDescription
offersoffer[]YesThe array returned by getWarrantyOffer. Init no-ops if empty.
settingsobjectYesPass mulberry.core.settings.
onWarrantySelectfunctionYesCalled with the selected offer when the customer adds coverage. (Defaults to a no-op if omitted — pass it for a working integration.)
onWarrantyDeclinefunctionNoCalled when the customer declines or closes the modal.
selectorstringNoCSS selector for a container to mount the modal into. Defaults to the document body.
triggerstringNoCSS selector for an element that opens the modal on click.

Returns: the modal instance (or false if there are no offers or the location is invalid).

Instance methods:

MethodDescription
open(showOverlay = true)Opens the modal. Pass false to open without the dimming overlay.
close()Closes the modal.
updateOffer(offers)Replaces the rendered offers with a new array (e.g. after a variant change).
setLoading(isLoading)Toggles the modal's loading state.

inline

Renders offers inline inside a container element you select. Returns an instance you keep a reference to.

inline.init(config)

const instance = mulberry.inline.init({
  offers,
  settings: mulberry.core.settings,
  selector: '#mulberry-inline',
  onWarrantyToggle: ({ offer, isSelected }) => {
    if (isSelected) addWarrantyToCart(offer.warranty_offer_id)
    else removeWarrantyFromCart()
  },
  layout: { input: 'radio' },
})

Parameters (single config object):

NameTypeRequiredDescription
offersoffer[]YesThe array returned by getWarrantyOffer. Init no-ops if empty.
settingsobjectYesPass mulberry.core.settings.
selectorstringYesCSS selector for the container to render into.
onWarrantyTogglefunctionNoCalled with { offer, isSelected } whenever the customer selects or deselects an offer.
layoutobjectNoPresentation overrides, merged over the defaults below.

layout fields:

NameTypeDescription
input'buttons' | 'radio' | 'dropdown'Selection control style. Default 'buttons'.
ctaTextbooleanShow the CTA heading. Default true.
faqbooleanShow the "what's covered" FAQ link. Default true.
logobooleanShow the Mulberry logo. Default true.
stackedbooleanStack offers vertically. Default false.

Returns: the inline instance (or false if there are no offers or the location is invalid).

Instance methods:

MethodDescription
updateOffer(offers)Replaces the rendered offers with a new array (e.g. after a variant change).
deselectOffer()Clears the current selection.
hide()Hides the offers (e.g. after the warranty is added to the cart).
setLoading(isLoading)Toggles the inline loading state.

button

Renders a single Mulberry button into a container. Clicking it opens the offer modal (initialized from core.offers).

button.init(config)

NameTypeRequiredDescription
selectorstringYesCSS selector for the container to render the button into.
settingsobjectYesPass mulberry.core.settings.
onWarrantySelectfunctionNoCalled with the selected offer when coverage is added from the modal.
onButtonClickfunctionNoCalled when the button is clicked, before the modal opens.
onButtonRemovefunctionNoCalled when the customer removes a previously added warranty. When set, the button offers a "remove" action.
alignment'center' | 'right'NoHorizontal alignment of the button.

Methods: setLoading(isLoading) toggles the button's loading state.


faq

Opens the standalone "what's covered" FAQ overlay for a single offer.

faq.init(config) / faq.open() / faq.close()

NameTypeRequiredDescription
coverageofferYesAn offer object (must include coverage_details). Init logs an error and returns if it's missing.
useOverlaybooleanNoRender with the dimming overlay. Default true.

Call faq.init(config) then faq.open() to display it, and faq.close() to dismiss.


learnMore

Wires up "Learn more" triggers on the page. Each element matching .mulberry-learn-more becomes a clickable trigger that opens the FAQ overlay.

learnMore.init(config)

NameTypeRequiredDescription
offerofferNoThe offer to show coverage for. When omitted, coverage is fetched via getCoverageDetails using each element's data-program-id.
settingsobjectNoPass mulberry.core.settings for branded CTA copy.

Each trigger element reads data-program-id and an optional data-layout ('text' by default) attribute. init no-ops if core.validLocation is false.


The offer object

getWarrantyOffer returns an array of these. The table covers the partner-relevant fields only — the response includes additional internal fields you can ignore.

FieldTypeDescription
warranty_offer_idstringThe offer identifier. This is the value you send at checkout/registration.
warranty_hashstringHash identifying the offer terms.
customer_coststringThe price the customer pays for the plan, as a decimal string (e.g. "9.99").
coststringThe plan cost, as a decimal string.
strikethrough_customer_coststring | nullOriginal price to show struck through, when the plan is discounted.
currencystringCurrency code, e.g. "USD".
duration_monthsstringPlan length in months (e.g. "12", "36").
coverage_detailsarray[{ long: string[], short: string[] }] — bullet lists of what's covered, long and short form.
service_typestringThe service type for the plan (e.g. repair_replace).
plan_typenull | 'subscription''subscription' for Mulberry Unlimited offers; null for standard plans.
policy_terms_urlstringURL of the plan's policy terms document.
mb_categorystringMulberry product category for the offer.
external_product_idstring | nullYour product identifier for the covered product, when known.
productobjectMulberry's view of the covered product (name, price, identifiers), including is_subscription_eligibletrue when the product qualifies for Mulberry Unlimited.
📘

product vs. product_meta

offer.product is Mulberry's serialized view of the covered product, and it carries is_subscription_eligible. offer.product_meta is a copy of the exact product object you passed to getWarrantyOffer. Use whichever is more convenient.


Typical flow

  1. Load the SDK script: <script src="https://app.getmulberry.com/plugin/static/js/mulberry.js"></script>.
  2. await mulberry.core.init({ publicToken }), then await mulberry.core.initCompleted. You should now have mulberry.core.settings populated.
  3. const offers = await mulberry.core.getWarrantyOffer(product), passing the product's price unchanged. You should now see an array of offers (or [] if there's no coverage).
  4. Render with mulberry.inline.init(...) or mulberry.modal.init(...), passing offers and mulberry.core.settings.
  5. On select, send offer.warranty_offer_id to your cart, checkout, or registration flow. See Add a warranty to an order.