Zoom Meeting is Not Generating Using Python

In a python (backend) and javascript (frontend) based application I was using jwt app to generate zoom meeting. So as jwt is deprecated now I want to implement Server-to-Server OAuth/ OAuth app to create zoom meeting.

Please check the below code and let me know where is the issue that not working and which type app should be make .

import requests
import json
import base64

# The Zoom client ID and client secret
client_id = "CLIENT ID"
client_secret = "CLIENT SECRET"

# The URL of the Zoom OAuth token endpoint
url = "https://zoom.us/oauth/token"

# The request body
payload = {
    "grant_type": "client_credentials"
}

# The request headers
headers = {
    "Authorization": "Basic " + base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()
}

# Make the request to the Zoom OAuth token endpoint
response = requests.post(url, headers=headers, data=payload)

# Check the response status code
if response.status_code == 200:
    # The request was successful, get the access token
    access_token = response.json()["access_token"]
    print("access token is", access_token)
else:
    # The request failed, raise an exception
    raise Exception("Failed to get access token")

# The topic of the meeting
topic = "My Meeting"

# The duration of the meeting in minutes
duration = 30

# The start time of the meeting in ISO 8601 format
start_time = "2023-09-10T13:00:00Z"

# The URL of the Zoom API endpoint to create a meeting
url = "https://api.zoom.us/v2/users/me/meetings"

# The request headers
headers = {
    "Authorization": f"Bearer {access_token}"
}

# The request body
payload = {
    "topic": topic,
    "duration": duration,
    "start_time": start_time
}

# Make the request to create the meeting
response = requests.post(url, headers=headers, data=payload)

# Check the response status code
if response.status_code == 200:
    # The request was successful, get the meeting ID
    meeting_id = response.json()["id"]
    print(f"Meeting created successfully, meeting ID: {meeting_id}")
else:
    # The request failed, raise an exception
    raise Exception("Failed to create meeting")

This code is working for creating token but at the end it’s not creating the meeting link . Error 400. If anyone have solved it please share. Advance thanks.

1 Like

Try using ‘json=payload’ instead of ‘data=payload’ in the request under the ‘# Make the request to create the meeting’

.

thanks for your reply, I tried this still not working :frowning:
response = requests.post(url, headers=headers, json=payload)

@shohagcsediu ,

the grant_type and account_type should be in the URL.

Here’s a partial sample to get the access_token from S2S OAuth

import requests
import base64
import os
from dotenv import load_dotenv


# Load environment variables from .env file, this will try to load these values from your .env file
load_dotenv()

# Your .env file should look something like this

#CLIENT_ID='xxxxxxxxxx'
#CLIENT_SECRET='yyyyyyyyyyyyy'
#ACCOUNT_ID='zzzzzzzzzzzz'


# Access the environment variables
client_secret = os.getenv("CLIENT_SECRET")
client_id = os.getenv("CLIENT_ID")
account_id = os.getenv("ACCOUNT_ID")
oauth_url = 'https://zoom.us/oauth/token?grant_type=account_credentials&account_id='+account_id  # Replace with your OAuth endpoint URL

def get_access_token():
    try:
        # Create the Basic Authentication header
        auth_header = f'Basic {base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()}'

        # Define the headers for the OAuth request
        headers = {
            'Authorization': auth_header,
        }

        # Make the OAuth request
        response = requests.post(oauth_url, headers=headers)

        # Check if the request was successful (status code 200)
        if response.status_code == 200:
            # Parse the JSON response to get the access token
            oauth_response = response.json()
            access_token = oauth_response.get('access_token')
            return access_token
        else:
            print(f'OAuth Request Failed with Status Code: {response.status_code}')
            print(response.text)
            return None
    except Exception as e:
        print(f'An error occurred: {str(e)}')
        return None


1 Like

This may be a long shot but it may be order specific, Try putting in order of duration, start time, topic.

This topic was automatically closed 368 days after the last reply. New replies are no longer allowed.