How to get location id list in shopify flow?

Solved

How to get location id list in shopify flow?

stoneqduc
Shopify Partner
15 0 0

Hi,

 

I have a question about how to obtain a list of location IDs in Shopify Flow. I want to update inventory quantities based on specific conditions. Since I have six locations and may have more in the future, obtaining a list of all location IDs would be the best solution. However, I haven't been able to find a useful variable to obtain the location ID list in Shopify Flow.

 

Thanks for your help.

Accepted Solution (1)
paul_n
Shopify Staff
1336 151 305

This is an accepted solution.

Thanks, knowing the trigger helps because sometimes they have a specific variant. In this case it doesn't. This is how I would output the ID for the REST API. 

{% for variants_item in product.variants %}
  {% for inventoryLevels_item in variants_item.inventoryItem.inventoryLevels %}
  {{inventoryLevels_item.location.legacyResourceId}}
{% endfor %}
{% endfor %}

That said, I'm not sure how you will do this for multiple inventory updates in one API call and this loop won't generate multiple API calls for you. See https://community.shopify.com/c/shopify-discussions/bulk-update-item-inventory-through-api/td-p/1507...

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 6 (6)

paul_n
Shopify Staff
1336 151 305

You could click the location in the Admin / Settings / Locations and look at the URL. You could also instead use the location name in Flow. 

 

Personally, I would use Shopify's GraphiQL app. You can use a query like this:

{
  locations(first:20, includeLegacy:true) {
    edges {
      node {
        name
        id
        legacyResourceId
      }
    }
  }  
}



Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
stoneqduc
Shopify Partner
15 0 0

Thank you Paul_n

 

My question is  like this, is there a useful variable for getting the locations in flow ?

{% for variants_item in product.variants %}
 {
  "location_id":828XXXXXXX,  // I don't want to use hard coding here, and the locations will increase in future.
  "inventory_item_id:{{variants_item.inventoryItem.variant.inventoryItem.legacyResourceId}},
  "available":0
}
{% endfor %}

 

Thanks for your help.

paul_n
Shopify Staff
1336 151 305

Please don't do that code. You have a circular reference in it (variants.inventoryItem.variant.inventoryItem).

 

What trigger are you using? 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
stoneqduc
Shopify Partner
15 0 0

trigger is : Product status updated

condition is : old status =  'ACTIVE' & product.status = 'DRAFT'

action: update the product inventory quantity = 0 in all  locations

 

 

{% for variants_item in product.variants %}
 {"location_id":828XXXXXXX,"inventory_item_id":
  {{variants_item.inventoryItem.variant.inventoryItem.legacyResourceId}}
,"available":0}
{% endfor %}​

 

 

paul_n
Shopify Staff
1336 151 305

This is an accepted solution.

Thanks, knowing the trigger helps because sometimes they have a specific variant. In this case it doesn't. This is how I would output the ID for the REST API. 

{% for variants_item in product.variants %}
  {% for inventoryLevels_item in variants_item.inventoryItem.inventoryLevels %}
  {{inventoryLevels_item.location.legacyResourceId}}
{% endfor %}
{% endfor %}

That said, I'm not sure how you will do this for multiple inventory updates in one API call and this loop won't generate multiple API calls for you. See https://community.shopify.com/c/shopify-discussions/bulk-update-item-inventory-through-api/td-p/1507...

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
stoneqduc
Shopify Partner
15 0 0

Thank you very much. I understand that it is not possible to make multiple API calls.

 

I'm not sure how you will do this for multiple inventory updates in one API call and this loop won't generate multiple API calls for you. See https://community.shopify.com/c/shopify-discussions/bulk-update-item-inventory-through-api/td-p/1507...