Skip to content

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.

To delete a calendar, you first need to get the calendar you want to delete.

Here’s one way to get it.

Get a calendar by its calendar ID
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.

To delete a calendar, use the following method.

Method details
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.

Delete a calendar
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}"`);
}