# Save a food

> Saves a food or recipe to your foods, or changes one you saved.

`POST /foods`

Needs the **Read and write** permission. The food is saved to the `mine` library, where only you see it.

## Body

| Field | Type | Description |
| --- | --- | --- |
| `name` | string | Required. The food's name. Up to 200 characters. |
| `data` | object | Required. Nutrition, portions and recipe details. |
| `brand` | string or null | The brand, for a packaged product. Up to 200 characters. |
| `barcode` | string or null | The barcode: 8 to 14 digits. |
| `copyFrom` | object | The food this one was changed from, as `{ "library", "key" }`, so where it came from is kept. |
| `id` | string | To change a food you saved before, its key. Leave out to save a new one. |

Nutrition and measures need a `base` unit. A recipe's `ingredients` are existing foods (`food`) or new ones (`newFood`), each with a `portion` such as `{ "amount": 200, "unit": "g" }`. Splot adds up its nutrition per serving, and a recipe is always logged in servings.

If a new food's barcode is already in the catalogue, the request answers `409` with `food_in_catalog` and the existing `food`. Log that one instead, or send `copyFrom` to save your own changed copy.

## Response

`201` with the saved [food](https://splot.health/docs/api/foods/object).

## Example

```sh
curl https://app.splot.health/v1/foods \
  -H "Authorization: Bearer $SPLOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Overnight oats",
    "data": {
      "base": "serving",
      "recipe": { "servings": 2, "steps": ["Stir everything together.", "Leave in the fridge overnight."] },
      "ingredients": [
        { "food": { "library": "composition", "key": "c3f1a2b4-5d6e-4f70-8a91-b2c3d4e5f607" }, "portion": { "amount": 80, "unit": "g" } },
        { "newFood": { "name": "Oat milk", "data": { "base": "ml", "nutrition": { "basisAmount": 100, "values": { "kcal": 46, "carbs": 6.7, "fat": 1.5, "protein": 0.3 } } } }, "portion": { "amount": 250, "unit": "ml" } }
      ]
    }
  }'
```
