import requests import base64 import os def get_zoom_access_token(): """ Gets a short-lived OAuth access token using Server-to-Server OAuth. """ ZOOM_CLIENT_ID = os.environ['ZOOM_CLIENT_ID'] ZOOM_CLIENT_SECRET = os.environ['ZOOM_CLIENT_SECRET'] ZOOM_ACCOUNT_ID = os.environ['ZOOM_ACCOUNT_ID'] creds = f"{ZOOM_CLIENT_ID}:{ZOOM_CLIENT_SECRET}" basic_token = base64.b64encode(creds.encode()).decode() token_url = "https://zoom.us/oauth/token" headers = {"Authorization": f"Basic {basic_token}"} params = { "grant_type": "account_credentials", "account_id": ZOOM_ACCOUNT_ID, } response = requests.post(token_url, headers=headers, params=params) response.raise_for_status() return response.json()['access_token'] def create_zoom_meeting(topic: str, duration_min: int = 60): """ Uses the access token to create a Zoom meeting. """ token = get_zoom_access_token() headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json" } body = { "topic": topic, "type": 2, # scheduled meeting "start_time": None, # leave out or set in ISO format if needed "duration": duration_min, "settings": { "join_before_host": False, "waiting_room": True, "auto_recording": "cloud" } } response = requests.post( "https://api.zoom.us/v2/users/me/meetings", headers=headers, json=body ) if not response.ok: print("Zoom meeting creation failed!") print(" URL:", response.url) print(" Payload:", body) print(" Status:", response.status_code) print(" Body :", response.text) response.raise_for_status() return response.json() meeting = create_zoom_meeting("Test Meeting") print(meeting["join_url"])