Sleep Logs
Function-calling namespace: sleepLogs
- Base URL:
https://api.aivida.in - Engine endpoint:
POST /api - Auth: Stack token middleware enabled in
optionalmode. - Send token in header:
x-stack-access-token: <access_token>(orAuthorization: Bearer <access_token>). - In
optionalmode: no token is allowed; invalid token is rejected with401.
deleteSleepLog
Source: backend/endpoints/sleep-logs/delete-sleep-log
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
logId | string | Yes | - |
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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
limit | integer | No | min: 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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
days | integer | No | min: 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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
date | string | Yes | format: YYYY-MM-DD |
hoursSlept | number | Yes | gte: 0 |
bedTime | string | No | format: HH:mm |
wakeTime | string | No | format: HH:mm |
notes | string | No | - |
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
| Field | Type | Required | Constraints |
|---|---|---|---|
stackUserId | string | Yes | - |
sleepTime | string | No | format: HH:mm; required on first setup; optional for reminder-only updates |
wakeTime | string | No | format: HH:mm; required on first setup; optional for reminder-only updates |
sleepReminderEnabled | boolean | No | nullable |
wakeReminderEnabled | boolean | No | nullable |
sleepGoalMinutes | integer | No | manual override only when allowManualGoalUpdate is true; 240-900; nullable |
allowManualGoalUpdate | boolean | No | - |
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
}
}