能否通过O365 Webhook订阅所有用户日历或邮箱的技术咨询
Hey there, great question! Let’s cut straight to the chase based on the current state of Microsoft Graph:
- Direct global subscriptions for all users' calendars or mailboxes are not supported right now
As you’ve already noticed, Microsoft’s previous response mentioned they’re working on supporting this scenario, but there’s no publicly available feature for it yet. You can’t skip creating individual subscriptions per user—you’ll need to set up a subscription for each user’s calendar or mailbox separately.
Workaround: Batch Create Subscriptions Using Application Permissions
If your app needs to monitor events across all users, here’s the practical way to do it today:
Get the right application permissions
First, make sure your app has the appropriate admin-consented application permissions. For calendars, useCalendars.ReadWrite.All; for mailboxes, useMail.ReadWrite.All. These permissions let your app access all users’ data without needing each user to sign in individually.Fetch all users in your tenant
Use the Graph API to retrieve the full list of users with:GET /usersYou can paginate through results if you have a large number of users.
Create a subscription for each user
Loop through each user ID from the previous step and create a subscription for their calendar or mailbox. For example, a calendar subscription request looks like this:POST /subscriptions Content-Type: application/json { "changeType": "created,updated,deleted", "notificationUrl": "https://your-app.com/webhook-endpoint", "resource": "/users/{userId}/calendars", "expirationDateTime": "2024-05-20T18:23:45.9356913Z", "clientState": "your-secret-client-state" }Adjust the
changeTypeandresourceparameters based on whether you’re targeting mailboxes (/users/{userId}/mailFolders/inbox/messages) or calendars.Handle subscription renewal
Subscriptions have a limited lifespan (currently up to 30 days for most resources). You’ll need to implement logic to renew each subscription before it expires using thePATCH /subscriptions/{subscriptionId}endpoint.Watch out for throttling
Microsoft Graph has rate limits, so avoid creating hundreds of subscriptions in rapid succession. Add delays between requests or use a queue-based approach to handle bulk creation without hitting throttling limits.
Key Notes
- While this workaround is tedious, it’s the only supported method right now. Keep an eye on the Microsoft Graph documentation for updates—if they release a global subscription feature, it’ll be announced there.
- Make sure your webhook endpoint can handle notifications from multiple subscriptions, and validate each notification’s
clientStateto prevent spoofing.
内容的提问来源于stack exchange,提问作者user1477388

