Creates a product together with its components. The product appears at storage location storage_id and at any storage location that stores all products or its categories.
v1/products/add.php
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Name |
| unit | string | Yes | Unit of measure, a code from Units of Measure |
| storage_id | int | Yes | Storage location where the stock is created |
| sku | string | No | SKU |
| price | float | No | Sale price per unit. Default 0 |
| batch_size | float | No | Batch size: the product quantity the components are given for. Default 1 |
| stock | float | No | Initial stock at storage location storage_id. Default 0 |
| minimum | float | No | Minimum stock at storage location storage_id. Default 0 |
| notes | string | No | Notes |
| categories | array | No | Categories: objects with id or name |
| suppliers | array | No | Supplier IDs from v1/suppliers/get_list |
| alternative_sku | array | No | Alternative SKUs: objects with sku and label (an optional caption) |
| materials | array | No | Materials in the components |
| products | array | No | Subassemblies in the components |
| resources | array | No | Resources in the components |
A category can be passed by name: if there is no such category, it is created. The IDs of existing categories are returned by v1/categories/get_list.
The uniqueness of the main and alternative SKUs is not checked.
Product components
The components are defined per batch (batch_size units) and passed as the arrays materials, products (subassemblies) and resources.
materials and products lines
| Field | Type | Required | Description |
|---|---|---|---|
| id | int | Yes | Material or product ID |
| amount_per_batch | float | Yes | Quantity per batch |
| unit | string | Yes | Line unit. From the same group as the material or product unit: for a material in "kg", "kg" or "g" fit |
| loss_percent | float | No | Loss, in percent. Default 0. Accepted only if showing loss in components is enabled in the company settings |
| position | int | No | Line position in the components |
position sets the order of component lines in the Controlata interface, shared by materials and products. Lines without it go last, in the order passed. Controlata renumbers positions from 0, so in Retrieving a Product they may differ from the ones you passed.
resources lines
Each resource line contains the resource id. Whether amount_per_batch and unit are needed depends on the resource type (see Creating a Resource):
| Resource type | amount_per_batch | unit |
|---|---|---|
| Fixed rate | Quantity per batch, e.g. work hours | Required |
| Fixed rate, price specified in the product components | A money amount per batch | Not needed |
| Percentage | Not passed: taken from the resource | Not needed |
| Percentage, specified in the product components | The percentage | Not needed |
| Depreciation | Quantity per batch, e.g. equipment hours | Required |
Example request
A table: 10 per batch, each batch uses 0.5 cu m of board with 5% loss, 400 screws, 40 legs (a subassembly) and 30 hours of carpenter's work. Overhead is a percentage set in the resource itself, so its id is enough.
{
"name": "Dining table",
"sku": "P100",
"unit": "pcs",
"price": 45000,
"batch_size": 10,
"storage_id": 3999,
"stock": 5,
"minimum": 2,
"categories": [{ "id": 21 }],
"suppliers": [{ "id": 46 }],
"alternative_sku": [
{
"label": "Shopify",
"sku": "SH-P100"
}
],
"materials": [
{
"id": 2051,
"amount_per_batch": 0.5,
"unit": "cu m",
"loss_percent": 5
},
{
"id": 2060,
"amount_per_batch": 400,
"unit": "pcs"
}
],
"products": [
{
"id": 312,
"amount_per_batch": 40,
"unit": "pcs"
}
],
"resources": [
{
"id": 57,
"amount_per_batch": 30,
"unit": "h"
},
{
"id": 58
}
]
}
Example response
{
"success": true,
"product_id": 3120
}
Errors
| Error | Reason |
|---|---|
| No name in input | A required field is missing (instead of name, the field's name) |
| Name must not be empty | Empty name |
| Name must be a string | Name passed not as a string, e.g. as an array |
| Unit not set | An empty unit of measure was passed |
| Unit not found | Unknown unit of measure, or a resources-only unit |
| Storage ID is not set | storage_id is 0 or empty |
| Storage ID not found | Storage location not found or deleted |
| Batch size must be greater than 0 | Batch size is 0 or less |
| Invalid price value. Must be a number | The value is not a number, e.g. "12,5" (same for batch_size, stock and minimum) |
| Category 12 not found | Category not found |
| Supplier not found or access denied | Supplier not found or deleted |
| Alternative_sku is not an array | alternative_sku was not passed as an array |
| SKU must be from 1 to 50 characters for alternative_sku 0 | The alternative SKU is empty or longer than 50 characters (the line number, from 0, at the end) |
| Label must not exceed 100 characters for alternative_sku 0 | The alternative SKU caption is longer than 100 characters |
Errors in component lines
In the error text, instead of 2051 there is the item ID, and instead of 0 the line number in the array (from 0).
| Error | Reason |
|---|---|
| Materials is not an array | materials was not passed as an array (same for products and resources) |
| Line 0 of materials must be an object | The line is not an object (same for products and resources) |
| No id for material 0 | The material id is missing or not a number (same for product) |
| Material 2051 not found | Material not found or deleted |
| Product 2051 not found | Product not found or deleted |
| Product cannot be a component of itself | The product was added to its own components |
| Amount per batch must be greater than 0 for material 2051 | The quantity is missing, not a number, or 0 after rounding to 3 decimals (same for product and resource) |
| Unit not found for material 2051. Use a unit of the same group as the material unit | The unit is missing, unknown or from another group (same for product) |
| Loss percent must be from 0 to 100 for material 2051 | Loss is below 0, above 100 or not a number (same for product) |
| Loss percent is disabled in company settings for material 2051 | Loss was passed, but showing loss in components is disabled in the company settings (same for product) |
| Resource for line 0 not found | Resource not found or deleted |
| Percent must not exceed 100 for resource 2051 | The percentage in the components is above 100 |
| Unit not found for resource 2051. Use a unit of the same group as the resource unit | The resource unit is missing, unknown or from another group |