Delete calendar
Google Apps Script has a standard CalendarApp
class, which is a library for operating Google Calendar.
Here, we will explain how to delete a specific calendar from the target account using the CalendarApp
class.
Since GAS will access Google Calendar, you will need to set the authority at the first run.
Prerequisite
To delete the calendar, you need to get the target calendar.
The following is an example of the acquisition method.
Get calendar from the calendar ID
const CALENDAR_ID = '___The ID of the calendar to get___';
/** @type { CalendarApp.Calendar | null } */
const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
For more information about how to get a calendar, see the following page.
Function to use
Use the following functions to delete the calendar.
Function details
Calendar.deleteCalendar();
Use the deleteCalendar
method provided in the Calendar
class.
There is no return value.
Sample code
Create a new calendar
const CALENDAR_ID = '___The ID of the calendar to get___';
function myFunction() {
const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
calendar.deleteCalendar();
console.log(`The calendar of the ID "${CALENDAR_ID}" has been deleted`);
}