# Food Log

[Full API reference](https://api.whisk.com/spec/#/FoodLogAPI/FoodLogAPI_GetFoodLog)

#### External Id

To avoid duplicated records being created, Whisk supports external\_id. The external id is uniquely maintained within the user. Trying to add another record with already existing external id will result in 400 Bad Request response.&#x20;

External id is a an arbitrary non empty string up to 128 chars length. External Id is optional. Whisk will generate it's own food log record identifier anyway.

#### Food type

`food_type` field is used to reference the source of nutritional information for a food item. It's a one of field featuring the following options

#### Measure

`measure` field is opaque for Whisk and is used only to indicate the number of serving a person has eaten. We expect the total nutrition (not per 100g) of the food to be passed in the food log.

#### Source

`source` field is used internally to track the origin of logged food data. It may take the following values

```
FOOD_ITEM_SOURCE_SMART_THINGS_COOKING
FOOD_ITEM_SOURCE_SAMSUNG_HEALTH
```

#### Log a recipe

```
"recipe":{
	"id":"107666fe014c3794f86b18bed2c80d5a1f2"
}
```

#### Log a manual item

Manual item can either be a manual input by a user or aggregated data.

```
"food_type":{
      "manual_product": {}
}
```

#### Log Whish HealthDB Food

```
 "food": {
	"id": "string"
}
```

For items found via [`Food Search`](https://api.whisk.com/spec/#/FoodAPI/FoodAPI_SearchFood)&#x20;

### Log recipe

```
curl -X POST "https://api.whisk.com/health/foodlog/v2/action" -H "accept: application/json" -H "Authorization: Bearer %USER_TOKEN%" -H "Content-Type: application/json" -d '{
  "add":{
    "items":[
      {
        "body":{
          "item":{
            "title":"my personal item",
            "nutrition":[
              {
                "amount":10,
                "unit_name":"NUTRITION_UNIT_KCAL",
                "code":"NUTRITION_CODE_FAT_UNSAT"
              }
            ],
            "measure":{
              "scale":{
                "value":5
              }
            },
            "source":"FOOD_ITEM_SOURCE_SMART_THINGS_COOKING",
            "food_type":{
              "recipe":{
                "id":"107666fe014c3794f86b18bed2c80d5a1f2"
              }
            }
          }
        },
        "external_id":"uuid-uuid-uuid-uuid",
        "meal_time":"MEAL_TIME_SNACK",
        "consumed_at":"1667912872000"
      }
    ]
  }
}'
```

### Log manual food item

```
curl -X POST "https://api.whisk.com/health/foodlog/v2/action" -H "accept: application/json" -H "Authorization: Bearer %USER_TOKEN%" -H "Content-Type: application/json" -d '{
  "add":{
    "items":[
      {
        "body":{
          "item":{
            "title":"my personal item",
            "nutrition":[
              {
                "amount":10,
                "unit_name":"NUTRITION_UNIT_KCAL",
                "code":"NUTRITION_CODE_FAT_UNSAT"
              }
            ],
            "measure":{
              "scale":{
                "value":5
              }
            },
            "source":"FOOD_ITEM_SOURCE_SMART_THINGS_COOKING",
            "food_type":{
              "manual_product": {}
            }
          }
        },
        "external_id":"uuid-uuid-uuid-uuid",
        "meal_time":"MEAL_TIME_SNACK",
        "consumed_at":"1667912872000"
      }
    ]
  }
}'
```

### Delete food items

```
curl -X POST "https://api.whisk.com/health/foodlog/v2/action" -H "accept: application/json" -H "Authorization: Bearer %USER_TOKEN%" -H "Content-Type: application/json" -d '{
  "delete": {
    "food_log_ids": [
      "uuid-uuid-uuid-uuid"
    ],
    "external_ids": [
      "uuid-uuid-uuid-uuid"
    ]
  }
}'
```

### Update food items

For update operation it's sufficient to pass either Whisk generated `food_log_id` or `external_id`

`mask` field should also be passed indicating what fields should be updated. The supported values are

```
"body.item.title"
"body.item.nutrition"
"body.item.measure"
"body.item.source"
"body.item.food_type"
"meal_time"
"consumed_at"
"external_id"
```

```
curl -X POST "https://api.whisk.com/health/foodlog/v2/action" -H "accept: application/json" -H "Authorization: Bearer %USER_TOKEN%" -H "Content-Type: application/json" -d '{
  "update":{
    "items":[
      {
        "external_id": "uuid-uuid-uuid-uuid",
        "body": {
          "item": {
            "title": "my personal item",
            "nutrition":[
              {
                "amount":10,
                "unit_name":"NUTRITION_UNIT_KCAL",
                "code":"NUTRITION_CODE_FAT_UNSAT"
              }
            ],
            "measure":{
              "scale":{
                "value":5
              }
            }
          }
        },
        "mask": {
          "paths": [
            "body.item.title",
	    "body.item.nutrition",
	    "body.item.measure"
          ]
        }
      }
    ]
  }
}'

```

#### Get logged food

```
curl -X GET "https://api.whisk.com/health/foodlog/v2?period.from=1667912872000&period.to=1667912872000" -H "accept: application/json" -H "Authorization: Bearer %USER_TOKEN%"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.whisk.com/api/food-log.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
