Skip to main content

REST API: Nutritional information

How to assign nutritional information to a product and calculate it for elaborations

Assign nutritional information to products, recipes and dishes, and calculate it for recipes and dishes from their ingredients.

PUT /ingredient/{idComponent}/nutritional
PUT /recipe/{idComponent}/nutritional
PUT /dish/{idComponent}/nutritional
GET /recipe/{idComponent}/nutritional
GET /dish/{idComponent}/nutritional

For products, information is expressed per 100 g. For recipes and dishes, per 100 g, for the whole recipe or dish, or for one of its quantities. You can calculate it or assign it directly; assigning it is recommended when the process (frying, baking…) changes the ingredients' values.


Before you start

Base URL: https://app.tspoonlab.com/recipes/api

Headers

  • rememberme · required — Session token returned by the login.

Login — Returns the token as plain text.

curl https://app.tspoonlab.com/recipes/api/login \
-d [email protected] \
-d password=XXXXXXX

Permissions — Every endpoint, including the read ones, requires permission to edit products, recipes or dishes, depending on the path.

Energy — energy is in kcal and energyKj in kJ. When calculating, by default kcal are obtained with the formula fat × 9 + carbohydrates × 4 + proteins × 4 + fiber × 2 and kJ from the kcal (1 kcal = 4.184 kJ). If automatic kcal or kJ calculation is turned off for the account, the ingredients' values are added up.

Responses may include fields other than the documented ones. Use only the documented fields.


Assign nutritional information

Replaces every stored value: fields not sent are left empty.

PUT /ingredient/{idComponent}/nutritional
PUT /recipe/{idComponent}/nutritional
PUT /dish/{idComponent}/nutritional

Path parameters

  • idComponent string · required — Product, recipe or dish id. It must match the type in the path.

Body

  • energy number · optional — Energy in kcal.

  • energyKj number · optional — Energy in kJ.

  • fat number · optional — Fat, in g.

  • saturated number · optional — Saturated fat, in g.

  • carbohydrates number · optional — Carbohydrates, in g.

  • sugar number · optional — Sugars, in g.

  • proteins number · optional — Proteins, in g.

  • salt number · optional — Salt, in g.

  • fiber number · optional — Fibre, in g.

  • nutritionalPercent boolean · optional — true: values are per 100 g (always for products). If not sent, values are stored per 100 g for products and for the whole recipe or dish otherwise, and nutritionalUnitari is ignored.

  • nutritionalUnitari boolean · optional — true (with nutritionalPercent set to false): values are for one quantity of the recipe or dish, the one in idComponentUnitNutritional. With both false, values are for the whole recipe or dish.

  • idComponentUnitNutritional string · optional — id of the recipe or dish quantity (from listComponentService in Recipes and dishes).

Example

curl -X PUT https://app.tspoonlab.com/recipes/api/ingredient/3515834441676562996102040001/nutritional \
-H "rememberme: $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"energy": 18,
"energyKj": 75.3,
"fat": 0.2,
"saturated": 0.03,
"carbohydrates": 3.9,
"sugar": 2.6,
"proteins": 0.9,
"salt": 0.01,
"fiber": 1.2,
"nutritionalPercent": true
}'

Response — No content.


Calculate nutritional information

Calculates a recipe or dish's information from its ingredients. "Sufficient quantity" lines and tools are not counted.

GET /recipe/{idComponent}/nutritional
GET /dish/{idComponent}/nutritional

Path parameters

  • idComponent string · required — Recipe or dish id.

Query parameters

  • percent boolean · optional — true calculates per 100 g. Defaults to true.

  • unitari boolean · optional — true (with percent=false) calculates for one quantity of the recipe or dish. With both false, calculates for the whole. Defaults to false.

  • idComponentUnit string · optional — id of the recipe or dish quantity (from listComponentService) when unitari=true. Defaults to the first one.

Example

curl "https://app.tspoonlab.com/recipes/api/dish/3515834441676562996102030010/nutritional?percent=false&unitari=true" \
-H "rememberme: $TOKEN"

Response

{
"energy": 412.6,
"energyKj": 1726.3,
"fat": 14.1,
"saturated": 6.2,
"carbohydrates": 55.3,
"sugar": 6.8,
"proteins": 16.4,
"salt": null,
"fiber": 3.1,
"nutritionalPercent": false,
"nutritionalUnitari": true,
"idComponentUnitNutritional": "3515834441676562996102030011",
"listIncomplete": [],
"listNoInfo": [],
"listNoInfoSalt": [
{
"id": "3515834441676562996102040010",
"descr": "Grated cheese",
"type": 0,
"color": 16766720
}
]
}
  • energy, energyKj, fat, saturated, carbohydrates, sugar, proteins, salt, fiber number — Calculated values. null if any ingredient lacks that value.

  • nutritionalPercent boolean — Whether it was calculated per 100 g.

  • nutritionalUnitari boolean — Whether it was calculated for one quantity of the recipe or dish.

  • idComponentUnitNutritional string — Quantity used in a per-quantity calculation.

  • listIncomplete array — Ingredients whose quantity cannot be converted to weight. If there are any, no value is calculated.

  • listNoInfo array — Ingredients with no nutritional information at all.

  • listNoInfoEnergy, listNoInfoEnergyKj, listNoInfoFat, listNoInfoSaturated, listNoInfoCarbohydrates, listNoInfoSugar, listNoInfoProteins, listNoInfoSalt, listNoInfoFiber array — Ingredients missing that value.

Each ingredient in the lists:

  • id string — Product, recipe or dish id.

  • descr string — Name.

  • type integer — 0 product · 1 recipe · 3 dish.

  • color integer — Colour (RGB) of its first category.

Need help? Message us from the support chat in the bottom-right corner.

Did this answer your question?