[Python] Event created successfully via Microsoft 365 API with application permissions, but...

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    import requests
    import msal

    # Microsoft Azure AD Credentials
    CLIENT_ID = "*************"
    CLIENT_SECRET = "**************"
    TENANT_ID = "****************"
    GRAPH_API_URL = "https://graph.microsoft.com/v1.0"

    # Get Access Token using MSAL
    app = msal.ConfidentialClientApplication(CLIENT_ID, authority=f"https://login.microsoftonline.com/{TENANT_ID}", client_credential=CLIENT_SECRET)
    token_response = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])

    if "access_token" not in token_response:
    print("❌ Failed to get access token:", token_response)
    exit()

    access_token = token_response["access_token"]
    headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
    }

    # Define Meeting Data
    meeting_data = {
    "subject": "Team Meeting",
    "body": {
    "contentType": "HTML",
    "content": "This is a scheduled Microsoft Teams meeting."
    },
    "start": {
    "dateTime": "2025-02-05T12:00:00",
    "timeZone": "UTC"
    },
    "end": {
    "dateTime": "2025-02-05T13:00:00",
    "timeZone": "UTC"
    },
    "location": {
    "displayName": "Microsoft Teams"
    },
    "attendees": [
    {
    "emailAddress": {
    "address": "kannan@echoapps360.com",
    "name": "Kannan M"
    },
    "type": "required"
    }
    ],
    "isOnlineMeeting": True,
    "onlineMeetingProvider": "teamsForBusiness"
    }

    USER_ID = "userid@usersid.com"

    # Create the Meeting Event
    response = requests.post(f"{GRAPH_API_URL}/users/{USER_ID}/events", headers=headers, json=meeting_data)

    # Print Response
    if response.status_code == 201:
    print("✅ Meeting created successfully!")
    print(response.json())
    else:
    print("❌ Failed to create meeting:", response.json())



    The event was created successfully, but the attendees did not receive the email. When we checked, it showed: 'Delivery has failed to these recipients or groups: userid@userid.com Your message wasn’t delivered because the recipient’s email provider rejected it. Remote server returned '550 5.7.708 Service unavailable. Access denied, traffic not accepted from this IP. For more information please go to http://go.microsoft.com/fwlink/?LinkId=526653 AS(7230)

    i already enabled the permissions calendars.ReadWrite, OnlineMeetings.ReadWrite but did not send the email

    I try that code event is created but mail not get attendees

    Continue reading...

Compartilhe esta Página