Searching Recipes
Learn about the different ways you can search for recipes using the Spoonacular API.
We'll cover the following...
We can use the Spoonacular API to add a powerful recipe search engine to our projects. To do so, we can use the following endpoints based on our use case:
- search recipes
- search recipes nutrients
- search recipes ingredients
The search recipes endpoint
The search recipes endpoint performs a complex search and fetches recipes for a given query. However, we can easily use most query parameters of other recipe search endpoints for advanced filtering. The search recipes endpoint has a cost of
GET https://api.spoonacular.com/recipes/complexSearch
Here are some of the request parameters we can use with the search recipes endpoint when performing a recipe search:
Request Parameters
Parameter | Type | Category | Description |
| String | Optional | The search query to look up the recipe. |
| String | Optional | Accepts a single cuisine or a comma-separated list of cuisines. The API will interpret the comma as an OR connection. |
| String | Optional | Excludes any associated recipes from the search results and accepts a single cuisine or a comma-separated list of cuisines. The API will interpret the comma as an AND connection. |
| String | Optional | Accepts a single diet or a list of diets. We can separate list elements by |
| String | Optional | Accepts a single intolerance or a comma-separated list of intolerances. |
| String | Optional | Accepts a comma-separated list of equipment. |
| String | Optional | Accepts a comma-separated list of ingredients. |
| String | Optional | The ingredient(s) that the queried recipes should not use. This parameter accepts a comma-separated list of ingredients. |
| String | Optional | The meal type of the queried recipes. |
| Boolean | Optional | The option, if set to |
Note: For additional request parameters, refer to the "Additional Request Parameters" lesson. A complete list of all supported cuisine values can be found in the "Supported Parameter Values" lesson.
Let’s see how to call the API endpoint to query recipes. Click the “Run” button to execute the code.
Take a look at the following explanation of the code above:
Line 5: We use the endpoint URL
/recipes/complexSearchto make a complex search of recipes.Line 8: Here, we assign the API key to the
apiKeyvariable.Lines 11–14: We define the header parameters for the API call. We can modify or add parameters using the
headerParametersvariable.Line 12: We pass the
apiKeyvariable to thex-api-keyheader parameter.
Lines 17–21: We define the query parameters for the API call. We can modify or add parameters using the
queryParametersvariable.Line 18: We fetch burger recipes using the
queryparameter to set the search query asBurger.Line 19: We fetch recipes that are part of the
Americancuisine by filtering the search results using thecuisineparameter.Line 20: We fetch recipes that do not contain any
dairyby filtering the search results using theintolerancesparameter.
The response of this endpoint is an array of recipe objects stored in the results field. Here are some of the fields from the API response:
Response Fields
Name | Type | Description |
| Number | The ID of the recipe |
| String | The title name of the recipe |
| String | The URL of the recipe’s image |
| String | The image type of the recipe's image |
The search recipes nutrients endpoint
The search recipes nutrients endpoint searches for recipes according to nutrients. We can set nutritional limits for both macronutrients and micronutrients. The search recipes nutrients endpoint itself has a cost of
GET https://api.spoonacular.com/recipes/findByNutrients
Here are some of the request parameters we can use with the search recipes nutrients endpoint when performing a recipe search:
Request Parameters
Parameter | Type | Category | Description |
| Number | Optional | The minimum number of carbohydrates that the recipes we’re fetching should have in grams. |
| Number | Optional | The maximum number of carbohydrates that the recipes we’re fetching should have in grams. |
| Number | Optional | The minimum number of calories that the recipes we’re fetching should have. |
| Number | Optional | The maximum number of calories that the recipes we’re fetching should have. |
| Number | Optional | The minimum amount of protein that the recipes we’re fetching should have in grams. |
| Number | Optional | The maximum amount of protein that the recipes we’re fetching should have in grams. |
| Number | Optional | The minimum amount of cholesterol that the recipes we’re fetching should have in milligrams. |
| Number | Optional | The maximum amount of cholesterol that the recipes we’re fetching should have in milligrams. |
| Boolean | Optional | The option, if set to |
| Boolean | Optional | The option, if set to |
Note: For additional request parameters, refer to the "Additional Request Parameters" lesson.
Let’s see how to call the API endpoint to query recipes by nutrients. Click the “Run” button to execute the code.
Take a look at the following explanation of the code above:
Line 2: We use the endpoint URL
/recipes/findByNutrientsto search for recipes according to the nutritional limits in the dish.Lines 5–12: We define the query parameters for the API call. We can modify or add parameters using the
queryParametersvariable.Line 6: We fetch recipes with a maximum carbohydrate amount of
40grams using themaxCarbsparameter.Line 7: We fetch recipes with a minimum calorie amount of
100using theminCaloriesparameter.Line 8: We fetch recipes with a maximum calorie amount of
400using themaxCaloriesparameter.Line 9: We fetch recipes with a maximum cholesterol amount of
0milligrams using themaxCholesterolparameter.Line 10: We randomize the recipe search results by setting the
randomparameter totrue, which means that the search results are random on every API call.
The response of this endpoint is an array of recipe objects. Here are some of the response fields of the API call we can get using its default behavior without enabling any additional request parameters:
Response Fields
Name | Type | Description |
| Number | The ID of the recipe |
| String | The title name of the recipe |
| String | The URL of the recipe’s image |
| String | The image type of the recipe’s image |
| String | The number of calories in the recipe |
| String | The amount of protein in the recipe in grams |
| String | The amount of fat in the recipe in grams |
| String | The amount of carbs in the recipe in grams |
| String | The amount of cholesterol in the recipe in milligrams |
The search recipes ingredients endpoint
The search recipes ingredients endpoint searches for recipes according to available ingredients. We can prioritize fetching either the recipes with the maximum usage of ingredients or recipes with the minimum number of unavailable ingredients. The search recipes ingredients endpoint itself has a cost of
GET https://api.spoonacular.com/recipes/findByIngredients
Here are the request parameters we can use with the search recipes ingredients endpoint when performing a recipe search:
Request Parameters
Parameter | Type | Category | Description |
| String | Optional | The ingredient(s) that the queried recipes should use. This parameter accepts a comma-separated list of ingredients. |
| Number | Optional | The option to either rank search results by most ingredients used if the set value is |
| Boolean | Optional | The option, if set to |
| Number | Optional | The number of results to include in the API response. Possible values: |
| Boolean | Optional | The option, if set to |
Let’s see how to call the API endpoint to query recipes by ingredients. Click the “Run” button to execute the code.
Take a look at the following explanation of the code above:
Line 2: We use the endpoint URL
/recipes/findByIngredientsto search for recipes according to the dish's ingredients.Lines 5–10: We define the query parameters for the API call. We can modify or add parameters using the
queryParametersvariable.Line 6: We find recipes based on the ingredients we have assigned in the
ingredientsparameter. The ingredients we have assigned are the essential ingredients of a custard. Therefore, the search will be representative of that.Line 7: We sort the recipe search results based on the minimum missing ingredients by setting the
rankingparameter to2.Line 8: We instruct Spoonacular to ignore pantry items while searching for recipes by ingredients by setting the
ignorePantryparameter totrue.
The response of this endpoint is an array of recipe objects. Here are some of the response fields of the API call that we can get:
Response Fields
Name | Type | Description |
| Number | The ID of the recipe |
| String | The title name of the recipe |
| String | The URL of the recipe’s image |
| String | The image type of the recipe’s image |
| Number | The number of ingredients used in the recipe |
| Number | The number of ingredients missing from the recipe |
| Object[ ] | An array of ingredient objects missing from the recipe |
| Object[ ] | An array of ingredient objects used in the recipe |
| Object[ ] | An array of ingredient objects not used in the recipe |