Keeping product inventory accurate doesn’t have to mean updating items one by one in your WooCommerce dashboard. With the WooCommerce REST API, you can change stock quantities quickly and automate updates from an external app, inventory system, or custom script.
In this guide, we’ll walk through how to update WooCommerce product stock using the REST API, including the key product data you’ll need and how to send an update request. Whether you’re managing a small catalog or streamlining a larger store, you’ll be able to make stock changes more efficiently and keep your inventory in sync.
Prepare a WooCommerce REST API update stock request
Before changing a quantity, make sure your connection can write to the store and that you’ve identified the exact item you want to update. A little preparation helps prevent failed requests—and avoids changing stock on the wrong product.
Create secure REST API credentials
Start by creating a key with the right permissions. In your WordPress dashboard, go to WooCommerce → Settings → Advanced → REST API, choose Add key, select the user the integration should act as, and set permissions to Read/Write. WooCommerce displays a consumer key and consumer secret; copy them when prompted, since the secret may not be shown again.
Treat these credentials like a password. Store them in environment variables or a secrets manager rather than in public code repositories, and use an HTTPS connection so credentials and requests are encrypted in transit. If a key is exposed or no longer needed, revoke it in the same settings area. The WooCommerce REST API documentation explains the available authentication methods and permissions.
Once access is ready, the next step is to make sure your request points to the correct product record. The product’s ID and stock-management configuration determine which endpoint and fields you’ll need.
Find product IDs and confirm stock management settings
Every product has a numeric ID that identifies it in API requests. You can find it by opening the product in the dashboard and checking the browser’s address bar, or by listing products through the API and matching the result by name or SKU. Use the ID, not the product name, in the update URL; names can change and may not be unique.
Before sending an update, check whether stock management is enabled. In the product’s Inventory settings, confirm that “Manage stock” is selected; through the API, the corresponding setting is managestock. If it’s disabled, changing a quantity alone may not produce the inventory behavior you expect.
- Simple product: use the product’s ID and confirm its own stock setting.
- Variable product: stock may be managed on an individual variation, so identify and update the variation ID when applicable.
With credentials, IDs, and stock settings verified, you’re ready to build the update request without guessing which record WooCommerce will change.
Make a WooCommerce REST API update stock change
With the product or variation identified, the update itself is a small JSON payload sent to the right endpoint. The key is to tell WooCommerce both to manage inventory and what quantity to use.
First, set the inventory fields deliberately: enabling stock management makes the quantity meaningful, while the quantity tells WooCommerce how many units are available.
Set managestock and stockquantity in the request body
Include managestock and stockquantity in the request body. Set managestock to true and provide the quantity as a whole number, such as 12. If stock management is off, sending a quantity by itself may not have the effect you intend.
A quantity of 0 means there are no units available; it is not the same as leaving the field out. For example:
{
"managestock": true,
"stockquantity": 12
}This request sets the stock to 12—it does not add 12 to the current amount. If another system also changes inventory, agree on which system is authoritative and send the latest intended total to avoid overwriting a newer update.
For a standalone product, send that payload to its product endpoint. The example below shows a typical request using HTTPS and the product ID you confirmed earlier.
Send a WooCommerce REST API update stock request for a simple product
Use the PUT method with /wp-json/wc/v3/products/{productid}. Replace the placeholders with your store domain, product ID, and API credentials:
curl -X PUT "https://example.com/wp-json/wc/v3/products/123"
-u "ckyourconsumerkey:csyourconsumersecret"
-H "Content-Type: application/json"
-d '{"managestock":true,"stockquantity":12}'On success, WooCommerce returns the updated product as JSON. Check the response for the expected managestock and stockquantity values; if the request fails, review the HTTP status and response message before retrying.
When inventory belongs to a specific size, color, or other option, target the variation record instead. This keeps the change focused on that option rather than applying it to the parent product.
Update variation stock without changing the parent product
Use the variation endpoint, which includes both the parent product ID and variation ID: /wp-json/wc/v3/products/{productid}/variations/{variationid}. Send the same fields in the body, for example {"managestock":true,"stockquantity":5}.
That update changes stock for the selected variation only. Before sending it, confirm that inventory is managed at the variation level; if stock is managed on the parent instead, update the parent product’s record. Always check the response to verify the intended item and quantity were returned.
Verify your WooCommerce REST API update stock result
A successful-looking request is only useful if the right item now shows the right quantity. A quick check helps catch mistaken IDs, rejected fields, or another inventory change that happened at the same time.
Start by reviewing what the server returned, then compare it with the store’s current inventory. These checks make it easier to spot a problem before it affects a customer’s order.
Check the API response and confirm inventory in WooCommerce
Look at both the HTTP status code and the response body. A successful response should include the product or variation you intended to update, with the expected managestock and stockquantity values. Don’t rely on a success message alone: confirm the returned ID as well.
For an additional check, retrieve the item with a GET request or open it in the WooCommerce dashboard and review its Inventory settings. If the response and dashboard disagree, allow for a brief delay, refresh the view, and check again. For variations, make sure you’re inspecting the specific variation rather than only its parent product.
If the returned quantity is missing or unexpected, use the status and error details to narrow down the cause. The following checks cover common failures without repeating the update blindly.
Fix permission, validation, and stale-stock errors
An authentication or permission error usually means the credentials are incorrect, revoked, or lack write access. A 401 response points to an authentication issue; a 403 indicates the request was understood but not permitted. Check the key’s permissions and the account it is associated with.
A 400 response often signals invalid JSON or a field value WooCommerce cannot accept. Verify that the body is valid JSON and that the quantity is a whole number. A 404 commonly means the product or variation ID—or the endpoint—is wrong. If the API accepts the request but the quantity soon changes, another process, such as an order or inventory integration, may have updated it afterward.
Once errors are resolved, consider what happens when requests are repeated or overlap. A few simple safeguards can prevent retries from undoing a newer inventory change.
Keep repeated stock updates safe and reliable
Setting stockquantity to a specific total is generally idempotent: sending the same value again sets the same total. However, that does not make a stale value safe. If an order reduces stock between your first request and a retry, resending an older quantity could overwrite the newer balance.
To reduce that risk, use one system as the inventory source of truth, process updates in order where possible, and read the current quantity before resolving a conflict. Log the item ID, intended quantity, timestamp, and API result; then schedule a fresh check if a request times out, rather than assuming it failed. These habits make a WooCommerce REST API update stock workflow easier to monitor and recover.
Make WooCommerce stock updates faster and more dependable
The WooCommerce REST API makes inventory updates easier to scale, whether you’re changing stock for a single product or a specific variation. With secure access, the right product record, and clear stock-management settings, you can keep inventory aligned without relying on repetitive dashboard edits.
For a reliable workflow, verify each result and pay attention to permissions, errors, and updates from other systems. Treat inventory as shared data: keep a clear source of truth and handle retries carefully to avoid overwriting newer changes. Once these habits are in place, WooCommerce REST API update stock tasks can become a quick, consistent part of managing your store.