1

I hitting an error when I try to add multiple attendees via my spreadsheet. It works with one but when I try comma-separate to include multiple attendees it throws an error:

Error GoogleJsonResponseException: API call to calendar.events.insert failed with error: Invalid attendee email. createNewEventWithMeet @ Code.gs:34

Link

function createNewEventWithMeet() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Calendar_Events");
  var last_row = sheet.getLastRow();
  var data = sheet.getRange("A2:E" + last_row).getValues();
  var cal = CalendarApp.getCalendarById("[email protected]");

  for(var i = 0;i< data.length;i++){

    var event_name = data[i][0];
    var start_time = data[i][1];
    var end_time = data[i][2];
    var event_description = data[i][3];
    var attendees_event = data[i][4];

//.setVisibility(CalendarApp.Visibility.PRIVATE);

  const mst = "-06:00";
  const calendarId = "[email protected]";
  const resource = {
    start: { dateTime: start_time+mst },
    end: { dateTime: end_time+mst },
    attendees: [{ email: attendees_event }],
    conferenceData: {
      createRequest: {
        requestId: "[email protected]",
        conferenceSolutionKey: { type: "hangoutsMeet" },
      },
    },
    summary: event_name,
    description: event_description,
  };
  const res = Calendar.Events.insert(resource, calendarId, {
    
    conferenceDataVersion: 1,
  });

  
  var googleMeet_Link = res.hangoutLink;
  
  console.log(res);
  }
}

I've tried to create multiple columns to split it out but I cannot seem to make it work.

1 Answer 1

0

The Event Resource requires a valid email address for each attendee.

From the code in the question,

var attendees_event = data[i][4];
attendees: [{ email: attendees_event }],

You should extend the code to split the values of data[i][4], then add one {email: value} to attendees for each value resulting from the split.

One way to do this is to change the above-referred code lines with the following:

var attendees_event = data[i][4].split(",");
attendees: attendees_event.map(attendee => ({email: attendee})),
Sign up to request clarification or add additional context in comments.

3 Comments

That worked PERFECTLY! One thing that I'd like to add, if it's easy enough. Everytime it runs it also re-creates the previous invites from old rows. I could autohide those rows or maybe put an "x" in a column for the ones that have already been created. Or is there a better way within that script?
@JBardo , it depends on whether you need to track the events created in the spreadsheet and how the event data is entered.
It would be nice to have the spreadsheet be the running log of all events created. I linked the spreadsheet in the initial comment and that's how I had planned to log in event data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.