Creating Items
Users may want to create items which aren’t already in the database. These are the steps to create an item.
- Creating an Item
- Searching or Creating a Serving Unit
- Adding a Nutrition Fact
- Adding an Identifier or a Barcode
- Searching or Creating a Brand
Creating an Item
To create can be created using the the create_item operation. The example below adds an item with a brand and is private to the current user.
POST /items/
curl--request POST \--url https://api-beta.bite.ai/items/ \--data '{"name": "Chocolate Turnover","details": "extra chocolatey","brand": "b1eef362-c30d-4a93-91b7-0399aff97b4d","is_private": true}'
The response will be an item object and an ID which can be used for adding nutrition facts or ingredients.
{"id": "021264e1-2864-4aaa-8b92-f30d089ed486","name": "Chocolate Turnover","details": "extra flavor","description": null,"brand": null,"type": null,"text_ingredients": null,"ingredients": [],"parents": [],"children": [],"nutrition_facts": [],"is_private": true,"is_generic": null,"categorizations": {}}
Searching or Creating a Serving Unit
Nutrition facts have serving units which can searched for or created.
Searching for Units
As a user is typing in the serving unit from a package a search query using the unit_search_list operation can be executed. Below is an example of searching for the unit ‘cup’.
curl -X GET \--url 'https://api-beta.bite.ai/units/search/?query=cup'
The response has a list of units and each of them have an ID which can be used in creating the nutrition fact.
{"count": 8,"next": null,"previous": null,"results": [{"id": "1f49b3a4-b335-492d-88b6-9f63f7ae0837","singular_name": "cup","abbreviated_singular_name": "cp","plural_name": "cups","abbreviated_plural_name": "cp","measure_type": "volume","measure_system": "usc","granularity": null,"details": null}]}
Creating a Unit
If a unit can not be found for this food item then it can be created. The example below creates a unit for ‘Turnover’.
curl --request POST \--url https://api-beta.bite.ai/units/ \--data '{"singular_name": "Turnover"}'
The response will include the unit and the ID needed when adding nutrition facts.
{"id": "44f497cc-9f6d-4352-b81d-3b4500fa6973","singular_name": "Turnover","abbreviated_singular_name": null,"plural_name": "null","abbreviated_plural_name": null,"measure_type": null,"measure_system": null,"granularity": null,"details": null}
Nutrition Fact
Items optionally have nutrition facts associated with them. To add a nutrition fact use the nutrition_facts_create operation, The example below adds the serving size, and nutrients to the Chocolate Turnover.
curl -X POST \--url https://api-beta.bite.ai/items/021264e1-2864-4aaa-8b92-f30d089ed486/nutrition_facts/ \--data '{"serving": {"amount": 1.0,"unit_id": "44f497cc-9f6d-4352-b81d-3b4500fa6973","grams": 83},"nutrition": {"calories": 250},"is_default": true}'
The response is below.
{"id": "fd24a365-ece6-473c-bce8-742607c7aee1","item": "021264e1-2864-4aaa-8b92-f30d089ed486","serving": {"amount": 1.0,"unit": {"id": "44f497cc-9f6d-4352-b81d-3b4500fa6973","singular_name": "Turnover","abbreviated_singular_name": null,"plural_name": null,"abbreviated_plural_name": null,"measure_type": null,"measure_system": null,"granularity": null,"details": null},"grams": 83.0,"details": null},"servings_per_package": null,"nutrition": {"calories": 250.0},"is_default": false,"identifiers": []}
Adding an Identifier or Barcode
Items can have identifiers like barcodes, ids from another database, or customer specific identifier. They can be added to an item with the item_ids_create operation. The example below adds an ID to the Chocolate Turnover.
curl --X POST \--url https://api-beta.bite.ai/items/021264e1-2864-4aaa-8b92-f30d089ed486/ids/ \--data '{"source": "gtin-13","id": "001234567890"}'
Searching or Creating a Brand
Items have an optional brand field which can is added by either finding or creating the brand.
Searching For a Brand
To search for a brand use the brand_search operation. An example below searches for Whole Foods.
curl -X GET \ “https://api-beta.bite.ai/brands/search/?query=Whole%20Foods”
The response includes the ID which can be used when creating an item.
{"count": 15,"next": null,"previous": null,"results": [{"id": "43534924-0a57-4972-8e30-32e1a8779cc1","name": "Whole Foods","manufacturer": null,"type": null}]}
Creating a Brand
If a Brand cannot be found by searching then a brand must be created using the brand_create operation.
curl -X POST \--url https://api-beta.bite.ai/brands/ \--data '{"name": "Turnover Company"}'
The response will be a brand object with the ID which can be used to create an Item.
{"id": "b1eef362-c30d-4a93-91b7-0399aff97b4d","name": "Turnover Company","manufacturer": null,"type": null}