How to update a value by key in sellables?

I have the following code and I need to update the total quantity of products in all warehouses. Unfortunately the solution below doesn’t work, although I looked at the documentation from GitHub and it seems to work:

quantity = sellable.get('available_stock_level_at_all_warehouses')
new_quantity = int(quantity) - product.quantity
if new_quantity < 0:
     logger.warning(f'New quantity for SKU {product.sku} would be negative. Skipping update.')

update_data = {
       'product': {
                'product_variants_attributes': [
                            'id': sellable['id'],
                             'available_stock_level_at_all_warehouses': new_quantity

         task = self.client.put(url, headers=headers, data=update_data)

Hey @shegor07,
Stock level updates are handled via the Stock entry endpoint. If you wish to update the stock level at all warehouses you would need to iterate through all the warehouses and set the stock level at each warehouse to the new value.

The available_stock_level_at_all_warehouses attribute is a value that is computed by summing all the stock entries at all active warehouses for a given product, and as such isn’t an attribute that can be directly updated.