Graph Delta information after second call in SDK/API

APIPointNewbie 146 Reputation points
2021-12-29T14:17:08.687+00:00

I want to know the last modified files with Delta (with C# in ASP.Net Core) in Microsoft Graph, I have realized this as follows:

 private async Task<IDriveItemDeltaCollectionPage> GetFiles(GraphServiceClient graphClient, object deltaLink)
 {
     IDriveItemDeltaCollectionPage page;
     if (lastPage == null)
     {
         var queryOptions = new List<QueryOption>() {
         new QueryOption("token", "latest"),
         };
         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 ?

But without new QueryOption("token", "latest"), I always get the complete content which I don't want either.

About help I would be very happy.

Greetings :-)

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,592 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,248 questions
0 comments No comments
{count} votes

Accepted answer
  1. ShivaniRai-MSFT 2,726 Reputation points
    2022-01-19T17:30:16.577+00:00

    Hi @APIPointNewbie ,

    As mentioned in this Microsoft Document on Delta queries, the initial request to the delta query function (no delta or skip token) will return the resources that currently exist in the collection that means if you are trying to maintain a full local representation of the items in a folder or a drive, you must use delta for the initial enumeration.

    Drive items that have been created and deleted prior to the initial delta query won't be returned. So, that is why you are getting the complete content in the initial request as this is how delta query works.
    The final page of items will include the @odata.deltaLink property, which provides the URL that can be used later to retrieve changes since the current set of items.

    And as you already know about this, using this new QueryOption("token", "latest") you can fetch delta token directly and can use it in future to fetch any changes in your drive.

    Reference Docs:
    https://learn.microsoft.com/en-us/graph/delta-query-overview
    https://learn.microsoft.com/en-us/graph/api/driveitem-delta?view=graph-rest-1.0&tabs=http#example-3-retrieving-the-current-deltalink

    Hope this will clarify your query.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful