Search code examples
c#microsoft-graph-apimicrosoft-graph-sdks

Microsoft Graph Delta information only after second call


I want to know the last modified files with Delta in Microsoft Graph, I have realized this as follows:

 //...
 private static object DeltaLink = null;
 private static IDriveItemDeltaCollectionPage lastPage = null;
 private async Task<IDriveItemDeltaCollectionPage> GetFiles(GraphServiceClient graphClient, object deltaLink)
 {
     IDriveItemDeltaCollectionPage page;
     if (lastPage == null)
     {
         var queryOptions = new List<QueryOption>() {
         new QueryOption("token", "latest"),
         new QueryOption("$select", "name,id")
         };
         page = await graphClient.Drives["{Drive-Id}"]
                                 .Items["{Folder-Id}"]
                                 .Delta()
                                 .Request(queryOptions)
                                 .GetAsync();
     }
     else
     {
         lastPage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
         page = await lastPage.NextPageRequest.GetAsync();
     }
     lastPage = page;
      
     return page;
 }

The problem is that I get the information about the file changes only after the second call of Delta. But how do I get it that I get the information already at the first call ?


Solution

  • That's because of token=latest returns empty response with latest delta token in the first call and then you need to make the second call to get the latest changes.

    This behavior is by design.

    Resources:

    Use delta query

    driveItem delta function parameters