Location(bin/item) inventory quantities

I see that this thread says there is no way to get to the actual quantity of a bin through the graph api but I wanted to see if this other approach could be expounded upon. Maybe im missing something about the arguments available but this is about as efficiently im able to get to this data.

Here’s my query:

```gql
query locations($location_id: String, $warehouse_id: String) {
locations(name: $location_id, warehouse_id: $warehouse_id) {
data(first:1){
edges {
node {
id
warehouse_id
products(first:50){
edges{
node{
sku
warehouse_products{
locations(first:20){
edges{
node{
location_id
quantity
}}}}}}}}}}}}

If i could pass the warehouse_id and/or the location_id at warehouse_products(warehouse_id:$warehouse_id) and locations(location_id:$location_id). this would allow me to filter ahead and time and make a much smaller request.

Well, in fairness, that thread doesn’t say there’s no way to get the quantity in a bin. It just says you can’t do it from the locations query alone. Instead, you have to start with the warehouse_products query and nest the locations inside of it. Depending on what info you need from it, that can turn into a pretty deep query (like your example) and wind up being slow and expensive to run.

Like it says in that thread, your best bet is going to be to run an inventory snapshot. That will get you every product location pairing. As long as you don’t set has_inventory to true, it should also give you back the empty locations associated with each product.

If you need to look for locations that are truly empty which have no product pairing history, you can pull a separate locations-only query via the graphql API, paginate through to get the full set of results, and then compare those results to the results in the inventory snapshot. That will run faster than the warehouse_products > locations nested version.