0
votes

I am trying to determine a method for inviting guests to an already created event using Google Script or Google Calendar API. just using addGuest(email) doesn't send an email invite when adding a guest after the event is created.

Is this the way to go about it?

var calid = 'some CalendarID';
var eventid = 'some eventid';
var ss = SpreadsheetApp.getActiveSpreadsheet();
var column = ss.getRange('A2:A2');
var emails = column.getValues();
var createdEvent = Calendar.Events.update(calid, eventid).attendees(emails);

I also saw this but it doesn't work.

function sendInvite(calendarId, eventId, emails) {
  var event = Calendar.Events.get(calendarId, eventId);
  event.attendees.push({email: emails});
  event = Calendar.Events.patch(event, calendarId, eventId, {
    sendNotifications: true
  });
}

And this one:

function sendInvite(calendarId, eventId, email) {
var event = Calendar.Events.get(calendarId, eventId);
if(event.attendees) {
  event.attendees.push({
    email: email
  });
} else {
  event.attendees = new Array({email: email});
}
event = Calendar.Events.patch(event, calendarId, eventId, {
  sendNotifications: true
});
}
1
These scripts use advanced calendar API, did you authorize the API before trying ? It has to be done in both the ressource menu and in the Google API console - Serge insas
Yes I have authorized it all. I can get the event created with the API. I see the event added on another email's calendar and it's waiting for the user to click Yes, No or Maybe. But it does not generate the email to invite to person. It's the email that I am struggling with. How do I get that sent with the API? Or how do I recreate? - Clay Smith

1 Answers

1
votes

Turns out the Google event prevents the sending of past events by email. I was using a past date to test with. When I changed to a date in the future it worked great.