Most efficient way to get all the locations of a product

Hello!

We checked the locations query, but we’re not sure if we’ve been able to get the best way to achieve this.
What’s the most efficient way to obtain all the locations of a SKU that have on hand inventory for a specific customer account?
We tried using the locations query, but we can’t get neither the customer account id filter nor the on hand value filter.
We also tried the warehouse products query, but a location subquery must be used to get all the locations, and then filter over that result to get the locations with inventory values.

Is there any more direct way to obtain the locations with inventory values for a SKU of a specific customer id?

Thanks!
Cristóbal

Hey @cmora,

Thanks for reaching out!
Just wanted to let you know we’re looking into this inquiry now.

Best,
RayanP

Hey @cmora,

I think this query might work for the use case you described:

{
  warehouse_products(sku: "CORVETTE") {
    request_id
    complexity
    data(first: 5) {
      edges {
        node {
          id
          on_hand
          locations(customer_account_id: "60534", first: 5) {
            edges {
              node {
                 id
                quantity
              }
            }
          }
        }
      }
    }
  }
}

This returns:

{
  "data": {
    "warehouse_products": {
      "request_id": "63bc2b6e9c8c976c9832f153",
      "complexity": 31,
      "data": {
        "edges": [
          {
            "node": {
              "id": "UHJvZHVjdDozNDcxNjQ3NzM=",
              "on_hand": 38,
              "locations": {
                "edges": [
                  {
                    "node": {
                      "id": "SXRlbUJpbjoxOTc2MzgyNw==",
                      "quantity": 38
                    }
                  },
                  {
                    "node": {
                      "id": "SXRlbUJpbjo0NjIxNzUwMw==",
                      "quantity": 6
                    }
                  }
                ]

Was your issue with the warehouse_products query the credit cost?

Let me know if this helps!

Best,
RayanP

Hello Rayan!

Thanks for the info! It’s similar to what we’re doing (our difference is that we filter the customer account id in the warehouse products query rather than in the locations query).
Yes, our issue is that we may have products with many empty locations that can make the query more expensive.
If we paginate over the results, we can control the costs but this makes the “total query” slower.
I assume that filtering by quantity > 0 before is not possible, right?

Thanks for the info and your help!
Cristóbal

Hey @cmora,

Thanks for hanging in there!

At the moment I believe that is the best that can be done. I will go ahead and pass along your feedback regarding the filters in the locations query. I also think a functionality like that would be super helpful.

Let me know if there’s anything I can do to assist here.

Best,
RayanP

Thanks Rayan!
Please keep us updated if this comes up in a release!

Best,
Cristóbal

1 Like