Add a Google Meet to Calendar Events with Google Apps Script

My small team relies on automation to make things run. Part of our PD process is a Google Form workflow that kicks off calendar events, document creation, and email notifications. Since we've moved to online learning, we wanted to update that process to automatically add a Google Meet link for any PD that doesn't have to be in person.

This is important for us so we have consistency and maintainability built in. Taking variability out of event creation and management allows us, as a team of two, to make sure all PD in the district is accessible from anywhere, recordings archvied for later, and a full record of all events run in a given time period.

There are some official Google guides that show how to attach a Meet event to the Calendar, but nothing from the perspective of Apps Script specifically, so that's what I'll show here.

The Setup

Before you start, this relies on the advanced Calendar service. So, you'll need to go into your project, click on Resources > Advanced Google Services and then enable the Calendar v3 API in the project and the cloud console.

Enabling the advance service will give you access to the Calendarobject which can take object arguments, which is what you need to for the Meet attachment.

Data Structure

We use a Google Form to populate a spreadsheet of events. I won't go into how that data is collected or processed, so let's assume we have an object which represents values we'll use in the Calendar event:

const obj = {
    "eventId": "abc123",
    "title": "Some event",
    "description": "Let's do stuff in a Meet",
    "start": "2020-06-01T13:00:00",
    "end": "2020-06-01T14:00:00"
}

To create an event with the Calendar advanced service, we need to build a payload object to send with the request with details for the calendar event:

const payload = {
    "start": {
        "dateTime": obj.start,
        "timeZone": "America/Indiana/Indianapolis",
    },
    "end": {
        "dateTime": obj.end,
        "timeZone": "America/Indiana/Indianapolis",
    },
    "conferenceData": {
        "createRequest": {
            "conferenceSolutionKey": {
                "type": "hangoutsMeet"
            },
            "requestId": obj.eventId,
        },
    },
    "summary": obj.title,
    "description": obj.description
}

The only required parameters are the start and end keys. I also defined my time zone instead of manually adding a time offset, but that's for another post.

Notice the new confereceData ket in the middle of the payload. We define a new request for a Meet and set the conferenceSolutionKey.type value to hangoutsMeet. Other valid values are eventHangout for consumers and eventNamedHangout if you haven't enabled Google Meet in your GSuite domain.

Each request needs a requestId value, so I just use the eventId I already have generated, but it can be any valid string.

Finally, we need to set one more argument before we send the request: { "conferenceDataVersion": 1}. This allows that attached Meet to be modified if necessary.

Create the Event

This method uses the insert endpoint on the Calendar service. This takes three arguments: your payload, a Google Calendar ID (as a string), and any additional arguments. You can programatically get Calendar IDs, but we only post to one calendar, so I copied/pasted from the account we're using and set it as a variable.

In your Apps Script project, you can now do something like this:

function demo() {
    const payload = { ... }
    const arg = { "conferenceDataVersion": 1 }

    try {
        const response = Calendar.Events.insert(payload, "yourCalendarID", args)
        console.log(`Success! ${response}`)
        // Do more with the object, like write the event ID or URL back to the sheet for reference, etc.
    } catch(e) {
        console.log(`Oh no: ${e.message}`)
    }
}

If all goes well, you should now have a calendar event with an attached Meet.

4 thoughts on “Add a Google Meet to Calendar Events with Google Apps Script

  1. Aaron says:

    Thank you for this post! Do you know if its possible to add an already existing Google Meets link to the payload instead of requesting for a new one? I found the .entryPoints method in the google documentation but cannot figure out how to implement it to save my life.

    • Brian says:

      Yeah, you can add existing meetings, but you have to use the 10-character Meet ID (aaa-bbbb-ccc)…you can’t use a nicknamed Meet, unfortunately.

      The conferenceData portion of the payload changes from createRequest, which generates all the necessary information asynchronously, to defining a conferenceId and conferenceSolution object.

      
      // ... start, end, etc
      conferenceData": {
              "conferenceId": "aaa-bbbb-ccc", // existing Meet ID you want to keep using
            "conferenceSolution": {
              "key": {
                "type": "hangoutsMeet",
                "name": "Your Meet Title"
              }
            },
          "entryPoints": [ // An array of objects. It accepts one video type.
            {
              "entryPointType": "video",
              "label": "meet.google.com/aaa-bbbb-ccc",
              "uri": "https://meet.google.com/aaa-bbbb-ccc"
            }
          ],
          "conferenceId": "aaa-bbbb-ccc",
        },
      // summary, description, etc
      

      This will post a calendar event with your specified Meet.

  2. Kenneth Griswold says:

    Hi,
    Thanks for this. I have generating events working. Now, I want to pull the Google Meet conference details including url and dial in number/pin from the generated events using script. Is that possible?

    Thanks!

    • Brian says:

      The response object from the creation call has all of those details. You can add a block to handle that data to write back to the sheet, send an email, etc…

      What are you trying to do with it if its attached to the calendar already?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.