|
| 1 | +/** |
| 2 | + * Create Zoom Meetings with Google Apps Script |
| 3 | + * |
| 4 | + * Author: Amit Agarwal |
| 5 | + |
| 6 | + * |
| 7 | + * MIT License |
| 8 | + */ |
| 9 | + |
| 10 | +const ZOOM_API_KEY = '<<your key here>>'; |
| 11 | +const ZOOM_API_SECRET = '<<your secret here>>'; |
| 12 | +const ZOOM_EMAIL = '<<your email here>>'; |
| 13 | + |
| 14 | +const getAccessToken_ = () => { |
| 15 | + const encode = (text) => Utilities.base64Encode(text).replace(/=+$/, ''); |
| 16 | + |
| 17 | + const header = { alg: 'HS256', typ: 'JWT' }; |
| 18 | + const encodedHeader = encode(JSON.stringify(header)); |
| 19 | + const claimData = { |
| 20 | + iss: ZOOM_API_KEY, |
| 21 | + exp: Date.now() + 3600, |
| 22 | + }; |
| 23 | + const encodedClaim = encode(JSON.stringify(claimData)); |
| 24 | + const toSign = `${encodedHeader}.${encodedClaim}`; |
| 25 | + const signature = encode(Utilities.computeHmacSha256Signature(toSign, ZOOM_API_SECRET)); |
| 26 | + return `${toSign}.${signature}`; |
| 27 | +}; |
| 28 | + |
| 29 | +const getZoomUserId_ = () => { |
| 30 | + const request = UrlFetchApp.fetch('https://api.zoom.us/v2/users/', { |
| 31 | + method: 'GET', |
| 32 | + contentType: 'application/json', |
| 33 | + headers: { Authorization: `Bearer ${getAccessToken_()}` }, |
| 34 | + }); |
| 35 | + const { users } = JSON.parse(request.getContentText()); |
| 36 | + const [{ id } = {}] = users.filter(({ email }) => email === ZOOM_EMAIL); |
| 37 | + return id; |
| 38 | +}; |
| 39 | + |
| 40 | +const createZoomMeeting = () => { |
| 41 | + const meetingOptions = { |
| 42 | + topic: 'Zoom Meeting created with Google Script', |
| 43 | + type: 1, |
| 44 | + start_time: '2020-07-30T10:45:00', |
| 45 | + timezone: 'America/New_York', |
| 46 | + password: 'labnol', |
| 47 | + agenda: 'Discuss the product launch', |
| 48 | + settings: { |
| 49 | + auto_recording: 'none', |
| 50 | + mute_upon_entry: true, |
| 51 | + }, |
| 52 | + }; |
| 53 | + |
| 54 | + const request = UrlFetchApp.fetch(`https://api.zoom.us/v2/users/${getZoomUserId_()}/meetings`, { |
| 55 | + method: 'POST', |
| 56 | + contentType: 'application/json', |
| 57 | + headers: { Authorization: `Bearer ${getAccessToken_()}` }, |
| 58 | + payload: JSON.stringify(meetingOptions), |
| 59 | + }); |
| 60 | + const { join_url, id } = JSON.parse(request.getContentText()); |
| 61 | + Logger.log(`Zoom meeting ${id} created`, join_url); |
| 62 | +}; |
0 commit comments