Getting an “invalid id” error arises from using a Checkout ID with the cart query. The ID returned by checkoutCreate is for a Checkout, not a Cart, so it can’t be used with cart(id: …).
Key distinctions:
Cart and Checkout are separate objects in Shopify’s Storefront API.
The cart query only accepts Cart IDs. There is no checkout field on QueryRoot in the Storefront API.
How to fetch the Checkout:
A Checkout implements the Node interface, so you can query it via node(id: …) and fragment on Checkout (returns id, webUrl, etc.).
Recommended flow:
Create and manage a Cart via the Storefront API (add items, quantities, totals). When ready, send the shopper to checkout using the cart’s checkoutUrl.
Resources and next steps:
Follow Shopify’s cart management guide to create a cart and add line items, then use cart query to retrieve cart contents and totals.
Use node(id: ) only if you specifically need Checkout details.
Status: Clarification provided with docs and a sample node query; no final confirmation from the original poster.
I am not understanding why my checkout Id is invalid. Its the same id that i get back in the response when i created the cart and added an item to the cart. For whatever reason I just cant seem to fetch the cart,
The issue you’re experiencing could be due to a misunderstanding of the differences between a ‘Checkout’ and a ‘Cart’ in Shopify’s API. In Shopify, a ‘Checkout’ and a ‘Cart’ are two separate concepts. The ID you’re getting back from the checkoutCreate mutation is a Checkout ID, not a Cart ID.
So, when you’re trying to use that Checkout ID in the cart query, it’s returning an error because it’s expecting a Cart ID instead. If you want to fetch the Checkout you just created, you should use the checkout query instead of the cart query, like this:
Hello, thank you for your reply. The reason I used cart instead of checkout is that it didnt appear that checkout was an option here (i get a red squiggly underlining checkout telling me so) but i saw cart was an option so i went with that. Note I am using the storefront API, but i dont see this as an option for Admin either anyway.
Using this query:
Let me get this straight, First I have to create a checkout or am i creating a new cart? Then take this id so that I can add line items to it. If I want to then display the cart contents from shopify to see quantity, subtotal etc. i’m supposed to get the checkout to do this or the cart? The naming is confusing, even more so that checkout isnt an option to use in the query, so im confused as to what im supposed to do here? I currently have a custom front end im working on thats basically useless because i cant query the cart/checkout whichever one im supposed to be using.
We have a guide on how to create and manage carts with the storefront API in our developer documentation here.
For most use cases it’s recommended to create and manage a cart, then redirect a customer to the Shopify checkout at the cart’s checkoutUrl. There is also a Hydrogen, Headless, and Storefront APIs board in the forums for more specific questions about how to manage your headless storefront.
The cart query on the Storefront API’s query root is what you are using above, and can only retrieve cart objects. You are correct that there is no checkout query on the Storefront API, but a checkout object implements the node interface so it can be queried directly like this if necessary: