Reputation: 465
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 = "[email protected]";
var calendar = '[email protected]';
var event = "33l5k7p5qocdprt5j2c9nhbhl8";
var cal = CalendarApp.getCalendarById(calendar);
var theEvent = cal.getEventSeriesById(event);
theEvent.addGuest(guest);
}
addToEvent();
Upvotes: 1
Views: 1559
Reputation: 154
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 }); }
Upvotes: 1