Focusing on managing products, variants, and collections through the API.
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 ?
Solved! Go to the solution
This is an accepted solution.
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 } } } }
To learn more visit the Shopify Help Center or the Community Blog.
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
This is an accepted solution.
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 } } } }
To learn more visit the Shopify Help Center or the Community Blog.
Hi, hassain
Thanks for you reply.
I have got your means. I can use "node" to get any Object information by object id. thank you!