Contents
On this page
Update Unit - Plugixa Inventory
PUT /plugixa-inventory/v1/units/{id}
Change some or all of a unit’s fields. PATCH does the same.
The user needs the plugixa_inventory_edit capability (administrators have every inventory capability). With Pro Roles and permissions enforcing, their role must also allow editing this unit. Needs Plugixa Inventory Pro with the Units of measurement app on in Plugixa Inventory -> App Manager; with it off, this route answers 404.
Note. Only the fields you send change: a field you leave out keeps its stored value, so
PUTandPATCHbehave the same. Sending a field with an empty value does clear it, and a blanknameis refused.
Request
PUT https://your-site.example/wp-json/plugixa-inventory/v1/units/4
Path parameters
| Name | Type | Description |
|---|---|---|
id |
integer |
The unit’s id |
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
code |
string |
No | The short form shown on lines, such as kg or pcs. Letters, digits, -, _, / and % only. Must be unique among live units. At most 20 characters. |
name |
string |
No | Must not be blank. At most 100 characters. |
base_unit_id |
integer |
No | A live unit this one converts to. 0 or null for a base unit of its own. |
operator |
string |
No | *, /, + or -. Required with base_unit_id. |
operation_value |
number |
No | Applied with operator to turn a quantity in this unit into the base unit. Not 0 with * or /. |
status |
string |
No | published (the default) or unpublished. |
modified_at |
string |
No | The modified_at you last read. When the stored value differs, the update is refused with 409 because someone else saved in between. Leave it out to skip the check. |
Sending base_unit_id as 0 or null also clears operator and operation_value.
{
"operation_value": 24,
"name": "Box of 24",
"modified_at": "2026-11-12 09:30:00"
}
Responses
200 OK. data is the updated unit.
{
"success": true,
"data": {
"id": 4,
"code": "box12",
"name": "Box of 24",
"base_unit_id": 1,
"operator": "*",
"operation_value": 24.0,
"status": "published",
"created_by": 1,
"modified_by": 1,
"created_at": "2026-11-12 09:30:00",
"modified_at": "2026-11-12 10:15:00",
"deleted_at": null,
"base_unit_code": "pcs"
}
}
| Field | Type | Meaning |
|---|---|---|
data.operation_value |
number |
The new conversion value |
data.modified_at |
string |
UTC datetime of this change |
Errors
| Status | Code | When |
|---|---|---|
404 |
plugixa_inventory_not_found |
No unit with that id, or it is in the trash. |
422 |
plugixa_inventory_missing_name |
name is missing or blank. |
422 |
plugixa_inventory_missing_code |
code is missing or blank. |
422 |
plugixa_inventory_invalid_choice |
status or operator is not one of the allowed values. data.allowed lists them. |
422 |
plugixa_inventory_not_a_number |
operation_value is not a number. |
422 |
plugixa_inventory_too_long |
A text field is longer than its column. data.field names it and data.max gives the limit. |
422 |
plugixa_inventory_invalid_code |
code contains a character that is not allowed. |
409 |
plugixa_inventory_duplicate_code |
Another live unit already uses this code. |
422 |
plugixa_inventory_unknown_unit |
base_unit_id is not a live unit. |
422 |
plugixa_inventory_unit_self_reference |
base_unit_id is this unit. |
422 |
plugixa_inventory_missing_operator |
base_unit_id is set without a valid operator. |
422 |
plugixa_inventory_invalid_operation_value |
operation_value is 0 with * or /. |
422 / 409 |
plugixa_inventory_unit_cycle |
The base unit would make the chain circular (422), or is already part of a circular chain (409). |
409 |
plugixa_inventory_conflict |
You sent modified_at and the record has changed since. data.expected and data.current carry both values. |
Plus the errors every endpoint can return.
Examples
curl -s -X PUT "https://your-site.example/wp-json/plugixa-inventory/v1/units/4" \
-u "admin:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"operation_value":24,"name":"Box of 24","modified_at":"2026-11-12 09:30:00"}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-inventory/v1/units/4');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => 'admin:' . getenv('WP_APP_PASSWORD'),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'operation_value' => 24,
'name' => 'Box of 24',
'modified_at' => '2026-11-12 09:30:00',
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const auth = 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`);
const response = await fetch('https://your-site.example/wp-json/plugixa-inventory/v1/units/4', {
method: 'PUT',
headers: { 'Authorization': auth, 'Content-Type': 'application/json' },
body: JSON.stringify({
operation_value: 24,
name: 'Box of 24',
modified_at: '2026-11-12 09:30:00',
}),
});
const { data } = await response.json();
Quick Links
Share