How do I post JSON to a web API method?
I hope you don't have the intention to "hack" Magento core files. I recommend to create your own classes / interfaces for that!
Anyway if you are implementing a custom method updateStockItems
for a webapi which updates more stockitems with a single request you should take care of the right method signature: You are expecting an array of stock items, therefore your input parameter should be of that type.
Your interface:
/**
*
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface[] $stockItems
* @return int
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function updateStockItems(\Magento\CatalogInventory\Api\Data\StockItemInterface[] $stockItems);
Your method implementation:
/**
*
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface[] $stockItems
* @return int
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function updateStockItems(\Magento\CatalogInventory\Api\Data\StockItemInterface[] $stockItems)
{
foreach ($stockItems as $stockItem){
//do whatever with your stock item
}
};
Please take care to use only parameter in your JSON objects which match the used interfaces, in this example \Magento\CatalogInventory\Api\Data\StockItemInterface
. So putting there some key sku
doesn't make sense and should either be ignored by Magento or give you an error in the API call.
Here is the documentation about the usage of custom webservices.
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/service-contracts/service-to-web-service.html