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:
pubnub.GetAllUuidMetadata()
.IncludeCustom(bool)
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNGetAllUuidMetadataResult, PNStatus>)
Parameter | Description |
---|---|
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 *Type: System.Action | System.Action of type PNGetAllUuidMetadataResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNGetAllUuidMetadataResult>> . |
Sample code
Reference code
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 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:
pubnub.GetUuidMetadata()
.Uuid(string)
.IncludeCustom(bool)
.Execute(System.Action<PNGetUuidMetadataResult, PNStatus>)
Parameter | Description |
---|---|
Uuid *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 *Type: System.Action | System.Action of type PNGetUuidMetadataResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNGetUuidMetadataResult>> . |
Sample code
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:
- 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:
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>)
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. |
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 *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
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)
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 . |
ExecuteAsync Type: None | Returns Task<PNResult<PNRemoveUuidMetadataResult>> . |
Sample code
Response
{}
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:
pubnub.GetAllChannelMetadata()
.IncludeCustom(bool)
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Execute(System.Action<PNGetAllChannelMetadataResult, PNStatus>)
Parameter | Description |
---|---|
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 *Type: System.Action | System.Action of type PNGetAllChannelMetadataResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNGetAllChannelMetadataResult>> . |
Sample code
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 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:
pubnub.GetChannelMetadata()
.Channel(string)
.IncludeCustom(bool)
Parameter | Description |
---|---|
Channel *Type: string | Channel name. |
IncludeCustom Type: bool | Whether to include the Custom object in the response. |
Execute *Type: System.Action | System.Action of type PNGetChannelMetadataResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNGetChannelMetadataResult>> . |
Sample code
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:
- 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:
pubnub.SetChannelMetadata()
.Channel(string)
.Name(string)
.Description(string)
.Custom(Dictionary<string, object>)
.IncludeCustom(bool)
.IfMatchesEtag(string)
.Execute(System.Action<PNSetChannelMetadataResult, PNStatus>)
Parameter | Description |
---|---|
Channel *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 *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
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
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)
Parameter | Description |
---|---|
Channel *Type: string | Channel name. |
Execute *Type: System.Action | System.Action of type PNRemoveChannelMetadataResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNRemoveChannelMetadataResult>> . |
Sample code
Response
{}
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:
pubnub.GetMemberships()
.Uuid(string)
.Include(PNMembershipField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Execute(System.Action<PNGetMembershipsResult, PNStatus>)
Parameter | Description |
---|---|
Uuid *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 *Type: System.Action | System.Action of type PNGetMembershipsResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNGetMembershipsResult>> . |
Sample code
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 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:
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>)
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). |
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 *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
Property | Description |
---|---|
Channel *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
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 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:
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>)
Parameter | Description |
---|---|
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[] | 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 *Type: System.Action | System.Action of type PNMembershipsResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNMembershipsResult>> . |
Sample code
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 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:
pubnub.ManageMemberships()
.Uuid(string)
.Set(List<PNMembership>)
.Remove(List<string>)
.Include(PNMembershipField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Execute(System.Action<PNMembership, PNStatus>)
Parameter | Description |
---|---|
Uuid *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 *Type: System.Action | System.Action of type PNMembership . |
ExecuteAsync Type: None | Returns Task<PNResult<PNMembership>> . |
Sample code
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 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:
pubnub.GetChannelMembers()
.Channel(string)
.Include(PNChannelMemberField[])
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNChannelMembersResult, PNStatus>)
Parameter | Description |
---|---|
Channel *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 *Type: System.Action | System.Action of type PNChannelMembersResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNChannelMembersResult>> . |
Sample code
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 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:
pubnub.SetChannelMembers()
.Channel(string)
.Uuids(List<PNChannelMember>)
.Include(PNChannelMemberField[])
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
.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). |
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 *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
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 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:
pubnub.RemoveChannelMembers()
.Channel(string)
.Uuids(List)
.Include(PNChannelMembersInclude[])
.IncludeCount(bool)
.Page(PnPageObject)
.Sort(List)
.Filter(string)
.Limit(int)
.Execute(System.Action<PNChannelMembersResult, PNStatus>)
Parameter | Description |
---|---|
Channel *Type: string | Channel name. |
Uuids *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 *Type: System.Action | System.Action of type PNChannelMembersResult . |
ExecuteAsync Type: None | Returns Task<PNResult<PNChannelMembersResult>> . |
Sample code
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