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 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.
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>)
| Parameter | Description |
|---|---|
IncludeCustomType: bool | Whether to include the Custom object in the response. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
LimitType: int | Number of objects to return. Default/Max: 100. |
Execute *Type: System.Action | System.Action of type PNGetAllUuidMetadataResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNGetAllUuidMetadataResult>>. |
Sample code
Reference code
1
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 linesGet 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>)
| Parameter | Description |
|---|---|
Uuid *Type: string | Unique user identifier. If not supplied then current user's Uuid is used. |
IncludeCustomType: bool | Whether to include the Custom object in the response. |
Execute *Type: System.Action | System.Action of type PNGetUuidMetadataResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNGetUuidMetadataResult>>. |
Sample code
1
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:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- 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>)
| Parameter | Description |
|---|---|
Uuid *Type: string | Unique user identifier. If not supplied then current user's Uuid is used. |
Name *Type: string | Display name for the user. |
EmailType: string | The user's email address. |
ExternalIdType: string | User's identifier in an external system. |
ProfileUrlType: string | The URL of the user's profile picture. |
CustomType: Dictionary <string, object> | Custom JSON values. Can be strings, numbers, or booleans. App Context filtering language doesn’t support filtering by custom properties. |
IfMatchesEtagType: 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. |
IncludeCustomType: bool | Whether to include the Custom object in the response. |
Execute *Type: System.Action | System.Action of type PNSetUuidMetadataResult. |
ExecuteAsyncType: 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
1
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)
| Parameter | Description |
|---|---|
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. |
ExecuteAsyncType: None | Returns Task<PNResult<PNRemoveUuidMetadataResult>>. |
Sample code
1
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.
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>)
| Parameter | Description |
|---|---|
IncludeCustomType: bool | Whether to include the Custom object in the response. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
Execute *Type: System.Action | System.Action of type PNGetAllChannelMetadataResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNGetAllChannelMetadataResult>>. |
Sample code
1
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 linesGet 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)
| Parameter | Description |
|---|---|
Channel *Type: string | Channel name. |
IncludeCustomType: bool | Whether to include the Custom object in the response. |
Execute *Type: System.Action | System.Action of type PNGetChannelMetadataResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNGetChannelMetadataResult>>. |
Sample code
1
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:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- 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>)
| Parameter | Description |
|---|---|
Channel *Type: string | Channel name. |
NameType: string | Name of a channel. |
DescriptionType: string | Description of a channel. |
CustomType: Dictionary <string, object> | Custom JSON values. Can be strings, numbers, or booleans. App Context filtering language doesn’t support filtering by custom properties. |
IncludeCustomType: bool | Whether to include the Custom object in the response. |
IfMatchesEtagType: 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 *Type: System.Action | System.Action of type PNSetChannelMetadataResult. |
ExecuteAsyncType: 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
1
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
1
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)
| Parameter | Description |
|---|---|
Channel *Type: string | Channel name. |
Execute *Type: System.Action | System.Action of type PNRemoveChannelMetadataResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNRemoveChannelMetadataResult>>. |
Sample code
1
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>)
| Parameter | Description |
|---|---|
Uuid *Type: string | Unique user identifier. If not supplied then current user's Uuid is used. |
IncludeType: PNMembershipField[] | Whether to include additional fields. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
Execute *Type: System.Action | System.Action of type PNGetMembershipsResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNGetMembershipsResult>>. |
Sample code
1
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 linesSet 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>)
| Parameter | Description |
|---|---|
Uuid *Type: string | Unique user identifier. If not supplied then current user's Uuid is used. |
Channels *Type: List <PNMembership> | List of memberships to set. Accepts channel names or PNMembership objects (with optional custom data). |
IncludeType: PNMembershipField[] | Whether to include additional fields. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
LimitType: int | Number of objects to return. Default/Max: 100. |
Execute *Type: System.Action | System.Action of type PNMembershipsResult. |
ExecuteAsyncType: 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
| Property | Description |
|---|---|
Channel *Type: string | The name of the channel associated with this membership. |
CustomType: Dictionary<string, object> | A dictionary that stores custom metadata related to the membership, allowing for additional context or information. |
StatusType: string | The status of the membership, for example: "active" or "inactive" |
TypeType: string | The type of membership for categorization purposes. |
Sample code
1
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 linesRemove 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>)
| Parameter | Description |
|---|---|
UuidType: String | Unique user identifier. If not supplied then current user's Uuid is used. |
Channels *Type: List <string> | Channels to remove from membership. |
IncludeType: PNMembershipField[] | Whether to include additional fields. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
LimitType: int | Number of objects to return. Default/Max: 100. |
Execute *Type: System.Action | System.Action of type PNMembershipsResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNMembershipsResult>>. |
Sample code
1
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 linesManage 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>)
| Parameter | Description |
|---|---|
Uuid *Type: string | Unique user identifier. If not supplied then current user's Uuid is used. |
SetType: List <PNMembership> | Set channel memberships for the user. |
RemoveType: List <string> | Remove channel memberships for the user. |
IncludeType: PNMembershipField[] | Whether to include additional fields. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
Execute *Type: System.Action | System.Action of type PNMembership. |
ExecuteAsyncType: None | Returns Task<PNResult<PNMembership>>. |
Sample code
1
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 linesChannel 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>)
| Parameter | Description |
|---|---|
Channel *Type: string | Channel name. |
IncludeType: PNChannelMemberField[] | Whether to include additional fields. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
LimitType: int | Number of objects to return. Default/Max: 100. |
Execute *Type: System.Action | System.Action of type PNChannelMembersResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNChannelMembersResult>>. |
Sample code
1
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 linesSet 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>)
| Parameter | Description |
|---|---|
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). |
IncludeType: PNChannelMemberField[] | Whether to include additional fields. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
LimitType: int | Number of objects to return. Default/Max: 100. |
Execute *Type: System.Action | System.Action of type PNChannelMembersResult. |
ExecuteAsyncType: 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
1
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 linesRemove 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>)
| Parameter | Description |
|---|---|
Channel *Type: string | Channel name. |
Uuids *Type: List <string> | Members to remove from channel. |
IncludeType: PNChannelMemberField[] | Whether to include additional fields. |
IncludeCountType: bool | Whether to include the total count in the paginated response. Default is false. |
PageType: PNPageObject | Cursor-based pagination. |
SortType: List <string> | Sort by id, name, updated with asc/desc (for example, {name: 'asc'}). |
FilterType: string | Filter expression. Only matching objects are returned. See filtering. |
LimitType: int | Number of objects to return. Default/Max: 100. |
Execute *Type: System.Action | System.Action of type PNChannelMembersResult. |
ExecuteAsyncType: None | Returns Task<PNResult<PNChannelMembersResult>>. |
Sample code
1
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