← Back to MacroLog

MacroLog API

Integrate other apps and scripts with your MacroLog diary. All endpoints live under api/v1.php and return JSON.

Authentication

Create an API key in Settings → API keys. The key is shown once — store it safely. Send it with every request as a Bearer token:

Authorization: Bearer mlog_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Keys can be revoked at any time from Settings. A missing or invalid key returns 401 with an error field.

Endpoints

GET?action=day&date=YYYY-MM-DD

Every diary entry for one day.

curl -H "Authorization: Bearer mlog_..." \
  "https://example.com/food/api/v1.php?action=day&date=2026-07-03"

{ "date": "2026-07-03",
  "entries": [
    { "id": 91, "meal": "breakfast", "quantity_g": "60.00", "calories": "226.20",
      "protein_g": "7.50", "carbs_g": "41.20", "fat_g": "3.10",
      "food_id": 12, "name": "Porridge Oats", "brand": "Quaker", "unit": "g" } ] }

GET?action=summary&date=YYYY-MM-DD

Dashboard-friendly view of one day: your daily target (including any per-day adjustment), consumed totals, calories remaining, and a per-meal breakdown with each meal's items. date is optional and defaults to today. target and remaining are null if you haven't set a target.

curl -H "Authorization: Bearer mlog_..." \
  "https://example.com/food/api/v1.php?action=summary&date=2026-07-03"

{ "date": "2026-07-03",
  "target":    { "calories": 2200, "protein_g": 160, "carbs_g": 200, "fat_g": 70 },
  "consumed":  { "calories": 1470, "protein_g": 96,  "carbs_g": 150, "fat_g": 52 },
  "remaining": 730,
  "meals": {
    "breakfast": { "calories": 320, "items": [ { "name": "Porridge Oats (Quaker)", "calories": 226 } ] },
    "lunch":     { "calories": 0,   "items": [] },
    "dinner":    { "calories": 0,   "items": [] },
    "snacks":    { "calories": 0,   "items": [] } } }

GET?action=range&from=YYYY-MM-DD&to=YYYY-MM-DD

Daily calorie/macro totals for a date range (max 1 year).

{ "days": [
    { "log_date": "2026-07-01", "calories": "1890.40", "protein_g": "141.00",
      "carbs_g": "180.20", "fat_g": "61.90" } ] }

GET?action=search&q=text

Search your foods and the local food cache (min 2 characters). Returns an array of foods; use a food's id as food_item_id when logging.

POST?action=log

Log a food to your diary. Body (JSON):

FieldRequiredNotes
food_item_idyesFrom search or create_food
mealyesbreakfast, lunch, dinner or snacks
quantity_gyesGrams (or ml for liquid foods), 1–5000
dateyesYYYY-MM-DD
curl -X POST -H "Authorization: Bearer mlog_..." -H "Content-Type: application/json" \
  -d '{"food_item_id":12,"meal":"lunch","quantity_g":150,"date":"2026-07-03"}' \
  "https://example.com/food/api/v1.php?action=log"

{ "logged": true, "id": 231 }

POST?action=create_food

Create a custom food (appears in "My Foods"). Nutrients are per 100 g / 100 ml.

FieldRequiredNotes
nameyesUp to 255 chars
calories_per_100gyeskcal per 100 g/ml
protein_per_100g, carbs_per_100g, fat_per_100gnoGrams per 100 g/ml (default 0)
brandno
unitnog (default) or ml
serving_descnoe.g. "1 bar (45 g)"
serving_size_gnoNumeric serving size
curl -X POST -H "Authorization: Bearer mlog_..." -H "Content-Type: application/json" \
  -d '{"name":"Protein Flapjack","brand":"HomeMade","calories_per_100g":420,
       "protein_per_100g":22,"carbs_per_100g":40,"fat_per_100g":18,
       "serving_desc":"1 bar (60 g)","serving_size_g":60}' \
  "https://example.com/food/api/v1.php?action=create_food"

{ "food": { "id": 87, "name": "Protein Flapjack", ... } }

POST?action=log_weight

Log a body weight — ideal for smart scales or shortcuts. Weights are always in kg. One weight is kept per day; logging again on the same date replaces it. Subscribed devices get a push notification for every weight logged or changed via the API. Logging a weight also refreshes your maintenance-calorie estimate, and a change there triggers its own notification.

FieldRequiredNotes
weight_kgyes25–400 kg
datenoYYYY-MM-DD, defaults to today; cannot be in the future
notenoUp to 255 chars
curl -X POST -H "Authorization: Bearer mlog_..." -H "Content-Type: application/json" \
  -d '{"weight_kg":82.4}' \
  "https://example.com/food/api/v1.php?action=log_weight"

{ "logged": true, "date": "2026-07-14", "weight_kg": 82.4,
  "maintenance": { "status": "ok", "kcal": 2450, "avg_intake": 2280,
                   "trend_kg_per_wk": -0.15, "confidence": "medium", ... } }

GET?action=weights&from=YYYY-MM-DD&to=YYYY-MM-DD

Weigh-ins in a date range (both bounds optional — omit for everything), plus the current maintenance-calorie estimate. maintenance.status is ok, insufficient (with a reason) or unreliable.

{ "weights": [
    { "log_date": "2026-07-13", "weight_kg": "82.60", "note": null, "source": "api" } ],
  "maintenance": { "status": "ok", "kcal": 2450, "confidence": "medium", ... } }

Errors

Errors return an appropriate HTTP status (400, 401, 404, 405) and a JSON body: { "error": "message" }.

Notes