App Context API for Unity SDK

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.

PubNub also triggers events when object data is changed: set, updated, or removed from the database. At the same time, making a request to set the same data that already exist, doesn't trigger any event. Clients can receive these events in real time and update their front-end application accordingly.

User

Get Metadata for All Users

Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All UUID Metadata you can use the following method(s) in the Unity SDK:

pubnub.GetAllUuidMetadata()
.IncludeCustom(bool)
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNGetAllUuidMetadataResult, PNStatus>)
* required
ParameterDescription
IncludeCustom
Type: bool
Whether to fetch Custom fields or not.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Execute *
Type: System.Action
System.Action of type PNGetAllUuidMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNGetAllUuidMetadataResult>>.

Basic Usage

PNResult<PNGetAllUuidMetadataResult> getAllUuidMetadataResponse = await pubnub.GetAllUuidMetadata()
.IncludeCustom(true)
.IncludeCount(true)
.ExecuteAsync();

PNGetAllUuidMetadataResult getAllUuidMetadataResult = getAllUuidMetadataResponse.Result;
PNStatus status = getAllUuidMetadataResponse.Status;

Response

{
"Uuids": [
{
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "jack@twitter.com",
"ExternalId": null,
"ProfileUrl": null,
"Custom": null,
"Updated": "2020-06-17T16:28:14.060718Z"
},
{
"Uuid": "uuid-2",
"Name": "Bob Cat",
"Email": "bobc@example.com",
show all 29 lines

Get User Metadata

Returns metadata for the specified UUID, optionally including the custom data object for each.

Method(s)

To Get UUID Metadata you can use the following method(s) in the Unity SDK:

pubnub.GetUuidMetadata()
.Uuid(string)
.IncludeCustom(bool)
.Execute(System.Action<PNGetUuidMetadataResult, PNStatus>)
* required
ParameterDescription
Uuid *
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
IncludeCustom
Type: bool
Whether to fetch Custom fields or not.
Execute *
Type: System.Action
System.Action of type PNGetUuidMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNGetUuidMetadataResult>>.

Basic Usage

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

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

Response

{
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "jack@twitter.com",
"ExternalId": null,
"ProfileUrl": null,
"Custom": null,
"Updated": "2020-06-17T16:28:14.060718Z"
}

Set User Metadata

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a UUID in the database, optionally including the custom data object for each.

Method(s)

To Set UUID Metadata you can use the following method(s) in the Unity SDK:

pubnub.SetUuidMetadata()
.Uuid(string)
.Name(string)
.Email(string)
.ExternalId(string)
.ProfileUrl(string)
.Custom(Dictionary<string, object>)
.IncludeCustom(bool)
.IfMatchesEtag(string)
.Execute(System.Action<PNSetUuidMetadataResult, PNStatus>)
* required
ParameterDescription
Uuid *
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Name *
Type: string
Display name for the user.
Email
Type: string
The user's email address.
ExternalId
Type: string
User's identifier in an external system.
ProfileUrl
Type: string
The URL of the user's profile picture.
Custom
Type: Dictionary<string, object>
JSON object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties.
IfMatchesEtag
Type: string
The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown.
IncludeCustom
Type: bool
Whether to fetch Custom fields or not.
Execute *
Type: System.Action
System.Action of type PNSetUuidMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNSetUuidMetadataResult>>.
API limits

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

Basic Usage

// Set Metadata for UUID set in the pubnub instance
PNResult<PNSetUuidMetadataResult> setUuidMetadataResponse = await pubnub.SetUuidMetadata()
.Uuid(config.Uuid)
.Name("John Doe")
.Email("john.doe@user.com")
.ExecuteAsync();
PNSetUuidMetadataResult setUuidMetadataResult = setUuidMetadataResponse.Result;
PNStatus status = setUuidMetadataResponse.Status;

Response

{
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "jack@twitter.com",
"ExternalId": null,
"ProfileUrl": null,
"Custom": null,
"Updated": "2020-06-17T16:28:14.060718Z"
}

Remove User Metadata

Removes the metadata from a specified UUID.

Method(s)

To Remove UUID Metadata you can use the following method(s) in the Unity SDK:

pubnub.RemoveUuidMetadata()
.Uuid(string)
* required
ParameterDescription
Uuid *
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Execute *
Type: System.Action
System.Action of type PNRemoveUuidMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNRemoveUuidMetadataResult>>.

Basic Usage

// Remove Metadata for UUID set in the pubnub instance
PNResult<PNRemoveUuidMetadataResult> removeUuidMetadataResponse = await pubnub.RemoveUuidMetadata()
.ExecuteAsync();
PNRemoveUuidMetadataResult removeUuidMetadataResult = removeUuidMetadataResponse.Result;
PNStatus status = removeUuidMetadataResponse.Status;

Response

{}

Channel

Get Metadata for All Channels

Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All Channel Metadata you can use the following method(s) in the Unity SDK:

pubnub.GetAllChannelMetadata()
.IncludeCustom(bool)
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Execute(System.Action<PNGetAllChannelMetadataResult, PNStatus>)
* required
ParameterDescription
IncludeCustom
Type: bool
Whether to fetch Custom fields or not.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Execute *
Type: System.Action
System.Action of type PNGetAllChannelMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNGetAllChannelMetadataResult>>.

Basic Usage

PNResult<PNGetAllChannelMetadataResult> getAllChannelMetadataResponse = await pubnub.GetAllChannelMetadata()
.IncludeCount(true)
.IncludeCustom(true)
.ExecuteAsync();

PNGetAllChannelMetadataResult getAllChannelMetadataResult = getAllChannelMetadataResponse.Result;
PNStatus status2 = getAllChannelMetadataResponse.Status;

Response

{
"Channels": [
{
"Channel": "my-channel",
"Name": "My channel",
"Description": "A channel that is mine",
"Custom": null,
"Updated": "2020-06-17T16:52:19.562469Z"
},
{
"Channel": "main",
"Name": "Main channel",
"Description": "The main channel",
"Custom": {
"public": true,
show all 26 lines

Get Channel Metadata

Returns metadata for the specified Channel, optionally including the custom data object for each.

Method(s)

To Get Channel Metadata you can use the following method(s) in the Unity SDK:

pubnub.GetChannelMetadata()
.Channel(string)
.IncludeCustom(bool)
* required
ParameterDescription
Channel *
Type: string
Channel name.
IncludeCustom
Type: bool
Whether to fetch Custom fields or not.
Execute *
Type: System.Action
System.Action of type PNGetChannelMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNGetChannelMetadataResult>>.

Basic Usage

// Get Metadata for a specific channel
PNResult<PNGetChannelMetadataResult> getChannelMetadataResponse = await pubnub.GetChannelMetadata()
.Channel("my-channel")
.IncludeCustom(true)
.ExecuteAsync();

PNGetChannelMetadataResult getChannelMetadataResult = getChannelMetadataResponse.Result;
PNStatus status = getChannelMetadataResponse.Status;

Response

{
"Channel": "my-channel",
"Name": "My channel",
"Description": "A channel that is mine",
"Custom": null,
"Updated": "2020-06-17T16:52:19.562469Z"
}

Set Channel Metadata

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a Channel in the database, optionally including the custom data object for each.

Method(s)

To Set Channel Metadata you can use the following method(s) in the Unity SDK:

pubnub.SetChannelMetadata()
.Channel(string)
.Name(string)
.Description(string)
.Custom(Dictionary<string, object>)
.IncludeCustom(bool)
.IfMatchesEtag(string)
.Execute(System.Action<PNSetChannelMetadataResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: string
Channel name.
Name
Type: string
Name of a channel.
Description
Type: string
Description of a channel.
Custom
Type: Dictionary<string, object>
Include respective additional fields in the response. App Context filtering language doesn’t support filtering by custom properties.
IncludeCustom
Type: bool
Whether to fetch custom fields or not.
IfMatchesEtag
Type: string
The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown.
Execute *
Type: System.Action
System.Action of type PNSetChannelMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNSetChannelMetadataResult>>.
API limits

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

Basic Usage

// Set Metadata for a specific channel
PNResult<PNSetChannelMetadataResult> setChannelMetadataResponse = await pubnub.SetChannelMetadata()
.Channel("my-channel")
.Name("John Doe")
.Description("sample description")
.Custom(new Dictionary<string, object>() { { "color", "blue" } })
.IncludeCustom(true)
.ExecuteAsync();

PNSetChannelMetadataResult setChannelMetadataResult = setChannelMetadataResponse.Result;
PNStatus status = setChannelMetadataResponse.Status;

Response

{
"Channel": "my-channel",
"Name": "John Doe",
"Description": "sample description",
"Custom": {
"color": "blue"
},
"Updated": "2020-06-17T16:52:19.562469Z"
}

Other Examples

Iteratively update existing metadata
using System.Collections.Generic;
using PubnubApi;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class PubNubChannelMetadataExample : MonoBehaviour {

//UI input for the channel ID
[SerializeField] private TMP_InputField channelInput;

//UI inputs for new values
[SerializeField] private TMP_InputField nameInput;
[SerializeField] private TMP_InputField descriptionInput;
[SerializeField] private Toggle overwriteToggle;
show all 96 lines

Remove Channel Metadata

Removes the metadata from a specified channel.

Method(s)

To Remove Channel Metadata you can use the following method(s) in the Unity SDK:

pubnub.RemoveChannelMetadata()
.Channel(string)
* required
ParameterDescription
Channel *
Type: string
Channel name.
Execute *
Type: System.Action
System.Action of type PNRemoveChannelMetadataResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNRemoveChannelMetadataResult>>.

Basic Usage

// Delete Metadata for a specific channel
PNResult<PNRemoveChannelMetadataResult> removeChannelMetadataResponse = await pubnub.RemoveChannelMetadata()
.Channel("mychannel")
.ExecuteAsync();

PNRemoveChannelMetadataResult removeChannelMetadataResult = removeChannelMetadataResponse.Result;
PNStatus status = removeChannelMetadataResponse.Status;

Response

{}

Channel Memberships

Get Channel Memberships

The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.

Method(s)

To Get Memberships you can use the following method(s) in the Unity SDK:

pubnub.GetMemberships()
.Uuid(string)
.Include(PNMembershipField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Execute(System.Action<PNGetMembershipsResult, PNStatus>)
* required
ParameterDescription
Uuid *
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Include
Type: PNMembershipField[]
Include respective additional fields in the response.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Execute *
Type: System.Action
System.Action of type PNGetMembershipsResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNGetMembershipsResult>>.

Basic Usage

PNResult<PNGetMembershipsResult> getMembershipsResponse = await pubnub.GetMemberships()
.Uuid("my-uuid")
.Include(new PNMembershipField[] { PNMembershipField.CUSTOM, PNMembershipField.CHANNEL, PNMembershipField.CHANNEL_CUSTOM })
.IncludeCount(true)
.Page(new PNPageObject() { Next = "", Prev = "" })
.ExecuteAsync();

PNGetMembershipsResult getMembeshipsResult = getMembershipsResponse.Result;
PNStatus status = getMembershipsResponse.Status;

Response

{
"Memberships": [
{
"ChannelMetadata": {
"Channel": "my-channel",
"Name": "My channel",
"Description": "A channel that is mine",
"Custom": null,
"Updated": "2020-06-17T16:55:44.632042Z"
},
"Custom": {
"starred": false
},
"Updated": "2020-06-17T17:05:25.987964Z"
},
show all 38 lines

Set Channel Memberships

Set channel memberships for a UUID.

Method(s)

To Set Memberships you can use the following method(s) in the Unity SDK:

pubnub.SetMemberships()
.Uuid(string)
.Channels(List<PNMembership>)
.Include(PNMembershipField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNMembershipsResult, PNStatus>)
* required
ParameterDescription
Uuid *
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Channels *List of Channels to add to membership. List can contain strings (channel-name only) or objects (which can include custom data).
Include
Type: PNMembershipField[]
Include respective additional fields in the response.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Execute *
Type: System.Action
System.Action of type PNMembershipsResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNMembershipsResult>>.
API limits

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

PNMembership

PropertyTypeRequiredDescription
Channel
string
Yes
The name of the channel associated with this membership.
Custom
Dictionary<string, object>
No
A dictionary that stores custom metadata related to the membership, allowing for additional context or information.
Status
string
No
The status of the membership, for example: "active" or "inactive"
Type
string
No
The type of membership for categorization purposes.

Basic Usage

List<PNMembership> setMembershipChannelMetadataIdList = new List<PNMembership>();
if (!string.IsNullOrEmpty(seMembershipChannelMetaId))
{
setMembershipChannelMetadataIdList.Add(new PNMembership() { Channel = "my-channel", Custom = new Dictionary<string, object>() { { "item", "book" } } });
}

PNResult<PNMembershipsResult> setMembershipsResponse = await pubnub.SetMemberships()
.Uuid("my-uuid")
.Channels(setMembershipChannelMetadataIdList)
.Include(new PNMembershipField[] { PNMembershipField.CUSTOM, PNMembershipField.CHANNEL, PNMembershipField.CHANNEL_CUSTOM })
.IncludeCount(true)
.ExecuteAsync();

PNMembershipsResult setMembershipsResult = setMembershipsResponse.Result;
PNStatus status = setMembershipsResponse.Status;

Response

{
"Memberships": [
{
"ChannelMetadata": {
"Channel": "my-channel",
"Name": "My channel",
"Description": "A channel that is mine",
"Custom": null,
"Updated": "2020-06-17T16:55:44.632042Z"
},
"Custom": {
"starred": false
},
"Updated": "2020-06-17T17:05:25.987964Z"
},
show all 38 lines

Remove Channel Memberships

Remove channel memberships for a UUID.

Method(s)

To Remove Memberships you can use the following method(s) in the Unity SDK:

pubnub.RemoveMemberships()
.Uuid(string)
.Channels(List<string>)
.Include(PNMembershipField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNMembershipsResult, PNStatus>)
* required
ParameterDescription
Uuid
Type: String
Unique user identifier. If not supplied then current user's Uuid is used.
Channels *
Type: List<string>
Channels to remove from membership.
Include
Type: PNMembershipField[]
Include respective additional fields in the response.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Execute *
Type: System.Action
System.Action of type PNMembershipsResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNMembershipsResult>>.

Basic Usage

List<string> removeMembershipList = new List<string>();
if (!string.IsNullOrEmpty(removeMembershipChannelMetaId))
{
removeMembershipList.Add("my-channel");
removeMembershipList.Add("your-channel");
}

PNResult<PNMembershipsResult> removeMembershipsResponse = await pubnub.RemoveMemberships()
.Uuid("uuid")
.Channels(removeMembershipList)
.Include(new PNMembershipField[] { PNMembershipField.CUSTOM, PNMembershipField.CHANNEL, PNMembershipField.CHANNEL_CUSTOM })
.IncludeCount(true)
.ExecuteAsync();

PNMembershipsResult removeMembershipsResult = removeMembershipsResponse.Result;
show all 16 lines

Response

{
"Memberships": [
{
"ChannelMetadata": {
"Channel": "my-channel",
"Name": "My channel",
"Description": "A channel that is mine",
"Custom": null,
"Updated": "2020-06-17T16:55:44.632042Z"
},
"Custom": {
"starred": false
},
"Updated": "2020-06-17T17:05:25.987964Z"
},
show all 38 lines

Manage Channel Memberships

Set and remove channel memberships for a user.

Method(s)

To Manage Memberships you can use the following method(s) in the Unity SDK:

pubnub.ManageMemberships()
.Uuid(string)
.Set(List<PNMembership>)
.Remove(List<string>)
.Include(PNMembershipField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Execute(System.Action<PNMembership, PNStatus>)
* required
ParameterDescription
Uuid *
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
SetSet channel memberships for the user.
Remove
Type: List<string>
Remove channel memberships for the user.
Include
Type: PNMembershipField[]
Include respective additional fields in the response.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Execute *
Type: System.Action
System.Action of type PNMembership.
ExecuteAsync
Type: None
Returns Task<PNResult<PNMembership>>.

Basic Usage

List<PNMembership> setMembrshipList = new List<PNMembership>();
setMembrshipList.Add(new PNMembership() { Channel = "ch1", Custom = new Dictionary<string, object>() { { "say","hello" } } });
setMembrshipList.Add(new PNMembership() { Channel = "ch2", Custom = new Dictionary<string, object>() { { "say", "world" } } });
setMembrshipList.Add(new PNMembership() { Channel = "ch3", Custom = new Dictionary<string, object>() { { "say", "bye" } } });

List<string> removeMembrshipList = new List<string>();
removeMembrshipList.Add("ch4");

PNResult<PNManageMembershipsResult> manageMmbrshipsResponse = await pubnub.ManageMemberships()
.Uuid("my-uuid")
.Set(setMembrshipList)
.Remove(removeMembrshipList)
.Include(new PNMembershipField[] { PNMembershipField.CUSTOM, PNMembershipField.CHANNEL, PNMembershipField.CHANNEL_CUSTOM })
.IncludeCount(true)
.Page(new PNPageObject() { Next = "", Prev = "" })
show all 20 lines

Response

{
"Memberships": [
{
"ChannelMetadata": {
"Channel": "my-channel",
"Name": "My channel",
"Description": "A channel that is mine",
"Custom": null,
"Updated": "2020-06-17T16:55:44.632042Z"
},
"Custom": {
"starred": false
},
"Updated": "2020-06-17T17:05:25.987964Z"
},
show all 38 lines

Channel Members

Get Channel Members

The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.

Method(s)

To Get Channel Members you can use the following method(s) in the Unity SDK:

pubnub.GetChannelMembers()
.Channel(string)
.Include(PNChannelMemberField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNChannelMembersResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: string
Channel name.
Include
Type: PNChannelMemberField[]
Include respective additional fields in the response.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Execute *
Type: System.Action
System.Action of type PNChannelMembersResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelMembersResult>>.

Basic Usage

// Get Members (uuids) for a specific channel
PNResult<PNChannelMembersResult> getChannelMembersResponse = await pubnub.GetChannelMembers()
.Channel("my-channel")
.Include(new PNChannelMemberField[] { PNChannelMemberField.CUSTOM, PNChannelMemberField.UUID, PNChannelMemberField.UUID_CUSTOM })
.IncludeCount(true)
.ExecuteAsync();

PNChannelMembersResult getChannelMembersResult = getChannelMembersResponse.Result;
PNStatus status2 = getChannelMembersResponse.Status;

Response

{
"ChannelMembers": [
{
"UuidMetadata": {
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "jack@twitter.com",
"ExternalId": "",
"ProfileUrl": "",
"Custom": null,
"Updated": "2019-02-20T23:11:20.89375"
},
"Custom": {
"role": "admin"
},
show all 39 lines

Set Channel Members

This method sets members in a channel.

Method(s)

To Set Channel Members you can use the following method(s) in the Unity SDK:

pubnub.SetChannelMembers()
.Channel(string)
.Uuids(List<PNChannelMember>)
.Include(PNChannelMemberField[])
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNChannelMembersResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: String
Channel name.
Uuids *
Type: List<PNChannelMember>
List of members to add to the channel. List can contain strings (Uuids only) or objects (which can include custom data).
Include
Type: PNChannelMemberField[]
Include respective additional fields in the response.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Execute *
Type: System.Action
System.Action of type PNChannelMembersResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelMembersResult>>.
API limits

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

Basic Usage

// Add Members (UUID) for a specific channel
List<PNChannelMember> setMemberChannelList = new List<PNChannelMember>();
if (!string.IsNullOrEmpty(setMemberChUuid))
{
setMemberChannelList.Add(new PNChannelMember() { Uuid = "my-uuid", Custom = new Dictionary<string, object>() { { "planet", "earth" } } });
}
PNResult<PNChannelMembersResult> setChannelMembersResponse = await pubnub.SetChannelMembers()
.Channel(setmemberChMetadataId)
.Uuids(setMemberChannelList)
.Include(new PNChannelMemberField[] { PNChannelMemberField.CUSTOM, PNChannelMemberField.UUID, PNChannelMemberField.UUID_CUSTOM })
.IncludeCount(true)
.ExecuteAsync();

PNChannelMembersResult setChannelMembersResult = setChannelMembersResponse.Result;
PNStatus status2 = setChannelMembersResponse.Status;

Response

{
"ChannelMembers": [
{
"UuidMetadata": {
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "jack@twitter.com",
"ExternalId": "",
"ProfileUrl": "",
"Custom": null,
"Updated": "2019-02-20T23:11:20.89375"
},
"Custom": {
"role": "admin"
},
show all 39 lines

Remove Channel Members

Remove members from a Channel.

Method(s)

To Remove Channel Members you can use the following method(s) in the Unity SDK:

pubnub.RemoveChannelMembers()
.Channel(string)
.Uuids(List)
.Include(PNChannelMembersInclude[])
.IncludeCount(bool)
.Page(PnPageObject)
.Sort(List)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNChannelMembersResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: string
Channel name.
Uuids *
Type: List<string>
Members to remove from channel.
Include
Type: PNChannelMemberField[]
Include respective additional fields in the response.
IncludeCount
Type: bool
Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
Page
Type: PNPageObject
Use for pagination.
Sort
Type: List<string>
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Execute *
Type: System.Action
System.Action of type PNChannelMembersResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNChannelMembersResult>>.

Basic Usage

// Remove Members (UUID) for a specific channel
List<string> removeChannelMemberList = new List<string>();
removeChannelMemberList.Add("my-uuid");
removeChannelMemberList.Add("your-uuid");

PNResult<PNChannelMembersResult> removeChannelMembersResponse = await pubnub.RemoveChannelMembers()
.Channel("my-channel")
.Uuids(removeChannelMemberList)
.Include(new PNChannelMemberField[] { PNChannelMemberField.CUSTOM, PNChannelMemberField.UUID, PNChannelMemberField.UUID_CUSTOM })
.IncludeCount(true)
.ExecuteAsync();

PNChannelMembersResult removeChannelMembersResult = removeChannelMembersResponse.Result;
PNStatus status = removeChannelMembersResponse.Status;

Response

{
"ChannelMembers": [
{
"UuidMetadata": {
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "jack@twitter.com",
"ExternalId": "",
"ProfileUrl": "",
"Custom": null,
"Updated": "2019-02-20T23:11:20.89375"
},
"Custom": {
"role": "admin"
},
show all 39 lines
Last updated on