Search code examples
google-apps-scriptgoogle-calendar-api

Create Out of office calendar events with Google Script Api that auto decline meetings


In the Google Calendar, it is possible to create an "Out of Office" event that automatically decline all future invitation for the set event. Event create through UI

I'm trying to create this type of event using the Google script api, but I somehow don't manage to.

So far, I'm stuck at writing this:

function createOutOfOffice(date){
  var startDate = new Date(date);
  startDate.setHours(0,0,0,0);
  var endDate = new Date(startDate);
  endDate.setDate(startDate.getDate() + 1);

  var outOfOffice = CalendarApp.createEvent('Out of office', startDate, endDate);
  outOfOffice.setVisibility(CalendarApp.Visibility.PUBLIC);
  outOfOffice.removeAllReminders();
}

But it does not create a true Out of office event, but generates a good old all day event instead:

Event created through the API

I'm obviously missing something there, as my created event won't auto decline meetings.

Reading through the api documentation, I don't find anything obvious to help me achieve what I want. Is it even remotely possible to do so with Google App Scripts?


Solution

  • The Out of Office event is a rather new feature of Google Calendar and thus, unfortunately it has not been implemented in Google Apps Script or Google API yet. You can see here that a respective feature request has been filed on Issuetracker already. You can give it a star to increase visibility, so that the feature will hopefully be implemented soon.