Microsoft Graph Client C#: Missing DeltaToken and SkipToken

822 views Asked by At

I'm using GraphServiceClient V5.7.0 to sync personal contacts with my desktop application and would like to use delta to get only changes since my last sync.

In Microsoft's example it say to use SkipToken or DeltaToken in the QueryParameters (i linked user example becauese there is no example for personal contacts)

var result = await graphClient.Users.Delta.GetAsync((requestConfiguration) =>
{
    requestConfiguration.QueryParameters.Skiptoken = "oEBwdSP6uehIAxQOWq_3Ksh_TLol6KIm3stvdc6hGhZRi1hQ7Spe__dpvm3U4zReE4CYXC2zOtaKdi7KHlUtC2CbRiBIUwOxPKLa";
});

But QueryParameters doesn't have SkipToken parameter. I found this GitHub's issue, and they suggest to use

requestConfiguration.QueryParameters.Add("%24skiptoken", "skiptoken");

But QueryParameters doesn't have even Add method.

Is there any solution to complete the request without waiting for the correction?

2

There are 2 answers

1
user2250152 On BEST ANSWER

Based on the workaround you need to create RequestInformation and when you access QueryParameters on RequestInformation you should be able to call Add method.

When using GetAsync((requestConfiguration) or ToGetRequestInformation((requestConfiguration) the type of requestConfiguration.QueryParameters is DeltaRequestBuilderGetQueryParameters and it has no method to add custom query parameter.

var requestInformation = graphClient.Users.Delta.ToGetRequestInformation((requestConfiguration) =>
        {
            requestConfiguration.QueryParameters.Count = true;
        });
requestInformation.UrlTemplate = requestInformation.UrlTemplate.Insert(requestInformation.UrlTemplate.Length - 1, ",%24skiptoken,%24deltatoken,changeType");
requestInformation.QueryParameters.Add("%24skiptoken", "skiptoken");
requestInformation.QueryParameters.Add("changeType", "created");
requestInformation.QueryParameters.Add("%24deltatoken", "deltatoken");

var result = await graphClient.RequestAdapter.SendAsync(requestInformation, UserCollectionResponse.CreateFromDiscriminatorValue);
0
Fabian On

I encountered exactly the same problem, and the answer by user2250152 was not helpful for me, but I managed to solve it eventually. My solution was the following:

string skipToken = result.OdataNextLink[(result.OdataNextLink.IndexOf("$skiptoken=") + "$skiptoken=".Length)..];

Microsoft.Kiota.Abstractions.RequestInformation requestInformation = graphClient
                        .Drives[driveId]
                        .Items[itemId]
                        .Children
                        .ToGetRequestInformation();

requestInformation.UrlTemplate = requestInformation.UrlTemplate[..^1] + ",%24skiptoken" + requestInformation.UrlTemplate[^1];

requestInformation.QueryParameters.Add("%24skiptoken", skipToken);

DriveItemCollectionResponse nextResult = await graphClient
                        .RequestAdapter
                        .SendAsync(requestInformation, DriveItemCollectionResponse.CreateFromDiscriminatorValue);