I have created a product, which has two different sources assigned to it with different quantity allocated to both sources. I want to update product's quantity for both sources separately.
I am using following api - /rest/default/V1/products/{productSku}/stockItems/{itemId} with request body as-
{
"stock_item": {
"qty": 2100,
"stock_id": "various for both sources", // 1 for 1st default source stock & 2 for my custom source stock
}
}
API is updating product inventory on default source when given stock_id=1. But on my custom source created with stock_id=2 API returns 400 Bad Request as follows
{
"message": "The stock item was unable to be saved. Please try again.",
"trace": "#0 /var/www/php74/magento241/vendor/magento/module-catalog-inventory/Model/StockRegistry.php(181): Magento\\CatalogInventory\\Model\\Stock\\StockItemRepository->save()\n#1 /var/www/php74/magento241/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\CatalogInventory\\Model\\StockRegistry->updateStockItemBySku()\n#2 /var/www/php74/magento241/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\CatalogInventory\\Model\\StockRegistry\\Interceptor->___callParent()\n#3 /var/www/php74/magento241/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\CatalogInventory\\Model\\StockRegistry\\Interceptor->Magento\\Framework\\Interception\\{closure}()\n#4 /var/www/php74/magento241/generated/code/Magento/CatalogInventory/Model/StockRegistry/Interceptor.php(59): Magento\\CatalogInventory\\Model\\StockRegistry\\Interceptor->___callPlugins()\n#5 [internal function]: Magento\\CatalogInventory\\Model\\StockRegistry\\Interceptor->updateStockItemBySku()\n#6 /var/www/php74/magento241/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(95): call_user_func_array()\n#7 /var/www/php74/magento241/vendor/magento/module-webapi/Controller/Rest.php(188): Magento\\Webapi\\Controller\\Rest\\SynchronousRequestProcessor->process()\n#8 /var/www/php74/magento241/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Webapi\\Controller\\Rest->dispatch()\n#9 /var/www/php74/magento241/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callParent()\n#10 /var/www/php74/magento241/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Webapi\\Controller\\Rest\\Interceptor->Magento\\Framework\\Interception\\{closure}()\n#11 /var/www/php74/magento241/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(23): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callPlugins()\n#12 /var/www/php74/magento241/vendor/magento/framework/App/Http.php(116): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch()\n#13 /var/www/php74/magento241/vendor/magento/framework/App/Bootstrap.php(263): Magento\\Framework\\App\\Http->launch()\n#14 /var/www/php74/magento241/index.php(39): Magento\\Framework\\App\\Bootstrap->run()\n#15 {main}"
}
How can I update product inventory on my custom source?