Published: 2020-05-28 10:38 |
Category: Code | Tags: automation, code, google apps script, google meet, programming
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.
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.
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
and object.This will post a calendar event with your specified Meet.
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?
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?
Is this just for adding a specific Meet code to an event that has NO meet data at all or has an existing Meet code and you’re just changing it? I have a big script using this code already but haven’t cracked the nut on how to change codes.
Hi Brian,
I’m also interested in grabbing the hangoutLink, which is easily done from the response, and what I’m wanting to do is patch/update the original description to append the hangoutLink / URL to the description. This is simply so that the URL is available through embedded views of the calendar. I’m struggling to find good docs on using Patch through Apps Scripts though; any pointers?
Paul,
In the example in the post, you can get the response in a
block that allows you to update more information. I would do something like this:Note that I haven’t tested this, so make sure not to overwrite something important.
Many thanks Brian – that worked perfectly!