I'm trying to create a Microsoft Teams online meeting using the Microsoft Graph API in Python. My Azure AD app has delegated permission OnlineMeetings.ReadWrite, and I'm using the /me/onlineMeetings endpoint to create the meeting. However, I keep encountering the following error:
Error: 400, {"error":{"code":"General","message":"Request payload cannot be null.","innerError":{"request-id":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","date":"2025-01-28T06:03:29","client-request-id":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"}}}
Here’s my Python code:
import requests
# Azure AD App credentials
CLIENT_ID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
TENANT_ID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
CLIENT_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTHORITY = f"https://login.microsoftonline.com/{TENANT_ID}"
# User credentials
USERNAME = "XXXX@example.com"
PASSWORD = "password"
# Authentication
def get_access_token():
data = {
"grant_type": "password",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"scope": "https://graph.microsoft.com/.default",
"username": USERNAME,
"password": PASSWORD,
}
response = requests.post(f"{AUTHORITY}/oauth2/v2.0/token", data=data)
if response.status_code == 200:
return response.json().get("access_token")
else:
raise Exception(f"Error: {response.status_code}, {response.text}")
def create_teams_meeting():
try:
access_token = get_access_token()
# Prepare the meeting data
meeting_data = {
"startDateTime": "2025-01-29T10:00:00",
"endDateTime": "2025-01-29T11:00:00",
"subject": "Random Meeting",
}
# Send the request to create the meeting
headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"}
response = requests.post(
"https://graph.microsoft.com/v1.0/me/onlineMeetings",
headers=headers,
json=meeting_data
)
if response.status_code == 201:
meeting = response.json()
return meeting["joinUrl"]
else:
raise Exception(f"Error creating meeting: {response.status_code}, {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
return None
What I’ve Checked:
The startDateTime and endDateTime fields should be in the correct ISO 8601 format, including the time zone offset.
For example:
"startDateTime": "2025-01-29T10:00:00Z",
"endDateTime": "2025-01-29T11:00:00Z"