Get a role with the Node.js SDK
permit.api.roles.get() fetches one role, identified by key or ID, from the Permit.io environment that your Node.js SDK client is connected to. This reference is for backend developers who read role definitions from code.
Prerequisites
- A
permitclient created with an API key for the environment. See Create a Permit client.
Method signature
| Method | Signature | Status |
|---|---|---|
permit.api.roles.get | get(roleKey: string): Promise<RoleRead> | Recommended |
permit.api.getRole | getRole(roleId: string): Promise<RoleRead> | Deprecated alias with the same argument |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
roleKey | string | Yes | Key or ID of the role to fetch. |
Example
const role = await permit.api.roles.get(roleKey);
Return value
The method resolves to a RoleRead object with these fields: key, id, name, description, permissions, extends, attributes, organization_id, project_id, environment_id, created_at, and updated_at.
If the role doesn't exist or the Permit API returns another error status code, permit.api.roles.get() throws a PermitApiError. The deprecated permit.api.getRole() rethrows the underlying Axios error.