Dashboard Campaigns
Returns two data sets: real-time active batch progress from v_call_batch_summary and historical campaign-level stats aggregated from call_stats_daily. Supports pagination for batch listing and optional status filtering.
Endpoint
| Property | Value |
|---|---|
| Function Name | dashboard-campaigns |
| HTTP Method | GET |
| Authentication | Supabase JWT (Bearer token) |
Request
Headers
Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
period | string | No | 30d | today, 7d, 30d, 90d, or custom (for historical stats) |
start_date | string (ISO date) | If period=custom | -- | Start date YYYY-MM-DD |
end_date | string (ISO date) | If period=custom | -- | End date YYYY-MM-DD |
status | string | No | -- | Filter batches: pending, processing, completed, failed |
campaign_id | string (UUID) | No | -- | Filter to a specific campaign |
limit | integer | No | 25 | Pagination limit (max 100) |
offset | integer | No | 0 | Pagination offset |
Response
Success (200)
{
"active_batches": [
{
"id": "uuid",
"agency_id": "uuid",
"campaign_id": "uuid",
"status": "processing",
"total_calls": 500,
"completed_count": 200,
"failed_count": 5,
"pending_count": 285,
"in_progress_count": 10,
"progress_pct": 41,
"created_at": "2026-02-14T10:00:00Z",
"completed_at": null
}
],
"campaign_stats": [
{
"campaign_id": "uuid",
"campaign_name": "Winter Outreach",
"total_calls": 200,
"completed_calls": 150,
"connected_calls": 80,
"meetings_booked": 5,
"qualified_leads": 12,
"conversations_had": 30,
"avg_duration_seconds": 95,
"contact_rate": 40.0, // %
"conversion_rate": 2.5 // %
}
],
"pagination": {
"total": 5,
"limit": 25,
"offset": 0,
"has_more": false
}
}
Error Responses
| Status | Condition |
|---|---|
| 401 | Missing or invalid authorization header |
| 403 | User exists but has no agency_id |
| 405 | HTTP method is not GET |
| 500 | Failed to query batches or campaign stats |
Behavior
- Authenticates the user via Supabase JWT and resolves their
agency_id. - Executes two queries in parallel:
- Active batches: Queries
v_call_batch_summaryview with optionalstatusfilter, ordered bycreated_atdescending with pagination. - Campaign stats: Queries
call_stats_dailyfor the date range, filters out rows with nocampaign_id, and aggregates bycampaign_id.
- Active batches: Queries
- Computes derived rates per campaign:
contact_rate(connected/total),conversion_rate(meetings/total),avg_duration_seconds. - Sorts campaign stats by
total_callsdescending. - Looks up campaign names from the
campaignstable and enriches the response.
Database Tables
| Table | Operation | Description |
|---|---|---|
users | Read | Fetches user profile to determine agency_id |
v_call_batch_summary | Read | Real-time batch progress view (queries on read) |
call_stats_daily | Read | Pre-aggregated daily stats, aggregated by campaign |
campaigns | Read | Campaign name lookup |
External APIs
None.
Related Functions
- Dashboard Overview -- Overall KPIs across all campaigns
- Create Call Batch -- Create new batches
- List Call Batches -- Detailed batch listing
- Frontend API Guide -- Campaign page integration