Skip to main content

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​

Method signature​

MethodSignatureStatus
permit.api.roles.getget(roleKey: string): Promise<RoleRead>Recommended
permit.api.getRolegetRole(roleId: string): Promise<RoleRead>Deprecated alias with the same argument

Parameters​

NameTypeRequiredDescription
roleKeystringYesKey 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.