Hi, is it possible to retrieve the quantity of variants added to the checkout in a Checkout UI app? I’m fetching values from the product variant metafields, but I can’t access their stock. Just to clarify, I have unauthenticated_read_product_inventory added to the scope. This is crucial, as the entire logic relies on fetching the stock.
Ah, gotcha! No worries @lynthius - you should be able to pull that info using the storefront API like this:
{
product(id:"gid://shopify/Product/7330367832086") {
title
variants(first: 10) {
edges {
node {
id
title
quantityAvailable
sku
price {
amount
currencyCode
}
}
}
}
}
}
You should be able to pull the product ID using the Cart Lines API there and then make the query directly using the Storefront API through this method within the UI extension: Storefront API
Do you have any idea how to fix this? I was thinking about bypassing this by adding a metafield to the product variant to fetch the stock after each update, but maybe there is a better way.
I am experiencing the same issue. @lynthius from what I can see, the unauthenticated_read_product_inventory scope isn’t allowed in the checkout usage of the Storefront API scopes, see Storefront API access scopes: Configuration - I suspect this is why you’re getting null from the response.
From my research, the only solution is going to be building an API myself that has access to the Admin API (and therefore inventory numbers for variants), which when fed a list of product variant ids (from my checkout extension), return the variant ids with the inventory count attached.
@Alan_G is there a nicer way to access inventory from the checkout? It seems like a data point that would make sense to expose at the checkout level.
Thanks, @Alex_Hooper. I think you’re right. If there’s no better solution, I’ll go ahead and build my own API with Admin API access. I already have some running on GCP, but I was hoping for a simpler way to handle this.
Let’s wait for @Alan_G’s response. Perhaps Shopify should consider adding unauthenticated_read_product_inventory to the scope, as it would make implementation much easier. On the other hand, there might be security concerns that justify its exclusion (although it’s strange that I can retrieve other data).
Hey all - thanks for mentioning that @Alex_Hooper - you’re correct there. For Checkout UI extensions specifically, the unauthenticated_read_product_inventory scope isn’t supported (just through the “regular” SF API).
I did some more testing on my end to see if I could share a more elegant way to grab that data, but I do think Alex’s idea to build a separate service that integrates with the extension to grab Admin API data (via inventoryItems/Inventory Levels) would be the best bet.
That said, I’ll raise this a feature request to our team here - can definitely see how this would make things a lot smoother if it could just be actioned within the extension itself.