Create Food Log
chevron down
 

Create Food Log

Creates a food log entry for a given day.

Scope: nutrition


Request

POST /1/user/[user-id]/foods/log.json

URI Arguments
user-id required The encoded ID of the user. Use "-" (dash) for current logged-in user.

Query Parameters
foodId optional/required ID of the food to be logged. Either foodId or foodName must be provided.
foodName optional/required Food entry name. Either foodId or foodName must be provided.
mealTypeId required Numerical value representing the meal type.
Supported: 1=Breakfast | 2=Morning Snack | 3=Lunch | 4=Afternoon Snack | 5=Dinner | 7=Anytime
unitId required ID representing the units used. The units ID can be retrieved using the Get Food Logs, Search Foods or Get Food Units endpoints.
amount required value representing the amount consumed in the format X.XX in the specified unitId.
date required Log entry date in the format yyyy-MM-dd.
favorite optional Supported: true | false
True will add the food to the user's favorite's after creating the log entry. Supported only when the foodId value is used.
brandName optional Brand name of the food. Supported only when the foodName parameter is used.
calories optional Number of calories for this serving size. Allowed with foodName parameter and defaults to zero. Otherwise, the parameter value is ignored.

Additional Nutritional Information
Here's a list of additional nutritional query parameter names that can be used with the Create Food Log endpoint. These parameters are optional and valid on when using the foodName parameter.
Common Vitamins Dietary Minerals
caloriesFromFat, totalFat(g), transFat(g), saturatedFat(g), cholesterol(mg), sodium(mg), potassium(mg), totalCarbohydrate(g), dietaryFiber(g), sugars(g), protein(g) vitaminA(IU), vitaminB6, vitaminB12, vitaminC(mg), vitaminD(IU), vitaminE(IU), biotin(mg), folicAcid(mg), niacin(mg), pantothenicAcid(mg), riboflavin(mg), thiamin(mg) calcium(g), copper(g), iron(mg), magnesium(mg), phosphorus(g), iodine(mcg), zinc(mg)

Request Headers
authorization required Specify the token type and Fitbit user’s access token.
Token type: Bearer
accept optional The media type of the response content the client is expecting.
Supported: application/json
accept-language optional The measurement unit system to use for response values. See Localization.
accept-locale optional The locale to use for response values. See Localization.
content-length required According to RFC 7230, section 3.3.2, this HTTP request requires the Content-Length header field containing the anticipated size of the payload body.

Examples
POST https://api.fitbit.com/1/user/-/foods/log.json?foodId=82294&mealTypeId=3&unitId=304&amount=2.55&date=2019-03-21&favorite=true
POST https://api.fitbit.com/1/user/GGNJL9/foods/log.json?foodId=82294&mealTypeId=3&unitId=304&amount=2.55&date=2019-03-21&favorite=true
curl -X POST "https://api.fitbit.com/1/user/-/foods/log.json?foodId=82294&mealTypeId=3&unitId=304&amount=2.55&date=2019-03-21&favorite=true" \
-H "accept: application/json" \
-H "authorization: Bearer <access_token>" \
-H "content-length: <message_body_size>"


Response

Element Name Description
foodDay : date
foodDay : summary
foodLog : isFavorite
foodLog : logDate
foodLog : logId
foodLog : loggedFood : accessLevel
foodLog : loggedFood : amount
foodLog : loggedFood : brand
foodLog : loggedFood : calories
foodLog : loggedFood : foodId
foodLog : loggedFood : locale
foodLog : loggedFood : mealTypeId
foodLog : loggedFood : name
foodLog : loggedFood : unit : id
foodLog : loggedFood : unit : name
foodLog : loggedFood : unit : plural
foodLog : loggedFood : units
foodLog : nutritionalValues Available nutritional values for the food consumed.
{
  "foodDay": {
    "date": "2019-03-21",
    "summary": {
      "calories": 1224,
      "carbs": 165.85,
      "fat": 48.13,
      "fiber": 17.75,
      "protein": 30.75,
      "sodium": 1588.75,
      "water": 1892.7099609375
    }
  },
  "foodLog": {
    "isFavorite": true,
    "logDate": "2019-03-21",
    "logId": 17406014466,
    "loggedFood": {
      "accessLevel": "PUBLIC",
      "amount": 2.55,
      "brand": "",
      "calories": 944,
      "foodId": 82294,
      "locale": "en_US",
      "mealTypeId": 3,
      "name": "Chips",
      "unit": {
        "id": 304,
        "name": "serving",
        "plural": "servings"
      },
      "units": [
        304,
        226,
        180,
        147,
        389
      ]
    },
    "nutritionalValues": {
      "calories": 944,
      "carbs": 119.85,
      "fat": 44.63,
      "fiber": 12.75,
      "protein": 12.75,
      "sodium": 828.75
    }
  }
}
      

Response Headers
content-type The media type of the response content being sent to the client.
Supported: application/json
fitbit-rate-limit-limit The quota number of calls.
fitbit-rate-limit-remaining The number of calls remaining before hitting the rate limit.
fitbit-rate-limit-reset The number of seconds until the rate limit resets.

Note: The rate limit headers are approximate and asynchronously updated. This means that there may be a minor delay in the decrementing of remaining requests. This could result in your application receiving an unexpected 429 response if you don't track the total number of requests you make yourself.

Response Type

HTTP Status Code HTTP response code. List of codes are found in the Troubleshooting Guide.
Status Message Description of the status code.
Response Body Contains the JSON response to the API call. When errors are returned by the API call, the errorType, fieldName and message text will provide more information to the cause of the failure.

Response Codes
201 A successful request.
400 The request had bad syntax or was inherently impossible to be satisfied.
401 The request requires user authentication.

Note: For a complete list of response codes, please refer to the Troubleshooting Guide.

Additional Information

Approaches to Food Logging

There are two scenarios for creating food log entries for the user - with or without foodId value. The common approach is to use foodId and create the entry with a link to the food from the Food DB Search Foods or to the user's private food Create Food. Fitbit recommends each integration use this first approach, when possible.

The second approach is used if you want just to upload some history data or to log a daily intake summary only (or several specific meal's summaries) for the user the foodName parameter might be helpful. In this case, you should also explicitly provide the calories and optionally brandName (or source name) and a full set of nutritional values for this log entry. Entries logged via foodName can not be edited on the website or added to the list of favorites.

Considerations

  1. The units field contains references to respective Food Units.
  2. The accessLevel field can be PUBLIC or PRIVATE. Sharing custom foods is not supported.

Access Levels

There are 2 access level types for food log entries that an authorized user can view via API requests. Each food is annotated with an accessLevel field with one of the following values:

  • PUBLIC - Foods that are in Fitbit's public food database and are visible to any Fitbit users. Only Fitbit populates this database to avoid spam and duplicate entries.
  • PRIVATE - Foods created by a user either on the website or via the Create Food endpoint.