“No field of name “inventoryQuantity” found on type “ProductVariant” in schema”
My product type is “event” and I do see an “available” field in my ProductVariant which is true. Could it be something wrong in how I set up my Shopify product?
A little more context would be required to understand your error. Are you making direct calls to the API or via a wrapper library / SDK? Are you using the correct endpoint? Storefront API and GraphQL Admin API are considerably different even though many resource object names are the same. It’s easy to tell: Storefront is a URL like https://storename.myshopify.com/api/graphql while GraphQL Admin API is https://storename.myshopify.com/admin/api/graphql.json.
For instance, the Storefront API only has availableForSale of type boolean. Admin API does in fact have the inventoryQuantity so a admin query such as below would work perfectly fine.
{
product(id: "gid:\/\/shopify\/Product\/<PRODUCT_ID>") {
id
variants(first: 100) {
edges {
node {
id
inventoryQuantity
}
}
}
}
}
Yes, I am saying you cannot get inventory levels via Storefront API.
No, not necessarily saying you should be using the admin API. That depends on what you are developing. If it is a store, I’d be very careful how you use the admin API. Unlike the Storefront APIs public access token, the admin API requires a key and password which you never want to expose publicly - that would be like giving away your admin UI access credentials.
Second, even if you used the admin API on a server, say a node.js express app or similar, the admin API is throttled and not designed for the kind of load demanded by a store - you’d need to account for this in your design.
Third, if you really need inventory levels you can also work with Liquid - the variant object in Liquid does have an inventory_quantity and you could use a nolayout template to output a JSON object thereby creating your own “kinda API endpoints”. However, even the Liquid inventory_quantity is an aggregate of all inventory locations so you wouldn’t be able to query how much at location 1, how much at location 2 etc.
If you need inventory level per location then there is no way around admin API, but it will be very difficult to get consistent levels because you will most likely not be able to query the admin API for every storefront request for inventory levels. You’d hit throttling soon. So expect to have cached inventory levels that may be outdated.
I use the Storefront API [end point api/2019-07/graphql.json]
I’m able to query my products in different ways, also using productByHandle, but for some reason i’m not able to use productVariants query like for example:
productVariants(first:1, query: “sku:BMY722”). I get an error that its not exists under QueryRoot.
Any idea what could be the probable reason for this ?