Storefront API GraphQL to Retrieve Checkout

Using the Storefront API and looking for some help retrieving a checkout that has been created (for example: via checkoutCreate) and not yet turned into an order.

The use case is that we’re wanting to create a Cart page on a website. When the customer goes to the Cart page, as long as we have a Checkout ID in their session, we retrieve the Checkout and show the line items in the cart.

Here’s the query we’re using:

{
node(id: “Z2lkOi8vc2hvcGlmeS9DaG…”) {
id
… on Checkout {
id
ready
currencyCode
subtotalPrice
taxesIncluded
totalTax
totalPrice
lineItems(first: 250) {
edges {
node {
id
title
quantity
variant {
id
price
}
}
}
}
}
}
}

We’re getting the following error back from the API:

{
“errors”: [
{
“message”: “Unexpected end of document”,
“locations”:
}
]
}

Any tips on how to successfully pull a Checkout back using the Checkout ID? Has anyone had any luck doing this on the 2019-10 version of the Storefront API? This doesn’t seem to be well documented…

Hi @DynamitDave ,

I tried your query, and although it’s using a bunch of deprecated parameters the syntax is fine and this should work. The error message you are getting leads me to believe it’s not an issue with the query itself but how you are sending it in code. It’s possible you are sending the query with some extra whitespace or characters. Can you try the same query in a client such as insomnia or postman and see if you get the same results? If so, can you pass along some more details so I can look it up on my end, most helpful is the X-Request-ID returned in the headers after you call the API.

My query is to

{mytestshop}.myshopify.com/api/2019-10/graphql.json
{
  node(id: "Z2lk...0ODc=") {
    id
    ... on Checkout {
      id
      ready
      currencyCode
      subtotalPrice
      taxesIncluded
      totalTax
      totalPrice
      lineItems(first: 250) {
        edges {
          node {
            id
            title
            quantity
            variant {
              id
              price
            }
          }
        }
      }
    }
  }
}

Hope this helps,

Ryan

3 Likes

I’m doing your exact query except with my checkout id, of course, and I keep getting the error: “No such type Checkout, so it can’t be a fragment condition” I’ve googled a bunch and can’t find a thing. Do you have any ideas?

Here’s the query I ended up using (that worked):

https://{mytestshop}.myshopify.com/api/2019-07/graphql.json
{
  node(id: "Z2lkOi8vc2h=") {
	id
	... on Checkout {
      id
      ready
      currencyCode
      subtotalPrice
      taxesIncluded
      totalTax
      totalPrice
	  lineItems(first: 250) {
    	edges {
    		node {
    			id
    			title
    			quantity
    			variant {
    				id
    				price
    			}
			}
    	}
      }
    }
  }
}

Before querying to retrieve the cart, I performed a request to create a new checkout and add an item.

mutation {
  checkoutCreate(input: {
    lineItems: [{ variantId: "Z2lkO=", quantity: 1 }]
  }) {
    checkout {
       id
       webUrl
       totalPriceV2
       {
    	amount
    	currencyCode
       }
       updatedAt
       lineItems(first: 5) {
         edges {
           node {
             title
             quantity
           }
         }
       }
    }
  }
}

I tested both of these queries today and they are still working for me.

Hope this helps,