Skip to main content

REST API: Units

How to retrieve and manage measurement units

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

  • start integer · required — Position of the first row, starting at 0.

  • rows integer · required — Number of rows to return.

  • filter string · 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" }
]
  • id string — Unit id.

  • descr string — 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

  • idUnit string · required — Unit id.

  • numElements integer · 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
}
  • id string — Unit id.

  • descr string — Name.

  • defecte boolean — Default unit for weight.

  • defectePlat boolean — Default unit for dishes.

  • defecteMenu boolean — Default unit for menus.

  • defecteDetall boolean — Default unit for the lines of a recipe or dish.

  • defecteFormat boolean — Default unit for suppliers' purchase formats.

  • listConversions array — Unit equivalences.

  • listComponents array — Products that have this unit among their units.

  • listDetails array — Recipes and dishes with at least one line in this unit.

  • listVendors array — Suppliers of the cost center with products or purchase formats in this unit.

  • listCustomers array — Customers of the cost center with products for sale in this unit.

  • listComponentsCount, listDetailsCount, listVendorsCount, listCustomersCount integer — Total items in each list.

Each equivalence:

  • id string — Equivalence id.

  • idUnitTo, unitTo string — Target unit.

  • conversion number — Conversion factor to the target unit.

  • comment string — Comment.

Each product, recipe or dish (listComponents, listDetails):

  • id string — Product id.

  • descr string — Name.

  • type integer — 0 ingredient / product · 1 recipe · 2 material / tool · 3 dish.

  • color integer — Color of the product's first category, as an RGB integer.

Each supplier or customer (listVendors, listCustomers):

  • id string — Id.

  • descr string — 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/paged
  • components — Same as listComponents.

  • details — Same as listDetails.

  • vendors — Same as listVendors.

  • customers — Same as listCustomers.

Path parameters

  • idUnit string · required — Unit id.

Query parameters

  • start integer · required — Position of the first row, starting at 0.

  • rows integer · required — Number of rows to return.

  • filter string · 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

  • descr string · required — Name.

  • listConversions array · required — Equivalences. Send [] if you do not want to create any.

  • defecte boolean · optional — Default unit for weight (usually kg). Defaults to false.

  • defectePlat boolean · optional — Default unit for dishes (usually portion). Defaults to false.

  • defecteMenu boolean · optional — Default unit for menus (usually pax). Defaults to false.

  • defecteDetall boolean · optional — Default unit for the lines of a recipe or dish (usually kg or g). Defaults to false.

  • defecteFormat boolean · optional — Default unit for suppliers' purchase formats. Defaults to false.

Each equivalence:

  • idUnitTo string · required — Target unit id.

  • conversion number · required — Conversion factor to the target unit. Must not be 0.

  • comment string · 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

  • idUnit string · 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.

Did this answer your question?