user object to store any app-specific metadata. This field is a generic JSON object up to 1KB in size. The JSON can contain arbitrary key-value pairs where the key is a string and value is a string, integer, or boolean (ie {username: 'name', isVerified: true, age: 23}).
- NodeJS
- NodeJS (server-auth)
- Java
- Rust
- REST API
Use the If a matching user is found for the ID and the custom metadata object is valid, the method will return the corresponding
PrivyClient’s setCustomMetadata method from the users() interface to set the custom metadata field for a user by their ID. As parameters, pass the user’s ID as a string and the JSON object that you wish to set as custom metadata:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/node';
const privy = new PrivyClient({
appId: process.env.PRIVY_APP_ID!,
appSecret: process.env.PRIVY_APP_SECRET!
});
try {
const user = await privy.users().setCustomMetadata('insert-user-id', {
custom_metadata: {
username: 'name'
}
});
} catch (error) {
console.error(error);
}
User object with updated custom metadata. If no matching user is found, or the custom metadata input is malformed or too large (>1KB), the method will throw an error.The
@privy-io/server-auth library is deprecated. We recommend integrating @privy-io/node for
the latest features and support.PrivyClient’s setCustomMetadata method to set the custom metadata field for a user by their DID. As parameters, pass the user’s DID as a string and the JSON object that you wish to set as custom metadata:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/server-auth';
const privy = new PrivyClient(process.env.PRIVY_APP_ID!, process.env.PRIVY_APP_SECRET!);
const user = await privy.setCustomMetadata('did:privy:XXXXXX', {username: 'name'});
User object with updated custom metadata. If no matching user is found, or the custom metadata input is malformed or too large (>1KB), the method will throw an error.When using the
setCustomMetadata function in TypeScript, you can specify a type generic in order to enable type inference on the method like so:Report incorrect code
Copy
Ask AI
// TypeScript will throw a type error if customMetadata is not of type {key1: string}
const user = await privy.setCustomMetadata<{key1: string}>('did:privy:XXXXXX', customMetadata);
You can set or update the custom metadata for a user by their ID using the
users().setCustomMetadata() method.Report incorrect code
Copy
Ask AI
try {
UserCustomMetadataSetRequestBody customMetadataRequestBody = UserCustomMetadataSetRequestBody.builder()
.customMetadata(Map.of("username", CustomMetadata.of("name")))
.build();
UserCustomMetadataSetResponse customMetadataResponse = privyClient
.users()
.setCustomMetadata()
.userId("did:privy:XXXXXX")
.requestBody(customMetadataRequestBody)
.call();
if (customMetadataResponse.user().isPresent()) {
User updatedUser = customMetadataResponse.user().get();
}
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
When setting the custom metadata for a user, you may specify the following values on theUserCustomMetadataSetRequestBody builder:A map of custom metadata key-value pairs. The key is a
String and value is CustomMetadata
object, which can be a String, double, or boolean.Returns
TheUserCustomMetadataSetResponse object contains an optional user() field that contains the
updated user object if the custom metadata was set successfully.The updated user object. See the user object for more
details.
Use the If a matching user is found for the ID and the custom metadata object is valid, the method will return the corresponding
PrivyClient’s set_custom_metadata method from the users() interface to set the custom metadata field for a user by their ID. As parameters, pass the user’s ID as a string and the metadata object:Report incorrect code
Copy
Ask AI
use privy_rs::{PrivyClient, generated::types::*};
use std::collections::HashMap;
let client = PrivyClient::new(app_id, app_secret)?;
// Create custom metadata using the typed enum values
let mut metadata_map = HashMap::new();
metadata_map.insert("username".to_string(), CustomMetadataValue::String("name".to_string()));
metadata_map.insert("isVerified".to_string(), CustomMetadataValue::Boolean(true));
metadata_map.insert("age".to_string(), CustomMetadataValue::Number(23.0));
let custom_metadata = CustomMetadata::from(metadata_map);
let user = client
.users()
.set_custom_metadata("insert-user-id", &UserCustomMetadataSetRequestBody {
custom_metadata,
})
.await?;
println!("Updated user: {}", user.id);
User object with updated custom metadata. If no matching user is found, or the custom metadata input is malformed or too large (>1KB), the method will return an error.Type Safety
The Rust SDK provides type-safe custom metadata through theCustomMetadataValue enum:CustomMetadataValue::String(String)for string valuesCustomMetadataValue::Number(f64)for numeric valuesCustomMetadataValue::Boolean(bool)for boolean values
To set the custom data for a user with a given DID, make a Replace A successful response will include the user object associated with the DID, with updated custom_metadata, like below:If there is no user associated with the provided DID, or the custom metadata input is malformed or too large (>1KB), the API will return an error.
POST request to:Report incorrect code
Copy
Ask AI
https://auth.privy.io/api/v1/users/<did>/custom_metadata
<did> with your desired Privy DID. It should have the format did:privy:XXXXXX.Below is a sample cURL command for this request:Report incorrect code
Copy
Ask AI
curl --request POST https://auth.privy.io/api/v1/users/<user-did>/custom_metadata \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>"
-d '{
"custom_metadata": {username: "name", isVerified: true, age: 23}
}'
Report incorrect code
Copy
Ask AI
{
"id": "did:privy:cfbsvtqo2c22202mo08847jdux2z",
"created_at": 1667165891,
"custom_metadata": {"username": "name"},
"linked_accounts": [
{
"type": "email",
"address": "[email protected]",
"verified_at": 1667350653
}
]
}

