PubNub Logo Docs
Support Contact Sales Login Try Our APIs

›Metadata

Collapse all
Dark mode

Home

  • Home

First steps

  • Set up your account
  • Get the SDK
  • Initialize PubNub
  • Identify users and devices
  • Send messages
  • Receive messages
  • Retrieve old messages
  • Check user presence
  • Add custom metadata
  • Manage access
  • Add serverless business logic
  • Send push notifications

Setup

  • PubNub account
  • Application
  • Users & devices
  • Connection management
  • Data security
  • Data persistence
  • API limits

Chat

  • In-App Chat

SDKs

  • SDKs

Messages

  • Publish
  • Receive
  • Actions
  • Payload type conventions

Channels

  • Basics
  • Subscription
  • Naming conventions

User presence

  • Basics
  • Events
  • State
  • Webhooks

Metadata

  • Channel
  • User
  • Membership

Message Persistence

  • Message Persistence

File sharing

  • File sharing

Access management

  • Manage access

Push notifications

  • Basics
  • iOS
  • Android
  • Troubleshooting

Best practices

  • Architectural choices
  • Message aggregation
  • Friend list & status feed
  • Troubleshooting
  • Migration guides

Serverless processing

    EVENTS & ACTIONS

    • Basics
    • Configure Events & Actions

    FUNCTIONS

    • Basics
    • Development guidelines
    • Functions API
    • Custom integrations

Debug Console
Network Status

User Metadata

The Objects feature provides easy-to-use, serverless storage for user metadata, channel metadata, channel memberships, and channel members without the need to stand up an external infrastructure.

Clients can optionally store metadata for users to use them in front-end applications and enhance your application. You can store any of the predefined properties for a user such as name, email, profileURL, externalId. Additionally, you can use a custom property to store any custom attribute for a user. Some examples of custom data are nickname, color etc.

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

Events for each user are published to a channel named for each user. For example, to receive events for the user with UUID chat-user-9A7X8, you would subscribe to the channel named chat-user-9A7X8.

Set User Metadata

You can set any of the predefined or custom user metadata by providing the desired information as key/value pairs. The code below adds the name, email, and custom nickname information to the current user.

JavaScript
Objective-C
Android
C#

Go to SDK

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

Go to SDK

self.client.objects().setUUIDMetadata()
.uuid(@"uuid")
.name(@"John Doe")
.custom(@{ @"nickname": @("Mr. Mysterious") })
.email(@"johndoe@pubnub.com")
.includeFields(PNUUIDCustomField)
.performWithCompletion(^(PNSetUUIDMetadataStatus *status) {
if (!status.isError) {
/**
* UUID metadata successfully has been set.
* UUID metadata information available here: status.data.metadata
*/

} else {
/**
* Handle UUID metadata set error. Check 'category' property to find out possible issue
* because of which request did fail.
*
* Request can be resent using: [status retry]
*/

}
});

Go to SDK

Map<String, Object> custom = new HashMap<>();
custom.put("nickname", "Mr. Mysterious");
pubnub.setUUIDMetadata()
.name("John Doe")
.email("johndoe@pubnub.com")
.custom(custom)
.includeCustom(true)
.async(new PNCallback<PNSetUUIDMetadataResult>() {
@Override
public void onResponse(@Nullable final PNSetUUIDMetadataResult result, @NotNull final PNStatus status) {
if (status.isError()) {
//handle error
}
else {
//handle result
}
}
});

Go to SDK

PNResult<PNSetUuidMetadataResult> setUuidMetadataResponse = await pubnub.SetUuidMetadata()
.Uuid(config.Uuid)
.Name("John Doe")
.Email("johndoe@pubnub.com")
.Custom(new Dictionary<string, object>() { { "nickname", "Mr. Mysterious" } })
.ExecuteAsync();
PNSetUuidMetadataResult setUuidMetadataResult = setUuidMetadataResponse.Result;
PNStatus status = setUuidMetadataResponse.Status;

On success, the PubNub SDK will return metadata of the user along with the status 200. It will also fire User Metadata Set event that can be consumed by other clients. Refer to the Receive Messages section to learn more.

Get User Metadata

You can retrieve the metadata of the current user. The code below returns all metadata for the current user.

JavaScript
Objective-C
Android
C#

Go to SDK

pubnub.objects.getUUIDMetadata();

Go to SDK

self.client.objects().uuidMetadata()
.uuid(@"uuid")
.includeFields(PNUUIDCustomField)
.performWithCompletion(^(PNFetchUUIDMetadataResult *result, PNErrorStatus *status) {
if (!status.isError) {
/**
* UUID metadata successfully fetched.
* Fetched UUID metadata information available here: result.data.metadata
*/

} else {
/**
* Handle UUID metadata fetch error. Check 'category' property to find out possible issue
* because of which request did fail.
*
* Request can be resent using: [status retry]
*/

}
});

