JJJ
JJJ

Reputation: 11

Can WooCommerce Api update stock quantities in bulk?

Is that possible to update the inventory/stock quanitity in bulk using WooCommerce API? From the documentation for every update we may need to call PUT /wp-json/wc/v3/products/. We have more than 1000 products, it is very inefficiency to call 1000+ api just to update the quatity?

If there is any other thoughts, please welcome to share. Thanks

Upvotes: 1

Views: 1046

Answers (2)

Misha Rudrastyh
Misha Rudrastyh

Reputation: 883

In the answer above it is ok about wp-json/wc/v3/products/batch but the request body is completely incorrect.

There are no such thing like StockQuantity which has a string value.

The correct body is going to be like this:

{
    "update": [
        {
            "id": 39,
            "stock_quantity": 5
        },
        {
            "id": 40,
            "stock_quantity": 4
        }
    ]
}

A little bit more information and example about sending this type of requests you can find here https://rudrastyh.com/woocommerce/bulk-update-product-stock-quantities.html

Upvotes: 1

Ben
Ben

Reputation: 180

You can use this endpoint wp-json/wc/v3/products/batch

{
    "Update": [
        {
            "Id": "39",
            "Default_attributes": [
                {
                    "Id": null,
                    "Name": null,
                    "Sku": "NEW-SKU",
                    "StockQuantity": "5"
                }
            ]
        }
    ]
}

here is an example body

Upvotes: 2

Related Questions