Checking product stock level at checkout

Is there any checkout API (functions, extensions, etc) that can determine if a product is in stock?

Maybe I overlooked something obvious, but I have been stuck on this for a bit.

Hey @Tyler_Fleming , you should be able to use the Storefront API via Checkout UI extensions to query product variant quantities:

The easiest way to grab the variant’s stock info would likely be getting the variant’s SKU through the CartLineItems Checkout Extension API, Cart Lines, and then running a SFAPI query like this:

query getVariantBySku($sku: String!) {
  products(first: 100, query: $sku) {
    edges {
      node {
        id
        title
        handle
        variants(first: 100) {
          edges {
            node {
              id
              sku
              title
              availableForSale
              currentlyNotInStock
              quantityAvailable
            }
          }
        }
      }
    }
  }
}

Hope this helps - let me know if I can clarify anything on my end here!

Thanks so much, Alan! :raising_hands:

1 Like

Hi again Alan and everyone,

I followed your suggestion, but even after adding the required scopes, I’m still encountering this error:

Access denied for quantityAvailable field. Required access: unauthenticated_read_product_inventory access scope.

Based on the documentation here:

it seems that this scope should be usable via the Storefront API within a Checkout UI Extension.

Do you have any suggestions on how to properly access the quantityAvailable field in this context?

Hey @Chi_n_Nguy_n_Van - thanks for getting in touch. Right now, this is actually an intended limitation of our Functions features. The unauthenticated_read_product_inventoryscope is not included as one that’s accessible through the Storefront API access that’s available via the Functions integrations themselves.

That said, you could look into implementing the network access feature to connect to a service on your server side that connects to the Admin API:

I definitely realize it’s not the most ideal since it adds some server infrastructure you’d have to account for on your end, so I’m happy to put through a feature request if you’re open to sharing your use case for this. Hope this helps - let me know if I can clarify anything on my end here!

1 Like

Hey @Chi_n_Nguy_n_Van - just checking in on this one, let me know if the above helped clarify the limitation or if you landed on a workaround that worked for your use case.