User Metadata

Manage user data with BizOps Workspace

You can create, edit, or delete users and their data using BizOps Workspace on Admin Portal. It provides a preview of all users available on your apps' keysets.

App Context provides easy-to-use, serverless storage for user metadata, channel metadata, channel memberships, and channel members. You don’t need to manage external infrastructure.

You can store user metadata to drive client features and enhance your application. Use predefined properties for a user, such as name, email, profileURL, and externalId. Use the custom object to store your own attributes, such as nickname or color.

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.

PubNub also generates events when the metadata associated with a particular user is set or deleted. Your application can receive these events in real-time and dynamically react to data changes. You can enable these events from the Admin Portal.

PubNub publishes each user’s events to a channel named for that user. For example, to receive events for the user with User ID chat-user-9A7X8, you would subscribe to the channel named chat-user-9A7X8.

Illuminate & sensitive data

You can capture and track your App Context data in Illuminate for real-time decisioning and analytics. Illuminate captures all data you define with JSON paths and map when creating measures and dimensions for the Business Objects. To protect privacy, avoid placing any PII (email address, profile URL, or IP address) in the custom fields of your App Context mappings.

Set user metadata

You can set predefined and custom user metadata by providing key-value pairs.

API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

The example below adds the name, email, and a custom nickname to the current user.

pubnub.objects.setUUIDMetadata({
data: {
name: "John Doe",
email: "johndoe@pubnub.com",
custom: {
"nickname": "Mr. Mysterious"
}
}
});

On success, the SDK returns the user’s metadata with HTTP 200. It will also fire a User Metadata Set event that can be consumed by other clients. Refer to the Receive Messages section to learn more.

Get user metadata

Retrieve the current user’s metadata. The following example returns all metadata for the current user.

pubnub.objects.getUUIDMetadata();

On success, the SDK returns all metadata for the user with HTTP 200.

Get metadata for all users

You can retrieve metadata for all users. To include custom metadata, set the optional flag in your request. The code below returns all predefined and custom metadata for all users:

pubnub.objects.getAllUUIDMetadata();

On success, the SDK returns all user metadata associated with the API key with HTTP 200.

Remove user metadata

Remove all metadata for a single user. The following example removes all metadata of the current user.

Cascading deletes

Enable referential integrity on your app’s keyset in the Admin Portal to automatically delete memberships when you delete a user. If you keep it disabled, delete related memberships manually.

pubnub.objects.removeUUIDMetadata();

On completion, the SDK emits an object -> uuid -> delete event that can be consumed by other clients. Refer to the Receive Messages document to learn more.

Last updated on