- NodeJS
- NodeJS (server-auth)
- Python
- Java
- REST API
- Rust
Querying users by identity token
Using identity tokens is the recommended way to query user information about authenticated users
in your backend. If you need user data about unauthenticated users, you can use the
_get
method by passing in a user’s DID.get method to get a single user by their identity token passed from the client, to learn more about identity tokens, see identity tokens.Report incorrect code
Copy
Ask AI
const user = await privy.users().get({id_token: 'your-id_token'});
Querying users by ID
To get a user by their Privy ID, call the.users()._get() method on the PrivyClient.Report incorrect code
Copy
Ask AI
try {
const user = privyClient.users()._get('insert-user-id');
} catch (error) {
console.error(error);
}
Querying for all users
To get all users for your app, call the.users().list() method on the PrivyClient.Report incorrect code
Copy
Ask AI
try {
for await (const user of privyClient.users().list()) {
console.log(user.id);
}
} catch (error) {
console.error(error);
}
Querying for users by account data
By email address
By email address
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByEmailAddress({ address: '[email protected]' });
} catch (error) {
console.error(error);
}
By phone number
By phone number
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByPhoneNumber({ number: '+1 555 555 5555' });
} catch (error) {
console.error(error);
}
By wallet address
By wallet address
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByWalletAddress({ address: '0x1234567890' });
} catch (error) {
console.error(error);
}
By smart wallet address
By smart wallet address
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getBySmartWalletAddress({ address: '0x1234567890' });
} catch (error) {
console.error(error);
}
By custom auth ID
By custom auth ID
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByCustomAuthID({ custom_user_id: 'insert-custom-auth-id' });
} catch (error) {
console.error(error);
}
By Farcaster ID
By Farcaster ID
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByFarcasterID({ fid: 1234 });
} catch (error) {
console.error(error);
}
By Twitter subject
By Twitter subject
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByTwitterSubject({ subject: 'insert-twitter-subject' });
} catch (error) {
console.error(error);
}
By Twitter username
By Twitter username
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByTwitterUsername({ username: 'batman' });
} catch (error) {
console.error(error);
}
By Discord username
By Discord username
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByDiscordUsername({ username: 'batman' });
} catch (error) {
console.error(error);
}
By Telegram User ID
By Telegram User ID
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByTelegramUserID({ telegram_user_id: 'insert-telegram-user-id' });
} catch (error) {
console.error(error);
}
By Telegram username
By Telegram username
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByTelegramUsername({ username: 'batman' });
} catch (error) {
console.error(error);
}
By GitHub username
By GitHub username
Report incorrect code
Copy
Ask AI
try {
const user = await privy.users().getByGitHubUsername({ username: 'batman' });
} catch (error) {
console.error(error);
}
The
@privy-io/server-auth library is deprecated. We recommend integrating @privy-io/node for
the latest features and support.Querying users by identity token
Using identity tokens is the recommended way to query user information about authenticated users in your backend. If you need user data about unauthenticated users, you can use the
getUsers method by passing in a user’s DID.getUser method to get a single user by their identity token passed from the client, to learn more about identity tokens, see identity tokens.Report incorrect code
Copy
Ask AI
const user = await privy.getUser({idToken: 'your-idToken'});
Other ways to query users
Privy rate limits REST API endpoints that you may call from your server. If you’re looking to get
information about an authenticated user, consider using identity
tokens as a more secure and efficient way to access user
data.
Querying users by ID
Use thegetUser method to get a single user by their Privy DID:Report incorrect code
Copy
Ask AI
const user = await privy.getUserById('did:privy:XXXXXX');
Querying for all users
Use thegetUsers method to get a list of all your users:Report incorrect code
Copy
Ask AI
const users = await privy.getUsers();
The
getUsers method automatically handles pagination and includes built-in exponential backoff to manage rate limits.Querying for users by account data
By email address
By email address
Use the
getUserByEmail method to get a user by their email address:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByEmail('[email protected]');
By phone number
By phone number
Use the
getUserByPhoneNumber method to get a user by their phone number:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByPhoneNumber('+1 555 555 5555');
By wallet address
By wallet address
Use the
getUserByWalletAddress method to get a user by their wallet address:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByWalletAddress('0xABCDEFGHIJKL01234567895C5cAe8B9472c14328');
By smart wallet address
By smart wallet address
Use the
getUserBySmartWalletAddress method to get a user by their smart wallet address:Report incorrect code
Copy
Ask AI
const user = await privy.getUserBySmartWalletAddress('0xABCDEFGHIJKL01234567895C5cAe8B9472c14328');
By custom auth ID
By custom auth ID
Use the
getUserByCustomAuthId method to get a user by their custom auth ID:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByCustomAuthId('123');
By Farcaster fid
By Farcaster fid
Use the
getUserByFarcasterId method to get a user by their Farcaster fid:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByFarcasterId(1402);
By Twitter subject
By Twitter subject
Use the
getUserByTwitterSubject method to get a user by their Twitter subject:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByTwitterSubject('456');
By Twitter username
By Twitter username
Use the
getUserByTwitterUsername method to get a user by their Twitter username:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByTwitterUsername('batman');
By Discord username
By Discord username
Use the
getUserByDiscordUsername method to get a user by their Discord username:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByDiscordUsername('batman');
By Telegram User ID
By Telegram User ID
Use the
getUserByTelegramUserId method to get a user by their Telegram User ID:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByTelegramUserId('456');
By Telegram username
By Telegram username
Use the
getUserByTelegramUsername method to get a user by their Telegram username:Report incorrect code
Copy
Ask AI
const user = await privy.getUserByTelegramUsername('batman');
Querying users by identity token
Using identity tokens is the recommended way to query user information about authenticated users in your backend. If you need user data about unauthenticated users, you can use the
get method by passing in a user’s DID.get_by_id_token method to get a single user by their identity token passed from the client, to learn more about identity tokens, see identity tokens.Report incorrect code
Copy
Ask AI
user = privy.users.get_by_id_token(id_token="your-idToken")
Other ways to query users
Privy rate limits REST API endpoints that you may call from your server. If you’re looking to get
information about an authenticated user, consider using identity
tokens as a more secure and efficient way to access user
data.
Querying users by ID
Use theget method to get a single user by their Privy DID:Report incorrect code
Copy
Ask AI
user = privy.users.get(user_id="did:privy:XXXXXX")
Querying for all users
Use thelist method to get a list of all your users:Report incorrect code
Copy
Ask AI
users = privy.users.list()
The
list method automatically handles pagination.Querying for users by account data
By email address
By email address
Use the
get_by_email_address method to get a user by their email address:Report incorrect code
Copy
Ask AI
user = privy.users.get_by_email_address(address="[email protected]")
By wallet address
By wallet address
Use the
get_by_wallet_address method to get a user by their wallet address:Report incorrect code
Copy
Ask AI
user = privy.users.get_by_wallet_address(address="0xABCDEFGHIJKL01234567895C5cAe8B9472c14328")
By custom auth ID
By custom auth ID
Use the
get_by_jwt_subject_id method to get a user by their custom auth ID:Report incorrect code
Copy
Ask AI
user = privy.users.get_by_jwt_subject_id(custom_user_id="123")
Querying users by ID
To get a user by their Privy DID, call the.users().retrieve() method on the PrivyClient.Report incorrect code
Copy
Ask AI
try {
UserRetrieveResponse response = privyClient.users().retrieve("<did>");
if (response.user().isPresent()) {
User user = response.user().get();
}
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
The user’s Privy DID (i.e.,
did:privy:XXXXXX).Returns
TheUserRetrieveResponse object contains an optional user() field, present if the user was
retrieved successfully.The retrieved
User object. See the user object for
more details.Querying for all users
To get all users for your app, call the.users().list() method on the PrivyClient.Report incorrect code
Copy
Ask AI
try {
UserListRequestBody requestBody = UserListRequestBody.builder()
UserListResponse response = privyClient
.users()
.list()
// .cursor("<cursor>") // Optional
// .limit(100) // Optional
.call();
if (response.object().isPresent()) {
List<User> users = response.object().get().data();
}
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
Cursor for pagination. Use the
next_cursor from the previous response.Number of users to return per request. Defaults to 100.
Returns
TheUserListResponse object contains an optional object() field, present if the users were
retrieved successfully.Querying for users by account data
By email address
By email address
To get a user by their email address, call the
.users().retrieveByEmailAddress() method on the
PrivyClient.Report incorrect code
Copy
Ask AI
try {
UserRetrieveByEmailAddressRequestBody request = UserRetrieveByEmailAddressRequestBody.builder()
.address("[email protected]")
.build();
UserRetrieveByEmailAddressResponse response = privyClient
.users()
.retrieveByEmailAddress(request);
if (response.user().isPresent()) {
User user = response.user().get();
}
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
You can specify the following values on theUserRetrieveByEmailAddressRequestBody builder:Email address of the user.
Returns
TheUserRetrieveByEmailAddressResponse object contains an optional user() field, present if the user was retrieved successfully.The retrieved
User object. See the user object for
more details.By custom auth ID
By custom auth ID
To get a user by their custom auth ID, call the
.users().retrieveByCustomAuthId() method on the
PrivyClient.Report incorrect code
Copy
Ask AI
try {
UserRetrieveByCustomAuthIdRequestBody request = UserRetrieveByCustomAuthIdRequestBody.builder()
.customUserId("123")
.build();
UserRetrieveByCustomAuthIdResponse response = privyClient
.users()
.retrieveByCustomAuthId(request);
if (response.user().isPresent()) {
User user = response.user().get();
}
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
You can specify the following values on theUserRetrieveByCustomAuthIdRequestBody builder:Custom user ID provided by your authentication system.
Returns
TheUserRetrieveByCustomAuthIdResponse object contains an optional user() field, present if the user was retrieved successfully.The retrieved
User object. See the user object for
more details.Querying users by ID
To get a user by their Privy DID, make aGET request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/<did>
Parameters
The user’s Privy DID (e.g.,
did:privy:XXXXXX).Sample request
Report incorrect code
Copy
Ask AI
curl --request GET https://auth.privy.io/api/v1/users/<user-did> \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>"
Querying for all users
To get all users for your app, make aGET request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users
Parameters
Cursor for pagination. Use the
next_cursor from the previous response.Number of users to return per request. Defaults to 100.
Response
The response will include:data: Array of user objectsnext_cursor: Cursor to use for the next batch of users
Sample request
Report incorrect code
Copy
Ask AI
# First batch of users
curl --request GET https://auth.privy.io/api/v1/users \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>"
# Subsequent batches using cursor
curl --request GET https://auth.privy.io/api/v1/users?cursor=<next_cursor> \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>"
Querying for users by account data
By email address
By email address
To get a user by their email address, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/email/address
Body
Email address of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/email/address" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"address": "[email protected]"
}'
By phone number
By phone number
To get a user by their phone number, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/phone/number
Body
Phone number of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/phone/number" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"number": "1234567890"
}'
By wallet address
By wallet address
To get a user by their wallet address, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/wallet/address
Body
Wallet address of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/wallet/address" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"address": "0xABCDEFGHIJKL01234567895C5cAe8B9472c14328"
}'
By smart wallet address
By smart wallet address
To get a user by their smart wallet address, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/smart_wallet/address
Body
Smart wallet address of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/smart_wallet/address" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"address": "0xABCDEFGHIJKL01234567895C5cAe8B9472c14328"
}'
By custom auth ID
By custom auth ID
To get a user by their custom auth ID, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/custom_auth/id
Body
Custom user ID provided by your authentication system.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/custom_auth/id" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"custom_user_id": "123"
}'
By Farcaster fid
By Farcaster fid
To get a user by their Farcaster fid, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/farcaster/fid
Body
Farcaster ID of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/farcaster/fid" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"fid": "789"
}'
By Twitter subject
By Twitter subject
To get a user by their Twitter subject, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/twitter/subject
Body
Twitter subject identifier of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/twitter/subject" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"subject": "12345"
}'
Use subject instead of username to get Twitter accounts with faster queries.
By Twitter username
By Twitter username
To get a user by their Twitter username, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/twitter/username
Body
Twitter username of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/twitter/username" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"username": "batman"
}'
By Discord username
By Discord username
To get a user by their Discord username, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/discord/username
Body
Discord username of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/discord/username" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"username": "batman"
}'
By Telegram User ID
By Telegram User ID
To get a user by their Telegram User ID, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/telegram/telegram_user_id
Body
Telegram User ID of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/telegram/telegram_user_id" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"telegram_user_id": "12345"
}'
Use ID instead of username to get Telegram accounts with faster queries.
By Telegram username
By Telegram username
To get a user by their Telegram username, make a
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/telegram/username
Body
Telegram username of the user.
Sample request
Report incorrect code
Copy
Ask AI
curl --request POST "https://auth.privy.io/api/v1/users/telegram/username" \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H 'Content-Type: application/json' \
-d '{
"username": "batman"
}'
Querying users by ID
To get a user by their Privy ID, call the.users().get() method on the PrivyClient.Report incorrect code
Copy
Ask AI
use privy_rs::PrivyClient;
let client = PrivyClient::new(app_id, app_secret)?;
let user = client.users().get("insert-user-id").await?;
println!("Found user: {}", user.id);
Querying for all users
To get all users for your app, call the.users().list() method on the PrivyClient.Report incorrect code
Copy
Ask AI
use privy_rs::{PrivyClient, generated::types::ListUsersQuery};
let client = PrivyClient::new(app_id, app_secret)?;
// Get users with optional pagination
let users_response = client
.users()
.list(Some(&ListUsersQuery {
cursor: None,
limit: Some(100),
}))
.await?;
for user in users_response.data {
println!("User ID: {}", user.id);
}
// Handle pagination if needed
if let Some(next_cursor) = users_response.next_cursor {
let next_page = client
.users()
.list(Some(&ListUsersQuery {
cursor: Some(next_cursor),
limit: Some(100),
}))
.await?;
}
Querying users by specific criteria
The Rust SDK provides several methods to query users by specific linked accounts:Report incorrect code
Copy
Ask AI
use privy_rs::generated::types::*;
// Get user by email address
let user = client
.users()
.get_by_email_address(&GetUsersByEmailAddressBody {
email: "[email protected]".to_string(),
})
.await?;
// Get user by wallet address
let user = client
.users()
.get_by_wallet_address(&GetUsersByWalletAddressBody {
address: "0x1234...".to_string(),
})
.await?;
// Get user by phone number
let user = client
.users()
.get_by_phone_number(&GetUsersByPhoneNumberBody {
phone_number: "+1234567890".to_string(),
})
.await?;
// Get user by custom auth ID
let user = client
.users()
.get_by_custom_auth_id(&GetUsersByCustomAuthIdBody {
custom_user_id: "custom-user-123".to_string(),
})
.await?;

