Hi guys
I'm having a problem updating a stock status when updating it via API.
I've been getting this error
"The stock item was unable to be saved. Please try again."
But it works just fine with the same request from Postman
I'm following the SWAGGER documentation
What works in postman:
https://store/index.php/rest/V1/products/DIG11925/stockItems/2725 headers: content-type: application/json Authorization: Bearer rgme26l6eg1rkoftm0f510qi0zzexk24g body: { "stockItem": { "is_in_stock": true, "qty": 1 } }
When performing this request in postman I'm getting back
var stockDataNewJSON = {}; stockDataNewJSON.stockItem = {}; stockDataNewJSON.stockItem.qty = Number(document.getElementById("quantity-held").value); if (document.getElementById("inputGroupSelect01").value === 1) { stockDataNewJSON.stockItem.is_in_stock = true; } else { stockDataNewJSON.stockItem.is_in_stock = false; } fetch('https://store/index.php/rest/V1/products/' + productData.sku + '/stockItems/' + stockData.item_id, { method: 'PUT', headers: { 'content-type': 'application/json', 'Authorization': 'Bearer ' + magentoToken }, body: JSON.stringify(stockDataNewJSON) }).then((response) => { return response.json(); }).then((data) => { resolve(data); console.log(data); alert(JSON.stringify(data)); });
Solved! Go to Solution.
Hi @roman_polevecko
Please follow below steps to update status of stock using rest api:
API url : http://<baseUrl>/rest/V1/products/my-sku/stockItems/16
Token : Admin Token
Method : PUT
Request:
{"stockItem":{"qty":2000,"is_in_stock":true}}
Status in admin:
If product is not updated after this step, please run below command :
php bin/magento indexer:reindex
and also check Index Management, mode should be Update on Save .
In Admin > System > Tools > Index Management.
It may help to resolve your issue.
If issue resolve, please click on 'Kudos' & Accept as Solution!
Hi @roman_polevecko
Please follow below steps to update status of stock using rest api:
API url : http://<baseUrl>/rest/V1/products/my-sku/stockItems/16
Token : Admin Token
Method : PUT
Request:
{"stockItem":{"qty":2000,"is_in_stock":true}}
Status in admin:
If product is not updated after this step, please run below command :
php bin/magento indexer:reindex
and also check Index Management, mode should be Update on Save .
In Admin > System > Tools > Index Management.
It may help to resolve your issue.
If issue resolve, please click on 'Kudos' & Accept as Solution!