Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Storefront API GraphQL to Retrieve Checkout

Storefront API GraphQL to Retrieve Checkout

DynamitDave
Shopify Partner
2 0 0

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....
Replies 3 (3)

Ryan
Shopify Staff
499 42 120

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

Ryan | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

code-ren
Shopify Partner
2 0 0

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?

DynamitDave
Shopify Partner
2 0 0

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,