Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging in MS Graph API

Graph API Paging explains that the response would contain a field @odata.nextLink which would contain a skiptoken pointing to the next page of contents.

When I test the API, I'm getting a fully-qualified MS Graph URL which contains the skiptoken as a query param. E.g. Below is the value I got for the field @odata.nextLink in the response JSON. https://graph.microsoft.com/v1.0/users?$top=25&$skiptoken=X%27445370740200001E3A757365723134406F33363561702E6F6E6D6963726F736F66742E636F6D29557365725F31363064343831382D343162382D343961372D383063642D653136636561303437343437001E3A7573657235407368616C696E692D746573742E31626F74322E696E666F29557365725F62666639356437612D333764632D343266652D386335632D373639616534303233396166B900000000000000000000%27

Is it safe to assume we'll always get the full URL and not just the skiptoken? Because if it's true, it helps avoid parsing the skiptoken and then concatenating it to the existing URL to form the full URL ourselves.

EDIT - Compared to MS Graph API, response obtained from Azure AD Graph API differs in that the JSON field @odata.nextLink contains only the skipToken and not the fully-qualified URL.

like image 692
asgs Avatar asked Dec 22 '16 09:12

asgs


People also ask

Is MS graph API deprecated?

Azure Active Directory (Azure AD) Graph is deprecated and will be retired at any time after June 30, 2023, without advance notice, as we announced in September, 2022.

Is Microsoft Graph API a REST API?

The Microsoft Graph API is a RESTful web API that enables you to access Microsoft Cloud service resources. After you register your app and get authentication tokens for a user or service, you can make requests to the Microsoft Graph API.


2 Answers

if you would like to have all users in single list, you can achieve that using the code that follows:

public static async Task<IEnumerable<User>> GetUsersAsync()
    {
        var graphClient = GetAuthenticatedClient();
        List<User> allUsers = new List<User>();
        var users = await graphClient.Users.Request().Top(998)
           .Select("displayName,mail,givenName,surname,id")
           .GetAsync();

        while (users.Count > 0)
        {
            allUsers.AddRange(users);
            if (users.NextPageRequest != null)
            {
                users = await users.NextPageRequest
                    .GetAsync();
            }
            else
            {
                break;
            }
        }
        return allUsers;
    }

I am using graph client library

like image 131
Ravi Anand Avatar answered Oct 21 '22 10:10

Ravi Anand


The above code did not work for me without adding a call to 'CurrentPage' on the last line.
Sample taken from here.

        var driveItems = new List<DriveItem>();
        var driveItemsPage = await graphClient.Me.Drive.Root.Children.Request().GetAsync();
        driveItems.AddRange(driveItemsPage.CurrentPage);
        while (driveItemsPage.NextPageRequest != null)
        {
            driveItemsPage = await driveItemsPage.NextPageRequest.GetAsync();
            driveItems.AddRange(driveItemsPage.CurrentPage);
        }
like image 21
Tracy Avatar answered Oct 21 '22 10:10

Tracy