HTTP Post to update Inventory 'available' to match metafield value

Hey all,

I have been trying to figure out a way to set my inventory levels to match my metafield value. We are using a PIM that regularly updates metafields and currently it’s our best way to automate stock levels. Essentially every product has a metafield called “Website Available Inventory” with namespace and key: web_available_inventory.web_available_inventory

I was able to manually set a single item’s inventory with the following (successfully):

So I know the settings are all correct and I just need help with the Body. However when I try to update it to a for each loop to iterate through every product and then use it’s metafield.value where the key is equal, I get error 400.

Any guidance would be greatly appreciated!

All of those \n are new lines and can be removed by either removing whitespace or using hyphens in the tags like {%- and -%}.

shop.products should never be used. I’m not sure what you are trying to do there, but you are actually looping over every product in your store and then every metafield on all those products and then all of the product variants. You are liking hitting API limits that prevent pulling that much data. You should use the product provided by your trigger.