In part 1 of this blog, we understood how to register our application with Zoom to get API Key and Secret Key to be used in programmatic interaction of your application with Zoom services. Now, we will understand how to create, update and delete a zoom meeting.
In every interaction of our application with Zoom services, we have to send JWT token for authentication and authorization to Zoom service. This JWT token is created by using API Key and Secret key that we have received during registration of our application with zoom market place. I am creating this JWT token in a middleware function in auth.js file
I have kept API Key and Secret Key in a config file named as config.js as follows:
const SendResponse = require("../utils/sendresponse");
const axios = require('axios');
const sendResponse = new SendResponse();
//Health check function
function healthCheck(req, res, next) {
try {
sendResponse.setSuccess(200, 'Success', "API is running");
return sendResponse.send(res);
} catch (error) {
console.log(error);
}
}
//Get user detail of host user
async function zoomuserInfo(req, res, next) {
try {
const token = req.body.token;
const email = 'abc@xyz.com'; //host email id
const result = await axios.get("https://api.zoom.us/v2/users/" + email, {
headers: {
'Authorization': 'Bearer ' + token,
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
}
});
sendResponse.setSuccess(200, 'Success', result.data);
return sendResponse.send(res);
} catch (error) {
console.log(error.message);
next();
}
}
//Create a zoom meeting
async function createZoomMeeting(req, res, next) {
try {
const token = req.body.token;
const email = 'abc@xyz.com'; //host email id;
const result = await axios.post("https://api.zoom.us/v2/users/" + email + "/meetings", {
"topic": "Discussion about today's Demo",
"type": 2,
"start_time": "2021-03-18T17:00:00",
"duration": 20,
"timezone": "India",
"password": "1234567",
"agenda": "We will discuss about Today's Demo process",
"settings": {
"host_video": true,
"participant_video": true,
"cn_meeting": false,
"in_meeting": true,
"join_before_host": false,
"mute_upon_entry": false,
"watermark": false,
"use_pmi": false,
"approval_type": 2,
"audio": "both",
"auto_recording": "local",
"enforce_login": false,
"registrants_email_notification": false,
"waiting_room": true,
"allow_multiple_devices": true
}
}, {
headers: {
'Authorization': 'Bearer ' + token,
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
}
});
sendResponse.setSuccess(200, 'Success', result.data);
return sendResponse.send(res);
} catch (error) {
console.log(error.message);
next();
}
}
//Update a zoom meeting
async function updateMeeting(req, res, next) {
try {
const token = req.body.token;
const meetingId = req.body.meetingId;
const result = await axios.patch("https://api.zoom.us/v2/meetings/" + meetingId, {
"topic": "UPDATE: Discussion about today's Demo",
"type": 2,
"start_time": "2021-03-18T17:00:00",
"duration": 20,
"timezone": "India",
"password": "1234567",
"agenda": "Discussion about how to update zoome meeting programatically",
"settings": {
"host_video": true,
"participant_video": true,
"cn_meeting": false,
"in_meeting": true,
"join_before_host": false,
"mute_upon_entry": false,
"watermark": false,
"use_pmi": false,
"approval_type": 2,
"audio": "both",
"auto_recording": "local",
"enforce_login": false,
"registrants_email_notification": false,
"waiting_room": true,
"allow_multiple_devices": true
}
}, {
headers: {
'Authorization': 'Bearer ' + token,
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
}
});
sendResponse.setSuccess(200, 'Success', result.data);
return sendResponse.send(res);
} catch (error) {
console.log(error.message);
next();
}
}
//Delete a zoom meeting
async function deleteMeeting(req, res, next) {
try {
const token = req.body.token;
const meetingId = req.body.meetingId;
const result = await axios.delete("https://api.zoom.us/v2/meetings/" + meetingId, {
headers: {
'Authorization': 'Bearer ' + token,
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
}
});
sendResponse.setSuccess(200, 'Success', result.data);
return sendResponse.send(res);
} catch (error) {
console.log(error.message);
next();
}
}
//Get details of a zoom meeting
async function getMeeting(req, res, next) {
try {
const token = req.body.token;
const meetingId = req.body.meetingId;
const result = await axios.get("https://api.zoom.us/v2/meetings/" + meetingId, {
headers: {
'Authorization': 'Bearer ' + token,
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
}
});
sendResponse.setSuccess(200, 'Success', result.data);
return sendResponse.send(res);
} catch (error) {
console.log(error.message);
next();
}
}
module.exports = {
healthCheck, zoomuserInfo, createZoomMeeting, getMeeting,
updateMeeting, deleteMeeting
}
Thus, we can trigger different services of zoom to perform several operation. We can create recurance meeting too programmatically. We can follow below link to get more information about several zoom services available for programmatica use.
how can I add registrants_email_notification :false here
ReplyDeleteI haven't tried with this email notification flag in my poc. Once I will try, I will update you. By that time, once you try to go through the discussion on zoom dev forum(link given below). You may get some idea. https://devforum.zoom.us/t/registrants-confirmation-email-vs-registrants-email-notification/12113/6
Deletecan you please provide source code?
ReplyDeleteRight now I dont have the source code. I had made the POC and forgot to commit in github.
ReplyDelete