JavaScript SDK
Spark JS
spark js type aliases spark type spark = { options sparklayeroptions; platform platform; switchimpersonatingcustomer promise\<null | userdata>; getproduct (parentproductid) => promise\<product>; getvariant (parentproductid, variantsku) => promise\<productvariant>; getpriceforproduct (parentproductid) => promise\<simplifiedproductprice>; calculatepricingforvariantdata (variant, qty, qtyacrossvariants?) => calculatepricingforvariantdataresult; isloggedin () => promise\<boolean>; updatecart promise\<null | object>; externalclearbasket promise\<void>; getpacksizeforvariant promise\<number>; getrrppriceforvariant promise<{ rrp number | null; currencycode string; }>; getpricingforvariant promise<{ price number | null; rrp number | null; pricebreaks variantpricebreak\[]; currencycode string; }>; calculatepricingforvariant promise\<calculatepricingforvariantdataresult>; getcart promise\<null | cart>; uploadfile promise\<string>; fetch (query, variables?, useimpersonatingcustomer?, bypassappproxy?) => promise\<response>; getcartcache null | cart; }; properties property type description options sparklayeroptions /#sparklayeroptions platform platform getproduct ( parentproductid ) => promise < product > fetch the graphql product object for a given parent product id throws if product not found or error occurred fetching product getvariant ( parentproductid , variantsku ) => promise < productvariant > fetch the graphql variant object for a given parent product id and variant sku throws if product/variant not found or error occurred fetching product getpriceforproduct ( parentproductid ) => promise < simplifiedproductprice > fetch the pricing for a parent product includes price breaks, lowest price and the number of prices (used to note if from is needed to be shown) throws if product not found or error occurred fetching product calculatepricingforvariantdata ( variant , qty , qtyacrossvariants? ) => calculatepricingforvariantdataresult isloggedin () => promise < boolean > check if user is logged in fetch ( query , variables? , useimpersonatingcustomer? , bypassappproxy? ) => promise < response > run a graphql query (with the user authenticated) methods switchimpersonatingcustomer() switchimpersonatingcustomer(customerid) promise\<null | userdata>; switch impersonating customer or end impersonation with null parameters parameter type customerid null | string returns promise < null | userdata > updatecart() updatecart( input, cartsuccesshandledlocally, carterrorshandledlocally) promise\<null | object>; run an update cart mutation, shows appropriate toasts and returns result parameters parameter type description input partial < updatecart > follows the graphql updatecart mutation object cartsuccesshandledlocally boolean do not show any success toasts, ask result will be handled locally (useful in the cart, as the change is shown by the update) carterrorshandledlocally boolean do not show any error toasts, ask result will be handled locally returns promise < null | object > returns cartresults or null if error (check console for error) throws error if request fails externalclearbasket() externalclearbasket() promise\<void>; call sparklayer to clear the basket, designed to be used on the thanks page returns promise < void > getpacksizeforvariant() getpacksizeforvariant(parentproductid, variantsku) promise\<number>; fetch the pack size for a variant given parent product id and variant sku parameters parameter type description parentproductid string variantsku string returns promise < number > pack size for variant throws if product/variant not found or error occurred fetching product getrrppriceforvariant() getrrppriceforvariant(parentproductid, variantsku) promise<{ rrp number | null; currencycode string; }>; fetch the rrp price for a variant given parent product id and variant sku parameters parameter type description parentproductid string variantsku string returns promise <{ rrp number | null ; currencycode string ; }> rrp price (null if not set for currency) and currency code throws if product/variant not found or error occurred fetching product getpricingforvariant() getpricingforvariant(parentproductid, variantsku) promise<{ price number | null; rrp number | null; pricebreaks variantpricebreak\[]; currencycode string; }>; fetch the pricing for a variant given parent product id and variant sku parameters parameter type description parentproductid string variantsku string returns promise <{ price number | null ; rrp number | null ; pricebreaks variantpricebreak \[]; currencycode string ; }> all price related data for variant throws if product/variant not found or error occurred fetching product calculatepricingforvariant() calculatepricingforvariant( parentproductid, variantsku, qty, qtyacrossvariants) promise\<calculatepricingforvariantdataresult>; given a product id, sku and quantity, return the price for the product parameters parameter type description parentproductid string variantsku string qty number qtyacrossvariants null | number for tiered pricing, this is calculated by qty across variants (if configured) returns promise < calculatepricingforvariantdataresult > total price (qty unit price) and unit price throws if product/variant not found or error occurred fetching product getcart() getcart() promise\<null | cart>; fetch the cart from graphql returns promise < null | cart > uploadfile() uploadfile(filename, filedata) promise\<string>; parameters parameter type filename string filedata blob returns promise < string > getcartcache() getcartcache() null | cart; returns null | cart sparklayeroptions type sparklayeroptions = { sparkdomain "app sparklayer io" | "test app sparklayer io"; platform "base" | "bigcommerce" | "shopify" | "wix" | "woocommerce"; siteid string; rooturl string; accountredirect { urlregex? regexp; goto? string; }; cartredirect { urlregex? regexp; goto? string; }; wordpresssiteurl? string; accountbuttonselectors string; logoutbuttonselectors string; cartbuttonselectors string; loginbuttonselectors string; display displayoptions; termsandconditionslink string; language string; locale string | null; translations translations; showtranslations boolean; checkoutcustomelements customcheckoutelementconfig\[]; paymentmethodsorder paymentmethodname\[]; productlink string; customaccountdetails { title string; value string | number; displaytext? string; type? customaccountdetaillinktype; }\[]; oncheckoutvalidation promise< \| null \| { message string; }\[]>; oncartupdate promise\<void>; oncartload promise\<void>; precartupdatelistener partial\<updatecart>; onready? promise\<void>; onload? promise\<void>; onlogout? promise\<void>; shopify? { useappproxy? boolean; }; bigcommerce? { appclientid? string; }; auth { user? string; token? string; }; authlogouturi string | null; analytics? analyticsoptions; }; properties property type description sparkdomain "app sparklayer io" | "test app sparklayer io" the domain of the sparklayer api (defaults to app sparklayer io) platform "base" | "bigcommerce" | "shopify" | "wix" | "woocommerce" sets the default options for the platform siteid string the client specific site id rooturl string the root url used to pre fix any created urls generally used for i18n accountredirect { urlregex? regexp ; goto? string ; } the account redirect options accountredirect urlregex? regexp accountredirect goto? string cartredirect { urlregex? regexp ; goto? string ; } the cart redirect options cartredirect urlregex? regexp cartredirect goto? string wordpresssiteurl? string the url of the wordpress site when using the woocommerce platform accountbuttonselectors string the selectors for the account button (defaults to \[href="/account"], \[data spark link=account] ) logoutbuttonselectors string the selectors for the logout button (defaults to \[href="/account/logout"], \[data spark link=logout] ) cartbuttonselectors string the selectors for the cart button (defaults to \[href="/cart"], \[data spark link=cart] ) loginbuttonselectors string the selectors for the login button (defaults to \[href="/spark b2b login"], \[data spark link=login] ) display displayoptions /#displayoptions the display options for the sparklayer termsandconditionslink string terms and conditions link (defaults to /terms and conditions ) language string the language to use for the sparklayer (defaults to en ) locale string | null the locale to use for formatting, currently only used for dates (defaults to the user's browser locale) examples en gb , en us , de de translations translations override internal translations, keyed by language code showtranslations boolean useful to debug translations, shows the translation key checkoutcustomelements customcheckoutelementconfig \[] a list of custom elements to display in checkout paymentmethodsorder paymentmethodname \[] the order of payment methods productlink string the link to the product page (defaults to /\ product slug ) customaccountdetails { title string ; value string | number ; displaytext? string ; type? customaccountdetaillinktype /#customaccountdetaillinktype ; }\[] an array of objects containing title, value pairs of data to show on the my details panel for a customer optionally can contain a type field to identify special formatting for values shopify? { useappproxy? boolean ; } shopify useappproxy? boolean bigcommerce? { appclientid? string ; } bigcommerce appclientid? string auth { user? string ; token? string ; } use sparklayer auth auth user? string auth token? string authlogouturi string | null analytics? analyticsoptions methods oncheckoutvalidation() oncheckoutvalidation(cart) promise< \| null \| { message string; }\[]>; an asynchronous function to validate whether the user is allowed to checkout with their current cart contents returns an array of error objects or null if no errors note this function must be asynchronous parameters parameter type cart cart returns promise < \| null \| { message string ; }\[]> oncartupdate() oncartupdate(cart, results) promise\<void>; a function called when the cart is updated, can be used to trigger analytics parameters parameter type cart cart results cartresults \[] returns promise < void > oncartload() oncartload(cart) promise\<void>; a function called when the cart is loaded, can be used to trigger analytics parameters parameter type cart cart returns promise < void > precartupdatelistener() precartupdatelistener(input) partial\<updatecart>; a function called before the cart is updated, can be used to modify the products before completing checkout parameters parameter type input partial < updatecart > returns partial < updatecart > onready()? optional onready(spark) promise\<void>; a function called when the sparklayer is ready parameters parameter type spark spark /#spark returns promise < void > onload()? optional onload(spark) promise\<void>; a function called when the user logs in parameters parameter type spark spark /#spark returns promise < void > onlogout()? optional onlogout() promise\<void>; a function called when the user logs out returns promise < void > displayoptions type displayoptions = { orderlistshowshippingaddress boolean; customerreferencehidden boolean; customerreferencerequired boolean; customerreferencemaxlength number; darktheme boolean; savingsuserrp boolean; roundpricebreakpercentages boolean; showpricebreaksavings boolean; sectionconfiguration displaysectionconfiguration; showslots string\[]; showrrptoggle boolean; hidefinancials? boolean; }; properties property type orderlistshowshippingaddress boolean customerreferencehidden boolean customerreferencerequired boolean customerreferencemaxlength number darktheme boolean savingsuserrp boolean roundpricebreakpercentages boolean showpricebreaksavings boolean sectionconfiguration displaysectionconfiguration /#displaysectionconfiguration showslots string \[] showrrptoggle boolean hidefinancials? boolean displaysectionconfiguration type displaysectionconfiguration = { my account? { order? string\[]; hide? string\[]; }; }; properties property type my account? { order? string \[]; hide? string \[]; } my account order? string \[] my account hide? string \[] customaccountdetaillinktype type customaccountdetaillinktype = "email" | "phone" | "sms" | "website";