Skip to main content

Fetch a resource with the Java SDK

permit.api.resources.get() fetches one resource type, with its actions and attributes, from 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

The SDK has three methods that fetch a resource:

MethodSignature
get()ResourceRead get(String resourceKey)
getByKey()ResourceRead getByKey(String resourceKey)
getById()ResourceRead getById(UUID resourceId)

All three methods throw IOException, PermitApiError, and PermitContextError. getByKey() and getById() call get() with the key or the ID as a string.

Parameters

ParameterTypeMethodDescription
resourceKeyStringget(), getByKey()The key or the ID (UUID) of the resource. The Permit API accepts either value.
resourceIdjava.util.UUIDgetById()The ID of the resource.

Example

Replace [RESOURCE ID OR KEY], [RESOURCE KEY], and [RESOURCE ID] with values from your environment.

import io.permit.sdk.openapi.models.ResourceRead;
import java.util.UUID;

// accepts both the resource id and the resource key
ResourceRead resource = permit.api.resources.get("[RESOURCE ID OR KEY]");

// if you want to be explicit, you can use getByKey
ResourceRead resource2 = permit.api.resources.getByKey("[RESOURCE KEY]");

// or getById
ResourceRead resource3 = permit.api.resources.getById(UUID.fromString("[RESOURCE ID]"));

Return value

Each method returns a ResourceRead object (io.permit.sdk.openapi.models.ResourceRead) with the resource's key, name, ID, actions, and attributes.

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. If no resource matches the key or ID, the 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.