MS GRAPH API SUBSCRIBER CREATED BUT NOT SENDING NOTIFICATIONS TO SERVER
Hi, I've been trying to integrate the graph API with a current project I'm working on but for some reason after configuring the app, setting the right permissions , creating the subscription for my test team including the desired channel. Validations were passed but whenever I'm sending messages on the channel, my project isn't receiving any notifications from none of the messages. I've been searching and reading online but haven't found a solution to this.
I've also seen other questions like this but haven't seen any solution viable so I wonder what I'm doing wrong that I'm not seeing? is there any additional permission or configuration needed?
I'd truly appreciate your answers
here's my apps permissions:
here's the code I'm using for generating the subscription:
from datetime import datetime, timedelta
from msal import ConfidentialClientApplication
from msal_extensions import ConfidentialClientApplicationWithCert
from microsoft.graph import GraphClient, models
# Set your Azure AD app credentials
tenant_id = "<my_tenant_id>"
client_id = "<my_client_id>"
client_cert_path = "<path_to_my_client_certificate>"
client_cert_thumbprint = "<my_client_certificate_thumbprint>"
scopes = ["https://graph.microsoft.com/.default"]
# Create a confidential client application using a certificate
app = ConfidentialClientApplicationWithCert(
client_id,
client_cert_path,
client_cert_thumbprint,
authority=f"https://login.microsoftonline.com/{tenant_id}",
)
# Get an access token
result = app.acquire_token_for_client(scopes=scopes)
access_token = result.get("access_token")
# Initialize GraphClient with the access token
graph_client = GraphClient(
access_token,
version="v1.0"
)
# Set subscription properties
notification_url = "https://mydomain.com/api/TeamsChannelWebhook?code=9qSdFkOk2QdHo_7WYfivVoC5XD6TFtIcbS5608SmolrUAzFuQelftw=="
team_id = "<my_team_id>"
channel_id = "<my_channel_id>"
expiration_datetime = (datetime.utcnow() + timedelta(minutes=5))
# Create subscription object
subscription = models.Subscription(
change_type="created",
notification_url=notification_url,
resource=f"/teams/{team_id}/channels/{channel_id}/messages",
expiration_date_time=expiration_datetime,
client_state="SecretClientState",
latest_supported_tls_version="v1_2",
include_resource_data=False
)
try:
# Create subscription
created_subscription = graph_client.subscriptions.create(subscription)
print("Subscription created successfully:")
print(created_subscription)
except Exception as e:
print(f"Error creating subscription: {e}")