Skip to main content

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

PropertyValue
Function Nameget-sync-status
HTTP MethodGET
AuthenticationSupabase JWT (Bearer token in Authorization header)
Required RoleAny authenticated agency user

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer <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

StatusCondition
401Missing or invalid Authorization header / JWT token
403Authenticated user is not associated with an agency
405HTTP method is not GET
500Unexpected server error

Behavior

  • Handles CORS preflight (OPTIONS) requests and rejects non-GET methods with a 405.
  • Validates the JWT token via supabase.auth.getUser().
  • Looks up the user's agency_id from the users table.
  • Calls get_active_sync_job RPC to check for a currently active (pending or in-progress) job.
  • If an active job exists:
    • Calculates progress_percent as Math.round((processed_calls / total_calls) * 100), or null if total_calls is unknown.
    • Returns active: true with the job's full progress details.
  • If no active job exists:
    • Queries historical_sync_jobs for the most recent job with status completed, failed, or cancelled, ordered by created_at descending.
    • Returns active: false with the most recent job (or null if none exist).

Database Tables / RPCs

Table / RPCOperationDescription
usersReadFetches agency_id for the authenticated user
get_active_sync_job (RPC)ReadReturns the active sync job for the agency, if any
historical_sync_jobsReadQueries the most recent non-active job as a fallback

External APIs

None.