Fitness freaks always talk about carbs, protein and fats. They eat fruit, vegetable-based on these parameters. This blog will show carbs, protein, fats and calories for given fruit or vegetable using Spoonacular API.
There are lot of food APIs to get nutrition and recipe for food products. Below are some Food APIs
I have used Spoonacular API to get food nutrition. Below are steps to get free API access
- Register at https://spoonacular.com/food-api/pricingÂ
- Select Free plan to check API
- Get API key at https://spoonacular.com/food-api/console#Profile
Now we have API key to use in Apex class to get product nutrition. Let us create Lightning Web Component for this. Below two steps are required
- Create Apex class to call API
- Create Lightning Web Component to show product information
Create Apex class to call API:
We need to call Spoonacular API using GET method of HTTPRequest. API key need to be added in GET request of API request. Change apiKey based on your profile.
callout.endPointurl='https://api.spoonacular.com/recipes/guessNutrition?'+
'apiKey=*******************'+
'&title='+foodName;
Create Lightning Web Component
Create lightning web component which will show product information. I have added one combo box with some predefined options, if you want to get information about other fruit or product, select other in option and enter fruit name in text box.
Demo Time:
Reference:
https://spoonacular.com/food-api
Other Posts
- Object Identification using Google Cloud Vision in Salesforce
- Logo Recognition using Google Cloud Vision in Salesforce
- Extract Text From Images using Google Cloud Vision
- Google FitBit Integration with Salesforce
- Â Audio to Text by Google Speech API in Salesforce Lightning

Dhanik Lal Sahni is a Salesforce Solution Architect, Independent Consultant, and the founder of SalesforceCodex.com. With nearly two decades of IT experience and extensive expertise in Salesforce architecture, he helps startups and enterprises design scalable, secure, and high-performance CRM solutions using Sales Cloud, Service Cloud, Experience Cloud, Data Cloud, Apex, Lightning Web Components (LWC), and enterprise integration patterns.
Through SalesforceCodex, he shares practical tutorials, real-world implementation guides, enterprise architecture best practices, and interview preparation resources for Salesforce Developers, Architects, and Administrators.
Learn more about his Salesforce consulting and freelance services at dhaniksahni.com.
