Recipe Price Breakdown Widget
Learn how to fetch interactive Spoonacular widgets that display the pricing data for recipes.
We'll cover the following...
We can use the Spoonacular API to fetch widgets that display the recipes’ pricing data in an interactive way. To do so, we can use the following endpoints based on our use case:
- recipe price breakdown widget
- recipe price breakdown by ID widget
We can use one of the following recipe IDs for any code widgets in this lesson that require them:
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 |
Note: The widgets in this lesson require the
jQueryandChartJSlibraries.
The recipe price breakdown widget endpoint
The recipe price breakdown widget endpoint fetches a widget that displays the pricing data for a recipe in an interactive way. The recipe price breakdown widget endpoint has a cost of
POST https://api.spoonacular.com/recipes/visualizePriceEstimator
Here are the request parameters we can use with the recipe price breakdown widget endpoint:
Request Parameters
Parameter | Type | Category | Description |
| String | Required | The list of ingredients of the recipe with each ingredient on a new line with the ingredient amount. Here’s an example:
We need to pass this parameter in the request body rather than as a query or path parameter. |
| Number | Optional | The number of servings of the recipe. We need to pass this parameter in the request body rather than as a query or path parameter. |
| Number | Optional | The option provides a choice of what view to use for the price breakdown widget. We can choose either |
| Boolean | Optional | The option, if set to |
| Boolean | Optional | The option, if set to |
| String | Optional | The input language of the response. It can be either |
Let’s see how to call the API endpoint. 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/visualizePriceEstimatorto fetch the Spoonacular widget that displays the pricing data for a recipe in an interactive way.Line 5: We assign the API key here to the
apiKeyvariable.Lines 8–12: We define the header parameters for the API call. We can modify or add parameters using the
headerParametersvariable.Line 9: We pass the
apiKeyvariable to thex-api-keyheader parameter.Line 10: We need to set the
acceptheader parameter totext/html.Line 11: We need to set the
content-typeheader parameter toapplication/x-www-form-urlencoded.
Lines 15–17: We define the query parameters for the API call. We can modify or add parameters using the
queryParametersvariable.Lines 20–29: We define the body parameters for the API call. We can modify or add parameters using the
bodyParametersvariable.
The recipe price breakdown by ID widget endpoint
The recipe price breakdown by ID widget endpoint takes in the ID of a recipe as a path parameter and fetches a widget that displays the pricing data for a recipe in an interactive way. The recipe price breakdown by ID widget endpoint has a cost of
GET https://api.spoonacular.com/recipes/{id}/priceBreakdownWidget
Here are the request parameters we can use with the recipe price breakdown by ID widget endpoint:
Request Parameters
Parameter | Type | Category | Description |
| Number | Required | The identifier of the recipe for which we’re fetching the price breakdown widget. |
| Number | Optional | The option provides a choice of what view to use for the price breakdown widget. We can choose either |
| 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.
Take a look at the following explanation of the code above:
Line 2: We set and store the ID of a recipe for which we want to fetch the price breakdown widget.
Line 5: We use the endpoint URL
/recipes/{id}/priceBreakdownWidgetto fetch the Spoonacular widget that displays the pricing data for the recipe in an interactive way.Lines 8–11: We define the header parameters for the API call. We can modify or add parameters using the
headerParametersvariable.Line 10: We need to set the
acceptheader parameter totext/html.
Lines 14–16: We define the query parameters for the API call. We can modify or add parameters using the
queryParametersvariable.