/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

Manage user metadata

Copy link

Metadata consists of key-value items in which you can store additional information to users. You can add up to five key-value items for user metadata. Each key can have up to 128 characters and each value can have up to 190 characters as string. This section explains how to manage user metadata.


Create metadata

Copy link

You can create additional information such as phone number, email address or other descriptions to a user, which can be fetched or rendered into the UI. As an object, user metadata in Dictionary<string, string> is stored into an SbUser object.

To store user metadata into an SbUser object, create Dictionary<string, string> of key-value items, and then pass it as an argument to a parameter when calling the CreateMetaData() method. You can add multiple key-value items in the map.

Dictionary<string, string> metaData = new Dictionary<string, string>
{
    { "Key1", "value1" },
    { "Key2", "value2" }
};

SendbirdChat.CurrentUser.CreateMetaData(metaData, (inMetaData, inError) =>
{
    if (inError != null)
    {
        return; // Handle error.
    }
});

Retrieve metadata

Copy link

You can retrieve metadata stored to a user by calling the MetaData property of a SbUser object.

IReadOnlyDictionary<string, string> metaData = SendbirdChat.CurrentUser.MetaData;

Update metadata

Copy link

You can update metadata of a user by adding a map of key-value items, and then pass it as an argument to the parameter in the UpdateMetaData() method. Values of existing keys will be updated and values of new keys will be added. You can put multiple key-value items in the map.

Dictionary<string, string> metaData = new Dictionary<string, string>
{
    { "Key1", "valueToUpdate1" },
    { "Key2", "valueToUpdate2" }
};

SendbirdChat.CurrentUser.UpdateMetaData(metaData, (inMetaData, inError) =>
{
    if (inError != null)
    {
        return; // Handle error.
    }
});

Delete metadata

Copy link

You can delete metadata stored to a user as below.

SendbirdChat.CurrentUser.DeleteMetaData("Key1", (inError) =>
{
    if (inError != null)
    {
        return; // Handle error.
    }
});