Diary
The Diary API lets you persist user food tracking entirely on the server. There is no need for local SQLite databases or complex cross-device syncing on the client. On this page, we'll cover CRUD operations for diary entries and how to retrieve daily macro totals.
The diary model
The diary model stores the details of a specific food item tracked by a user on a given date.
Properties
- Name
id- Type
- string
- Description
Unique identifier for the diary entry.
- Name
date- Type
- string
- Description
The date the entry belongs to in
YYYY-MM-DDformat.
- Name
mealType- Type
- string
- Description
The category of the meal (
breakfast,lunch,dinner, orsnacks).
- Name
foodName- Type
- string
- Description
The display name of the food item.
- Name
calories- Type
- number
- Description
Total calories for the recorded serving size.
- Name
protein- Type
- number
- Description
Protein in grams.
- Name
carbs- Type
- number
- Description
Carbohydrates in grams.
- Name
fat- Type
- number
- Description
Fat in grams.
- Name
addedMethod- Type
- string
- Description
How the food was added (
manual,barcode,image, orrecipe).
Get diary entries
Retrieve all diary entries for a specific user on a given date.
Required attributes
- Name
date- Type
- string
- Description
The date to query in
YYYY-MM-DDformat.
Request
curl -G https://api.macrofy.com/v1/users/xyz/diary \
-H "Authorization: Bearer {token}" \
-d date="2026-03-12"
Response
[
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"userId": "xyz",
"date": "2026-03-12",
"mealType": "lunch",
"foodName": "Chicken Salad",
"calories": 350,
"protein": 30,
"carbs": 10,
"fat": 20,
"addedMethod": "manual",
"createdAt": "2026-03-12T12:00:00Z",
"updatedAt": "2026-03-12T12:00:00Z"
}
]
Get daily totals
Retrieve the aggregated macro and calorie totals for a given date. The backend computes this on-the-fly from the diary entries.
Request
curl -G https://api.macrofy.com/v1/users/xyz/diary/totals \
-H "Authorization: Bearer {token}" \
-d date="2026-03-12"
Response
{
"calories": 1800,
"protein": 120,
"carbs": 200,
"fat": 60,
"fiber": 25,
"sodium": 2000
}