Cart token missing from cart object in snippet

Highlighted
Tourist
4 0 2

Hi, we are developing a webpush notification app for abandoned carts. For this, we need to capture the cart token on the front end so we can connect a checkout with a push subscription. Initially, we were able to capture the cart token by inserting a snippet with {{ cart | json }} and that JSON would have the token. Recently we are seeing that cart token is missing from this object. Even if items are added to the cart, the token doesn't show up in the cart object. 

Was there a recent change that has caused this? Is there another way to capture the cart token on the store frontend?

Thanks in advance.

1 Like
Highlighted
New Member
2 0 0

We have seen the same issue. The cart object used to contain the token - but since ~ 12th/13th Aughust 2020 it no longer does.

Shopify - please can you confirm that this is no longer available, as oppose to being dropped accidentally?

What alternatives do we have to get access to the cart token from the liquid snippet?

Has anyone else got a workaround?!

0 Likes
Highlighted
Tourist
4 0 2

Not really a work around for the liquid snippet, but we switched to using the theme AJAX api to get the cart data.

https://shopify.dev/docs/themes/ajax-api/reference/cart 

1 Like
Highlighted
Shopify Partner
521 38 109

It's disappointing the your original post was 2 weeks ago, yet there is no response from anyone at Shopify. If support calls are redirected to clients posting here then I'd hope a reply would come a bit sooner?

0 Likes
Highlighted
New Member
2 0 0

Thanks for the response. For reference, this is what we ended up doing as well.

It seems crazy to have to make another API call to get the cart - just to get the cart token, when the cart is already present (just without the token!).

 

Oh well - at least we have a workaround!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
586 71 128

Hey @JohnBarton @peakengage @Greg_Kujawa,

The behaviour that recently changed on that liquid drop wasn't listed in our documentation, so it's not unexpected for undocumented behaviour to change without notice. Right now the best way to get the token is from cart.js as was already mentioned.

I agree that having the token available in the liquid drop is a better solution than having to make an AJAX call, I'll bring this up with our teams to see whether it's possible to have this added as an officially documented liquid attribute.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes