preloading the font
BonAPI | Dynamic Recipe API Documentation
BonAPI-logo

DYNAMIC RECIPE API DOCUMENTATION

Page Overview

GET /api/v1/dynamic/recipes

The Dynamic Recipe API is a solution tailored to adjusting ingredients in a recipe to suit given dietary requirements and updating the instructions accordingly to reflect any changes. Both the ingredient list and recipe instructions are required inputs to be provided in the API body as the payload, both are necessary for the analysis that determines which ingredients are most suitable as alternatives. Parameters may also be provided to define the dietary requirements that the recipe should be made to conform to: these include both a diet and an allergies parameter. Diet can be defined in a single argument, while allergies may be given multiple arguments. Changes in composition data due to ingredient substitutions can be requested with each desired composition type being referenced specifically. The parameter composition is also an optional parameter and can be given multiple arguments. Finally, a language parameter may also be provided to specify the language of the provided ingredients and instructions.

Dynamic Recipe API Request

The Dynamic Recipe API solution also has in it included an ingredient analysis API that is designed to be executed as a set-up on all recipes for which the Dynamic Recipe functionality is desired. This verifies all ingredients are correctly matched (without fully matched ingredients, Dynamic Recipe functionality cannot guarantee the recipe fully complies with any desired dietary restrictions) and also returns the dietary profile of the recipe, including suitable diet and present allergens; this information may be stored and displayed on the recipe page. Below is an overview of the construction a Dynamic Recipe API request with examples provided.

Required Inputs

The Dynamic Recipes API request must contain authorization through the header as well as declaration of the json content type of the payload.

API Headers

Header Type Example
Authorization string Authorization: Token <YOUR_BONAPI_TOKEN> required
Content-type string application/json required

API Request Body application/json

The payload consists of the ingredients and instructions which are provided in a JSON format object, where the key "ingredients" contains its value pair as an array containing the ingredients, and the key "instructions" contains its value pair as an array containing the instrucitons steps.

data={"ingredients": <array of ingredients>, "instructions": <array of instructions>}

The ingredients are provided through the payload in the API body, provided in an array where each element is a separate ingredient entry.
Ingredients should be provided with their respective quantities as well as with some descriptive and processing information if present: for example “1 cup of finely chopped Onion” or “2 large potatoes” as these allow for identifying the quantity of that ingredient.

Input Type Description
Ingredients array Ingredients must be provided in a JSON formatted array, where each element is an individual ingredient or item in an ingredient list. required
Example ingredients array:
['2 tbsp Olive Oil', '4 tbsp Ghee', '0.5 tsp Turmeric', '1 tsp Garam Masala', '0.5 tsp Chili Powder', '1 tsp Pepper', '1.5 tsp Salt', '2 tsp Mustard Seeds', '600 g Onion', '120 g Garlic', '120 g Ginger', '150 g Yoghurt', '1 kg Chicken', 'Coriander for garnish']

data={"ingredients": <array of ingredients>, "instructions": <array of instructions>}

The instructions are provided in the payload of the api body.
Instructions are provided in an array with each element representing a separate step or paragraph in the recipe instructions.

Input Type Description
Instructions array Instructions must be provided in a JSON formatted array, where each element is an individual step or paragraph. required
Example instructions array:
['Chop Ginger and Garlic into small dices. Then chop the Onion. The Chicken can be cut into smaller pieces for a shorter cooking time.', 'In a large saucepan or wok, add 2 tablespoons of Ghee and Olive Oil and fry the Mustard seeds on medium heat until they start popping. Add chopped Ginger and Garlic and fry till a golden brown.', 'Add the chopped Onion and let it sauté for approximately 5 minutes.', 'Add in the spices: Turmeric, Garam masala, Chili powder, Coriander powder and Pepper and keep stirring for 30 seconds. Add the Chicken along with 2 more tablespoons of Ghee and let it fry for 10 minutes while stirring on high fire.', 'Add in the Yoghurt and stir well on medium fire until it starts boiling. At this point reduce the heat to low and let it simmer until the sauce has thickened up.', 'Garnish with fresh Coriander and enjoy!']

Query Parameters

Different parameters can be provided to define the dietary requirements the ingredients should be made to conform to.
Parameters can be declared in any order, and their arguments should be provided using the keys defined in the Reference APIs and Support and shown below.
Multiple parameters can be passed through joined by an ampersand (&).

/api/v1/dynamic/recipes/?diet=

The diet parameter accepts one argument and defines the diet that the recipe must conform to.
A diet is understood to be conformed to if all ingredients fall within it or a more restrictive diet: for example cow’s milk (vegetarian) is understood to also conform to a Pescetarian and unrestricted (Meat-eater) diet and would only be substituted if a vegan parameter was provided.

Arguments Type Description
pescetarian string Requires that results must be suitable for a pescetarian diet. optional
vegetarian string Requires that results must be suitable for a vegetarian diet. optional
vegan string Requires that results must be suitable for a vegan diet. optional
Example diet parameter:
diet=vegetarian

/api/v1/dynamic/recipes/?allergies=

The allergies parameter accepts multiple arguments and defines any allergies or intolerances that the ingredients must no longer contain. Multiple arguments are joined with a comma (' , ').
Any ingredients containing any of the provided allergies or intolerances will be substituted with viable alternatives.

Arguments Type Description
celery_allergy string Requires that results must be suitable for a celery allergy. optional
crustacean_allergy string Requires that results must be suitable for a crustacean allergy. optional
egg_allergy string Requires that results must be suitable for an egg allergy. optional
fish_allergy string Requires that results must be suitable for a fish allergy. optional
gluten_allergy string Requires that results must be suitable for a gluten allergy (Celiac disease). optional
lactose_intolerance string Requires that results must be suitable for a lactose intolerance. optional
lupin_allergy string Requires that results must be suitable for a lupin allergy. optional
milk_allergy string Requires that results must be suitable for a milk allergy. optional
mollusc_allergy string Requires that results must be suitable for a mollusc allergy. optional
mustard_allergy string Requires that results must be suitable for a mustard allergy. optional
peanut_allergy string Requires that results must be suitable for a peanut allergy. optional
sesame_allergy string Requires that results must be suitable for a sesame allergy. optional
soy_allergy string Requires that results must be suitable for a soy allergy. optional
tree_nut_allergy string Requires that results must be suitable for a tree nut allergy. optional
wheat_allergy string Requires that results must be suitable for a wheat allergy. optional
Example allergies parameter:
allergies=gluten_allergy,lactose_intolerance

Substitute Ingredient Conformity

All provided ingredient alternatives will conform to all provided parameters. For example, a vegan alternative for cow’s milk could be Soy Drink, however if both a vegan and soy allergy parameter are provided, an alternative conforming to all provided parameters will be returned, for example Rice Drink.

/api/v1/dynamic/recipes/?composition=

The composition parameters accepts multiple arguments and defines which data-points of the included ingredients composition should be returned. Multiple arguments are joined with a comma (' , ').
Composition data is returned reflecting the change in overall composition of all included ingredients and as a result of any ingredient substitutions.

Arguments Type Description
Nutrients
energy string Returns overall energy composition change, in kilocalories (Kcal). optional
carbohydrate string Returns overall carbohydrate composition change, in grams (g). optional
sugar string Returns overall sugar composition change, in grams (g). optional
protein string Returns overall protein composition change, in grams (g). optional
total_fat string Returns overall total fat composition change, in grams (g). optional
fibre string Returns overall fibre composition change, in grams (g). optional
starch string Returns overall starch composition change, in grams (g). optional
monosach string Returns overall monosaccharide composition change, in grams (g). optional
disach string Returns overall disaccharide composition change, in grams (g). optional
saturated_fat string Returns overall saturated fat composition change, in grams (g). optional
mono_unsaturated_fat string Returns overall monounsaturated fat composition change, in grams (g). optional
poly_unsaturated_fat string Returns overall polyunsaturated fat composition change, in grams (g). optional
cholesterol string Returns overall cholesterol composition change, in milligrams (mg). optional
Minerals
calcium string Returns overall calcium composition change, in milligrams (mg). optional
iron string Returns overall iron composition change, in milligrams (mg). optional
magnesium string Returns overall magnesium composition change, in milligrams (mg). optional
phosphorus string Returns overall phosphorus composition change, in milligrams (mg). optional
potassium string Returns overall potassium composition change, in milligrams (mg). optional
sodium string Returns overall sodium composition change, in milligrams (mg). optional
zinc string Returns overall zinc composition change, in milligrams (mg). optional
copper string Returns overall copper composition change, in milligrams (mg). optional
manganese string Returns overall manganese composition change, in milligrams (mg). optional
selenium string Returns overall selenium composition change, in micrograms (µg). optional
iodine string Returns overall iodine composition change, in micrograms (µg). optional
Vitamins
vit_a string Returns overall total vitamin A composition change, in international units (iu). optional
retinol_vit_a string Returns overall retinol (vitamin A) composition change, in micrograms (µg). optional
a_carot_vit_a string Returns overall alpha carotene (vitamin A) composition change, in micrograms (µg). optional
b_carot_vit_a string Returns overall beta carotene (vitamin A) composition change, in micrograms (µg). optional
b_crypt_vit_a string Returns overall beta cryptoxanthin (vitamin A) composition change, in micrograms (µg). optional
thiamin_vit_b1 string Returns overall thiamin (vitamin B1) composition change, in milligrams (mg). optional
riboflavin_vit_b2 string Returns overall riboflavin (vitamin B2) composition change, in milligrams (mg). optional
niacin_vit_b3 string Returns overall niacin (vitamin B3) composition change, in milligrams (mg). optional
panto_acid_vit_b5 string Returns overall pantothenic acid (vitamin B5) composition change, in milligrams (mg). optional
pyridoxin_vit_b6 string Returns overall pyridoxine (vitamin B6) composition change, in milligrams (mg). optional
vit_b9 string Returns overall total vitamin B9 composition change, in micrograms (µg). optional
folate_vit_b9 string Returns overall folate (vitamin B9) composition change, in micrograms (µg). optional
folic_acid_vit_b9 string Returns overall folic acid (vitamin B9) composition change, in micrograms (µg). optional
cobalamin_vit_b12 string Returns overall cobalamin (vitamin B12) composition change, in micrograms (µg). optional
ascorbate_vit_c string Returns overall ascorbate (vitamin C) composition change, in milligrams (mg). optional
vit_d string Returns overall total vitamin D composition change, in international units (iu). optional
ergocalciferol_vit_d string Returns overall ergocalciferol (vitamin D) composition change, in micrograms (µg). optional
cholecalciferol_vit_d string Returns overall cholecalciferol (vitamin D) composition change, in micrograms (µg). optional
vit_e string Returns overall total vitamin E composition change, in milligrams (mg). optional
a_tocopherol_vit_e string Returns overall alpha tocopherol (vitamin E) composition change, in milligrams (mg). optional
b_tocopherol_vit_e string Returns overall beta tocopherol (vitamin E) composition change, in milligrams (mg). optional
g_tocopherol_vit_e string Returns overall gamma tocopherol (vitamin E) composition change, in milligrams (mg). optional
d_tocopherol_vit_e string Returns overall delta tocopherol (vitamin E) composition change, in milligrams (mg). optional
vit_k string Returns overall total vitamin K composition change, in micrograms (µg). optional
phytomenadione_vit_k string Returns overall phytomenadione (vitamin K) composition change, in micrograms (µg). optional
menaquinone_vit_k string Returns overall menuquinone (vitamin K) composition change, in micrograms (µg). optional
Example composition parameter:
composition=energy,fibre,calcium,iron,cobalamin_vit_b12,ascorbate_vit_c

/api/v1/dynamic/recipes/?language=

The default API language can be defined in the BonAPI Account page, meaning all requests with the corresponding token will automatically be analysed in the chosen language.
However, a language parameter can be passed to specify the language of the included inputs of a specific API call.

Arguments Type Description
en string Indicates that the request inputs are in english. optional
de string Indicates that the request inputs are in german. optional
Example language parameter:
language=en

/api/v1/dynamic/recipes/?match_criteria=

The best ingredient alternatives can be identified through a focus on different elements of the ingredients themselves. This allows for the best match to be determined on a nutrient or mineral content basis for example.
By default, all ingredient alternatives are identified on an overall best match level, which takes into account all available data points. Some pillars for identification are still in development and experimental, these are marked with an*.

Arguments Type Description
overall string Find the overall best alternative given the supplied constraints. default
nutrients string Find the best alternative based on nutrients given the supplied constraints. optional
minerals string Find the best alternative based on minerals given the supplied constraints. optional
vitamins string Find the best alternative based on vitamins given the supplied constraints. optional
flavor_profile* string Find the best alternative based on flavour profile given the supplied constraints. optional
structure* string Find the best alternative based on structure given the supplied constraints. optional

/api/v1/dynamic/recipes/?replace_only_unsuitable_ingredients=

By default only ingredients that do not conform to the supplied dietary requirements in diet and allergies with be substituted. However, you can declare that all supplied ingredients should be replaced, regardless of their initial suitability.

Arguments Type Description
True string Only for ingredients that do not adhere to all the provided parameters will ingredient alternative suggestions be provided. default
False string Ingredient alternative suggestions will be provided for all the ingredients included in the call, regardless if they initially conform to the supplied dietary parameters or not. optional

Example Dynamic Recipe API

Combining the above examples by creating a JSON format object containing the ingredients and instructions and appending the optional parameters in the examples provided joined with ampersand (&) sign to the api endpoint, we come to the below example query.

Example payload to be provided in the API body and in JSON format object
data={"ingredients": ['2 tbsp Olive Oil', '4 tbsp Ghee', '0.5 tsp Turmeric', '1 tsp Garam Masala', '0.5 tsp Chili Powder', '1 tsp Pepper', '1.5 tsp Salt', '2 tsp Mustard Seeds', '600 g Onion', '120 g Garlic', '120 g Ginger', '150 g Yoghurt', '1 kg Chicken', 'Coriander for garnish'], "instructions": ['Chop Ginger and Garlic into small dices. Then chop the Onion. The Chicken can be cut into smaller pieces for a shorter cooking time.', 'In a large saucepan or wok, add 2 tablespoons of Ghee and Olive Oil and fry the Mustard seeds on medium heat until they start popping. Add chopped Ginger and Garlic and fry till a golden brown.', 'Add the chopped Onion and let it sauté for approximately 5 minutes.', 'Add in the spices: Turmeric, Garam masala, Chili powder, Coriander powder and Pepper and keep stirring for 30 seconds. Add the Chicken along with 2 more tablespoons of Ghee and let it fry for 10 minutes while stirring on high fire.', 'Add in the Yoghurt and stir well on medium fire until it starts boiling. At this point reduce the heat to low and let it simmer until the sauce has thickened up.', 'Garnish with fresh Coriander and enjoy!']}
Example Dynamic Recipe API endpoint with parameters:
https://www.bon-api.com/api/v1/dynamic/recipes/?diet=vegetarian&allergies=gluten_allergy,lactose_intolerance&composition=energy,fibre,calcium,iron,cobalamin_vit_b12,ascorbate_vit_c&language=en

Dynamic Recipe API Response

The above example Dynamic Recipe API request returns the below response.

JSON Dynamic Recipe API response:

Dynamic Recipe API response schema

Attribute Type Description
response_code number A JSON response code indicating the success or reason for failure of the request.
request object Object containing the received inputs and parameters of the request. Contents include:
language string Indicates the specified language with which the request was made.
provided_ingredients array An array containing each element in the ingredients input extracted from its JSON formatting.
provided_instructions array An array containing each step or paragraph of the instructions input extracted from its JSON formatting.
diet string If provided, the specified diet to which all returned ingredient alternatives should conform to.
allergies array If provided, an array of allergies and intolerance for which all returned ingredient alternatives should be suitable.
composition array If provided, an array of all composition data points requested for each ingredient (with respect to their quantity).
response object Object containing the results of the analysis as per the received inputs and parameters of the request. Contents include:
alerts null or object Alerts will highlight any not understood ingredients, parameters and arguments provided, as well as notifying of any other caught anomalies. If there are no alerts, null is returned. Alerts are only included if an alert is present; possible alerts include:
Alert Type Description
ingredients_not_found array Contains all provided ingredients that were not matched to any internal ingredient and thereby not found. This is present in conjunction with a 404 response code.
diet string Indicates the provided argument for diet was not understood, returns the not understood argument.
allergies array Indicates the provided arguments for allergies were not understood, returns the not understood arguments.
composition array Indicates the provided arguments for composition were not understood, returns the not understood arguments.
na_composition array Contains a list of all provided ingredients for which no quantity was deduced, making it not possible to return composition information for them. These ingredients' composition information are also not included in the overall composition values.
matched_ingredients array An array of all provided ingredients together with an indication of the ingredient to which they were matched in BonAPI's database. Each element is a string containing a provided ingredient, " ---> ". the respective matched ingredient.
updated_ingredients array An array of all ingredients with all unsuitable ingredients, as specified by the provided arguments within the parameters of diet and allergies, now replaced by suitable ingredient alternatives. All quantities are also provided for the new ingredients.
updated_instructions array An array of the instructions with all references to unsuitable ingredients now replaced with their respective new ingredient alternatives.
diet_1 array An array of all diets to which the updated recipe, containing the new ingredient alternatives, could be further constrained to. Returned in the language specified in the request.
allergens_1 array An array containing all the allergies and intolerances present in the updated recipe, containing the new ingredient alternatives. Returned in the language specified in the request.
diet_2 array An array of all diets that are offered by BonAPI to constrain a diet to. Returned in the language specified in the request.
allergens_2 array An array of all allergies and intolerances understood by BonAPI. Returned in the language specified in the request.
composition_info null or object If no composition data was specified in the composition parameter in the request, this will return null. Otherwise returns an object containing further objects. The first, "overall", contains the composition data of the recipe, as calculated from all the provided ingredient quantities. Following "overall" is then composition data for each data point referenced by their name as stated in the updated_ingredients. Within each object are all specified composition data points as provided in the request. Each composition data point is itself an object, referenced by its key (the same as it was called for in the request) and with contents:
Attribute Type Description
name string The name of the given composition data point. Returned in the language specified in the request.
unit string The unit of the given composition data point.
value number A decimal value of the given composition data point contained in the "overall" or specific ingredient given the provided quantities.

Response Codes

With each BonAPI request, a JSON response code is returned to indicate the success or reason for failure of the request. Response codes are provided with a detail and description.


{
    "response": {
        "200 Success": {
            "response_code": 200
            "detail": "A successful request and response with no identified errors or alerts."
            "description": "Indicates that request has succeeded."
        },
        "400 Bad Request": {
            "response_code": 400
            "detail": "The criteria: <match_criteria> cannot be used as a match criteria for <ingredient_name>. Please review our documentation and reference APIs."
            "description": "The request could not be understood by the server due to incorrect syntax. The client SHOULD NOT repeat the request without modifications."
        },
        "401 Unauthorized": {
            "response_code": 401
            "detail": "Invalid token/Authentication credentials were not provided.",
            "description": "Indicates that the request requires user authentication information. The client MAY repeat the request with a suitable Authorization header field."
        },
        "404 Not Found": {
            "response_code": 404
            "detail": "The requested resource does not exist.",
            "description": "The server can not find the requested resource."
        },
        "405 Method Not Allowed": {
            "response_code": 405
            "detail": "The Dynamic Recipe API only accepts POST requests. For further information please check out the documentation page.",
            "description": "The request HTTPS method is known by the server but has been disabled and cannot be used for that resource."
        },
        "426 Upgrade Required": {
            "response_code": 426
            "detail": "The current plan does not allow the <composition> parameter. Please upgrade to a plan that allows it.",
            "description": "The server refuses to perform the request. The server will process the request after the client upgrades to a different protocol."
        },
        "429 Too Many Requests": {
            "response_code": 429
            "detail": "Request was throttled. Expected available in x seconds.",
            "description": "The user has sent too many requests in a given amount of time."
        },
    }
}