Table of Contents
Note #
- This documentation can also be found in the plugin settings at: Products > Batch Numbers > REST.

- WooCommerce REST API must be active (see below).
Activate WooCommerce REST API #
Path: WooCommerce > Settings > Advanced > REST API.
Our Batch Numbers plugin uses the WooCommerce REST API in order to provide REST API functionality.
Samples #
Compatible software | File |
Insomnia , Postman | rest-collection-v1.3.json |
Get all batches #
GET
http://localhost:10003/wp-json/wc/v3/products/batches
JSON response example:
{ "23": { "id": "23", "date_created": "2024-02-01 09:55:08", "date_expiry": "2024-10-01 09:55:08", "user_id": "1", "batch_number": "c40b0dc24d", "supplier": "WP Overnight", "location": "Netherlands", "quantity": "20.0000", "quantity_available": "18.0000", "units": "1", "status": "active", "order_ids": "[1037,1038]", "shared_ids": "[275]" }, }
Insert a new batch through a product #
PUT
http://localhost:10003/wp-json/wc/v3/products/<product_id>
Body form-data
Parameter | Type | Description |
---|---|---|
batches | array | An array of batch objects. |
batches[].batch_number | string | A unique identifier for the batch. |
batches[].date_expiry | string (datetime) | The expiration date of the batch, formatted as “YYYY-MM-DD HH:MM:SS”. |
batches[].quantity | integer | The total quantity of items in the batch. |
batches[].quantity_available | integer | The number of available items in the batch. |
batches[].location | string | The location of items in the batch. |
batches[].status | string | The status of the batch. Valid values are active or archived . The default value is active . |
batches[].user_id | integer | The unique identifier for the user. This parameter is used to associate the batch with a specific user. The default value is 1 . |
batches[].po | object | The purchase order details. |
batches[].po.date_created | string (datetime) | Date the purchase order was created in “YYYY-MM-DD HH:MM:SS” format. |
batches[].po.po_number | string | The purchase order number. |
batches[].po.supplier | string | The name of the supplier. |
batches[].po.cost | float | The cost price of the item. |
batches[].po.regular_price | float | The regular selling price of the item. |
batches[].po.sale_price | float | The sale price of the item, if applicable. |
batches[].po.price_margin | float | The profit margin on the item. |
batches[].po.price_discount | float | The discount amount applied to the item. |
The id
should be omitted for batch objects because it will be created automatically.
JSON response example:
{ "batches": [ { "batch_number": "EOEOEOEOEOEOE", "date_expiry": "2023-12-31 00:00:00", "quantity": "50", "po": { "date_created": "2023-01-16 00:00:00", "po_number": "PO23456", "supplier": "WPO", "cost": 10.99, "regular_price": 14.99, "sale_price": 13.99, "price_margin": 30.00, "price_discount": 5.00 } } ] }
Update a batch through a product #
PUT
http://localhost:10003/wp-json/wc/v3/products/<product_id>
Body form-data
Parameter | Type | Description |
---|---|---|
batches | array | An array of batch objects. |
batches[].id | integer | Required The unique identifier for the batch. |
batches[].batch_number | string | A unique identifier for the batch. |
batches[].date_expiry | string (datetime) | The expiration date of the batch, formatted as “YYYY-MM-DD HH:MM:SS”. |
batches[].quantity | integer | The total quantity of items in the batch. |
batches[].quantity_available | integer | The number of available items in the batch. |
batches[].location | string | The location of items in the batch. |
batches[].status | string | The status of the batch. Valid values are active or archived . The default value is active . |
batches[].user_id | integer | The unique identifier for the user. This parameter is used to associate the batch with a specific user. The default value is 1 . |
batches[].po | object | The purchase order details. |
batches[].po.date_created | string (datetime) | Date the purchase order was created in “YYYY-MM-DD HH:MM:SS” format. |
batches[].po.po_number | string | The purchase order number. |
batches[].po.supplier | string | The name of the supplier. |
batches[].po.cost | float | The cost price of the item. |
batches[].po.regular_price | float | The regular selling price of the item. |
batches[].po.sale_price | float | The sale price of the item, if applicable. |
batches[].po.price_margin | float | The profit margin on the item. |
batches[].po.price_discount | float | The discount amount applied to the item. |
JSON response example:
{ "batches": [ { "id": "53", "quantity_available": "20", "po": { "date_created": "2023-01-16 00:00:00", "po_number": "PO23456", "supplier": "WPO", "cost": 10.99, "regular_price": 14.99, "sale_price": 13.99, "price_margin": 30.00, "price_discount": 5.00 } } ] }
Update a batch directly #
PUT
http://localhost:10003/wp-json/wc/v3/products/batches/<batch_id>
Body form-data
Parameter | Type | Description |
---|---|---|
batch_number | string | A unique identifier for the batch. |
date_expiry | string (datetime) | The expiration date of the batch, formatted as “YYYY-MM-DD HH:MM:SS”. |
quantity | integer | The total quantity of items in the batch. |
quantity_available | integer | The number of available items in the batch. |
location | string | The location of items in the batch. |
status | string | The status of the batch. Valid values are active or archived . The default value is active . |
user_id | integer | The unique identifier for the user. This parameter is used to associate the batch with a specific user. The default value is 1 . |
po | object | The purchase order details. |
po.date_created | string (datetime) | Date the purchase order was created in “YYYY-MM-DD HH:MM:SS” format. |
po.po_number | string | The purchase order number. |
po.supplier | string | The name of the supplier. |
po.cost | float | The cost price of the item. |
po.regular_price | float | The regular selling price of the item. |
po.sale_price | float | The sale price of the item, if applicable. |
po.price_margin | float | The profit margin on the item. |
po.price_discount | float | The discount amount applied to the item. |
JSON response example:
{ "quantity_available": "20", "po": { "date_created": "2023-01-16 00:00:00", "po_number": "PO23456", "supplier": "WPO", "cost": 10.99, "regular_price": 14.99, "sale_price": 13.99, "price_margin": 30.00, "price_discount": 5.00 } }
Delete a batch through a product #
PUT
http://localhost:10003/wp-json/wc/v3/products/<product_id>
Body form-data
Parameter | Type | Description |
---|---|---|
batches | array | An array of batch objects. |
batches[].id | integer | Required The unique identifier for the batch. |
batches[].delete | boolean | Indicates whether the batch should be deleted. When set to true, the batch is marked for deletion. Only one of delete or force_delete should be sent in the request. |
batches[].force_delete | boolean | Indicates whether the batch should be forcefully deleted. By using this setting, you can delete batches without needing to detach the associated products first. Additionally, this will also remove the corresponding Purchase Order linked to the batch. Only one of delete or force_delete should be sent in the request. |
JSON response example:
{ "batches": [ { "id": "53", "delete": "yes" } ] }
Delete a batch purchase order through a product #
PUT
http://localhost:10003/wp-json/wc/v3/products/<product_id>
Body form-data
Parameter | Type | Description |
---|---|---|
batches | array | An array of batch objects. |
batches[].id | integer | Required The unique identifier for the batch. |
batches[].po | object | The purchase order details associated with the batch. |
batches[].po.delete | boolean | Indicates whether the associated purchase order should be deleted. When set to true, the purchase order linked to the batch will be deleted. |
JSON response example:
{ "batches": [ { "id": "53", "po": { "delete": "yes" } } ] }