Create Meal
Creates a meal with the given food.
Scope: nutrition
Request
POST | /1/user/[user-id]/meals.json |
URI Arguments
user-id | required | The encoded ID of the user. Use "-" (dash) for current logged-in user. |
Body Parameters
name | required | Name of the meal. | string |
description | required | Short description of the meal. | string |
foodId | required | ID of the food to be included in the meal. | integer |
unitId | required | ID of the units used. The units ID can be retrieved through a call to Get Food Logs, Search Foods or Get Food Units. | integer |
amount | required | Amount consumed in the format X.XX, in the specified unitId. | integer |
POST Body Format
{ "name" :Request Headers, "description" : , "mealFoods" : [ { "foodId" : , "amount" : , "unitId" : }, <...> ] }
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/-/meals.json
POST https://api.fitbit.com/1/user/GGNJL9/meals.json
POST https
curl -X POST "https://api.fitbit.com/1/user/-/meals.json" \
-H "accept: application/json" \
-H "authorization: Bearer <access_token>" \
-H "content-length: <message_body_size>" \
--data '{"name":"Breakfast","description":"Banana","mealFoods":[{"foodId":81000,"amount":1,"unitId":147}]}'
-H "accept: application/json" \
-H "authorization: Bearer <access_token>" \
-H "content-length: <message_body_size>" \
--data '{"name":"Breakfast","description":"Banana","mealFoods":[{"foodId":81000,"amount":1,"unitId":147}]}'
Response
Element Name | Description |
meal : description | |
meal : id | |
meal : mealFoods : accessLevel | |
meal : mealFoods : amount | |
meal : mealFoods : brand | |
meal : mealFoods : calories | |
meal : mealFoods : foodId | |
meal : mealFoods : locale | |
meal : mealFoods : mealTypeId | |
meal : mealFoods : name | |
meal : mealFoods : unit : id | |
meal : mealFoods : unit : name | |
meal : mealFoods : unit : plural | |
meal : mealFoods : units | |
meal : name |
{ "meal": { "description": "Banana", "id": 383590338, "mealFoods": [ { "accessLevel": "PUBLIC", "amount": 1, "brand": "", "calories": 1, "foodId": 81000, "locale": "en_US", "mealTypeId": 7, "name": "Banana", "unit": { "id": 147, "name": "gram", "plural": "grams" }, "units": [ 16, 121, 120, 304, 319, 204, 179, 91, 256, 279, 226, 180, 147, 389 ] } ], "name": "Breakfast" } }
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
Considerations
- The units field contains references to respective Food Units.
- The accessLevel field can be PUBLIC or PRIVATE. Sharing custom foods is not supported.
- The mealTypeId field is always 7 (Anytime). Meals are not associated with particular times.
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.