Delta Query Using the Microsoft Graph SDK 1.4 NuGet

Viewed 1892

I am trying to set up a sample for delta query using the .NET client library (version 1.4 from https://www.nuget.org/packages/Microsoft.Graph). Doing the initial calls is smooth:

var page = await _graphClient.Users.Delta().Request().GetAsync();

while (page.NextPageRequest != null)
{
  page = await page.NextPageRequest.GetAsync();
}

Getting the deltaLink after the while is still pretty obvious:

string deltaLink = (string)page.AdditionalData["@odata.deltaLink"];

But what is the correct way to later use this deltaLink? I haven't found the obvious method / builder that would allow me to continue at a later time by using the URL (my current solution is to use code from section "Send HTTP requests with the .Net Microsoft Graph client library" at https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/overview.md and cast the thing to UserDeltaCollectionResponse - at that point I can use the normal APIs again).

2 Answers

I wrote some code to get the actual delta token string.

 Uri deltaUri = new Uri(delta.AdditionalData[deltaLinkKey].ToString());
 var queries = System.Web.HttpUtility.ParseQueryString(deltaUri.Query);
 string token = queries.Get("$deltatoken");

There is then a QueryOption object in the API that you can add to the request. So, your code from above would look something like this.

QueryOption deltaOption = new QueryOption("$deltaToken", deltaToken);
var page = await _graphClient.Users.Delta().Request(new[] { deltaOption }).GetAsync();
Related