Add Google Meet links to Calendar Events using the Calendar API and Google Apps Script

Aryan Irani
5 min readJul 16, 2021

--

Welcome to the Third part of the Calendar API Tutorial Series.

In this blog, I will show you how to Add Google Meet links to Calendar Events using the Calendar API and Google Apps Script.

So let’s get started.

Step 1: Sample Google Sheet

The Google Sheet that I will be using in this blog, contains the following details. If you prefer working with the sheet click here.

  1. Name of the Event
  2. Start date/time of the Event
  3. End date/time of the Event
  4. Description of the Event
  5. Attendees for the Event
var start_time = "7/1/2021 12:00 AM";  var end_time = "7/20/2021 11:59 PM";  var events = cal.getEvents(new Date(start_time), new Date(end_time));

Step 2: Add the Google Calendar API

  1. To add the Google Calendar API, follow these steps:
    Open the Script Editor. To open the Script Editor, follow these steps :

    (1) Click on the Tools button next to the Add-ons button.

(2) Next click on the Script Editor option. This brings up the Script Editor as
shown below.

We have reached the Script Editor.

(3) Go to the left side of the Script Editor and click on the Add a Service button.

On clicking on Add a Service, you will see the following Services you can add to your Google Apps Script Project.

Scroll down to Google Calendar API and select it.

After selecting the Google Calendar API, click on Add.

The Google Calendar API has successfully been added to the Project.

Step 3: Write the Automation Script

We have already opened the Script Editor, it’s time to write the script.

function createNewEventWithMeet() {1.  var ss = SpreadsheetApp.getActiveSpreadsheet();2.  var sheet = ss.getSheetByName("Calendar_Events");3.  var last_row = sheet.getLastRow();4.  var data = sheet.getRange("A2:E" + last_row).getValues();5. var cal = CalendarApp.getCalendarById("aryanirani123@gmail.com");

Declaring the function :

  1. Get the Active Spreadsheet
  2. Get the sheet by name
  3. Get the Last row of the sheet
  4. Get the range followed by getting the values for the range
for(var i = 0;i< data.length;i++){      1. var event_name = data[i][0];   
2. var start_time = data[i][1];
3. var end_time = data[i][2];
4. var event_description = data[i][3];
5. var attendees_event = data[i][4];

Here we have created a for loop that will go through all the events in the Google Sheet and store them into the assigned variable. We are going to get the following details from the sheet :

  1. Name of the Event
  2. Start time of the Event
  3. End time of the Event
  4. Description of the Event
  5. Attendees for the Event
const gmt = "+05:30";  
const calendarId = "aryanirani123@gmail.com";

To add Google meet links we need to specify the GMT (Greenwich Mean Time). Next, you have specified the calendar ID where you want to add the calendar events.

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

To add links to google meet we have to start by specifying the start date and end date, followed by adding the GMT value that we declared previously. Next, we are going to specify the attendees for the event. The next part of the code is a mandatory code that you need to add to add google meet links to the events.

Next, you have to specify the event name followed by the description of the event. Then we pass all the details into the Calendar function using the insert function.

We are done with our code.

Step 4: Check the Output

Our code is complete. Select the correct function (getEvents) as shown below and run the program. Or you can run the code using a trigger, macros and more. Check out the link below to know more.

On successful execution, the script will add all the events to the calendar.

Here you can see the 3 events that we created in the sheet have successfully been added to the Google Calendar.

If you click on it you can see all the details clearly.

Here you can see the Google meet link has been added to the event. Also, we can see that the attendee has been added to the event.

Summary

We saw how you can add Google meet links to Calendar Events to Google Calendar using Calendar API and Google Apps Script. To sum up :

  1. Added all the events into the sheet [Title, Start Time, End Time, description of the event, Attendees of the event]
  2. Accessed the sheet by name
  3. Got the last row
  4. Got the range and the values
  5. Created a for loop to go through each event in the sheet
  6. Declared the GMT followed by the Calendar ID
  7. Next, we specified the start date, end date followed by the attendees for the event
  8. Next, we added the required snippet of code to create meet links
  9. In the end, we passed all the variables into the Calendar function using the insert command.

I hope you have understood how to add Google meet links to Calendar Events to Google Calendar using Calendar API and Google Apps Script.

This is all for the blog, I hope you enjoyed the Calendar API Tutorial series. If you prefer watching the video series you can click on the link below. You can send your feedback to aryanirani123@gmail.com.

Originally published on the YAMM blog.

--

--

Aryan Irani
Aryan Irani

Written by Aryan Irani

I write and create on the internet :)

No responses yet