Skip to main content

Dashboard Timeseries

Returns daily aggregated data points from call_stats_daily for charting. Each entry represents one day's stats. The frontend can request only specific metrics to reduce payload size.

Endpoint

PropertyValue
Function Namedashboard-timeseries
HTTP MethodGET
AuthenticationSupabase JWT (Bearer token)

Request

Headers

Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json

Query Parameters

ParameterTypeRequiredDefaultDescription
periodstringNo7dtoday, 7d, 30d, 90d, or custom
start_datestring (ISO date)If period=custom--Start date YYYY-MM-DD
end_datestring (ISO date)If period=custom--End date YYYY-MM-DD
metricsstringNoallComma-separated column names to include
campaign_idstring (UUID)No--Filter to a specific campaign
client_idstring (UUID)No--Filter to a specific client

Available Metrics

total_calls, completed_calls, failed_calls, connected_calls,
conversations_had, meetings_booked, qualified_leads,
total_duration_seconds, avg_duration_seconds,
inbound_calls, outbound_calls,
positive_sentiment_calls, neutral_sentiment_calls, negative_sentiment_calls,
objections_encountered, issues_resolved, escalations,
voicemail_calls, callback_requested_calls, not_interested_calls,
wrong_number_calls, dnc_requested_calls, gatekeeper_blocked_calls,
no_answer_calls, conversation_calls,
avg_talk_ratio, avg_listen_ratio, total_interruptions,
avg_script_adherence, total_objections_handled, total_buying_signals,
emails_sent, sms_sent

Response

Success (200)

{
"period": { "start_date": "2026-02-10", "end_date": "2026-02-16" },
"data": [
{
"date": "2026-02-10",
"total_calls": 22,
"connected_calls": 16,
"meetings_booked": 2
},
{
"date": "2026-02-11",
"total_calls": 18,
"connected_calls": 12,
"meetings_booked": 1
}
// ... one entry per day that has data
]
}

Days with zero calls will not have an entry. Fill gaps with zeros on the frontend if needed.

Error Responses

StatusCondition
401Missing or invalid authorization header
403User exists but has no agency_id
405HTTP method is not GET
500Failed to query call_stats_daily

Behavior

  • Authenticates the user via Supabase JWT and resolves their agency_id.
  • Parses the optional metrics parameter. Invalid metric names are silently ignored; if none are valid, all metrics are returned.
  • Queries call_stats_daily ordered by stat_date ascending.
  • Aggregates multiple rows for the same date (e.g., different client/campaign combinations) into a single row per day.
  • For count fields, values are summed. For avg_* fields, weighted averages are computed using completed_calls as the weight.
  • Internal weight tracking fields are stripped from the final response.

Database Tables

TableOperationDescription
usersReadFetches user profile to determine agency_id
call_stats_dailyReadPre-aggregated daily stats, dynamically selecting requested metrics

External APIs

None.