User metadata

Users can optionally store metadata such as a name, profile URL, external ID, and email address. You can also use a custom field to store additional data for a user. The metadata can be fetched by other users and persists in the database until it's explicitly removed. Some examples of custom data are display names, last online time, and user roles.

Refer to User Metadata to learn more about working with user metadata or you can view our interactive sample regarding user metadata at PubNub Tour.

PubNub generates user metadata events when a user metadata is set or deleted.

User ID / UUID

User ID is also referred to as UUID/uuid in some APIs and server responses but holds the value of the userId parameter you set during initialization.

Set user metadata

The setUUIDMetadata method stores user metadata in PubNub. You can use it to add new or update existing metadata properties. The method returns the updated user metadata, including the user's custom data.

Note

If you update the custom property, you must completely replace the entire object; partial updates aren't supported.

pubnub.objects.setUUIDMetadata({
data: {
uuid: 'john-doe',
name: "John Doe",
email: "johndoe@pubnub.com",
custom: {
"nickname": "jonny"
}
}
});

Get user metadata

The getUUIDMetadata method retrieves metadata for the current user. On success, the PubNub SDK will return the all metadata of the user along with the status 200.

pubnub.objects.getUUIDMetadata({
uuid: 'john-doe',
});

User events

User events are triggered when user metadata is set or deleted. Other users can receive these events by subscribing to the user's channel or if they are members of the same channel.

EventDescriptionPublish location
User Metadata SetUser metadata is set or updated.These events are published on {uuid} and {channel} memberships for the user.
User Metadata DeletedUser metadata is deleted.These events are published on {uuid} and {channel} memberships for the user.

User metadata set:

{
"channel":"john-doe",
"message":{
"event":"set",
"type":"uuid",
"data":{
"id":"john-doe",
"name":"John Doe",
"email":"johndoe@pubnub.com",
"updated":"2020-06-10T16:22:11.035374Z",
"eTag":"AY39mJKK//C0VA"
}
},
"subscription":null,
"timetoken":"15119446002445794"
show all 16 lines

User metadata removed:

{
"channel":"john-doe",
"message":{
"event":"deleted",
"type":"uuid",
"data":{
"id":"john-doe",
"name":"John Doe",
"email":"johndoe@pubnub.com",
"updated":"2020-06-10T16:22:11.035374Z",
"eTag":"AY39mJKK//C0VA"
}
},
"subscription":null,
"timetoken":"15119446002445794"
show all 16 lines
Last updated on