How can I update product quantity using Shopify Flow?

Adding my experience to this thread since it was beneficial in getting to the solution I created. What was unique about my problem was I needed to iterate through every product and use metafield variables in my POST request. In my company’s situation our PIM syncs daily but can only house the stock levels in a metafield. So in my metafield with key=web_enabled_inventory that is the most accurate stock level as opposed to Shopify’s that reduces/increases with orders & returns. So I need to overwrite all stock levels daily with the metafield value.

Above is my workflow in Shopify Flow with the {store name} crossed out. You would enter your store’s name there. Above in this thread does a great job already of detailing how to get Access Tokens and such. This comment here keeps it concise. The only piece missing now is below, the body of my HTTP request with some varibles you would replace bolded:

{% for metafields_item in productsForeachitem.metafields %}{% if metafields_item.key == ‘web_available_inventory’ %}{% for variants_item in productsForeachitem.variants %}{“location_id”: [your location_id here],“inventory_item_id”: {{variants_item.inventoryItem.id | split: “/” | last}},“available”:{{metafields_item.value}}}{% endfor %}{% endif %}{% endfor %}

Hope this information helps anyone else looking to utilize Shopify Flow for inventory level automation!

2 Likes

Hello, I followed the steps you had here except that I removed the last 2 steps, which are the notifications. I aim to make the inventory quantity equal to 0 when it reaches 10 only. I don’t know if the flow works because it says like this:

We are going to have a new launch of products and we want to make sure that we don’t oversell, hence we make the flow.

Does this mean the flow I created doesn’t work because it says “The request was unsuccessful” and the condition is true?

There are successful reports though, here is the sample of succeeded runs that I got:

Thank you so much! Big help!

If you are calling the Shopify API, use the new action, “Send Admin API Request”. It’s way easier and handles the API key for you.

That error looks like whatever API key you are using does not have the correct permissions for that mutation. You can adjust that in the Admin

1 Like

Hi Paul_n

Perhaps you could assist. I am trying to adjust inventory quantities in select locations on select orders when they are created, adding an increment of 1 for each item within the order (a workaround for limited inter-location transfer functionality and staff permissions), which fits in with this discussion.

So the flow is set up to Get Order Data, and then loop for each item. The HTTP request body is:

{“location_id”:154example,“inventory_item_id”:{{lineItemsForeachitem.id}},“available_adjustment”:1}

However I am receiving this error:

{“status”:400,“response_body”:“Bad Request”,“verb”:“POST”,“url”:“https://core.sfe.shopifyinternal.com/admin/api/2023-01/inventory_levels/set.json”,“request_body”:“{"location_id":154example,"inventory_item_id":gid://shopify/LineItem/154example,"available_adjustment":1}\n”}

Is this type of request possible? Any advice would be appreciated.

Thanks

Please add my name to the list of people requesting this. Thanks.

That id you are putting in inventory_item_id is not an iventory_item_id but an order_id. Also, your comma is inside the double-quote rather than outside it. This should read like {“location_id”:154example", and NOT {“location_id”:154example,"

Not sure of your use case here, but if you need to update each inventory item in the order, you will need to loop over the lineItems and their inventory items in the action using liquid to build the list of items you want to update.

I’d recommend using Send Admin API request instead and call the inventoryAdjustQuantities mutation, which allows setting multiple quantities at once and should be easier to use than Send HTTP Request. See https://shopify.dev/docs/api/admin-graphql/2024-01/mutations/inventoryAdjustQuantities

This is doable now using Send Admin API request.