Get All Events by Date in Google Calendar API

 import os
import logging
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
from pydantic import BaseModel
import requests
from datetime import datetime

logger = logging.getLogger(__name__)

app = FastAPI()

# The builder needs to provide the Google Calendar API key in the Env Secrets tab.
    raise Exception("The GOOGLE_CALENDAR_API_KEY environment variable is not set.")

def fetch_events(calendar_id: str, date: str):
    url = f"{calendar_id}/events"
    params = {
        'timeMin': f"{date}T00:00:00Z",
        'timeMax': f"{date}T23:59:59Z",

About this template

This application allows you to retrieve a list of events for a specific date from a Google Calendar. For each event, you will receive the start time, end time, summary, description, and other information returned by google api.

Introduction to the Google Calendar Events by Date Template

Welcome to the Lazy template guide for retrieving events from a Google Calendar on a specific date. This template is designed to help you build an application that interacts with the Google Calendar API to fetch and display events for a given date. It includes endpoints to get events in a list format and to download them as a JSON file. Additionally, it provides a simple HTML frontend to interact with these endpoints.

Getting Started

To begin using this template, click on "Start with this Template" in the Lazy builder interface. This will pre-populate the code in the Lazy Builder, so you won't need to copy or paste any code manually.

Initial Setup

Before you can use the application, you need to set up an environment secret for the Google Calendar API key:

  1. Go to the Google Developers Console (
  2. Create a new project or select an existing one.
  3. Enable the Google Calendar API for your project.
  4. Create credentials (API key) for your project.
  5. Copy the generated API key.
  6. In the Lazy Builder interface, navigate to the Environment Secrets tab.
  7. Create a new secret with the key as GOOGLE_CALENDAR_API_KEY and paste your copied API key as the value.


Once you have set up the environment secret, press the "Test" button. This will deploy your application and launch the Lazy CLI. The CLI will not prompt for any user input as all necessary information is provided through the API endpoints.

Using the App

After pressing the "Test" button, Lazy will provide you with a dedicated server link to access your application. If you're using FastAPI, Lazy will also provide a link to the API documentation.

To interact with the app:

  • Open the provided server link in your web browser to view the simple HTML frontend.
  • Enter a public Google Calendar ID and a date in the respective fields.
  • Click on "Fetch Events" to display the events for the specified date.
  • Click on "Download Events" to download the events as a JSON file.

Integrating the App

If you wish to integrate this application into another service or frontend, you can use the provided API endpoints. Here's an example of how to make a request to the API:

GET /events/{calendar_id}/{date}

Replace {calendar_id} with the ID of the Google Calendar and {date} with the date you want to fetch events for (in YYYY-MM-DD format).

A sample response from the API might look like this:

        "start": {"dateTime": "2023-04-01T10:00:00Z"},
        "end": {"dateTime": "2023-04-01T11:00:00Z"},
        "summary": "Event Title",
        "description": "Event Description"
    // ... more events

Use the server link provided by Lazy to make requests to your deployed application. If you need to integrate these endpoints into a frontend application, you can make AJAX calls to these endpoints and process the response as needed.

Last published
April 7, 2024

More templates like this

Customisable Server Status Dashboard

This template allows you to create a dashboard to report about incidents regarding your server to your users.


A bot that answers questions about data

Ask questions about your database via a chat bot. This chatbot connects to a SQLITE database, generates queries for it based on the schema and then runs the queries printing the response all in a nicely styled chat UI. This template is pre-loaded with sample data (car parts) to play around with - here are the sample data columns that you can query: part_number, part_name, price, units_left_in_stock, manufacturer .


WhatsApp Bot Builder

The WhatsApp Bot Builder app allows users to create a WhatsApp bot that responds to every message with "Hello World".

Get All Events by Date in Google Calendar API