App Context API for Unity SDK

Starting a new app? Use DataSync

DataSync is the successor to App Context. It covers the same users, channels, and memberships, and adds typed schemas, JSON Patch updates with ETags, field-level projections, and per-class expiry. Refer to the feature-by-feature comparison for details.

DataSync is currently available to new accounts and to accounts that are not actively using App Context. If your keysets already use App Context, keep using it for now. App Context remains fully supported.

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 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. Making a request to set the same data that already exists doesn't trigger an event. Clients can receive these events in real time and update their front-end application accordingly.

User​

Manage UUID metadata: list, fetch, set, and remove. Include only the fields you need to reduce payload size.

Get metadata for all users​

Get a paginated list of UUID metadata. Use filters and sorting to narrow results.

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

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

1pubnub.GetAllUuidMetadata()
2 .IncludeCustom(bool)
3 .IncludeCount(bool)
4 .Page(PNPageObject)
5 .Sort(List<string>)
6 .Filter(string)
7 .Limit(int)
8 .Execute(System.Action<PNGetAllUuidMetadataResult, PNStatus>)
required
IncludeCustom#
Type: bool
Whether to include the Custom object in the response.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Limit#
Type: int
Number of objects to return. Default/Max: 100.
Execute required#
Type: System.Action
System.Action of type PNGetAllUuidMetadataResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNGetAllUuidMetadataResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3using UnityEngine;
4
5public class GetAllUuidMetadataExample : MonoBehaviour {
6 // Reference to a pubnub manager previously setup in Unity Editor
7 // For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
8 [SerializeField] private PNManagerBehaviour pubnubManager;
9
10 private async void Start() {
11 // Getting a reference to the Pubnub instance
12 var pubnub = pubnubManager.pubnub;
13
14 // Note that you can also initialize Pubnub instance for Unity directly from code:
15 /*
show all 49 lines

Response​

1{
2 "Uuids": [
3 {
4 "Uuid": "uuid-1",
5 "Name": "John Doe",
6 "Email": "jack@twitter.com",
7 "ExternalId": null,
8 "ProfileUrl": null,
9 "Custom": null,
10 "Updated": "2020-06-17T16:28:14.060718Z"
11 },
12 {
13 "Uuid": "uuid-2",
14 "Name": "Bob Cat",
15 "Email": "bobc@example.com",
show all 29 lines

Get user metadata​

Fetch metadata for a single UUID. Include the Custom object if you need custom fields.

Method(s)​

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

1pubnub.GetUuidMetadata()
2 .Uuid(string)
3 .IncludeCustom(bool)
4 .Execute(System.Action<PNGetUuidMetadataResult, PNStatus>)
required
Uuid required#
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
IncludeCustom#
Type: bool
Whether to include the Custom object in the response.
Execute required#
Type: System.Action
System.Action of type PNGetUuidMetadataResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNGetUuidMetadataResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 33 lines

Response​

1{
2 "Uuid": "uuid-1",
3 "Name": "John Doe",
4 "Email": "jack@twitter.com",
5 "ExternalId": null,
6 "ProfileUrl": null,
7 "Custom": null,
8 "Updated": "2020-06-17T16:28:14.060718Z"
9}

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, including the Custom object. Use the eTag to avoid overwriting concurrent updates.

Method(s)​

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

1pubnub.SetUuidMetadata()
2 .Uuid(string)
3 .Name(string)
4 .Email(string)
5 .ExternalId(string)
6 .ProfileUrl(string)
7 .Custom(Dictionary<string, object>)
8 .IncludeCustom(bool)
9 .IfMatchesEtag(string)
10 .Execute(System.Action<PNSetUuidMetadataResult, PNStatus>)
required
Uuid required#
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Name required#
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>
Custom JSON values. Can be strings, numbers, or booleans. App Context filtering language doesn’t support filtering by custom properties.
IfMatchesEtag#
Type: string
Use the eTag from an applicable get metadata call to ensure updates only apply if the object hasn’t changed. If the eTags differ, the server returns HTTP 412.
IncludeCustom#
Type: bool
Whether to include the Custom object in the response.
Execute required#
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.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 29 lines

Response​

1{
2 "Uuid": "uuid-1",
3 "Name": "John Doe",
4 "Email": "jack@twitter.com",
5 "ExternalId": null,
6 "ProfileUrl": null,
7 "Custom": null,
8 "Updated": "2020-06-17T16:28:14.060718Z"
9}

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:

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

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 26 lines

Response​

1{}

Channel​

Manage channel metadata: list, fetch, set, and remove.

Get metadata for all channels​

Get a paginated list of channel metadata. Use filters and sorting to narrow results.

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

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

1pubnub.GetAllChannelMetadata()
2 .IncludeCustom(bool)
3 .IncludeCount(bool)
4 .Page(PNPageObject)
5 .Sort(List<string>)
6 .Filter(string)
7 .Execute(System.Action<PNGetAllChannelMetadataResult, PNStatus>)
required
IncludeCustom#
Type: bool
Whether to include the Custom object in the response.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Execute required#
Type: System.Action
System.Action of type PNGetAllChannelMetadataResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNGetAllChannelMetadataResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 28 lines

Response​

1{
2 "Channels": [
3 {
4 "Channel": "my-channel",
5 "Name": "My channel",
6 "Description": "A channel that is mine",
7 "Custom": null,
8 "Updated": "2020-06-17T16:52:19.562469Z"
9 },
10 {
11 "Channel": "main",
12 "Name": "Main channel",
13 "Description": "The main channel",
14 "Custom": {
15 "public": true,
show all 26 lines

Get channel metadata​

Fetch metadata for a single channel. Include the Custom object if you need custom fields.

Method(s)​

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

1pubnub.GetChannelMetadata()
2 .Channel(string)
3 .IncludeCustom(bool)
required
Channel required#
Type: string
Channel name.
IncludeCustom#
Type: bool
Whether to include the Custom object in the response.
Execute required#
Type: System.Action
System.Action of type PNGetChannelMetadataResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNGetChannelMetadataResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 29 lines

Response​

1{
2 "Channel": "my-channel",
3 "Name": "My channel",
4 "Description": "A channel that is mine",
5 "Custom": null,
6 "Updated": "2020-06-17T16:52:19.562469Z"
7}

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, including the Custom object. Use the eTag to avoid overwriting concurrent updates.

Method(s)​

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

1pubnub.SetChannelMetadata()
2 .Channel(string)
3 .Name(string)
4 .Description(string)
5 .Custom(Dictionary<string, object>)
6 .IncludeCustom(bool)
7 .IfMatchesEtag(string)
8 .Execute(System.Action<PNSetChannelMetadataResult, PNStatus>)
required
Channel required#
Type: string
Channel name.
Name#
Type: string
Name of a channel.
Description#
Type: string
Description of a channel.
Custom#
Type: Dictionary<string, object>
Custom JSON values. Can be strings, numbers, or booleans. App Context filtering language doesn’t support filtering by custom properties.
IncludeCustom#
Type: bool
Whether to include the Custom object in the response.
IfMatchesEtag#
Type: string
Use the eTag from an applicable get metadata call to ensure updates only apply if the object hasn’t changed. If the eTags differ, the server returns HTTP 412.
Execute required#
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.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 32 lines

Response​

1{
2 "Channel": "my-channel",
3 "Name": "John Doe",
4 "Description": "sample description",
5 "Custom": {
6 "color": "blue"
7 },
8 "Updated": "2020-06-17T16:52:19.562469Z"
9}

Other examples​

Iteratively update existing metadata​
1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 71 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:

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

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 28 lines

Response​

1{}

Channel memberships​

Manage the channels a UUID belongs to: list, set, remove, and manage in bulk.

Get channel memberships​

List channel memberships for a UUID. This doesn't return subscriptions.

Method(s)​

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

1pubnub.GetMemberships()
2 .Uuid(string)
3 .Include(PNMembershipField[])
4 .IncludeCount(bool)
5 .Page(PNPageObject)
6 .Execute(System.Action<PNGetMembershipsResult, PNStatus>)
required
Uuid required#
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Include#
Type: PNMembershipField[]
Whether to include additional fields.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Execute required#
Type: System.Action
System.Action of type PNGetMembershipsResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNGetMembershipsResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 30 lines

Response​

1{
2 "Memberships": [
3 {
4 "ChannelMetadata": {
5 "Channel": "my-channel",
6 "Name": "My channel",
7 "Description": "A channel that is mine",
8 "Custom": null,
9 "Updated": "2020-06-17T16:55:44.632042Z"
10 },
11 "Custom": {
12 "starred": false
13 },
14 "Updated": "2020-06-17T17:05:25.987964Z"
15 },
show all 38 lines

Set channel memberships​

Replace or add memberships for a UUID. Provide channels (optionally with custom data).

Method(s)​

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

1pubnub.SetMemberships()
2 .Uuid(string)
3 .Channels(List<PNMembership>)
4 .Include(PNMembershipField[])
5 .IncludeCount(bool)
6 .Page(PNPageObject)
7 .Sort(List<string>)
8 .Filter(string)
9 .Limit(int)
10 .Execute(System.Action<PNMembershipsResult, PNStatus>)
required
Uuid required#
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Channels required#
Type: List<PNMembership>
List of memberships to set. Accepts channel names or PNMembership objects (with optional custom data).
Include#
Type: PNMembershipField[]
Whether to include additional fields.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Limit#
Type: int
Number of objects to return. Default/Max: 100.
Execute required#
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​

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

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 36 lines

Response​

1{
2 "Memberships": [
3 {
4 "ChannelMetadata": {
5 "Channel": "my-channel",
6 "Name": "My channel",
7 "Description": "A channel that is mine",
8 "Custom": null,
9 "Updated": "2020-06-17T16:55:44.632042Z"
10 },
11 "Custom": {
12 "starred": false
13 },
14 "Updated": "2020-06-17T17:05:25.987964Z"
15 },
show all 38 lines

Remove channel memberships​

Remove memberships for a UUID. Provide the channels to remove.

Method(s)​

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

1pubnub.RemoveMemberships()
2 .Uuid(string)
3 .Channels(List<string>)
4 .Include(PNMembershipField[])
5 .IncludeCount(bool)
6 .Page(PNPageObject)
7 .Sort(List<string>)
8 .Filter(string)
9 .Limit(int)
10 .Execute(System.Action<PNMembershipsResult, PNStatus>)
required
Uuid#
Type: String
Unique user identifier. If not supplied then current user's Uuid is used.
Channels required#
Type: List<string>
Channels to remove from membership.
Include#
Type: PNMembershipField[]
Whether to include additional fields.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Limit#
Type: int
Number of objects to return. Default/Max: 100.
Execute required#
Type: System.Action
System.Action of type PNMembershipsResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNMembershipsResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 36 lines

Response​

1{
2 "Memberships": [
3 {
4 "ChannelMetadata": {
5 "Channel": "my-channel",
6 "Name": "My channel",
7 "Description": "A channel that is mine",
8 "Custom": null,
9 "Updated": "2020-06-17T16:55:44.632042Z"
10 },
11 "Custom": {
12 "starred": false
13 },
14 "Updated": "2020-06-17T17:05:25.987964Z"
15 },
show all 38 lines

Manage channel memberships​

Add and remove memberships for a UUID in one request.

Method(s)​

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

1pubnub.ManageMemberships()
2 .Uuid(string)
3 .Set(List<PNMembership>)
4 .Remove(List<string>)
5 .Include(PNMembershipField[])
6 .IncludeCount(bool)
7 .Page(PNPageObject)
8 .Sort(List<string>)
9 .Execute(System.Action<PNMembership, PNStatus>)
required
Uuid required#
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Set#
Type: List<PNMembership>
Set channel memberships for the user.
Remove#
Type: List<string>
Remove channel memberships for the user.
Include#
Type: PNMembershipField[]
Whether to include additional fields.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Execute required#
Type: System.Action
System.Action of type PNMembership.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNMembership>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 44 lines

Response​

1{
2 "Memberships": [
3 {
4 "ChannelMetadata": {
5 "Channel": "my-channel",
6 "Name": "My channel",
7 "Description": "A channel that is mine",
8 "Custom": null,
9 "Updated": "2020-06-17T16:55:44.632042Z"
10 },
11 "Custom": {
12 "starred": false
13 },
14 "Updated": "2020-06-17T17:05:25.987964Z"
15 },
show all 38 lines

Channel members​

Manage the users in a channel: list, set, and remove.

Get channel members​

List users in a channel. Include user metadata if needed.

Method(s)​

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

1pubnub.GetChannelMembers()
2 .Channel(string)
3 .Include(PNChannelMemberField[])
4 .IncludeCount(bool)
5 .Page(PNPageObject)
6 .Sort(List<string>)
7 .Filter(string)
8 .Limit(int)
9 .Execute(System.Action<PNChannelMembersResult, PNStatus>)
required
Channel required#
Type: string
Channel name.
Include#
Type: PNChannelMemberField[]
Whether to include additional fields.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Limit#
Type: int
Number of objects to return. Default/Max: 100.
Execute required#
Type: System.Action
System.Action of type PNChannelMembersResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNChannelMembersResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 30 lines

Response​

1{
2 "ChannelMembers": [
3 {
4 "UuidMetadata": {
5 "Uuid": "uuid-1",
6 "Name": "John Doe",
7 "Email": "jack@twitter.com",
8 "ExternalId": "",
9 "ProfileUrl": "",
10 "Custom": null,
11 "Updated": "2019-02-20T23:11:20.89375"
12 },
13 "Custom": {
14 "role": "admin"
15 },
show all 39 lines

Set channel members​

Set users in a channel. Provide UUIDs (optionally with custom data).

Method(s)​

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

1pubnub.SetChannelMembers()
2 .Channel(string)
3 .Uuids(List<PNChannelMember>)
4 .Include(PNChannelMemberField[])
5 .Page(PNPageObject)
6 .Sort(List<string>)
7 .Filter(string)
8 .Limit(int)
9 .Execute(System.Action<PNChannelMembersResult, PNStatus>)
required
Channel required#
Type: String
Channel name.
Uuids required#
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[]
Whether to include additional fields.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Limit#
Type: int
Number of objects to return. Default/Max: 100.
Execute required#
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.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 37 lines

Response​

1{
2 "ChannelMembers": [
3 {
4 "UuidMetadata": {
5 "Uuid": "uuid-1",
6 "Name": "John Doe",
7 "Email": "jack@twitter.com",
8 "ExternalId": "",
9 "ProfileUrl": "",
10 "Custom": null,
11 "Updated": "2019-02-20T23:11:20.89375"
12 },
13 "Custom": {
14 "role": "admin"
15 },
show all 39 lines

Remove channel members​

Remove users from a channel. Provide the UUIDs to remove.

Method(s)​

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

1pubnub.RemoveChannelMembers()
2 .Channel(string)
3 .Uuids(List)
4 .Include(PNChannelMembersInclude[])
5 .IncludeCount(bool)
6 .Page(PnPageObject)
7 .Sort(List)
8 .Filter(string)
9 .Limit(int)
10 .Execute(System.Action<PNChannelMembersResult, PNStatus>)
required
Channel required#
Type: string
Channel name.
Uuids required#
Type: List<string>
Members to remove from channel.
Include#
Type: PNChannelMemberField[]
Whether to include additional fields.
IncludeCount#
Type: bool
Whether to include the total count in the paginated response. Default is false.
Page#
Type: PNPageObject
Cursor-based pagination.
Sort#
Type: List<string>
Sort by id, name, updated with asc/desc (for example, {name: 'asc'}).
Filter#
Type: string
Filter expression. Only matching objects are returned. See filtering.
Limit#
Type: int
Number of objects to return. Default/Max: 100.
Execute required#
Type: System.Action
System.Action of type PNChannelMembersResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNChannelMembersResult>>.

Sample code​

1using PubnubApi;
2using PubnubApi.Unity;
3
4// Configuration
5PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
6{
7 SubscribeKey = "demo",
8 PublishKey = "demo",
9 Secure = true
10};
11
12// Initialize PubNub
13Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
14
15// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
show all 37 lines

Response​

1{
2 "ChannelMembers": [
3 {
4 "UuidMetadata": {
5 "Uuid": "uuid-1",
6 "Name": "John Doe",
7 "Email": "jack@twitter.com",
8 "ExternalId": "",
9 "ProfileUrl": "",
10 "Custom": null,
11 "Updated": "2019-02-20T23:11:20.89375"
12 },
13 "Custom": {
14 "role": "admin"
15 },
show all 39 lines

Was this page useful?

Last updated on