I have some questions regarding the cart ID tokens we’ve observed during customer support.
We encountered an issue where the error “The specific cart does not exist” prevented a discount code from being applied via API. Specifically, we noticed that the Lorenza theme version 4.2.2 is generating a cart token in the format “34dde8e3d88087ea76beb7ea8d3e7079”. Typically, the token follows a format like “Z2NwLXVzLWNlbnRyYWwxOjAxSkNNNjY2UUFXSzdNOTMzS1Y2UzBGOUZB?key=866b72d5c9747a71efd462d01020375f”.
Could you please clarify the difference between these two token formats? Any insight into this variation would be greatly helpful for addressing this issue.
I’ve encountered a similar issue with the Cart AJAX API (https://shopify.dev/docs/api/ajax/reference/cart#get-locale-cart-js). In the response I sometimes get a token of the format “71cd49da38c1dffdec7c795ed577ae52”, but in the Orders Create Webhook when ordering the cart I get a different cart_token which is of the “Z2N…” format.
Any Help or Information from Shopify would be really helpful because our App breaks if the cart tokens do not match. The weird thing is though that sometimes the tokens did match today - Maybe a bug? Or some undocumented is being rolled out?
What I found out: If a cart already exists, then the Cart AJAX API reliably returns the same cart token (“Z2N…”) which is also reflected in the Orders Create webhook. If there is no cart (e.g. new browser session) then every GET to the Cart AJAX API returns a different token (which is also not in the “Z2N…” format).
It would be nice if someone from Shopify could clarify whether this intended behavior or not so we can adjust our App accordingly.
returns tokens in the longer format (Z2NwLXVzLWVhc3QxOjAxSkpOSEhDR05IM0tENlRBV0FDMktUWlBD?key=6184a46df0a4e29cbea6cf658ae903a6)
sometimes in the shorter format (6a6d0880ec1fce20e61deaf9c6f0b188)
With the shorter tokens, when we use the cartDiscountCodesUpdate mutation to apply a discount to the cart via storefront API, we get a ‘cart not found’ error. But it works with the longer tokens.
Can someone from Shopify please help? This inconsistency in token format is breaking a key feature in our app.
Personally, I worked around this by using the cart/add.js api with a quantity 0 item in order to get the correct cart token in the cookies. It has magically been working for me so far. Basically my flow goes:
check for existing cart token in cookies
if it does not exist, hit cart/add.js with a quantity 0 item
We have the same problem. It seems that the shopify sometimes return a old cached token.
First of all, the token format is irrelevant. In my case, the cached token has the same format (the long format with the “key=” above) as the correct token in my store default language, but when i switch to another store language, the cart api returns the short format.
Second, as mentiond by ck_3_1, it only happens to the cart.js call, other calls like add.js or clear.js returns the correct token. You can try the following fetch call in console.
After checking with the shopify support, turns out the root cause is the domain settings on shopify admin portal. The CNAME record is not pointing to shops.myshopify.com.
After we have fixed the CNAME issue. The problem is gone.