Skip to content

Nutrition Logs API

Get User Logs

Endpoint

URLs:

  • Development: https://api.rex.fit/[org-id]/dev/v1/get-user-logs
  • Production: https://api.rex.fit/[org-id]/prod/v1/get-user-logs

Method: GET
Authorization: Bearer <api_key>

Required Query Parameters

Parameter Type Description Example
from_id string Unique identifier for the user user_abc123
start_date string Start date in YYYY-MM-DD format 2023-05-01
end_date string End date in YYYY-MM-DD format 2023-05-31

Example Request

GET https://api.rex.fit/[org-id]/prod/v1/get-user-logs?from_id=user_abc123&start_date=2023-05-01&end_date=2023-05-31

Response Fields

Field Type Description
start_date string The date of the log in YYYY-MM-DD format
data object Contains the log data
data.date string The date of the log in YYYY-MM-DD format
data.meals array List of meals for the day
data.meals[].meal_type string Type of meal (breakfast, lunch, dinner, snack)
data.meals[].display_name string Display name of the meal
data.meals[].calories number Total calories for the meal
data.meals[].protein number Total protein in grams
data.meals[].carbohydrates number Total carbohydrates in grams
data.meals[].total_fat number Total fat in grams
data.meals[].timestamp string When the meal was logged (ISO format)
data.meals[].foods_consumed array List of food items in the meal
data.meals[].foods_consumed[].name string Name of the food
data.meals[].foods_consumed[].display_name string Display name of the food
data.meals[].foods_consumed[].quantity_grams number Quantity in grams
data.meals[].foods_consumed[].calories number Calories per serving
data.meals[].foods_consumed[].nutrients object Nutritional information
data.total_calories number Total calories for the day
data.total_macros object Total macronutrients for the day

Response

Success (200 OK):

{
  "status": "success",
  "logs": [
    {
      "date": "2023-05-15",
      "data": {
        "date": "2023-05-15",
        "meals": [
          {
            "meal_type": "breakfast",
            "display_name": "Morning Oatmeal",
            "calories": 350,
            "protein": 12,
            "carbohydrates": 45,
            "total_fat": 10,
            "timestamp": "2023-05-15T08:30:00Z",
            "foods_consumed": [
              {
                "name": "oatmeal",
                "display_name": "Oatmeal",
                "quantity_grams": 100,
                "calories": 150,
                "nutrients": {
                  "protein": 5,
                  "carbohydrates": 27,
                  "total_fat": 3,
                  "fiber": 4,
                  "sugars": 1
                }
              }
            ]
          }
        ],
        "total_calories": 1800,
        "total_macros": {
          "protein": 90,
          "carbohydrates": 200,
          "total_fat": 60
        }
      }
    }
  ]
}

Error Responses

Code Description Example
400 Bad Request Missing required parameters or invalid date format {"error": "Invalid date format. Use YYYY-MM-DD"}
401 Unauthorized Invalid or missing API key {"error": "Invalid API key"}
404 Not Found User with the provided from_id not found {"error": "User with from_id user_abc123 not found"}
500 Internal Server Error Internal server error occurred {"error": "Internal server error"}

Error Response Examples

Missing Parameter:

{
  "error": "Missing required parameter: start_date"
}

Invalid Date Format:

{
  "error": "Invalid date format. Must be YYYY-MM-DD"
}

User Not Found:

{
  "error": "User with from_id user_abc123 not found"
}

Notes

  • The date range is inclusive of both start_date and end_date.
  • Sensitive information like firebase_url and user_id is automatically filtered out.
  • Timestamps are returned in ISO 8601 format.
  • If no logs exist for the specified date range, an empty logs array is returned.

Edit User Logs

Endpoint

URLs:

  • Development: https://api.rex.fit/[org-id]/dev/v1/edit-user-logs
  • Production: https://api.rex.fit/[org-id]/prod/v1/edit-user-logs

Method: POST
Content-Type: application/json
Authorization: Bearer <api_key>

Required Fields

Field Type Description Example
from_id string Unique identifier for the user "user_abc123"
date string Date of the log in YYYY-MM-DD format "2023-05-15"
operation string Operation to perform: "edit" or "delete" "edit"
meal_index integer Index of the meal to edit/delete (0-based) 0

Optional Fields

Field Type Description Example
food_index integer Index of food item within meal (0-based) 0
meal_data object Required when editing a meal See below
food_data object Required when editing a food item See below

Meal Data Fields (for meal editing)

Field Type Description Example
calories number Total calories for the meal 450
protein number Total protein in grams 25
carbohydrates number Total carbohydrates in grams 40
total_fat number Total fat in grams 15
sugars number Total sugars in grams 5
fiber number Total fiber in grams 3
meal_type string Type of meal (breakfast, lunch, dinner, snack) "lunch"
display_name string Display name of the meal "Chicken Salad"
quantity_grams number Quantity in grams 250
saturated_fat number Saturated fat in grams 4
quantity_raw string Raw quantity description "1 bowl"

Food Data Fields (for food item editing)

Field Type Description Example
name string Name of the food "chicken_breast"
display_name string Display name of the food "Grilled Chicken Breast"
quantity_grams number Quantity in grams 150
calories number Calories per serving 250
brand string Brand of the food "Tyson"
nutrients object Nutritional information object See nutrients object below

Nutrients Object

{
  "protein": 45,
  "carbohydrates": 0,
  "total_fat": 6,
  "saturated_fat": 2,
  "fiber": 0,
  "sugars": 0
}

Example Requests

Edit a Meal

{
  "from_id": "user_abc123",
  "date": "2023-05-15",
  "operation": "edit",
  "meal_index": 0,
  "meal_data": {
    "calories": 450,
    "protein": 25,
    "carbohydrates": 40,
    "total_fat": 15,
    "meal_type": "lunch",
    "display_name": "Updated Lunch"
  }
}

Edit a Food Item

{
  "from_id": "user_abc123",
  "date": "2023-05-15",
  "operation": "edit",
  "meal_index": 0,
  "food_index": 0,
  "food_data": {
    "name": "chicken_breast",
    "display_name": "Grilled Chicken Breast",
    "quantity_grams": 150,
    "calories": 250,
    "nutrients": {
      "protein": 45,
      "carbohydrates": 0,
      "total_fat": 6,
      "fiber": 0,
      "sugars": 0
    }
  }
}

Delete a Food Item

{
  "from_id": "user_abc123",
  "date": "2023-05-15",
  "operation": "delete",
  "meal_index": 0,
  "food_index": 0
}

Delete a Meal

{
  "from_id": "user_abc123",
  "date": "2023-05-15",
  "operation": "delete",
  "meal_index": 0
}

Response Fields

Field Type Description Example
status string Success status of the operation "success"
message string Description of the action performed "Food item successfully
edited in meal 0"
updated_log object Information about the updated log See below
date string The date of the updated log "2023-05-15"
meals_count integer The number of meals in the updated log 3
last_updated string Timestamp of when the
log was updated
"2023-05-16T14:30:00Z"

Response

Success (200 OK):

{
  "status": "success",
  "message": "Food item successfully edited in meal 0",
  "updated_log": {
    "date": "2023-05-15",
    "meals_count": 3,
    "last_updated": "2023-05-16T14:30:00Z"
  }
}

Error Responses

Code Description Example
400 Bad Request Missing fields or invalid operation {"error": "Operation must be either 'edit' or 'delete'"}
401 Unauthorized Invalid API key {"error": "Invalid API key"}
404 Not Found User, log, meal, or food not found {"error": "No log found for date: 2023-05-15"}
500 Internal Server Error Server error {"error": "Internal server error"}

Error Response Examples

Invalid Operation:

{
  "error": "Operation must be either 'edit' or 'delete'"
}

Missing Required Data:

{
  "error": "meal_data is required for editing a meal"
}

Invalid Index:

{
  "error": "meal_index 5 is out of range"
}

No Log Found:

{
  "error": "No log found for date: 2023-05-15"
}

Notes

  • When editing a food item, the meal's nutritional totals are automatically recalculated.
  • When deleting the last food item in a meal, the meal's nutritional values are set to zero.
  • Sensitive fields like firebase_url, user_id, timestamp, foods_consumed, and signed_url are preserved during edits.
  • After any edit or delete operation, the daily nutrition totals are automatically recalculated.