Setup
Start Subbly.js with your Storefront API key, then set the currency and the language.
Starts Subbly.js with your Storefront API key and resolves with the SDK instance. Every other method in this reference is a method of that instance.
init always loads the shop first, so subbly.shop is filled in by the time
the promise resolves. It then checks the stored access token, and, when you pass
loadCart, loads or creates a cart and copies the cart currency onto the
instance. A failed shop load rejects the promise.
Call init once per page. The SDK builds one shared HTTP client and keeps it,
so a second call with a different apiKey, apiUrl or lang quietly reuses
the first one.
Method parameters
configRequiredSubblyConfigHow to start the SDK. Leave it out, or pass an empty apiKey, and init
rejects with Error('Missing required apiKey config').
ReturnsPromise<Subbly>
The SDK instance.
Start the SDK
Start with a cart and a customer
Sets the currency for the prices in later product, bundle and survey responses.
The SDK sends it as the x-currency header.
It only fans the code out to subbly.products.setCurrency,
subbly.bundles.setCurrency and subbly.surveys.setCurrency, which each store
it for their own requests; an x-currency header you pass on a single call
still wins.
This does not change the cart currency. Use
subbly.cart.update({ currencyCode }) for that. When init loads a cart, it
calls setCurrency with the cart currency itself.
Method parameters
currencyCodeRequiredstringA currency abbreviation the shop supports, such as USD. Read the list from
subbly.shop.currencies[].abbreviation.
Returnsvoid
Nothing.
Set the currency
Sets the accept-language header the SDK sends with every later request.
Method parameters
languageCodeRequiredstringA language code the shop supports. Read the list from
subbly.shop.languages[].code.
Returnsvoid
Nothing.
Set the language
A read-only property with the version of the @subbly/sdk package the page
loaded. Useful in a bug report.
Returnsstring
The version of the @subbly/sdk package on the page.
Read the version
The three client values init received, exactly as you passed them. It leaves
out cartId, loadCart and accessToken, and it does not follow a later
setLanguage call.
subbly.config is not the configuration in use. The SDK applies its defaults
deeper in, when it builds the HTTP client, so a value you left out stays
undefined here.
ReturnsSubblyConfig
The values passed to init.
Read the configuration