Unable to retrieve Cart Details using Storefront API

dharavathkarthi
Visitor
2 0 0

API URL : https://<shop>.myshopify.com/admin/api/unstable/graphql.json

 

graphql Query:: 

{
  cart(id"gid://shopify/Cart/<cart_id>") {
    id
    createdAt
    updatedAt
  }
}
 
API Response:
{
    "errors": [
        {
            "message": "Field 'cart' doesn't exist on type 'QueryRoot'",
            "locations": [
                {
                    "line": 3,
                    "column": 3
                }
            ],
            "path": [
                "query",
                "cart"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "QueryRoot",
                "fieldName": "cart"
            }
        }
    ]
}
 
Can someone please help me out with the above issue?

Replies 2 (2)

rushikesh93
Excursionist
78 1 6

Same Error i get, but not get any solution still,
have you got any solutions? if YES then pls provide me to.

Thanks.

Shopify Beginner.

josemilioz
Shopify Partner
3 0 0

I think that you're using the wrong API schema. Cart queries are only available in the Storefront API, and in your example you're asking Admin API for the Cart.

Try removing /admin from your URL request like this

 

https://<shop>.myshopify.com/api/<API version>/graphql.json

 

 

Also check the headers you're sending. The correct name for your request's header should be X-Shopify-Storefront-Access-Token, and of course you should use the Storefront Access Token for those requests as well.