Shopify-code-snippets icon indicating copy to clipboard operation
Shopify-code-snippets copied to clipboard

Can’t get Shopify cart via jsonp crossdomain anymore

Open oscarni opened this issue 4 years ago • 3 comments

I’m using “Get Shopify cart data with JSONP“. Since a couple of days ago the request returns empty carts. Anyone else experiencing the same?

I make sure the Shopify store has items in the cart, but when getting the cart via Jsonp from another domain the cart response is without any cart items. Did Shopify change it’s api in some way?

oscarni avatar Jul 17 '20 10:07 oscarni

Interesting. It's possible that JSONP is no longer accepted but would have to look into it. Do you have some replication steps/code used so I can give it a test using the same process?

freakdesign avatar Jul 23 '20 01:07 freakdesign

To test I'm running your script in the console. I get the response from shopify, it's just without any items which I can see are in the cart when I visit the shop.

This could be far fetched, but I think I've figured it out. It looks like it works when I have https setup and only when i'm running the script from the same main domain. So it works when I run it on a subdomain of the main shopify store. But cross-domain with a totally different domain doesn't look like it works anymore. Could be related to chrome setting same-site: lax as default on cookies or some other cookie restriction shopify has limiting the session to only be available on the main domain.

Edit: I can confirm that it get the correct cart when request is made from a subdomain of the same main Shopify domain and over ssl. To test locally i suggest running your local server over https (adding certificates was a pain) and adding a testing subdomain.maindomain to your hosts file.

oscarni avatar Jul 24 '20 12:07 oscarni

Looks like @oscarni is correct about the cookies. My shop is on a subdomain, so I'm able to set my own cookie that is usable by both domains.

NotARobit avatar Jan 06 '21 20:01 NotARobit