Get location_id for product variants

Highlighted
Shopify Partner
2 0 1

Hello,

 

I'm upgrading my app to support the new multi-location inventory and I am wondering how to get locations on which product inventory is located?

Our app is basically connecting other peoples' stores to our and selling their inventory on our page and after an order I want to decrease the quantity on the store by setting inventory_quantity_adjustment. However, for that I need to know the location_id of a product.

I am getting the product details by going to the /admin/products.json endpoint and there I cannot get the location_id parameter for a product.

Can someone help me with this?

P.S. I don't really need multi location functionality, just want my app to continue functioning after 1st of August. Will I be able to use everything as before by not setting a location_id anywhere?

 

All best,

Zvonimir

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 81 287

To get the location ID using REST:

  1. Get a variant
  2. Get the inventory_item_id from the variant
  3. Get /inventory_levels.json?inventory_item_ids=id1,id2,etc
  4. Post /inventory_levels/adjust.json, { location_id: id, inventory_item_id: id, available_adjustment: int } as outlined here.

You can do so with a bit less back and forth using the admin graphql api since you can access by first checking inventory levels for a variant in one request:

{
  productVariant(id: "gid://shopify/ProductVariant/12209701060664") {
    id
    inventoryItem {
      id
      inventoryLevels(first: 10) {
        edges {
          node {
            id
            available
            location {
              id
            }
          }
        }
      }
    }
  }
}

then updating it in a second request:

mutation inventoryAdjustQuantity($input: InventoryAdjustQuantityInput!) {
  inventoryAdjustQuantity(input: $input) {
    userErrors {
      field
      message
    }
    inventoryLevel {
      id
    }
  }
}

variables:

{
  "input": {
    "inventoryLevelId": "Z2lkOi8vU2hvcGlmeS9FeGFtcGxlLzE=",
    "availableDelta": 1
  }
}

Hope that helps.

0 Likes
Highlighted
Shopify Partner
2 0 1

Hey Alex,

 

This is great, thanks, I already have variants and inventory_item_ids so I'll go with REST.

Now, in /admin/inventory_levels/adjust.json, location_id is a required field.

Is there a way where I can reduce the quantity of an item without setting its location_id?

 

Zvonimir

Highlighted
Shopify Staff
Shopify Staff
1555 81 287

Hey Zvonimir,

Can confirm you're going to have to specify the location_id. I don't think there's any way around that.

Cheers.

0 Likes
Highlighted
Shopify Partner
25 0 8

... never mind!

0 Likes