Create Nutrition Plan (v1)
Method & Path
POST /api/v1/workspace/:workspaceId/nutrition/plans
Description
Creates a new nutrition plan for a client. Creating a new active plan will automatically archive any existing active plans for the same client.
Authentication
Required: Workspace token with nutrition management permission.
Headers
| Header | Required | Description |
|---|---|---|
| Authorization | Yes | Bearer <token> |
| Content-Type | Yes | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| workspaceId | string | Yes | Workspace ID |
Request Body
{
"clientId": "507f1f77bcf86cd799439011",
"name": "خطة إنقاص الوزن - شهر يناير",
"startDate": "2024-01-15T00:00:00.000Z",
"endDate": "2024-02-15T00:00:00.000Z",
"dailyCalories": 1800,
"macros": {
"protein": 120,
"carbs": 180,
"fats": 60
},
"days": [
{
"dayNumber": 1,
"meals": [
{
"id": "meal-1",
"name": "الفطور",
"time": "08:00",
"calories": 400,
"items": [
{ "name": "بيض مسلوق", "quantity": "2 حبة", "calories": 140 },
{ "name": "خبز أسمر", "quantity": "شريحة", "calories": 80 },
{ "name": "جبنة قريش", "quantity": "50 جرام", "calories": 80 }
],
"alternatives": [
{ "name": "شوفان بالحليب", "quantity": "كوب", "calories": 300 }
]
}
],
"totalCalories": 1800
}
],
"notes": "تجنب الأطعمة المقلية"
}
Body Fields
| Field | Type | Required | Description |
|---|---|---|---|
| clientId | string | Yes | Client ID |
| name | string | Yes | Plan name |
| startDate | string | Yes | ISO 8601 start date |
| endDate | string | No | ISO 8601 end date |
| dailyCalories | number | No | Target daily calories |
| macros | object | No | Target macros (protein, carbs, fats in grams) |
| days | array | No | Array of daily meal plans |
| notes | string | No | Additional notes |
| templateId | string | No | ID of template to use |
Response 201 Created
{
"plan": {
"id": "507f1f77bcf86cd799439013",
"workspaceId": "507f1f77bcf86cd799439012",
"clientId": "507f1f77bcf86cd799439011",
"name": "خطة إنقاص الوزن - شهر يناير",
"startDate": "2024-01-15T00:00:00.000Z",
"endDate": "2024-02-15T00:00:00.000Z",
"status": "active",
"dailyCalories": 1800,
"macros": {
"protein": 120,
"carbs": 180,
"fats": 60
},
"days": [...],
"notes": "تجنب الأطعمة المقلية",
"templateId": null,
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
}
}
Common Errors
- 400 Bad Request: Invalid input data
- 401 Unauthorized: Missing or invalid token
- 404 Not Found: Workspace or client not found