List, retrieve, create and delete units, and see where they are used.
GET /listUnitsPaged
GET /unit/{idUnit}/num/{numElements}
GET /unit/{idUnit}/components/paged
GET /unit/{idUnit}/details/paged
GET /unit/{idUnit}/vendors/paged
GET /unit/{idUnit}/customers/paged
POST /unit
DELETE /unit/{idUnit}
Units express the quantities in recipes and purchase formats. A unit can have equivalences with other units, for example 1 kg = 1000 g. Equivalences must always hold true: 1 bottle = 750 ml works for wine, but not for a soft drink or a spirit, so it is not an equivalence.
Before you start
Base URL: https://app.tspoonlab.com/recipes/api
Headers
rememberme· required — Session token returned by the login.order· optional — Cost center id (Cost centers). The suppliers and customers that use a unit are those of this cost center. Defaults to the user's active cost center.
Units belong to the whole account.
Login — Returns the token as plain text.
curl https://app.tspoonlab.com/recipes/api/login \
-d [email protected] \
-d password=XXXXXXX
Permissions — Reading requires permission to view units. Creating requires permission to add units; deleting, permission to delete units.
Responses may include fields other than the documented ones. Use only the documented fields.
List units
GET /listUnitsPaged
Query parameters
startinteger · required — Position of the first row, starting at 0.rowsinteger · required — Number of rows to return.filterstring · optional — Text to filter by name.
Example
curl "https://app.tspoonlab.com/recipes/api/listUnitsPaged?start=0&rows=50" \
-H "rememberme: $TOKEN"
Response
[
{ "id": "3515834441676562996102020601", "descr": "g" },
{ "id": "3515834441676562996102020602", "descr": "kg" }
]
idstring — Unit id.descrstring — Name.
Retrieve a unit
Returns the unit, its equivalences and the first products, suppliers and customers that use it.
GET /unit/{idUnit}/num/{numElements}Path parameters
idUnitstring · required — Unit id.numElementsinteger · required — Maximum number of items to return in each list.
Example
curl https://app.tspoonlab.com/recipes/api/unit/3515834441676562996102020602/num/20 \
-H "rememberme: $TOKEN"
Response
{
"id": "3515834441676562996102020602",
"descr": "kg",
"defecte": true,
"defectePlat": false,
"defecteMenu": false,
"defecteDetall": true,
"defecteFormat": false,
"listConversions": [
{
"id": "3515834441676562996102020701",
"idUnitTo": "3515834441676562996102020601",
"unitTo": "g",
"conversion": 1000,
"comment": null
}
],
"listComponents": [
{ "id": "3515834441676562996102020301", "descr": "Fresh celery", "type": 0, "color": 3381555 }
],
"listComponentsCount": 1,
"listDetails": [
{ "id": "3515834441676562996102020302", "descr": "Vegetable stock", "type": 1, "color": 16750848 }
],
"listDetailsCount": 1,
"listVendors": [
{ "id": "3515834441676562996102020801", "descr": "Green Farm Produce" }
],
"listVendorsCount": 1,
"listCustomers": [],
"listCustomersCount": 0
}idstring — Unit id.descrstring — Name.defecteboolean — Default unit for weight.defectePlatboolean — Default unit for dishes.defecteMenuboolean — Default unit for menus.defecteDetallboolean — Default unit for the lines of a recipe or dish.defecteFormatboolean — Default unit for suppliers' purchase formats.listConversionsarray — Unit equivalences.listComponentsarray — Products that have this unit among their units.listDetailsarray — Recipes and dishes with at least one line in this unit.listVendorsarray — Suppliers of the cost center with products or purchase formats in this unit.listCustomersarray — Customers of the cost center with products for sale in this unit.listComponentsCount,listDetailsCount,listVendorsCount,listCustomersCountinteger — Total items in each list.
Each equivalence:
idstring — Equivalence id.idUnitTo,unitTostring — Target unit.conversionnumber — Conversion factor to the target unit.commentstring — Comment.
Each product, recipe or dish (listComponents, listDetails):
idstring — Product id.descrstring — Name.typeinteger —0ingredient / product ·1recipe ·2material / tool ·3dish.colorinteger — Color of the product's first category, as an RGB integer.
Each supplier or customer (listVendors, listCustomers):
idstring — Id.descrstring — Name.
List where a unit is used
Use them to get more items than Retrieve a unit returns. Each endpoint returns the items of one of its lists.
GET /unit/{idUnit}/components/paged
GET /unit/{idUnit}/details/paged
GET /unit/{idUnit}/vendors/paged
GET /unit/{idUnit}/customers/pagedcomponents— Same aslistComponents.details— Same aslistDetails.vendors— Same aslistVendors.customers— Same aslistCustomers.
Path parameters
idUnitstring · required — Unit id.
Query parameters
startinteger · required — Position of the first row, starting at 0.rowsinteger · required — Number of rows to return.filterstring · optional — Text to filter by name.
Example
curl "https://app.tspoonlab.com/recipes/api/unit/3515834441676562996102020602/vendors/paged?start=0&rows=20" \
-H "rememberme: $TOKEN"
Response — List of items, with the same fields as in Retrieve a unit.
[
{ "id": "3515834441676562996102020801", "descr": "Green Farm Produce" }
]
Create a unit
Returns the id of the new unit. If you make it a default unit for something, the unit that was the default for it stops being so. After the unit is created, the account's recipes and dishes are recalculated, so the call may take a while.
POST /unit
Body
descrstring · required — Name.listConversionsarray · required — Equivalences. Send[]if you do not want to create any.defecteboolean · optional — Default unit for weight (usually kg). Defaults tofalse.defectePlatboolean · optional — Default unit for dishes (usually portion). Defaults tofalse.defecteMenuboolean · optional — Default unit for menus (usually pax). Defaults tofalse.defecteDetallboolean · optional — Default unit for the lines of a recipe or dish (usually kg or g). Defaults tofalse.defecteFormatboolean · optional — Default unit for suppliers' purchase formats. Defaults tofalse.
Each equivalence:
idUnitTostring · required — Target unit id.conversionnumber · required — Conversion factor to the target unit. Must not be 0.commentstring · optional — Comment.
The reverse equivalence is created automatically on the target unit.
Example
curl https://app.tspoonlab.com/recipes/api/unit \
-H "rememberme: $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"descr": "25 kg sack",
"listConversions": [
{ "idUnitTo": "3515834441676562996102020601", "conversion": 25000 }
]
}'
Without equivalences: {"descr": "tray", "listConversions": []}.
Response
{ "id": "3515834441676562996102020603" }Delete a unit
Deletes the unit and its equivalences. If the unit is used in products, recipes, dishes, menus, purchases, suppliers, customers, sales or inventories, it cannot be deleted and the call returns an error.
DELETE /unit/{idUnit}Path parameters
idUnitstring · required — Unit id.
Example
curl -X DELETE https://app.tspoonlab.com/recipes/api/unit/3515834441676562996102020603 \
-H "rememberme: $TOKEN"
Response — No content.
Need help? Message us from the support chat in the bottom-right corner.
