I’m using WooCommerce API to update a specific product. I’m sending the following:
{
"regular_price": "4000",
"stock_quantity": 1
}
I’m getting a 200 OK with the PUT request, but the following response:
{
...
"regular_price": "3000",
...
"stock_quantity": 0,
...
}
Basically, no update is being performed.
How can I troubleshoot this specific problem? WordPress 5.5.3, WooCommerce 4.7.1, SiteGround as host.
2
Answers
Solution of product updat issue:
Solution of product stock issue
manage_stock
parameter astrue
. then you can update stock quentitystock_quantity
as10
.I see that the behaviour depends totally of the tool you are using (e.g Curl, postman, node.js, etc)
It is true that there are some specific conditions to be able to update stocks. Let’s work under the assumption that such conditions are set and the situation is exactly as indicated in the question: 200 OK answer, and output of product exactly as it was before.
In my use case, I’d found exactly same situation in this post. I was under the same situation described in the thread where it was working with the curl example provided by Woocommerce support but not in postman:
After checking several option I’d noticed that curl generated by postman contains the auto-generated header:
–header ‘Content-Type: text/plain’
after disabling the auto-generated content-type in postman and adding application/json, the generated curl will have the header as:
–header ‘Content-Type: application/json’
It solved the issue both directly with postman and its generated curl command.