Skip to main content

Overview

The Calendar API provides endpoints for retrieving available time slots and creating calendar events for booked virtual classes. Events are automatically integrated with Google Calendar and include Google Meet conference links.

Get Calendar Events

Retrieve upcoming calendar events to display available time slots for class booking.

Endpoint

GET /api/calendar

Response

events
array
Array of calendar events with start time, end time, and status

Example Request

curl https://your-domain.com/api/calendar

Example Response

[
  {
    "start": {
      "dateTime": "2024-03-15T17:00:00-03:00"
    },
    "end": {
      "dateTime": "2024-03-15T18:30:00-03:00"
    },
    "status": "confirmed"
  },
  {
    "start": {
      "dateTime": "2024-03-16T19:00:00-03:00"
    },
    "end": {
      "dateTime": "2024-03-16T20:30:00-03:00"
    },
    "status": "confirmed"
  }
]

Error Responses

Create Calendar Event

Create a Google Calendar event with Google Meet link after successful payment. This endpoint is typically called by the webhook handler after payment confirmation.

Endpoint

POST /api/calendar

Authentication

Requires admin-level OAuth2 refresh token stored in the database.

Request Body

preferenceId
string
required
Mercado Pago preference ID linking the payment to the virtual class

Response

success
boolean
Whether the calendar event was created successfully
message
string
Success message: “Event created successfully”

Example Request

curl -X POST https://your-domain.com/api/calendar \
  -H "Content-Type: application/json" \
  -d '{
    "preferenceId": "123456789-abc123"
  }'

Example Response

{
  "success": true,
  "message": "Event created successfully"
}

Error Responses

Implementation Details

Event Creation Flow

1

Retrieve Virtual Class

Find the virtual class record using the provided preferenceId
2

OAuth Authentication

Use admin refresh token to authenticate with Google Calendar API
3

Create Google Calendar Event

Create event with Google Meet conference link enabled
4

Update Database

Store googleEventId and htmlLink in the VirtualClass record

Google Calendar Configuration

The calendar event includes:
  • Summary: Class type and learning focus
  • Description: Detailed class information
  • Conference: Google Meet link automatically generated
  • Timezone: America/Argentina/Buenos_Aires
  • Attendees: Student email address
  • Reminders: Email notification 60 minutes before start

Environment Variables

CALENDAR_ID
string
required
Google Calendar ID where events are created
AUTH_GOOGLE_ID
string
required
Google OAuth2 client ID
AUTH_GOOGLE_SECRET
string
required
Google OAuth2 client secret
GOOGLE_REDIRECT_URI
string
required
OAuth2 redirect URI configured in Google Cloud Console
ADMIN_EMAIL
string
required
Admin email address with calendar access

Virtual Classes

Learn about the class booking system

Payment System

Understand the payment flow that triggers calendar events

Calendar Integration

Detailed guide on Google Calendar setup

Calendar Setup

Admin configuration for Google Calendar

Build docs developers (and LLMs) love