Fetching Recipe Information
Learn how to fetch detailed information for specific recipes using the Spoonacular API.
We'll cover the following
The Spoonacular API allows us to fetch detailed information for specific or multiple recipes. To do so, we can use the following endpoints based on our use case:
- recipe information
- recipe information bulk
We can use one of the following recipe IDs for the code widgets in this lesson:
Recipe IDs
Recipe Name | ID |
Classic Fruit Salad | 639600 |
Tex-Mex Burger | 663050 |
Baked Sirloin Steak | 633790 |
Vegan Chana Masala Curry | 1096306 |
Belgian Hot Chocolate | 634818 |
The recipe information endpoint
The recipe information endpoint takes in the ID of a recipe as a path parameter and fetches detailed information for that recipe. The recipe information endpoint has a cost of includeNutrition
option is enabled. The endpoint method and the URL are as follows:
GET https://api.spoonacular.com/recipes/{id}/information
Here are the request parameters we can use with the recipe information endpoint:
Request Parameters
Parameter | Type | Category | Description |
| Number | Required | The identifier of the recipe for which we’re fetching the detailed information. |
| Boolean | Optional | The option, if set to |
Let’s see how to call the API endpoint. Click the “Run” button to execute the code. Please provide the value for RECIPE_ID
.
// Importing libraries hereimport fetch from 'node-fetch';// Define the ID of any recipe hereconst id = '{{RECIPE_ID}}';// Define endpoint URL hereconst endpointUrl = new URL(`https://api.spoonacular.com/recipes/${id}/information`);// Define API key hereconst apiKey = '{{API_KEY}}';// Define Header Parameters hereconst headerParameters = {'x-api-key': apiKey,'content-type': 'application/json',};// Define Query Parameters hereconst queryParameters = new URLSearchParams({includeNutrition: true,});// Setting API call optionsconst endpointOptions = {method: 'GET',headers: headerParameters,};// Function to make API callasync function fetchRecipeInformation(url, options) {try {// Using the fetch method to make an API call to Spoonacularconst response = await fetch(url, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Attaching query parameters to the endpoint URLendpointUrl.search = queryParameters;// Calling function to make API callfetchRecipeInformation(endpointUrl, endpointOptions);
Take a look at the following explanation of the code above:
Line 5: We set and store the ID of a recipe for which we want to fetch the recipe information.
Line 8: We use the endpoint URL
/recipes/{id}/information
to fetch detailed information for a specific recipe.Line 11: We assign the API key here to the
apiKey
variable.Lines 14–17: We define the header parameters for the API call. We can modify or add parameters using the
headerParameters
variable.Line 15: We pass the
apiKey
variable to thex-api-key
header parameter.
Lines 20–22: We define the query parameters for the API call. We can modify or add parameters using the
queryParameters
variable.Line 21: We set the
includeNutrition
variable totrue
, which will include nutritional data in the API response.
The response of this endpoint is an array of recipe objects. Here are some of the fields from the API response:
Response Fields
Name | Type | Description |
| Boolean | Indicates whether the recipe is a vegetarian dish |
| Number | The per-serving price to make the recipe |
| Number | The ID of the recipe |
| String | The title name of the recipe |
| Number | The time that it takes to cook the recipe in minutes |
| Number | The number of servings in the recipe |
| String | The source URL of the recipe |
| String | The instructions to make the recipe |
| Object[ ] | The detailed nutritional data for the recipe |
The recipe information bulk endpoint
The recipe information bulk endpoint fetches detailed information for a list of recipes. It’s faster to use this endpoint to fetch detailed information for multiple recipes rather than calling the recipe information endpoint several times. The recipe information bulk endpoint for the first recipe has a cost of
GET https://api.spoonacular.com/recipes/informationBulk
Here are the request parameters we can use with the recipe information bulk endpoint:
Request Parameters
Parameter | Type | Category | Description |
| String | Optional | The comma-separated list of identifiers of the recipes for which we’re fetching the detailed bulk information. |
| Boolean | Optional | The option, if set to |
Let’s see how to call the API endpoint. Click the “Run” button to execute the code. Make sure to provide the value for RECIPE_ID2
. Also, provide the value for RECIPE_ID
.
// Define endpoint URL hereconst endpointUrl = new URL('https://api.spoonacular.com/recipes/informationBulk');// Define Query Parameters hereconst queryParameters = new URLSearchParams({ids: '{{RECIPE_ID}},{{RECIPE_ID2}}',includeNutrition: false,});// Setting API call optionsconst endpointOptions = {method: 'GET',headers: headerParameters,};// Attaching query parameters to the endpoint URLendpointUrl.search = queryParameters;// Calling function to make API callfetchRecipeInformationBulk(endpointUrl, endpointOptions);
Take a look at the following explanation of the code above:
Line 2: We use the endpoint URL
/recipes/informationBulk
to fetch detailed information for multiple specific recipes.Lines 5–8: We define the query parameters for the API call. We can modify or add parameters using the
queryParameters
variable.Line 6: We set the comma-separated list of recipe IDs in the
ids
variable to fetch the detailed information for those recipes.Line 7: We set the
includeNutrition
variable tofalse
to exclude nutritional data in the API response.
The response of this endpoint is a recipe object. Here are some of the fields from the API response:
Response Fields
Name | Type | Description |
| Boolean | Indicates whether the recipe is a vegetarian dish |
| Number | The per-serving price to make the recipe |
| Number | The ID of the recipe |
| String | The title name of the recipe |
| Number | The time that it takes to cook the recipe in minutes |
| Number | The number of servings in the recipe |
| String | The source URL of the recipe |
| String | The instructions to make the recipe |