The following blog post is a continuation from the connecting to the Zoom API via OAuth one here (please familiarise yourself with it before proceeding). In addition to this post for getting your Zoom meeting settings via the API.
We have already demonstrated successfully getting an Access Token for authentication from Zoom OAuth and then getting our Zoom meeting settings. Now that we have those items we can go ahead and create a Zoom meeting, as we will do here. You may find this page on creating a meeting via the API useful.
Zoom meeting details in a Google Sheet |
Again we have a Google Sheet with the Apps Script linked to it. We have various details of the meeting that can be entered into the Sheet as well as some of the meeting settings we captured in the last blog post. The Apps Script is configured to pick-up these individual pieces of information to help show how they are being used.
One of the more difficult pieces of information to handle is the start date/time which needs to be formatted as ISO 8601 Extended format: yyyy-mm-ddThh:mm:ss.000
// get and format the Start date/time
var startDate_Time = ss.getRange(4, 2).getValue();
var startDate = new Date(startDate_Time);
var startHour = startDate.getUTCHours();
var startMin = startDate.getUTCMinutes();
var formattedStartDate = Utilities.formatDate(startDate, timeZone, "yyyy-MM-dd");
// recombine above parts to created suitably formatted date
var startTime = formattedStartDate + 'T' + startHour + ':' + startMin + ':' + '00' + '.000';
Where boolean values are required ('true', 'false') we need to convert them from text on the Google Sheet:
// get the Host video setting and convert to Boolean
var hostVideo = ss.getRange(7, 2).getValue();
if (hostVideo == "True") {
hostVideo = true;
}
else {
hostVideo = false;
}
Next we combine all of the values into a payload for the API:
var payload = {
"topic": topic,
"type": 2,
"start_time": startTime,
"timezone": timeZone,
"duration": duration,
"agenda": agenda,
"password": password,
"settings": {
"host_video": hostVideo,
"participant_video": participantsVideo,
"join_before_host": beforeHost,
"mute_upon_entry": entryMute,
"waiting_room": waitingRoom
}
};
We can then set the HTTP headers and include the Access Token as we get ready to make the API call:
// set the HTTP headers and include the Access Token for authentication
var options = {
'method': "post",
'contentType': "application/json",
'headers': {
"Authorization": "Bearer " + accessToken
},
'payload': JSON.stringify(payload)
};
Now we can make the call to the User Meetings API as specified by the Zoom documentation:
// make Zoom API call
var response = UrlFetchApp.fetch("https://api.zoom.us/v2/users/me/meetings", options);
Lots of information is returned so this script both puts all of that into the Google Sheet so you can see what details are available for accessing and specifically extracts the meeting ID and join URL:
// gather data from response
var resultText = response.getContentText();
var resultObj = JSON.parse(resultText);
// specifically get meeting ID and join URL
var meetingID = resultObj['id'];
saveIntoSheet(joinURL, 14);
File Download
Download the Create a Zoom meeting via the API here. Please use 'File' > 'Make a copy' for your own version. This is a Google Sheet with the Apps Script bound to it. You will need to deploy it as a Web App and create your own Zoom OAuth App.
Hello, Mr. Bainbridge.
ReplyDeleteGreat blog and article.
I'm new to the apps-script world so thanks in advance and i'll keep going :). just one thing, in the first paragraph the link to the 'connecting to the Zoom API via OAuth one here' leads to blogger.com so after using the search tool i've found the other article. Thanks again. :)
Hi
DeleteThank you for your feedback and for highlighting that broken link - I have now fixed it.
Kind regards
Phil
Thanks for the examples. I worked thought the last Oauth post, and got it working.
ReplyDeleteThese scripts are bound a particular sheet. To attach to a new sheet, as I understand it, I would have to copy/paste the code into a new sheet.
I guess what I want is an add-on that would have access to the sheet (for meeting info) and to Zoom to create the meetings.
But it's unclear how an add-on could also be deployed as an WebApp to allow for the OAuth flow to complete.
Hi Bob
DeleteGlad you got it working.
Yes these are bound scripts. An alternative is to make a copy of the Google Sheet itself and the Apps Script code will come along with it.
I have been exploring Add-ons last week but I'm yet to figure a way to overcome the 30 second execution time-out/limit with Functions that use the Card Service. Which means for bulk processes such as this it is not possible.
Kind regards
Phil