Delete a calendar
Google Apps Script has a built-in CalendarApp class, a library for working with Google Calendar.
This article explains how to use the CalendarApp class to delete a specific calendar from an account.
Because GAS accesses Google Calendar, you need to grant permissions the first time you run the script.
Prerequisites
Section titled “Prerequisites”To delete a calendar, you first need to get the calendar you want to delete.
Here’s one way to get it.
const CALENDAR_ID = '___ID_of_the_calendar_to_get___';
/** @type { CalendarApp.Calendar | null } */const calendar = CalendarApp.getCalendarById(CALENDAR_ID);For details on how to get a calendar, see Get a calendar.
Method to use
Section titled “Method to use”To delete a calendar, use the following method.
Calendar.deleteCalendar();Use the deleteCalendar method provided by the Calendar class.
The calendar is permanently deleted and can’t be restored. You can delete only calendars that the user running the script owns. Also, running this method on an imported calendar causes an error.
This method doesn’t return a value.
Sample code
Section titled “Sample code”const CALENDAR_ID = '___ID_of_the_calendar_to_delete___';
function myFunction() { const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
if (!calendar) { console.log('The calendar was not found'); return; }
calendar.deleteCalendar();
console.log(`Deleted the calendar with ID "${CALENDAR_ID}"`);}