Using Google Calendar API to Create Events with Google Meet and Apps Script

July 15, 2021
Using Google Calendar API to Create Events with Google Meet and Apps Script
Table of Contents
Table of Contents

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

In this blog, I am going to show you how to use Google Calendar API to create  Events with Google Meet links and Google Apps Script.

So let’s get started.

Google Calendar API Tutorial: How to Add Event to Google Calendar with API

If you prefer to watch a video of this Google Calendar API tutorial instead of reading, we've got you covered:

Step 1: Sample Google Sheet

The Google Sheet that I will be using in this blog contains the following details.  

  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
  6. Visibility of the Event

Step 2: Documentation: Adding the Google Calendar API to create event

  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 to Create Calendar Event

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";

Google Meet API create meeting:

To add Google meet links we need to specify the TimeZone you are in Next you have to specify 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 use Google Calendar API and events from Google meet we have to start by specifying the start date and end date, followed by adding the timezone 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 of Google Calendar API with Get Events Function

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.

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 of how to use Google Calendar API to create events

We saw how you can Create Calendar Events with Google Meet link using the 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 time zone 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 use Google Calendar API to Create  Events with Google Meet link and Google Apps Script.

Hope you enjoyed the series and learned about the Calendar API. Feel free to reach out if you have any issues/feedback at aryanirani123@gmail.com.


Great! Next, complete checkout for full access to The Yet Another Mail Merge Blog
Welcome back! You've successfully signed in
You've successfully subscribed to The Yet Another Mail Merge Blog
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated