I have not been able to find a method of using the graph to subscribe to all users changes, it looks like it is not possible.
So I set about subscribing to everyone individually, ideally I would like all updates from calendars, email and contacts eventually, but I started with calendars.
The code works perfectly with just my user, however when I try to subscribe for everyone (around 300 users), I hit a hard a limit, at seven subscriptions, as in further requests fail with a generic Bad Request
status.
In the official docs https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/webhooks it says:
Limitations Certain limits apply and may generate errors when exceeded:
1) Maximum subscription quotas
- Per App: 50,000 total subscriptions
- Per Tenant: 35 total subscriptions across all apps
- Per App and Tenant combination: 7 total subscriptions
It seems that Tenant refers to an actual active directory, so we are limited to 7 per app, or 35 in total.
There is zero chance of splitting users into multi Active Directories of domains, even juggling multiple apps to do the same thing seems strange, these limits make no sense at all to me.
Is there any way to increase these tiny limits?
I am subscribing to users/$email/events
so I post to https://graph.microsoft.com/v1.0/subscriptions
{
"changeType": "created,updated,deleted",
"notificationUrl": "https://webhooks.mydomain.com/my/endpoint",
"resource": "users/$email/events",
"expirationDateTime":"2018-05-12T16:00:00.9356913Z",
"clientState": "my-super-secret-identifier"
}
And it works great, as long as I want <=7 subscriptions. I also subscribed to, the root /users to see if that would give me all changes, which meant I could then only subscribe to 6 individual calendars.
I am using the official PHP library, but presume/hope that doesn't matter.
As Jason said in the comments, the restriction in the question should only have applied to Active Directory Resources, not on the user level, the docs have now been changed:
Whether it was a case of the power of suggestion causing the issue, or some transient bug somewhere I don't know, but the Gods of the Interwebs have smiled on me, and my code works now; even though I didn't change it.
Maybe removing and adding permissions helped in my case? Not sure.
At least the docs are right now.
I'm going to add an answer (because I can't comment, but this would have helped me to know).
The "AD" in the documentation "Azure AD" means "Active Directory" which seems to be something a little different than just the Graph API. In any case, I was able to set up 62 subscriptions, to the same calendar, on the same user, and promptly got 62 notifications after making a change to the calendar. I wanted to test the limits, but I figure 50,000 is a bit much to sit and click the button in the graph API explorer, so I stopped at 62. In any case, it's possible to add more than 7 and more than 35 subscriptions.
The account in question was registered by a company, however apparently not Active directory... Or the documentation is just wrong or being wrongly interpreted. In these cases it's hard to tell sometimes :)