EndpointsSleep Logs

Sleep Logs

Function-calling namespace: sleepLogs

  • Base URL: https://api.aivida.in
  • Engine endpoint: POST /api
  • Auth: Stack token middleware enabled in optional mode.
  • Send token in header: x-stack-access-token: <access_token> (or Authorization: Bearer <access_token>).
  • In optional mode: no token is allowed; invalid token is rejected with 401.

deleteSleepLog

Source: backend/endpoints/sleep-logs/delete-sleep-log

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-
logIdstringYes-

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "deleteSleepLog",
  "data": {
    "stackUserId": "stackuser_123",
    "logId": "log_123"
  }
}'

Example Response

{ "status": "ok", "data": {} }

getSleepHistory

Source: backend/endpoints/sleep-logs/get-sleep-history

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-
limitintegerNomin: 1; max: 365

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "getSleepHistory",
  "data": {
    "stackUserId": "stackuser_123"
  }
}'

Example Response

{ "status": "ok", "data": {} }

getSleepPreferences

Source: backend/endpoints/sleep-logs/get-sleep-preferences

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "getSleepPreferences",
  "data": {
    "stackUserId": "stack_user_123"
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "id": "sleep_pref_123",
    "patientId": "patient_123",
    "stackUserId": "stack_user_123",
    "sleepTime": "23:30",
    "wakeTime": "07:30",
    "sleepGoalMinutes": 480,
    "sleepGoalHours": "8h 0m",
    "sleepReminderEnabled": true,
    "wakeReminderEnabled": true,
    "createdAt": 1779971037247,
    "updatedAt": 1779971037247
  }
}

getSleepStats

Source: backend/endpoints/sleep-logs/get-sleep-stats

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-
daysintegerNomin: 1; max: 365

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "getSleepStats",
  "data": {
    "stackUserId": "stack_user_123",
    "days": 30
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "averageHours": 7.8,
    "averageSleepMinutes": 468,
    "goalMinutes": 480,
    "goalHours": 8,
    "goalCompletionRate": 80,
    "totalLogs": 30,
    "qualityDistribution": {
      "excellent": 12,
      "good": 10,
      "fair": 6,
      "poor": 2,
      "too_much": 0
    },
    "weeklyAverage": [
      {
        "week": 26,
        "average": 7.8,
        "days": 7
      }
    ]
  }
}

getTodaySleep

Source: backend/endpoints/sleep-logs/get-today-sleep

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "getTodaySleep",
  "data": {
    "stackUserId": "stack_user_123"
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "_id": "sleep_log_123",
    "patientProfileId": "patient_123",
    "stackUserId": "stack_user_123",
    "date": "2026-06-23",
    "hoursSlept": 8,
    "quality": "excellent",
    "bedTime": "23:30",
    "wakeTime": "07:30",
    "sleptMinutes": 480,
    "goalMinutes": 480,
    "goalHours": 8,
    "completionPercentage": 100
  }
}

getWeeklySleepSummary

Source: backend/endpoints/sleep-logs/get-weekly-sleep-summary

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "getWeeklySleepSummary",
  "data": {
    "stackUserId": "stack_user_123"
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "averageHours": 8,
    "weeklyAverageMinutes": 480,
    "goalMinutes": 480,
    "goalHours": 8,
    "dailyGoalAchievement": [
      {
        "date": "2026-06-23",
        "sleptMinutes": 480,
        "goalMinutes": 480,
        "achieved": true,
        "completionPercentage": 100
      }
    ],
    "logsThisWeek": 7,
    "lastNight": {
      "hours": 8,
      "quality": "excellent"
    },
    "trend": "up"
  }
}

logSleep

Source: backend/endpoints/sleep-logs/log-sleep

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-
datestringYesformat: YYYY-MM-DD
hoursSleptnumberYesgte: 0
bedTimestringNoformat: HH:mm
wakeTimestringNoformat: HH:mm
notesstringNo-

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "logSleep",
  "data": {
    "stackUserId": "stackuser_123",
    "date": "2026-03-12",
    "hoursSlept": 1
  }
}'

Example Response

{ "status": "ok", "data": {} }

updateSleepPreferences

Source: backend/endpoints/sleep-logs/update-sleep-preferences

Input Fields

FieldTypeRequiredConstraints
stackUserIdstringYes-
sleepTimestringNoformat: HH:mm; required on first setup; optional for reminder-only updates
wakeTimestringNoformat: HH:mm; required on first setup; optional for reminder-only updates
sleepReminderEnabledbooleanNonullable
wakeReminderEnabledbooleanNonullable
sleepGoalMinutesintegerNomanual override only when allowManualGoalUpdate is true; 240-900; nullable
allowManualGoalUpdatebooleanNo-

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "sleepLogs",
  "apiName": "updateSleepPreferences",
  "data": {
    "stackUserId": "stack_user_123",
    "sleepTime": "11:30 PM",
    "wakeTime": "07:30 AM",
    "sleepReminderEnabled": true,
    "wakeReminderEnabled": true
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "id": "sleep_pref_123",
    "patientId": "patient_123",
    "stackUserId": "stack_user_123",
    "sleepTime": "23:30",
    "wakeTime": "07:30",
    "sleepGoalMinutes": 480,
    "sleepGoalHours": "8h 0m",
    "sleepReminderEnabled": true,
    "wakeReminderEnabled": true,
    "createdAt": 1779971037247,
    "updatedAt": 1779971037247
  }
}