Using WooCommerce REST API to query/update product/variation inventory

By default, inventory can be added/updated for each location when editing a product or variation manually in the WooCommerce admin. Once the inventory is set, and the product is saved, we will recalculate the total inventory for the product/variation to be the sum of the inventory in all locations.

We are also compatible with retrieving and updating inventory levels over the WooCommerce REST API.

  • Inventory is always stored/managed using the location ID. This is set when creating a location, in the Locations tab of our integration. The Location ID is used both in the custom fields in the database and over the WooCommerce REST API.

Querying Simple Product inventory

wp-json/wc/v3/products/

We support retrieving inventory levels for simple products via the WooCommerce REST API by including the Warehouse/Location ID in the top-level API response. When sending a GET request for the products endpoint, the response will contain a new property called warehouse - that will contain a list of location IDs and inventory value in that location. The structure is: "locationid": "inventorylevel".

Simple Product (full response)

"warehouse": {

        "204": "5",

        "205": "9"

    }

 

Querying Variation inventory

wp-json/wc/v3/products/000/variations

We support retrieving inventory levels of variations via the WooCommerce REST API by including the Warehouse/Location ID in the API response for each variation. When sending a GET request for the product/variation endpoint, the response will contain a new property called warehouse - that will contain a list of location IDs and inventory value in that location. The structure is: "locationid": "inventorylevel".

Variable Product (full response)

{

        "id": 267,

        "sku": "LG-12",

        "price": "15",

        "regular_price": "15",

        "warehouse": {

            "204": "1",

            "205": "3"

        },

    },

    {

        "id": 266,

        "sku": "M-12",

        "price": "11",

        "regular_price": "11",

        "sale_price": "",

        "warehouse": {

            "204": "2"

        },

 

Updating Product inventory

wp-json/wc/v3/products/

wp-json/wc/v3/products/00/variations/00

We support updating inventory levels for simple products and variations via the WooCommerce REST API with a PUT request. When sending a PUT request for the products or variation endpoint, the request should follow the below structure:

Simple Product

{

  "meta_data" : [

      {

          "key": "_stocks_location_204",

          "value": "25"

      },

      {

          "key": "_stocks_location_205",

          "value": "20"

      }      

      ]

}

Was this article helpful?
0 out of 0 found this helpful

Navigation