Skip to main content

Calendar API

Connect a Google Calendar account and manage events, check availability, and schedule directly through the API.
All calendar endpoints require an authenticated session. The user is identified from the session automatically — you do not pass a userId parameter.
Most calendar endpoints also require a connected Google Calendar account. Use the connect flow to authorize access before calling event endpoints.

Base URL

Authentication

All calendar endpoints require a valid NextAuth session. Requests without an active session receive a 401 Unauthorized response (or a redirect to /login for browser-based flows). The authenticated user’s identity is derived from the session. You do not need to include a userId parameter in any request.

Token storage

Calendar tokens (access and refresh tokens) are encrypted at rest using AES-256-GCM before being persisted to the database. Tokens are never stored in plaintext.

Connect calendar

Initiates the Google Calendar OAuth flow. Returns an authorization URL that the user must visit to grant calendar access.

Request body

Response

Redirect the user to authUrl to begin the OAuth consent flow. After granting access, Google redirects to the callback endpoint below.

Errors

OAuth callback

Handles the OAuth authorization code exchange after Google redirects the user back from the consent screen. You do not call this endpoint directly — Google redirects to it automatically.

Query parameters

Behavior

On success, this endpoint:
  1. Verifies the HMAC-signed state parameter and checks it has not expired.
  2. Exchanges the authorization code for access and refresh tokens.
  3. Retrieves the user’s primary calendar ID and timezone.
  4. Encrypts and persists the tokens to the database (AES-256-GCM).
  5. Redirects to /dashboard/calendar?connected=true.

Error redirects

If an error occurs, the endpoint redirects to /dashboard/calendar with an error query parameter:

Start OAuth (redirect)

Redirects the browser directly to the Google OAuth consent screen. This is an alternative to the POST-based connect flow — use it when you want a simple link-based authorization. Requires an active session. If the user is not authenticated, this endpoint redirects to /login.

Query parameters

List events

Returns calendar events within a date range. The user is identified from the session.

Query parameters

Response

Errors

Check availability

Returns available and busy time slots for a given date. Slots are one hour each, from 09:00 to 23:00. The user is identified from the session.

Query parameters

Response

Errors

Create event

Creates a new calendar event. The user is identified from the session.

Request body

Example request

Response

Errors

Update event

Updates an existing calendar event. Only the fields you include are changed. The user is identified from the session.

Request body

Response

Errors

Delete event

Deletes a calendar event. The user is identified from the session.

Request body

Response

Errors

Quick add

Creates an event from a natural language string using Google Calendar’s quick-add feature. The user is identified from the session.

Request body

Response

Errors