Carts - storefront api

How can we distinguish abandoned and completed carts using storefront api? Like if we are assuming that a completed cart will result in null on querying then how can we distinguish an abandoned cart as shopify mentioned that abandoned carts will expire and not deleted as is the case for completed checkout carts?

Hey again @Jaspreet_Singh, you’re basically right. For Storefront session handling, the normal approach is to query the saved cart ID and, if it returns null, clear it and create a new cart.

The cart lifecycle docs say abandoned carts expire within 30 days, while completed carts are deleted. There’s also a bit more info here on GitHub that goes over how a successfully checked-out cart should return null.

That said, for definitive tracking, I’d use an order/checkout completion event; the Admin API’s abandonedCheckouts can help with checkouts where the buyer supplied contact information.

You can use something like the orders/create webhook and cross reference it with the checkout token value of the checkout to confirm the order was created.

Let me know if I can clarify anything on our end here.

@Alan_G the other approach is the one that we are also using in one of our embedded apps. But, currently we are looking for approaches to use in a non-embedded standalone app which will not be installed via the merchant in shopify at all

Hey @Jaspreet_Singh , thanks for clarifying! Yeah, right now there unfortunately isn’t a definitive way to distinguish the two using the Storefront API alone. Once the cart query returns null, it doesn’t expose whether the cart expired or completed checkout. Confirming completion would require authenticated access to order data or an equivalent completion signal.

I’m more than happy to pass this along as a feature request though - feel free to share any specific use cases you have and I’ll send that along for sure. Really appreciate your patience here :slight_smile: