Google Calendar Integration
Connect your Google Calendar to automatically block time when you have external appointments.Initiate Google Calendar OAuth
Requires authentication.
POST /api/v1/merchant/integrations/google/calendar
- Generates a Google OAuth authorization URL
- Sets a secure state cookie for CSRF protection
- Redirects the user to Google’s authorization page
Response
The endpoint returns an HTTP redirect (307 Temporary Redirect) to Google’s OAuth consent screen where the user will:- Log in to their Google account (if not already logged in)
- Review the permissions requested
- Authorize the application
- Be redirected back to the callback URL
OAuth Flow
Handle OAuth Callback
This endpoint is called by Google after authorization. Do not call directly.
PUT /api/v1/merchant/integrations/google/calendar/callback
- Validates the OAuth state to prevent CSRF attacks
- Exchanges the authorization code for access and refresh tokens
- Stores the tokens securely in the database
- Sets up calendar sync
- Redirects to the integrations page in the app
OAuth authorization code from Google
OAuth state token for CSRF protection
Error Handling
If the state validation fails:- Invalid or expired state token
- Mismatched state (potential CSRF attack)
- Failed token exchange with Google
- Database storage failure
Calendar Change Notifications
Google sends notifications to this endpoint when calendar events change.POST /api/v1/merchant/integrations/google/calendar/watch
- Receives notifications from Google about calendar changes
- Triggers a sync to update blocked times
- Always returns 200 OK (required by Google’s protocol)
- Logs errors internally without failing the request
Unique identifier for the notification channel
Google’s resource identifier
Type of change: “sync” (initial), “exists”, “not_exists”, or “update”
Notification States
- sync: Initial handshake notification (ignored)
- exists: Resource exists (triggers sync)
- not_exists: Resource deleted (triggers sync)
- update: Resource updated (triggers sync)
How Calendar Sync Works
Initial Setup
- User connects Google Calendar via OAuth
- System retrieves user’s calendar events
- Creates blocked times for existing events
- Sets up a notification channel for real-time updates
Ongoing Sync
- User creates/updates/deletes event in Google Calendar
- Google sends notification to the watch endpoint
- System fetches updated calendar data
- Creates, updates, or deletes corresponding blocked times
- Merchant calendar reflects the changes immediately
Blocked Time Creation
For each Google Calendar event:All-Day Events
All-day events in Google Calendar:Managing Connected Calendars
While the API provides connection endpoints, calendar management typically includes:Viewing Connected Calendars
Check which external calendars are connected:- Google Calendar connection status
- Last sync time
- Sync errors (if any)
Disconnecting Calendars
To disconnect a calendar integration:- Revoke the OAuth tokens
- Stop the notification channel
- Optionally delete synced blocked times
Best Practices
Calendar Selection
After connecting Google Calendar:- Choose which calendars to sync (work, personal, etc.)
- Only sync calendars with relevant availability
- Exclude calendars with tentative or optional events
Sync Preferences
- Event Types: Sync “busy” events but not “free” or “tentative”
- Privacy: Sync time blocks without exposing event details to customers
- Two-Way Sync: Consider if bookings should also appear in Google Calendar
Security
- Token Storage: OAuth tokens are stored securely encrypted
- State Validation: CSRF protection via state parameter
- Scope Limitation: Request only necessary calendar scopes
- Revocation: Users can revoke access anytime via Google Account settings
Error Recovery
- Token Expiration: System automatically refreshes expired tokens
- Sync Failures: Logs errors and retries failed syncs
- Manual Re-sync: Users can trigger manual sync if needed
Permissions Required
The Google Calendar integration requires:https://www.googleapis.com/auth/calendar.readonly- Read calendar eventshttps://www.googleapis.com/auth/calendar.events.readonly- Read event details
- No modification of Google Calendar events
- Read-only access to prevent accidental changes
- User maintains full control of their calendar
Future Integrations
Planned integrations may include:- Microsoft Outlook Calendar
- Apple Calendar
- Office 365
- iCloud Calendar