App Context API for PubNub C# 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 C# SDK:
pubnub.GetAllUuidMetadata()
.IncludeCustom(bool)
.IncludeCount(bool)
.Page(PNPageObject)
.Sort(List<string>)
.Filter(string)
.Limit(int)
Parameter | Type | Required | Description |
---|---|---|---|
IncludeCustom | bool | Optional | Whether to fetch Custom fields or not. |
IncludeCount | bool | Optional | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
Page | PNPageObject | Optional | Use for pagination. |
Sort | List<string> | Optional | 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 | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
Limit | int | Optional | Number of objects to return in response. Default is 100 , which is also the maximum value. |
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 linesGet 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 C# SDK:
pubnub.GetUuidMetadata()
.Uuid(string)
.IncludeCustom(bool)
Parameter | Type | Required | Description |
---|---|---|---|
Uuid | string | Yes | Unique user identifier. If not supplied then current user's Uuid is used. |
IncludeCustom | bool | Optional | Whether to fetch Custom fields or not. |
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:
- 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, optionally including the custom data object for each.
Method(s)
To Set UUID Metadata
you can use the following method(s) in the C# SDK:
pubnub.SetUuidMetadata()
.Uuid(string)
.Name(string)
.Email(string)
.ExternalId(string)
.ProfileUrl(string)
.Custom(Dictionary<string, object>)
.IncludeCustom(bool)
.IfMatchesEtag(string)
Parameter | Type | Required | Description |
---|---|---|---|
Uuid | string | Yes | Unique user identifier. If not supplied then current user's Uuid is used. |
Name | string | Yes | Display name for the user. |
Email | string | Optional | The user's email address. |
ExternalId | string | Optional | User's identifier in an external system. |
ProfileUrl | string | Optional | The URL of the user's profile picture. |
Custom | Dictionary<string, object> | Optional | JSON object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties. |
IncludeCustom | bool | Optional | Whether to fetch Custom fields or not. |
IfMatchesEtag | String | No | 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. |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.