New JS simple integration returns error 500

Hi there,

I’ve switched site from the old installation method (link to snipcart CDN, hidden div with data-api-key attribute), to the new js installation, but I’m now getting an empty cart with a ‘We’re getting your cart ready’ message and the following error in the console:

snipcart.js:1          POST https://app.snipcart.com/api/cart 500

I can’t figure out where it’s going wrong as the cart was working with the old installation method.

Any suggestions?

Hi @Kelsey, thanks for reaching out!

Can you send us a screenshot or snippet of how the new code looks like in your site HTML?
If you prefer you can also contact us at at geeks@snipcart.com

Thanks.

Hi there, I already sent an email to geeks@snipcart.com a few days ago, but haven’t heard back yet.

Here’s what I sent:

My snipcart code looks like this:

<script>
    window.SnipcartSettings = {
        publicApiKey: 'myActualAPIKey',
        loadStrategy: 'on-user-interaction',
    };

    (()=>{var a,d;(d=(a=window.SnipcartSettings).version)!=null||(a.version="3.0");var s,S;(S=(s=window.SnipcartSettings).currency)!=null||(s.currency="usd");var l,p;(p=(l=window.SnipcartSettings).timeoutDuration)!=null||(l.timeoutDuration=2750);var w,u;(u=(w=window.SnipcartSettings).domain)!=null||(w.domain="cdn.snipcart.com");var m,g;(g=(m=window.SnipcartSettings).protocol)!=null||(m.protocol="https");var y=window.SnipcartSettings.version.includes("v3.0.0-ci")||window.SnipcartSettings.version!="3.0"&&window.SnipcartSettings.version.localeCompare("3.4.0",void 0,{numeric:!0,sensitivity:"base"})===-1,f=["focus","mouseover","touchmove","scroll","keydown"];window.LoadSnipcart=o;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r):r();function r(){window.SnipcartSettings.loadStrategy?window.SnipcartSettings.loadStrategy==="on-user-interaction"&&(f.forEach(t=>document.addEventListener(t,o)),setTimeout(o,window.SnipcartSettings.timeoutDuration)):o()}var c=!1;function o(){if(c)return;c=!0;let t=document.getElementsByTagName("head")[0],e=document.querySelector("#snipcart"),i=document.querySelector(`src[src^="${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}"][src$="snipcart.js"]`),n=document.querySelector(`link[href^="${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}"][href$="snipcart.css"]`);e||(e=document.createElement("div"),e.id="snipcart",e.setAttribute("hidden","true"),document.body.appendChild(e)),h(e),i||(i=document.createElement("script"),i.src=`${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}/themes/v${window.SnipcartSettings.version}/default/snipcart.js`,i.async=!0,t.appendChild(i)),n||(n=document.createElement("link"),n.rel="stylesheet",n.type="text/css",n.href=`${window.SnipcartSettings.protocol}://${window.SnipcartSettings.domain}/themes/v${window.SnipcartSettings.version}/default/snipcart.css`,t.prepend(n)),f.forEach(v=>document.removeEventListener(v,o))}function h(t){!y||(t.dataset.apiKey=window.SnipcartSettings.publicApiKey,window.SnipcartSettings.addProductBehavior&&(t.dataset.configAddProductBehavior=window.SnipcartSettings.addProductBehavior),window.SnipcartSettings.modalStyle&&(t.dataset.configModalStyle=window.SnipcartSettings.modalStyle),window.SnipcartSettings.currency&&(t.dataset.currency=window.SnipcartSettings.currency),window.SnipcartSettings.templatesUrl&&(t.dataset.templatesUrl=window.SnipcartSettings.templatesUrl))}})();
</script>

My button code looks like this:

<button class="snipcart-add-item btn-primary btn btn-default"
data-item-id="<?php echo $item_id ?>"
data-item-price="<?php echo $item_price ?>"
data-item-url="<?php echo $item_url ?>"
data-item-description="<?php echo $item_description ?>"
data-item-image="<?php echo $item_image ?>"
data-item-name="<?php echo $item_name ?>"
data-item-weight="<?= $item_weight ?>"
data-item-length="<?= $item_length ?>"
data-item-height="<?= $item_height ?>"
data-item-width="<?= $item_width ?>"
>
Add to cart
</button>

And the result is a forever spinning loader on the cart page.

Any thoughts?

Hi Nelitow, any chance of a follow up on this?

Hi @Kelsey

Can you please check if your currency in the cart matches your dashboard settings?

Thanks.

That solved it, thank you!

1 Like