[GraphQL Storefront API] Get cart id by customer

I couldn’t find any solution to get cart id by customer.
Our application require a customer auth for shopping, so we always have the customer data in hand. So we always create carts with buyerIdentity (customerAccessToken and email)

We would like to show the same cart to our customers on web and in all the connected device app. Without this feature we can not use a shared cart in different platforms.

I have found an old (2023) topic about it, but this solution does not meet with our needs. How to get cart details or cart ID for a given customer in Storefront API - Custom Storefronts - Shopify Community
We would like to achive this with graqhQL Storefront API features.

Thanks, Adam

1 Like

Hi Adam,

At this time there is no way to retrieve a cart from a specific customer using the Storefront API only. The only way to retrieve a cart via the Storefront API is with the cart’s id.

However I do have a couple different workarounds I can suggest:

  1. Most Recommended: When the cart is created on one storefront, you save the cart id and customer id to a backend database on your end that can be accessed by any Headless Storefronts clients to retrieve the associated cart from the customer id.

  2. Using the Customer Account API, make a metafieldsSet mutation call to save the customer’s last cart id in a custom metafield on the Customer Object. Then you can use the Storefront API to retrieve the cart id from the metafield on any other storefront.

  3. Using the Customer Account API, you can access the customer.lastIncompleteCheckout field to get info on the customers last abandoned checkout, including a URL to redirect them back to the checkout. However this does require the customer to have accessed and interacted with the checkout at least once from a cart.

If you were not wanting to handle any back end apps and databases, then workaround 2 would probably be your best bet. Here’s some more info on how you could implement that in more detail.

On Storefront 1:

  • Create Customer Account Token and Cart
  • Uses Customer Account Token with Customer Account API to store the cart id in a metafield on the Customer object with the metafieldsSet mutation.

On Storefront 2.

  • Creates new Customer Account Token (each token is authenticated per storefront)
  • Uses Customer Account Token to retrieve the Customer object from the Storefront API, with a customer query

Here’s some additional documentation on using the Customer Account API with headless storefronts:

Thank you very much for your detailed feedback.

As we currently do not have a backend solution, we are unable to implement the first method you suggested. We are therefore relying exclusively on the Storefront API.

Our team is developing applications for more than seven Shopify stores, and we believe this feature would be highly beneficial within the Storefront API. I noticed that this functionality was requested back in 2023, which is why I am kindly submitting this request again.

Thank you in advance for your consideration.

Hi Adam,

I have submitted some feedback internally on your behalf with this request. While we can’t guarantee when or if changes will be made, I can assure you all feedback is taken with great value by our developers and product managers when determining future features and updates to the platform.

Additionally, you can submit feedback yourself via the Shopify.dev article directly, scrolling to the bottom of the page, you can select Was this section helpful?: No and submit your customized feedback.

1 Like