1

I have a prototype script that is designed to add a guest to a calendar event. It adds them to the event just fine, but it does not trigger an invite. Could someone point me in the right direction to what's missing?

function addToEvent() {

 var guest = "you@gmail.com";
 var calendar = 'pbekisz@keuka.edu';
 var event = "33l5k7p5qocdprt5j2c9nhbhl8";

 var cal = CalendarApp.getCalendarById(calendar);
 var theEvent = cal.getEventSeriesById(event); 
 theEvent.addGuest(guest); 
}

addToEvent();
Pete
  • 467
  • 7
  • 20
  • Very similar to https://stackoverflow.com/questions/40842714/how-can-i-send-an-invitation-to-the-guest-by-google-apps-script-for-calendar/40843667 – carbontracking Jan 10 '22 at 12:14
  • Very similar again to https://stackoverflow.com/questions/53992955/how-do-i-send-the-standard-invitation-email-when-calling-addguest-on-a-calendare/55509409 with the bonus that this one has a very clear answer ! – carbontracking Jan 10 '22 at 12:53

1 Answers1

1

The CalendarApp documentation indicates that invitations can be sent when the event is created. Because the addGuest method does not include any indication as to how one might send the invitation, it appears that this functionality is currently limited to the time of event creation.

As a work around, you can continue with your prototype, and email your new guest(s) that they have been invited and that it should be appearing on their calendar. Alternatively, you could create a new event with your new guest(s) and send the invitation, then add the existing guests with their statuses from your original event, and then remove the original event.

Edit As I was looking in to this further, I came across an old thread on google-apps-scripts-issues where they found the advanced Calendar API service could be used to achieve what you are trying to accomplish:

function sendInvite(calendarId, eventId, email) {
  var event = Calendar.Events.get(calendarId, eventId);
  event.attendees.push({
    email: email
  });
  event = Calendar.Events.patch(event, calendarId, eventId, {
    sendNotifications: true
  });
}
Reno Blair
  • 154
  • 5
  • According to this https://developers.google.com/calendar/api/v3/reference/events/patch sendNotifications has been deprecated and now you need to use sendUpdates. However I wonder if this will send notifications to all previously invited attendees. – carbontracking Jan 10 '22 at 12:09