Introduction

The United States Department of Agriculture (USDA) has an API as part of their Food Central program that provides access to nutritional information. The information is intended to help policy makers, researchers, health professionals, and product developers. The information contained is either submitted by manufacturers of branded products or is derived from food labels by a service called Label Insights (now owned by NielsenIQ) that obtains nutritional information from labels uploaded by manufacuturers.

Accessing the API

Access to the API can be done by visiting USDA Food Central API and requesting an API to be used to access the data via API in R. The API is in a REST design format or Representational State Transfer that allows the user familiarity with the protocols based upon the protocol definitions.

The base URL to access the server is [API Server] (https://api.nal.usda.gov/fdc). Using the “GET” command we can also obtain information based upon a search of a brand or product name. As an example below for a search using “Mezzetta” branded food items.

GET Request suing a search query of Brand, this can also be replaced with a food type: https://api.nal.usda.gov/fdc/v1/foods/search?api_key=DEMO_KEY&query=Mezzetta

The result of this information contains many details about the product queried and provides additional data available in additional tables such as nutritional information. The output of in information is in JSON formatting. We can utilize the jsonlite library to flatten the file down to the specific data we are interested in as the results contain many different tables of information with a product identifier acting as the primary key (“fdcid”).