Home > front end >  Never receiving "@odata.nextLink" in Azure Active Directory Graph API Delta call
Never receiving "@odata.nextLink" in Azure Active Directory Graph API Delta call

Time:01-06

I'm trying to get the differences in the groups of my Azure Active Directory with C#. I need to know when users are deleted or added. I have used the following URL; enter image description here

CodePudding user response:

You can read @odata.nextLink and @odata.deltaLink form AdditionalData property

delta.AdditionalData.TryGetValue("@odata.deltaLink", out var deltaLink)
delta.AdditionalData.TryGetValue("@odata.nextLink ", out var nextLink)

Just a tip:

When you call

var deltaPage = await graphServiceClient.Groups
    .Delta().Request().Select("displayName,description,members")
    .GetAsync();

the type of the result is IGroupDeltaCollectionPage and you can iterate all pages to get all groups in the code

var deltaPage = await graphServiceClient.Groups
    .Delta().Request().Select("displayName,description,members")
    .GetAsync();

deltaPage.AdditionalData.TryGetValue("@odata.deltaLink", out var deltaLink)

var groups = new List<Group>();

groups.AddRange(deltaPage.CurrentPage);
while (deltaPage.NextPageRequest != null)
{
    deltaPage = await deltaPage.NextPageRequest.GetAsync();
    groups.AddRange(deltaPage.CurrentPage);
}

CodePudding user response:

Maybe there's a little different. Here's my test.

When I test via http request, it has "@odata.context and @odata.nextLink":

enter image description here

When I visit the url provided by nextLink, I will get deltaLink:

enter image description here

Then going to the SDK, I can't get nextLink in AdditionalData, but I can get the next page request in NextPageRequest variable:

enter image description here

I can get deltaLink when there's no response in AdditionalData:

enter image description here

So I'm afraid you can follow my code snippet to test again:

var delta = await _graphServiceClient.Users.Delta().Request().GetAsync();

            var queryOptions = new List<QueryOption>()
            {
                new QueryOption("$skiptoken", delta.NextPageRequest.QueryOptions[0].Value)
            };

            var delta2 = await _graphServiceClient.Users
                .Delta()
                .Request(queryOptions)
                .GetAsync();

I also test the client credential flow, it has the same behavior:

enter image description here enter image description here

  • Related