Logging using an Image

To log a meal with an image requires three steps

  1. Create a Meal
  2. Add an Image to the Meal
  3. Adding Entries to an Image

Create a Meal

Execute the meal_create operation.

curl -X POST https://api-beta.bite.ai/meals/

The response will contain a meal_id which is used for subsequent requests like adding an image to the meal or adding items to a meal.

{
"id": "422d6199-c1b6-4037-866f-e28c1ea0b0ca",
"title": "",
"description": "",
"images": [],
"entries": [],
"local_eaten_at_time": null,
"utc_eaten_at_time": null,
"time_created": "2018-02-27T03:27:05.971980Z",
"time_modified": "2018-02-27T03:27:05.972097Z"
}

Add an Image to a Meal

To add an image to the meal post the image data with the meal_images_create operation.

The meal_id is from the previous step, Create a Meal. For more information on how images are accepted see Image Input In the API.

curl -X POST \
https://api-beta.bite.ai/meals/422d6199-c1b6-4037-866f-e28c1ea0b0ca/images/ \
-H multipart/form-data' \
-F file=@/home/user/pictures/avacado.jpg

The response contains a set suggestions, similar images, and likely entries with portion size.

{
"id": "ceefab10-a0a6-4c78-80a4-995e6c18d0cc",
"url": "https://media.bite.ai/media/ce/ef/ab10-a0a6-4c78-80a4-995e6c18d0cc.jpg",
"type": "",
"source_url": null,
"suggestions": {
"images": [
{
"image": {
"id": "519c66cd-f8b5-4be0-a445-941c0f85e1f7",
"url": "/media/51/9c/66cd-f8b5-4be0-a445-941c0f85e1f7.jpg",
"source_url": null
},
"entries": [
{
"item": {
"id": "ea916a99-389c-45d2-940d-44d886af9e98",
"name": "Avocado"
},
"serving_amount": 0.5,
"nutrition": "aaf734e1-6b2b-49ea-82e4-dc745126084b"
}
],
"score": 0.2260914806461778
}
],
"entries": [
{
"entry": {
"item": {
"id": "ea916a99-389c-45d2-940d-44d886af9e98",
"name": "Avocado"
},
"serving_amount": 0.5,
"nutrition": "aaf734e1-6b2b-49ea-82e4-dc745126084b"
},
"score": 1
}
],
"items": [
{
"item": {
"id": "ea916a99-389c-45d2-940d-44d886af9e98",
"name": "Avocado"
},
"score": 0.18991
},
{
"item": {
"id": "4f941073-def2-4be7-8147-cd706514bb10",
"name": "Egg"
},
"score": 0.11009
}
]
}
}

These suggestions should be displayed to the user so they can choose which items best represent their meals. Once a user selects one or more of the items the nutrition facts and serving sizes can be looked up using the item_read operation.

Adding Entries To An Image

Once the user has picked one or more items it can be added to the image using the meal_images_entries_create operation. In this example the user has also selected a serving amount for a nutrition fact.

curl -X POST \ https://api-beta.bite.ai/meals/
422d6199-c1b6-4037-866f-e28c1ea0b0ca/images/
d2ecaabd-a7a8-4a64-80ba-0631f6e3f781/entries/ \
-d '{
"item": "ea916a99-389c-45d2-940d-44d886af9e98",
"serving_amount": 0.5,
"nutrition_fact": "aaf734e1-6b2b-49ea-82e4-dc745126084b"
}'

The response includes an entry item and the item added.

{
"id": "f3a17171-eab2-4976-9a26-c4241661bb0c",
"item": {},
"serving_amount": 0.5,
"nutrition_fact": "aaf734e1-6b2b-49ea-82e4-dc745126084b",
"image": "519c66cd-f8b5-4be0-a445-941c0f85e1f7",
"time_created": "2018-03-27T04:09:13.383117Z",
"time_modified": "2018-03-27T04:09:13.383220Z"
}