Home > Enterprise >  how to delete completely a google calendar instance via goggle-apps-script?
how to delete completely a google calendar instance via goggle-apps-script?

Time:04-21

I searched for the answer here (StackOverflow) but without success.

I need to delete an entire calendar in the Goggle Calendar via Google-apps-script. It is exactly what I need. Delete at once a Calendar and consequently all the events that were associated with this respective calendar. After that, My intent is to create a new Calendar from scratch having only the events that matter. My main goal is to synchronize all the appointments that exist in my system with the google calendar application. I think it is a direct way to reach there. I am open to new suggestions as well.
Any help on this subject will be hugely appreciated.

CodePudding user response:

About the method for permanently deleting Calendar using Google Apps Script, there are 2 methods.

Pattern 1:

Uses Calendar Service (CalendarApp). The sample script is as follows.

function myFunction() {
  const calendarId = "###"; // Please set the calendar ID you want to delete.
  CalendarApp.getCalendarById(calendarId).deleteCalendar();
}

Pattern 2:

Uses Calendar API. The sample script is as follows. In this case, please enable Calendar API at Advanced Google services.

function myFunction() {
  const calendarId = "###"; // Please set the calendar ID you want to delete.
  Calendar.Calendars.remove(calendarId);
}

Note:

  • When this script is run, the calendar is permanently deleted. So please be careful about this. When you test this, please use a sample Calendar.
  • When the primary calendar is deleted, an error occurs. So, if you want to delete all events from the primary calendar, it is required to delete all events using a script instead of deleting the calendar. Please be careful about this.
  • When you want to delete a lot of events from a Calendar using Google Apps Script, this report might be useful. Ref

References:

CodePudding user response:

Delete Calendar

function deleteCalendar() {
  CalendarApp.getCalendarById('calid').deleteCalendar();
}
  • Related