How to get current cart

Topic summary

Main issue: how to access a shopper’s existing cart to add items, especially from custom apps or non-browser contexts.

Key points:

  • Storefront API has a cart query/mutations but requires a cart ID. Cart interoperability (sharing a cart between Liquid/AJAX and Storefront API) is rolling out and not on all stores yet.
  • AJAX API (/cart endpoints) works with the storefront session cookie, so it can read/update the current cart in the browser. Non-browser clients (e.g., Unity WebGL via raw HTTP) typically can’t rely on that cookie.

Guidance offered:

  • If running in the storefront page, use AJAX API. A working example was shared using fetch to /cart/add.js to add a variant to the current cart. This code snippet is central.
  • For custom apps/backends, use an App Proxy to route a storefront request through Shopify to your backend, then invoke the AJAX add-to-cart from that context.

Open questions/unresolved:

  • How to retrieve the current cart purely via Storefront API or by customer token remains unanswered.
  • A backend-only way to fetch/update the active cart without the browser session cookie was not provided.

Status: no definitive solution for cart-by-customer-token; thread remains open.

Summarized with AI on December 22. AI used: gpt-5.

Hi !
If my customer had already a cart with products, how can I get this cart for add other product with my custom app ?
In the Storefront API, I seen cart query but with an id (that I don’t know) :confused:

Kind regards

Hey @Marconino

Your app would need to read the Cart ID - one approach would be to use the AJAX API. Keep in mind cart interoperability is only just starting to roll out (share a cart with Liquid/Storefront API) and wont be available on all stores yet, so it’s safest to also update the cart using the AJAX API too.

Hi, thank you for the reply.

I’ve seen that you can use AJAX API like this : https://shopify.dev/docs/api/ajax#making-requests-to-the-api

But I’m using a Unity webGL application that makes HTTP requests (UnityWebRequest)

Is it possible to use HTTP requests with the AJAX API?

(Sorry if this is a dumb question, I’m a beginner)

Hey @Marconino ,

I’m not familiar with Unity webGL, but you’ll need the session/cookie to access the cart via AJAX - so I suspect Storefront API will be your best bet!

But it is possible to get current cart of my customer with Storefront API ? :confused:
I don’t understand how :pensive_face:

For more context, I have php script which execute a request to Shopify and I want to get current cart of my customer

Hello @Marconino did you find a way to get the current user cart? i’m facing the same problem.

Hello @scerelli ! I use this code in Javascript for add product to current user cart ! :slightly_smiling_face:
(This request is on one of my Shopify pages, if you want to add product from custom app, you have to create a proxy between Shopify and your app)

function addToCart(variantId, quantity) {

let data = {
‘items’: [{
‘id’: variantId,
‘quantity’:quantity
}]
};
fetch(‘/cart/add.js’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify(data)
})
}

1 Like

Thanks, it’s the same I’m using. I wanted to find a way to add to cart from the backend as there are important calculations and price cart transformations to be done before adding products to cart, if using my app, but so far I could find a way, only frontend side.

You should to check about Shopify proxy : https://shopify.dev/docs/apps/online-store/app-proxies
In “Proxy URL” you put your url backend like this https://siteweb/add_product_to_cart.php for example, and in this script you use addToCart function !

1 Like

I will check it out! thanks

1 Like

is there any API which gets the cart information using the customer token for the user

I’m also facing the same issue, need guidance to get the API which gets the cart information using the customer token for the user, can anyone help me Out

Did anyone get any solution?