An error code 400 is returned with the message: The product was unable to be saved. Please try again.
#
After some debugging, I found out what was happening. As the error message is not very clear about the problem itself, and there was no other information about the error being logged to the log files. I found where the exception was being thrown and just added the actual error message to the exception:
#
With that change the error message now returns: The product was unable to be saved. Please try again.Registry key \"movement_section\" already exists
The error occurs on vendor/elgentos/magento2-inventory-log/Plugin/Webapi/Stock/StockItemRepository.php at line 20. If I comment out the register->register() method. The product stock is updated successfully, but it means that the registration of the movement_section key has already been set before the beforeSave() method was called. We can see on the screenshot below, that the the last two records have the message indicating that this stock update was made manually, but it was made through the rest API.
#
After a little more digging, I found out that the registration of the movement_section key is happening at /vendor/elgentos/magento2-inventory-log/Observer/SaveInventoryDataObserver.php. Configured under etc/events.xml:
Error updating product stock through rest API
Preconditions
Steps to reproduce
Request example: PUT: /rest/all/V1/products/24-MB01 Body:
Expected result
Actual result
#
After some debugging, I found out what was happening. As the error message is not very clear about the problem itself, and there was no other information about the error being logged to the log files. I found where the exception was being thrown and just added the actual error message to the exception:
#
With that change the error message now returns: The product was unable to be saved. Please try again.
Registry key \"movement_section\" already exists
The error occurs on
vendor/elgentos/magento2-inventory-log/Plugin/Webapi/Stock/StockItemRepository.php
at line 20. If I comment out the register->register() method. The product stock is updated successfully, but it means that the registration of themovement_section
key has already been set before the beforeSave() method was called. We can see on the screenshot below, that the the last two records have the message indicating that this stock update was made manually, but it was made through the rest API.#
After a little more digging, I found out that the registration of the
movement_section
key is happening at/vendor/elgentos/magento2-inventory-log/Observer/SaveInventoryDataObserver.php
. Configured under etc/events.xml: