Skip to main content

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

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

Request

Headers

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

Query Parameters

ParameterTypeRequiredDefaultDescription
periodstringNo30dtoday, 7d, 30d, 90d, or custom (for historical stats)
start_datestring (ISO date)If period=custom--Start date YYYY-MM-DD
end_datestring (ISO date)If period=custom--End date YYYY-MM-DD
statusstringNo--Filter batches: pending, processing, completed, failed
campaign_idstring (UUID)No--Filter to a specific campaign
limitintegerNo25Pagination limit (max 100)
offsetintegerNo0Pagination 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

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

Behavior

  • Authenticates the user via Supabase JWT and resolves their agency_id.
  • Executes two queries in parallel:
    1. Active batches: Queries v_call_batch_summary view with optional status filter, ordered by created_at descending with pagination.
    2. Campaign stats: Queries call_stats_daily for the date range, filters out rows with no campaign_id, and aggregates by campaign_id.
  • Computes derived rates per campaign: contact_rate (connected/total), conversion_rate (meetings/total), avg_duration_seconds.
  • Sorts campaign stats by total_calls descending.
  • Looks up campaign names from the campaigns table and enriches the response.

Database Tables

TableOperationDescription
usersReadFetches user profile to determine agency_id
v_call_batch_summaryReadReal-time batch progress view (queries on read)
call_stats_dailyReadPre-aggregated daily stats, aggregated by campaign
campaignsReadCampaign name lookup

External APIs

None.