The following code does not throw exceptions. However, on occasion I have to run it a few times in a row for it to return a list of subscriptions I know are there.
This is running as a confidential client.
I am subscribing to Calendar Events
static async Task<GraphServiceSubscriptionsCollectionPage> ListSubscriptions(GraphServiceClient graphClient)
{
GraphServiceSubscriptionsCollectionPage subscriptions = null;
try
{
subscriptions = (GraphServiceSubscriptionsCollectionPage)await graphClient.Subscriptions.Request().GetAsync();
}
catch(Exception e)
{
System.Diagnostics.Debug.WriteLine(e);
}
return subscriptions;
}
Based on this and this it looks like that subscriptions are internally stored in CosmosDB and the endpoint GET /subscriptions
has some issue with getting correct results from CosmosDB.
Even if the first page doesn't return any data check the NextPageRequest
and make request to get next page.
var subscriptions = new List<Subscription>();
try
{
var subscription = await client.Subscriptions.Request().GetAsync();
subscriptions.AddRange(subscription.CurrentPage);
while (subscription.NextPageRequest != null)
{
subscription = await subscription.NextPageRequest.GetAsync();
subscriptions.AddRange(subscription.CurrentPage);
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e);
}