Go to SDK

pubnub.getUUIDMetadata().async(new PNCallback<PNGetUUIDMetadataResult>() {
@Override
public void onResponse(@Nullable final PNGetUUIDMetadataResult result, @NotNull final PNStatus status) {
if (status.isError()) {
//handle error
}
else {
//handle result
}
}
});

Go to SDK

// Get Metadata for the current user
PNResult<PNGetUuidMetadataResult> getUuidMetadataResponse = await pubnub.GetUuidMetadata()
.ExecuteAsync();
PNGetUuidMetadataResult getUuidMetadataResult = getUuidMetadataResponse.Result;
PNStatus status = getUuidMetadataResponse.Status;


// Get Metadata for a specific user
PNResult<PNGetUuidMetadataResult> getUuidMetadataResponse = await pubnub.GetUuidMetadata()
.Uuid("my-uuid")
.ExecuteAsync();
PNGetUuidMetadataResult getUuidMetadataResult = getUuidMetadataResponse.Result;
PNStatus status = getUuidMetadataResponse.Status;

On success, the PubNub SDK will return the all metadata of the user along with the status 200.

Get Metadata for All Users

You can also retrieve metadata for all users at once. If you're interested in their custom metadata as well, you can optionally specify whether custom metadata should be included in the response. The code below returns all predefined and custom metadata of all users:

JavaScript
Objective-C
Android
C#

Go to SDK

pubnub.objects.getAllUUIDMetadata();

Go to SDK

self.client.objects().allUUIDMetadata()
.start(@"<next from previous request>")
.includeFields(PNUUIDCustomField)
.performWithCompletion(^(PNFetchAllUUIDMetadataResult *result, PNErrorStatus *status) {
if (!status.isError) {
/**
* UUID metadata successfully fetched.
* Result object has following information:
* result.data.metadata - list of fetched UUID metadata,
* result.data.next - cursor bookmark for fetching the next page,
* result.data.prev - cursor bookmark for fetching the previous page,
* result.data.totalCount - total number of created UUID metadata.
*/

} else {
/**
* Handle UUID metadata fetch error. Check 'category' property to find out possible
* issue because of which request did fail.
*
* Request can be resent using: [status retry]
*/

}
});

Go to SDK

pubnub.getAllUUIDMetadata()
.includeTotalCount(true)
.includeCustom(true)
.async(new PNCallback<PNGetAllUUIDMetadataResult>() {
@Override
public void onResponse(@Nullable final PNGetAllUUIDMetadataResult result, @NotNull final PNStatus status) {
if (status.isError()) {
//handle error
}
else {
//handle result
}
}
});

Go to SDK

PNResult<PNGetAllUuidMetadataResult> getAllUuidMetadataResponse = await pubnub.GetAllUuidMetadata()
.IncludeCustom(true)
.IncludeCount(true)
.ExecuteAsync();
PNGetAllUuidMetadataResult getAllUuidMetadataResult = getAllUuidMetadataResponse.Result;
PNStatus status = getAllUuidMetadataResponse.Status;

On success, the PubNub SDK will return the all metadata of all users associated with the API key along with the status 200.

Remove User Metadata

You can remove all metadata for a single user. The code below removes all metadata of the current user.

JavaScript
Objective-C
Android
C#

Go to SDK

pubnub.objects.removeUUIDMetadata();

Go to SDK

self.client.objects().removeUUIDMetadata()
.uuid(@"uuid")
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// User successfully deleted.
} else {
/**
* Handle user delete error. Check 'category' property to find out possible issue
* because of which request did fail.
*
* Request can be resent using: [status retry]
*/

}
});

Go to SDK

pubnub.removeUUIDMetadata()
.async(new PNCallback<PNRemoveUUIDMetadataResult>() {
@Override
public void onResponse(@Nullable final PNRemoveUUIDMetadataResult result, @NotNull final PNStatus status) {
if (status.isError()) {
//handle error
}
else {
//handle result
}
}
});

Go to SDK

PNResult<PNRemoveUuidMetadataResult> removeUuidMetadataResponse = await pubnub.RemoveUuidMetadata()
.ExecuteAsync();
PNRemoveUuidMetadataResult removeUuidMetadataResult = removeUuidMetadataResponse.Result;
PNStatus status = removeUuidMetadataResponse.Status;

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

← ChannelMembership →
  • Set User Metadata
  • Get User Metadata
  • Get Metadata for All Users
  • Remove User Metadata
© PubNub Inc. - Privacy Policy