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:
-
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.
-
Using the Customer Account API, make a
metafieldsSetmutation 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. -
Using the Customer Account API, you can access the
customer.lastIncompleteCheckoutfield 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
metafieldsSetmutation.
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
customerquery
Here’s some additional documentation on using the Customer Account API with headless storefronts: