Field 'variants' doesn't exist on type 'QueryRoot'

Estoy tratando de obtener la id de una variante de un producto para poder estructurar y crear un checkout, los datos con los que cuentos, son información de la variante obtenida con la API de admin.

Tengo esta ID: 32225551155258

y tengo esta: gid://shopify/ProductVariant/32225551155258

(la id que necesito es la de este tipo: Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ2MjgwMDA1Mzg2ODI== )

Para esto lo que entiendo es que debemos usar GraphQL, por lo que la query con la que estoy intentando es la siguiente:

query {
productVariants (id: “gid://shopify/ProductVariant/32225551455258”) {
id
title
}
}

Aunque estoy haciendo las pruebas en Postman, las usare en una app con el elenguaje DART

la version de api que estoy ocupando es 2020-10.

Este es el error que me sale:

“message”: “Field ‘productVariants’ doesn’t exist on type ‘QueryRoot’”,

Aunque “productVariant” si existe en los fields que muestra la lista de QueryRoot

(aquí: https://shopify.dev/docs/admin-api/graphql/reference/common-objects/queryroot?api%5Bversion%5D=2020-…)

Try productVariant not productVariants if you are providing a specific ID then you are looking for just one.

Of course, y was tryed this option “productVariant” and also “ProductVariants”

The result is equal.

“message”: “Field ‘productVariant’ doesn’t exist on type ‘QueryRoot’”,

It must have something to do with how you are enclosing things with the Query {} block. Here is a sample GQL request I just made through the Shopify GraphiQL app, and it works just fine.

And here is the same thing run through Postman.

Hi!, Thancks for anwers me.

Well, I tryed with “productVariant” and “productVariants”, also with API “2020-10” and “2021-01”

My headers data is fine?


I want ID variants to make my create Checkout so similar of this:

(This query is fine, is funcionality)(the headers data and the api version is equal)

mutation {
checkoutCreate(input: {
lineItems: [{ variantId: “Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTQ4NDM0OTU3OTMyMg==”, quantity: 4 }]
}) {
checkout {
id
webUrl
lineItems(first: 5) {
edges {
node {
title
quantity
}
}
}
}
}
}

I think you have the URL wrong. should be /admin/api/2021-01 or whatever.

Hey @daniort ,

I believe you’re using the Storefront API which doesn’t have the productVariant field on its QueryRoot. This is only available for the Admin API.

Hopefully this helps clarify the confusion.

Best,
Seth.

Hello @Gregarican @daniort I’m having same issue, I fixed the url (https://xxxxxx.myshopify.com/admin/api/2021-01/graphql.json) but I’m not getting any data. I’m getting "productVariant":null as you can see. Any idea why? I tried with Shopify GraphiQL as well and same result.

thanks in advance