Get a user with the Node.js SDK
permit.api.users.get() fetches one user, 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 user data from Permit, for example to check whether a user was synced.
Prerequisites
- A
permitclient created with an API key for the environment. See Create a Permit client.
Method signature
| Method | Signature |
|---|---|
permit.api.users.get | get(userKey: string): Promise<UserRead> |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
userKey | string | Yes | Key or ID of the user to fetch. |
Example
await permit.api.users.get(userKey);
Return value
The method resolves to a UserRead object with these fields:
| Field | Type | Description |
|---|---|---|
key | string | Key of the user. |
id | string | Unique ID of the user. |
email, first_name, last_name | string | Profile fields of the user, if set. |
attributes | object | User attributes. |
roles | array | Roles assigned to the user. |
associated_tenants | array | Tenants the user belongs to. |
organization_id, project_id, environment_id | string | IDs of the organization, project, and environment of the user. |
created_at, updated_at | string | ISO 8601 timestamps. |
If the user doesn't exist or the Permit API returns another error status code, the method throws a PermitApiError.