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 Calendar
object 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.