How to use paging on Management API v2 requests

How to use paging on Management API v2 requests

Most endpoints that return sets of data from the API will return a maximum of 50 elements. To move beyond that, you’ll need to use paging. The page and per_page parameters let you specify the page number (zero-based index) and the number of items to return per page (up to a maximum of 100 items).

E.g. to return a list of users in a connection, you can use the GET /api/v2/users endpoint with a query that says q=identities.connection:my-connection:

GET /api/v2/users?q=identities.connection:my-connection

This query would only return the first 50 results, so it’s essentially behaving as if page was 0 and per_page had a value of 50. While this will still work, it’s better to make the application that is requesting this date “paging-aware”, and be explicit about paging. E.g. to get the first page, using a page size of 25 items:

GET /api/v2/users?q=identities.connection:my-connection&page=0&per_page=25

How to specify paging parameters from SDKs

Most SDKs provided by Auth0 support paging options. Make sure to upgrade to the latest version to get the newest features.

node-auth0

Include page and per_page in the params object:

// Pagination settings.
var params = {
  per_page: 10,
  page: 0
};

management.users.getAll(params, function (err, users) {
  console.log(users.length);
})

Example at https://auth0.github.io/node-auth0/module-management.UsersManager.html#getAll

Go Auth0

Use .Page() and .PerPage() to specify the paging parameters. E.g.:

c, err := m.Connection.List(
    management.Context(ctx),
    management.Page(2),
    management.PerPage(10)
)

Check auth0 package - gopkg.in/auth0.v5 - Go Packages for an example

Auth0 .Net

Methods that return multiple items take an instance of the PaginationInfo class, that lets you specify the pagination parameters.

E.g.

var users = await _apiClient.Users.GetAllAsync(
  new GetUsersRequest(), 
  new PaginationInfo(0, 50, false));

Docs at Documentation

Auth0 Java

Use withPage when building a filter to specify paging information. E.g.:

UserFilter filter = new UserFilter()
    .withPage(1, 20);
//...
Request<UsersPage> request = mgmt.users().list(filter);
try {
    UsersPage response = request.execute();
} catch (APIException exception) {
    // api error
} catch (Auth0Exception exception) {
    // request error
}

Example at GitHub - auth0/auth0-java: Java client library for the Auth0 platform

Auth0 Python

Specify the page and per_page parameters in methods that return many items:

auth0.connections.all(page=0, per_page=25)

auth0.users.list(page=0, per_page=25)

Auth0 Ruby

Add page and per_page in the @params:

    @params = {
      q: "email:*auth0*",
      fields: 'email,user_id,name',
      include_fields: true,
      page: 0,
      per_page: 50
    }
    @users = auth0_client.users @params

See docs at File: README — Documentation for auth0 (5.10.0)

Supporting Documentation: