Skip to main content

List resources with the Java SDK

permit.api.resources.list() fetches one page of the resource types in your Permit environment. This reference is for Java developers who read their authorization schema from code. The examples assume an initialized Permit client named permit, as set up in Check permissions with the Java SDK.

Signature

OverloadBehavior
ResourceRead[] list()Fetches page 1 with 100 results per page.
ResourceRead[] list(int page)Fetches the given page with 100 results per page.
ResourceRead[] list(int page, int perPage)Fetches the given page with the given page size.

All overloads throw IOException, PermitApiError, and PermitContextError.

Parameters

ParameterTypeRequiredDescription
pageintNoThe page number to fetch, starting at 1. Defaults to 1.
perPageintNoThe number of results per page. Defaults to 100.

Example

The example fetches the first page of resources. To fetch another page, pass the page number, for example permit.api.resources.list(2, 50). The example uses ResourceRead from io.permit.sdk.openapi.models.

import io.permit.sdk.openapi.models.ResourceRead;

ResourceRead[] resources = permit.api.resources.list();

Return value

list() returns an array of ResourceRead objects (io.permit.sdk.openapi.models.ResourceRead). The array is empty when the page has no resources. The array does not include a total count. permit.api.users.list() returns a paginated result object instead, as described in List users with the Java SDK.

Exceptions

All exception classes except IOException are in the io.permit.sdk.api package.

ExceptionThrown when
IOExceptionThe HTTP request to the Permit API fails, for example because of a network error.
PermitApiErrorThe Permit API returns an error status code. getResponseCode() returns the HTTP status code and getRawResponse() returns the response body.
PermitContextErrorThe SDK context does not include an environment, for example because the API key is scoped to an organization or project.