---
title: "Sync Calendar"
method: POST
path: "/api/focused/tools/sync_calendar"
tags: ["focused-tools"]
---

# Sync Calendar

`POST /api/focused/tools/sync_calendar`

Manually trigger calendar sync for a user.

Used for testing and manual sync operations.
Syncs Google Calendar events into focused_focus_sessions table.

Process:
    1. Check needs_sync flag in Redis
    2. Fetch events from Google Calendar (timeMin=-1d, timeMax=+30d)
    3. Upsert events in batches of 100
    4. Detect and soft-delete orphaned events
    5. Update last_synced_at timestamp
    6. Clear needs_sync flag

Identity Source (Increment 7D):
    - Primary: X-User-ID header (from MCP after JWT validation)
    - Fallback: payload.user_id (for backward compatibility)
    - Logs warning if fallback is used or mismatch detected

Returns:
    {
        "success": True,
        "data": {
            "events_fetched": int,
            "events_inserted": int,
            "events_updated": int,
            "events_deleted": int
        }
    }

## Request body

- SyncCalendarRequest — Request model for sync_calendar endpoint (Increment 6B).
  - `user_id` string, required — User ID to sync calendar for

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/priority-guard/apis/priority-guardian.md) · [All operations](https://skmtc.net/priority-guard/apis/priority-guardian/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/priority-guard/priority-guardian/revisions/8579218b716d/schema)
