Updates a resource. Only the fields you pass are changed, the rest stay as they were.
v1/resources/edit.php
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| resource_id | int | Yes | Resource ID |
| name | string | No | Name |
| type | string | No | Calculation type: "rate", "percent" or "amortized" |
| dynamic | int | No | 1: the price or percentage is specified in the product components |
| unit | string | No | Unit of measure. Used only for a fixed rate and depreciation |
| price | float | No | Price per unit |
| base | string | No | Calculation basis: "cost" or "price" |
| percent | float | No | Percentage |
| initial_cost | float | No | Initial cost |
| useful_life | float | No | Useful life, in the resource's units |
| notes | string | No | Notes |
| categories | array | No | Categories: objects with id or name. Replace the current ones as a whole |
Which fields each type needs is described in Creating a Resource.
When changing type, pass the fields the resource does not have yet: unit for a fixed rate and depreciation, base and percent for a percentage, initial_cost and useful_life for depreciation. The resource's quantity in product components is not recalculated, so check it after the change.
For a resource that has already been consumed in production, the calculation type cannot be changed, and for a depreciated resource the initial cost, useful life and unit cannot either. The other fields can be changed.
Example request
{
"resource_id": 57,
"price": 650
}
Example response
{
"success": true
}
Errors
| Error | Reason |
|---|---|
| No resource_id in input | resource_id is missing |
| Resource not found or access denied | Resource not found or deleted |
| Name must not be empty | An empty name was passed |
| Name must be a string | Name passed not as a string, e.g. as an array |
| Invalid type value. Must be one of: rate, percent, amortized | Invalid type |
| No unit in input | Type changed to a fixed rate or depreciation, but the resource has no unit |
| Unit not set | An empty unit of measure was passed |
| Unit not found | Unknown unit of measure |
| Unit cannot be changed to another unit group: the resource is used in components of products | Changing the unit group of a resource used in product components |
| Invalid price value. Must be a number, 0 or greater | Price is not a number or below 0 (same for initial_cost) |
| Invalid base value. Must be one of: cost, price | Invalid calculation basis, or it was not passed when changing the type to percentage |
| Percent must be greater than 0 and not exceed 100 | Percentage out of range, or not passed when changing the type to percentage |
| Useful life must be greater than 0 | Useful life is 0 or less, or not passed when changing the type to depreciation |
| The resource is already used in production, so these fields cannot be changed: type, useful_life | The resource has already been consumed in production. The fields that cannot be changed are listed at the end: type, initial_cost, useful_life, unit |
| Category 12 not found | Category not found |