Could I query a productvariant by id of the variant?

Solved
New Member
14 0 0

I use the follow command to get, but the response error is "Field 'productVariant' doesn't exist on type 'QueryRoot'".

 

curl -H "X-Shopify-Storefront-Access-Token: xxxxxxxxxxx" -H "Content-Type: application/graphql" https://connecty-store.myshopify.com/api/2019-10/graphql.json -d 'query {productVariant(id:"31338369777769") {... on productVariant{image{src}}}}'

Yes, I can't find productVariant in the list of  Storefront API > API reference > QueryRoot, but it exist in  Storefront API > API reference > Queryable objects, so I believe productVariant can be queried. 

 

Is it possible to query productVariant use Storefront API ?

 

0 Likes
New Member
14 0 0

convert gid://shopify/ProductVariant/31338369777769 to "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTMzODM2OTc3Nzc2OQ==" and use this id to query

curl -H "X-Shopify-Storefront-Access-Token: xxxxxxxxxxx" -H "Content-Type: application/graphql" https://connecty-store.myshopify.com/api/2019-10/graphql.json -d 'query {productVariant(id:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTMzODM2OTc3Nzc2OQ==") {... on productVariant{image{src}}}}'

I get the same error

0 Likes

Success.

Shopify Staff
Shopify Staff
220 36 38

Hi @guid ,

 

As you mentioned in your above comment, Product Variant is not a Query Root Object for the Storefront API. This means that you cannot direct query for Product Variants or by a specific Product Variant using the Storefront API. However you can do this if you use the GraphQL Admin API.

 

However if you already do know the Product Variant ID in it's Base64 encoded value (as per your last comment), you can query for it by using the "node" Query Root. Here is the query to show how you can do this: 

 

query {
  node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTMzODM2OTc3Nzc2OQ==") {
    ... on ProductVariant {
      image {
        originalSrc
      }
    }
  }
}

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
New Member
14 0 0

Hi, hassain

 

 

0 Likes