1

I'm referencing https://cloud.google.com/blog/products/application-development/hangouts-meet-now-available-in-google and https://developers.google.com/calendar/v3/reference/events, but can't seem to figure out how to add the Google Meet link to the Google Calendar event programmatically. Here is my Google Apps Script code:

/**
 * Creates an event in the user's default calendar.
 */
function createEvent() {
  var calendarId = 'primary';
  var start = getRelativeDate(1, 12);
  var end = getRelativeDate(1, 13);
  var event = {
    summary: 'Test Event',
    description: 'Test.',
    start: {
      dateTime: start.toISOString()
    },
    end: {
      dateTime: end.toISOString()
    },
    attendees: [
      {email: 'XXXXXX@XXXX.XXX'},
    ],
      conferenceData: {createRequest: {conferenceSolutionKey: {type: 'hangoutsMeet'}}}
  };
      event = Calendar.Events.insert(event, calendarId, {sendNotifications: true, conferenceDataVersion: 1}  );
  Logger.log('Event ID: ' + event.id);
}

/**
 * Helper function to get a new Date object relative to the current date.
 * @param {number} daysOffset The number of days in the future for the new date.
 * @param {number} hour The hour of the day for the new date, in the time zone
 *     of the script.
 * @return {Date} The new date.
 */
function getRelativeDate(daysOffset, hour) {
  var date = new Date();
  date.setDate(date.getDate() + daysOffset);
  date.setHours(hour);
  date.setMinutes(0);
  date.setSeconds(0);
  date.setMilliseconds(0);
  return date;
}

Any help is appreciated. Thanks!

Benny
  • 11
  • 3
  • 1
    The official document says `You can create a new conference for an event by providing a createRequest with a newly generated requestId which can be a random string.`. [Ref](https://developers.google.com/calendar/create-events) From this, it seems that it is required to include `requestId` for creating a new conference like `conferenceData: {createRequest: {requestId: Utilities.getUuid(), conferenceSolutionKey: {type: 'hangoutsMeet'}}}`. – Tanaike Sep 17 '20 at 05:52

1 Answers1

0

I've been successfully using this code to create an event and return the Meet link using text variables 'summary', 'id'; and date variables 'start' and 'end':

var event = {
  "summary": summary,
 "start": {
   "dateTime": start.toISOString()
     },
  "end": {
    "dateTime": end.toISOString()
      },
       "conferenceData": {
          "createRequest": {
           "conferenceSolutionKey": {
             "type": "hangoutsMeet"
         },   
           "requestId": id
          }
     }
  };

 event = Calendar.Events.insert(event, 'primary', {
   "conferenceDataVersion": 1});
 return event.hangoutLink;
sjo
  • 15
  • 2