Open In App

How to create a meeting with zoom API in Python?

In this article, we will discuss how to create a zoom meeting with the help of zoom API using Python. To integrate zoom API, we need to create it. Follow the given steps for the same:



Before you start, you need to install these two python packages:



Here we are going to create two functions: the first function generateToken() will generate a JWT token, so we can authenticate and later use this token in the second function createMeeting(), which will make a POST request to create the meeting.

Since we are creating a meeting, we would need to send some extra information to the zoom API like meeting title and start time, etc., that’s why here we have created some JSON data with the name meetingdetails.




import jwt
import requests
import json
from time import time
 
 
# Enter your API key and your API secret
API_KEY = 'Your API key'
API_SEC = 'Your API secret'
 
# create a function to generate a token
# using the pyjwt library
 
 
def generateToken():
    token = jwt.encode(
 
        # Create a payload of the token containing
        # API Key & expiration time
        {'iss': API_KEY, 'exp': time() + 5000},
 
        # Secret used to generate token signature
        API_SEC,
 
        # Specify the hashing alg
        algorithm='HS256'
    )
    return token.decode('utf-8')
 
 
# create json data for post requests
meetingdetails = {"topic": "The title of your zoom meeting",
                  "type": 2,
                  "start_time": "2019-06-14T10: 21: 57",
                  "duration": "45",
                  "timezone": "Europe/Madrid",
                  "agenda": "test",
 
                  "recurrence": {"type": 1,
                                 "repeat_interval": 1
                                 },
                  "settings": {"host_video": "true",
                               "participant_video": "true",
                               "join_before_host": "False",
                               "mute_upon_entry": "False",
                               "watermark": "true",
                               "audio": "voip",
                               "auto_recording": "cloud"
                               }
                  }
 
# send a request with headers including
# a token and meeting details
 
 
def createMeeting():
    headers = {'authorization': 'Bearer ' + generateToken(),
               'content-type': 'application/json'}
    r = requests.post(
        headers=headers, data=json.dumps(meetingdetails))
 
    print("\n creating zoom meeting ... \n")
    # print(r.text)
    # converting the output into json and extracting the details
    y = json.loads(r.text)
    join_URL = y["join_url"]
    meetingPassword = y["password"]
 
    print(
        f'\n here is your zoom meeting link {join_URL} and your \
        password: "{meetingPassword}"\n')
 
 
# run the create meeting function
createMeeting()

Output:

creating zoom meeting …  

here is your zoom meeting link https://us04web.zoom.us/j/73327261770?pwd=aUxvYUIwNjZEa2oxOXY5VEM0YzlaUT09 and your password: “WS0wwu”

Code Explanation:

  1. The code first creates a token object, which contains the following information: token = jwt.encode( # Create a payload of the token containing API Key & expiration time {‘iss’: API_KEY, ‘exp’: time() + 5000}, # Secret used to generate token signature API_SEC, # Specify the hashing alg algorithm=’HS256′ ) The first two arguments are the string representation of the token (in this case, an encoded JSON object).
  2. The third argument is the secret used to generate the signature for the token.
  3. Finally, you specify how to hash the data in this object using an algorithm called HS256.
  4. This algorithm uses 256-bit encryption and is considered secure.
  5. The next line of code generates a random number and stores it in a variable named RND .
  6. This number will be used as part of the cryptographic key that’s used to create and sign tokens with JWT.
  7. Next, you create an instance of jwt , specifying your API key and secret as well as your desired hashing algorithm ( HS256 ).
  8. Then you call encode on your token object, passing in RND as one of its arguments.
  9. This function will
  10. The code will generate a token that can be used to authenticate requests to the API.
  11. The generated token will have the following properties: The iss property will contain the API key, while the exp property will hold the time until the token expires.
  12. The secret used to generate the signature for the token is also specified in this snippet.
  13. This value is obtained from the API secret key and must be provided as an argument when calling jwt.encode() .
  14. The hashing algorithm used to create the token is also specified in this code block.
  15. This value can be either ‘HS256’ or ‘HS512’.
  16. The code in this example contains the following: topic: The title of your zoom meeting type: 2 (meeting) start_time: 2019-06-14T10: 21: 57 duration: 45 minutes timezone: Europe/Madrid agenda: test recurrence type : 1 (daily) settings : host_video : true, participant_video : true, join_before_host : False, mute_upon_entry : False, watermark : true, audio : voip, auto_recording : cloud
  17. The code creates a JSON data structure that represents the meeting details.
  18. The key values are as follows: topic – The title of your zoom meeting type – 2 (meeting type) start_time – 2019-06-14T10: 21: 57 duration – 45 minutes timezone – Europe/Madrid agenda – test recurrence – {type: 1, repeat_interval: 1} settings – {host_video: “true”, participant_video: “true”, join_before_host: “False”, mute_upon_entry: “False”, watermark: “true”, audio: “voip”, auto_recording: “cloud”}
  19. The code starts by creating a request object, which will be used to send the HTTP POST request to the Zoom API.
  20. The first parameter is the URL of the Zoom meeting details page (https://api.zoom.us/v2/users/me/meetings).
  21. The second parameter is a set of headers that will be sent with the request (in this case, only one header: authorization).
  22. The next line of code sets up the content type for the POST request.
  23. This tells Zoom what kind of data is being sent along with the request.
  24. In this case, it’s an application/json payload containing meeting details (in JSON format).
  25. Finally, on lines 9-10, the code creates and sends the HTTP POST request to Zoom’s meeting details page.
  26. If everything goes according to plan, Zoom should return a response object containing information about the requested meeting (in this case, a list of attendees and their corresponding IDs).
  27. The code will send a request to the Zoom API with the header authorization set to the token generated earlier.
  28. The content-type of the response will be set to application/json, which is the standard format for JSON data.
  29. Finally, the meetingdetails object will be sent as the data parameter.

Article Tags :