Get Sync Status
Retrieves the current state of the agency's historical sync operation. If a sync job is actively running, returns its real-time progress. If no active job exists, returns the most recent completed, failed, or cancelled job for reference.
Endpoint
| Property | Value |
|---|---|
| Function Name | get-sync-status |
| HTTP Method | GET |
| Authentication | Supabase JWT (Bearer token in Authorization header) |
| Required Role | Any authenticated agency user |
Request
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <supabase_jwt> |
Query Parameters
None.
Response
Success -- Active Job (200)
{
"active": true,
"job": {
"id": "uuid",
"status": "in_progress",
"date_from": "2025-01-01T00:00:00Z",
"date_to": "2025-03-01T00:00:00Z",
"total_calls": 1500,
"processed_calls": 750,
"imported_calls": 720,
"skipped_calls": 25,
"failed_calls": 5,
"progress_percent": 50,
"started_at": "2025-03-15T10:00:00Z",
"last_activity_at": "2025-03-15T10:05:00Z"
}
}
Success -- No Active Job (200)
{
"active": false,
"recent_job": {
"id": "uuid",
"status": "completed",
"date_from": "2025-01-01T00:00:00Z",
"date_to": "2025-03-01T00:00:00Z",
"total_calls": 1500,
"processed_calls": 1500,
"imported_calls": 1450,
"skipped_calls": 40,
"failed_calls": 10,
"created_at": "2025-03-14T10:00:00Z"
}
}
If no jobs have ever been created for the agency, recent_job will be null.
Error Responses
| Status | Condition |
|---|---|
| 401 | Missing or invalid Authorization header / JWT token |
| 403 | Authenticated user is not associated with an agency |
| 405 | HTTP method is not GET |
| 500 | Unexpected server error |
Behavior
- Handles CORS preflight (
OPTIONS) requests and rejects non-GETmethods with a405. - Validates the JWT token via
supabase.auth.getUser(). - Looks up the user's
agency_idfrom theuserstable. - Calls
get_active_sync_jobRPC to check for a currently active (pending or in-progress) job. - If an active job exists:
- Calculates
progress_percentasMath.round((processed_calls / total_calls) * 100), ornulliftotal_callsis unknown. - Returns
active: truewith the job's full progress details.
- Calculates
- If no active job exists:
- Queries
historical_sync_jobsfor the most recent job with statuscompleted,failed, orcancelled, ordered bycreated_atdescending. - Returns
active: falsewith the most recent job (ornullif none exist).
- Queries
Database Tables / RPCs
| Table / RPC | Operation | Description |
|---|---|---|
users | Read | Fetches agency_id for the authenticated user |
get_active_sync_job (RPC) | Read | Returns the active sync job for the agency, if any |
historical_sync_jobs | Read | Queries the most recent non-active job as a fallback |
External APIs
None.
Related Functions
start-historical-sync-- Creates new sync jobs whose status this function reportsprocess-historical-sync-- Processes sync jobs, updating the progress that this function readscancel-historical-sync-- Cancels jobs, changing their status tocancelled