List users with the Java SDK
permit.api.users.list() fetches one page of the users in your Permit environment. This reference is for Java developers who read Permit users from code. The examples assume an initialized Permit client named permit, as set up in Check permissions with the Java SDK.
Signature
| Overload | Behavior |
|---|---|
PaginatedResultUserRead list() | Fetches page 1 with 100 results per page. |
PaginatedResultUserRead list(int page) | Fetches the given page with 100 results per page. |
PaginatedResultUserRead list(int page, int perPage) | Fetches the given page with the given page size. |
All overloads throw IOException, PermitApiError, and PermitContextError.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
page | int | No | The page number to fetch, starting at 1. Defaults to 1. |
perPage | int | No | The number of results per page. Defaults to 100. |
Example
The example fetches the first page of users. To fetch another page, pass the page number, for example permit.api.users.list(2, 50).
import io.permit.sdk.openapi.models.PaginatedResultUserRead;
PaginatedResultUserRead users = permit.api.users.list();
Return value
Unlike resources.list(), roles.list(), and tenants.list(), which return arrays, users.list() returns a PaginatedResultUserRead object (io.permit.sdk.openapi.models.PaginatedResultUserRead) with these fields:
| Field | Type | Description |
|---|---|---|
data | List<UserRead> | The users on the requested page. |
totalCount | Integer | The total number of users in the environment. |
pageCount | Integer | The number of pages at the requested page size. |
To read every user, call list(page, perPage) for each page from 1 to pageCount.
Exceptions
All exception classes except IOException are in the io.permit.sdk.api package.
| Exception | Thrown when |
|---|---|
IOException | The HTTP request to the Permit API fails, for example because of a network error. |
PermitApiError | The Permit API returns an error status code. getResponseCode() returns the HTTP status code and getRawResponse() returns the response body. |
PermitContextError | The SDK context does not include an environment, for example because the API key is scoped to an organization or project. |