Getting 'invalid ID' error when fetching cart using id from creating a new checkout

Topic summary

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.

Summarized with AI on January 16. AI used: gpt-5.

Hi @artsycoder ,

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:

query checkoutNode($id: ID!){
 node(id:$id){
   ...on Checkout{
     id
     webUrl
   }
 }
}

variables:
{
 "id":"gid://shopify/Checkout/95fc07e10e53218fdba96451e45f4eeb?key=58af8673d32769d7e82e3f5ec8fa6dee"
}

Hope that helps!

  • James