DataSync API for Unity SDK
DataSync is PubNub's data layer for storing application state (users, channels, memberships, and any custom object type) and keeping every connected client current through real-time events. Use it to model the objects your application works with and to react the moment they change.
DataSync is the successor to App Context.
DataSync entities and SDK entities are different things
This page is about DataSync entities, the records the service stores and treats as the source of truth for your application state. They are created and read through the pubnub.DataSync.* methods documented here.
An SDK entity is a local client-side handle such as pubnub.Channel("room-1"). It carries no stored state of its own, it just gives you a scoped surface for subscribing and calling APIs. Refer to SDK entities in Publish and subscribe.
The Unity SDK has no dedicated DataSync SDK entity. To observe a DataSync object you subscribe to its channel with an ordinary Channel SDK entity and attach a DataSync listener to the resulting Subscription, a SubscriptionSet, or the PubNub client. Refer to Real-time updates.
The classes that your objects conform to (their types and schemas) are defined through the Admin API or the Admin Portal, not through this SDK:
- Entity classes, which back users, channels, and custom entities: list, read, create, replace, and delete. Partial updates aren't implemented, replace the complete class version instead.
- Relationship classes, which back memberships and custom relationships: list, read, create, replace, and delete.
User and Channel entity classes and the Membership relationship class are predefined on every keyset, so you only need to define classes for your own custom entities and relationships.
A class definition is what decides, for every object of that class, which Payload fields are filterable and sortable, which projection each field belongs to, and how long the object lives before it expires. Refer to managing classes for more information.
Every method returns a PNResult<T> carrying the HTTP Status and a Result holding the object, or the list of objects for a list method. The Delete* methods return an empty Result, so read Status to see whether the delete worked. A stored object carries its free-form Status and its ExpiresAt auto-deletion timestamp (ISO 8601) whenever those are set on it.
- Authorization
- Pagination
- Filtering and sorting
- Concurrency (ETag)
- Partial updates
- Expiry (TTL)
Every DataSync request must be authorized with a token or signature. A request with no credential fails with a 401, an invalid credential or a credential that doesn't permit the operation fails with a 403.
A signature means the client is configured with a SecretKey, and the SDK then signs every request with it automatically. Never put a secret key in a client-side application, use it only on a server you control. Give client-side applications a token from GrantToken() instead, set with SetAuthToken().
DataSync pagination is forward-only. There is no previous-page cursor, and PaginationMeta exposes no PrevCursor or HasPrev. To revisit an earlier page, page from the start again.
All list methods (GetUsers, GetChannels, GetMemberships, GetEntities, and GetRelationships) accept Cursor and Limit (default 20, max 100) and can return a Meta object of type PaginationMeta with NextCursor, HasNext, and Limit. The Meta object is optional, so guard the access when you read it, for example response.Result.Meta?.NextCursor.
To page forward, pass the returned NextCursor back as Cursor on the next call, and stop when HasNext is false. NextCursor is null on the last page. Refer to sorting and pagination for details.
All list methods accept two mutually exclusive filter parameters, FilterFast and Filter. The SDK sends whatever you set, so a call that carries both reaches the server and fails there with a 400.
| Parameter | Consistency | Properties it can read | Expression complexity |
|---|---|---|---|
FilterFast | Strongly consistent, reflects the latest writes | Filtering mode simple or full | Up to 10 conditions by default (raisable per keyset) |
Filter | Eventually consistent, results can briefly lag writes | Filtering mode full only | Full expression language |
Reach for FilterFast when the query has to see an object you just wrote, and for Filter when you need the full expression language over a full-indexed property.
danger
Filter is not the strongly consistent oneThe two names read the wrong way round if you assume Filter is the basic option. FilterFast is the strongly consistent, limited one. Filter is the richer, eventually consistent one.
Both parameters share the same expression language, a string built from a property name, an operator, and a value:
| Operators | |
|---|---|
| Comparison | ==, !=, <, >, <=, >= |
| Pattern matching | LIKE (case-insensitive), SLIKE (case-sensitive), ILIKE (case-insensitive, same as LIKE) |
| Logical | &&, ||, !, and parentheses for grouping |
Values are quoted strings, numbers, true, false, or null. Pattern operators (LIKE, SLIKE, ILIKE) apply to string properties only, and null is only valid with == and !=. Reference a property by its name, not its declared path, and only properties declared on the class are filterable. To reach a nested Payload property, declare it as a class property first, then filter by that property's name, for example "price < 100" for a product class that declares price.
Some examples:
1FilterFast = "price < 100" // strongly consistent, single condition
2FilterFast = "(price < 100 && stock > 0) || price > 500" // strongly consistent, grouped conditions
3Filter = "name LIKE \"*sneaker*\"" // eventually consistent, needs filtering mode "full"
4Filter = "!(status == \"discontinued\")" // eventually consistent, negated condition
Both parameters only work over properties declared on the class, plus the built-in id, createdAt, updatedAt, and status fields, which are always filterable and sortable without being declared. eTag and expiresAt are neither. The status exception does not hold if the class redeclares /status scoped to projections your token cannot fully reach. Refer to filtering for the two filtering tiers, and property definitions for how properties are declared.
Use Sort to order results. Its value is a comma-separated list of fields, each a property name optionally suffixed with :asc or :desc. A bare name sorts ascending:
1Sort = "price:desc" // single field, descending
2Sort = "type,price:desc" // type ascending, then price descending
3Sort = "createdAt:asc" // explicit ascending
The +field and -field prefixes are not accepted. A leading - is read as part of the property name, so "-price" fails with a 400. Only properties declared on the class with a filtering mode other than none can be sorted on when sorting alone or alongside FilterFast. Sorting alongside Filter additionally requires the field to be declared full. The built-in fields id, createdAt, updatedAt, and status are always sortable without declaring them on the class.
The SDK doesn't validate FilterFast, Filter, Sort, or Limit locally, it passes them through as-is. An invalid expression, an unsortable field, or an out-of-range Limit only surfaces as an error response from the server, not as a client-side exception.
Every stored object carries an ETag. To guard against concurrent writes, pass the ETag you read earlier as IfMatch on Set*, Update*, and Delete* calls. The SDK sends it as the If-Match request header.
If the server-side value has changed in the meantime, the operation fails with a 412, and you should re-read the object and retry. Refer to optimistic concurrency with ETags for details.
The Update* methods apply a partial update using raw JSON Patch (RFC 6902). Each operation is a JsonPatchOperation with an Op (Add, Remove, Replace, Move, Copy, or Test), a Path (a full JSON Pointer, for example /status or /payload/price), and, depending on the operation, a Value or a From.
Each path is a full JSON Pointer (RFC 6901) and is sent as you write it. The SDK does not add a /payload prefix. To target a field inside Payload, include the prefix yourself, for example /payload/price, not /price. A bare /price targets a top-level field named price, which doesn't exist. Top-level fields like /status can be patched directly. Refer to partial update for details.
Correct patch forms:
1new JsonPatchOperation { Op = JsonPatchOperationType.Add, Path = "/payload/tags/-", Value = "featured" } // adds a value inside payload.tags
2new JsonPatchOperation { Op = JsonPatchOperationType.Replace, Path = "/payload/price", Value = 79.99 } // replaces payload.price
3new JsonPatchOperation { Op = JsonPatchOperationType.Remove, Path = "/payload/tempFlag" } // removes payload.tempFlag
4new JsonPatchOperation { Op = JsonPatchOperationType.Move, Path = "/payload/newField", From = "/payload/oldField" }
5new JsonPatchOperation { Op = JsonPatchOperationType.Copy, Path = "/payload/backupField", From = "/payload/field" }
6new JsonPatchOperation { Op = JsonPatchOperationType.Test, Path = "/payload/price", Value = 79.99 } // fails the patch if the current value doesn't match
Move and Copy require From (the source pointer) instead of Value. Test requires Value and fails the entire patch if the current value at Path doesn't match, use it to guard the rest of the operations against a stale read.
Paths address the object's stored property names, the same keys that come back in responses. The class version is entityClassVersion on users, channels, and entities, and relationshipClassVersion on memberships and relationships. The fields set at creation cannot be patched: entityClass and entityClassLevel on users, channels, and entities, relationshipClass, entityAId, and entityBId on relationships, and userId and channelId on memberships.
All operations in the call apply together or not at all.
The Operations list must contain at least one operation. The SDK checks this before it sends anything and returns a Status with Error set to true if the list is null or empty, it doesn't throw.
An object's ExpiresAt is computed once when the object is created, and updates never refresh it. The value is the creation time plus the class TTL, rounded up to the start of the next whole UTC day, so it rarely lands exactly one TTL from the moment you wrote the object.
Entity classes you create default to a 31-day TTL, while the built-in Global User and Channel classes use 30 days. TTL cannot be disabled. A relationship expires at the earlier expiry time of the two entities it links, fixed when the relationship is created.
Refer to data expiry for details.
Calling DataSync methods in Unity
Every DataSync method has two overloads. One returns a Task<PNResult<T>> that you await, and the other takes the parameters object plus a PNDataSync...ResultExt callback. The samples on this page use await. DataSync methods take a single parameters object, so they don't use the .Execute() and .ExecuteAsync() builder chain of other Unity SDK methods.
Invalid parameters and server errors do not throw. The call returns a PNResult<T> whose Status.Error is true, with the reason in Status.ErrorData.Information. Only a null parameters object or a null callback throws.
Requires Access Manager
DataSync requires that the Access Manager add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Users
Users are built-in objects. There are no top-level Name or Email properties, all application data lives in the free-form Payload. Refer to users for the concept.
A user is an entity of the built-in User entity class, which the service provides at the Global class level. To give your users their own declared, filterable properties, define a subclass of User with Create a new entity class and pass its name as EntityClass.
Create user
Creates a user. Supply an Id to control the identifier, or omit it to let the server generate one.
Method(s)
1pubnub.DataSync.CreateUser(CreateUserParameters parameters)
| Parameter | Description |
|---|---|
IdType: string Default: server-generated | User identifier. Omit to let the server generate a UUID. Max 255 characters. |
EntityClassType: string Default: User | Name of the entity class this user belongs to. Must be User or one of its subclasses. Defaults to User on the server if omitted. Set at creation and immutable afterward. |
EntityClassVersion *Type: int Default: n/a | Version of the user class schema. |
EntityClassLevelType: string Default: service default | Class hierarchy level of EntityClass, either Global for a class the service provides or SubKey for one defined on your keyset. Used to disambiguate classes with the same name defined at different levels. Set at creation and immutable afterward. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
Sample code
Reference code
1
Response
1{
2 "status": 201,
3 "data": {
4 "id": "user-alice",
5 "entityClass": "User",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Alice",
10 "type": "shopper"
11 },
12 "createdAt": "2026-07-13T09:00:00.000Z",
13 "updatedAt": "2026-07-13T09:00:00.000Z",
14 "eTag": "AbQdEfGhIjKlMn"
15 }
show all 16 linesGet user
Returns a single user by Id.
Method(s)
1pubnub.DataSync.GetUser(GetUserParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | User identifier. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClass": "User",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Alice",
10 "type": "shopper"
11 },
12 "createdAt": "2026-07-13T09:00:00.000Z",
13 "updatedAt": "2026-07-13T09:00:00.000Z",
14 "eTag": "AbQdEfGhIjKlMn"
15 }
show all 16 linesGet all users
Returns a paginated list of users. All parameters are optional, so you can call GetUsers with an empty parameters object. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.DataSync.GetUsers(GetUsersParameters parameters)
| Parameter | Description |
|---|---|
EntityClassType: string Default: all user classes | User class to list. Omit to list the Global User class and all of its subclasses. |
EntityClassVersionType: int Default: all versions | User class version to list. Omit to list users across every version of the class. |
EntityClassLevelType: string Default: service default | Class hierarchy level of EntityClass, either Global for a class the service provides or SubKey for one defined on your keyset. Used to disambiguate a class name defined at both levels. |
CursorType: string Default: n/a | Opaque pagination cursor. Omit for the first page. |
LimitType: int Default: 20 | Maximum number of users per page. Max 100. |
FilterFastType: string Default: n/a | Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. Accepts up to 10 conditions by default (raisable per keyset), over properties declared with filtering mode simple or full. Cannot be combined with Filter. |
FilterType: string Default: n/a | Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. Supports the full expression language, over properties declared with filtering mode full. Cannot be combined with FilterFast. |
SortType: string Default: n/a | Order results. Comma-separated fields, each optionally suffixed with :asc or :desc, for example "createdAt:desc". |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "user-alice",
6 "entityClass": "User",
7 "entityClassVersion": 1,
8 "entityClassLevel": "Global",
9 "payload": {
10 "name": "Alice",
11 "type": "shopper"
12 },
13 "createdAt": "2026-07-13T09:00:00.000Z",
14 "updatedAt": "2026-07-13T09:00:00.000Z",
15 "eTag": "AbQdEfGhIjKlMn"
show all 23 linesOther examples
Filter with FilterFast
FilterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. It runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (raisable per keyset). Reference a declared property by its name, not its path. It shares the same expression language as Filter, so only one of the two can be sent per call.
1
Filter with Filter
Filter runs over properties declared with filtering mode full and is evaluated against eventually consistent storage, so a very recent write may not be matched yet. Reference a declared property by its name, not its path. It shares the same expression language as FilterFast, so only one of the two can be sent per call.
1
Page through results with Cursor
Pass no Cursor on the first call. Take Meta.NextCursor from the response and pass it back as Cursor on the next call. Stop when Meta.HasNext is false.
1
Set user
Replaces a user in full (PUT). Send the complete set of fields, any field you omit is cleared. EntityClass is immutable after creation and cannot be sent. Refer to optimistic concurrency with ETags for IfMatch. For a partial update, use Update user.
Method(s)
1pubnub.DataSync.SetUser(SetUserParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | User identifier. |
EntityClassVersion *Type: int Default: n/a | Version of the user class schema. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
IfMatchType: string Default: n/a | The ETag from a prior read. The update succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClass": "User",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Alice B.",
10 "type": "shopper"
11 },
12 "createdAt": "2026-07-13T09:00:00.000Z",
13 "updatedAt": "2026-07-13T10:15:00.000Z",
14 "eTag": "CdEfGhIjKlMnOp"
15 }
show all 16 linesUpdate user
Applies a partial update to a user with raw JSON Patch operations. Refer to partial update for the operation model.
Method(s)
1pubnub.DataSync.UpdateUser(UpdateUserParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | User identifier. |
Operations *Type: List <JsonPatchOperation>Default: n/a | One or more JSON Patch operations. Must contain at least one item. |
IfMatchType: string Default: n/a | The ETag from a prior read. The patch succeeds only if it still matches, otherwise the server returns 412. |
Use a JSON Pointer that starts with /payload/ to target payload fields, or a root pointer (for example /status) to target a top-level field.
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClass": "User",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Alice B.",
10 "type": "shopper"
11 },
12 "createdAt": "2026-07-13T09:00:00.000Z",
13 "updatedAt": "2026-07-13T10:20:00.000Z",
14 "eTag": "EfGhIjKlMnOpQr"
15 }
show all 16 linesRemove user
Deletes a user by Id.
Method(s)
1pubnub.DataSync.DeleteUser(DeleteUserParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | User identifier. |
IfMatchType: string Default: n/a | The ETag from a prior read. The delete succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200
3}
Channels
Channels work like users. They have no top-level Name property, all application data lives in Payload, and they support the same operations. Refer to channels for the concept.
A channel is an entity of the built-in Channel entity class, which the service provides at the Global class level. Subclass it with Create a new entity class to add declared properties, then pass the subclass name as EntityClass.
Create channel
Creates a channel. Supply an Id to control the identifier, or omit it to let the server generate one.
Method(s)
1pubnub.DataSync.CreateChannel(CreateChannelParameters parameters)
| Parameter | Description |
|---|---|
IdType: string Default: server-generated | Channel identifier. Omit to let the server generate a UUID. Max 255 characters. |
EntityClassType: string Default: Channel | Name of the entity class this channel belongs to. Must be Channel or one of its subclasses. Defaults to Channel on the server if omitted. Set at creation and immutable afterward. |
EntityClassVersion *Type: int Default: n/a | Version of the channel class schema. |
EntityClassLevelType: string Default: service default | Class hierarchy level of EntityClass, either Global for a class the service provides or SubKey for one defined on your keyset. Used to disambiguate classes with the same name defined at different levels. Set at creation and immutable afterward. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
Sample code
Reference code
1
Response
1{
2 "status": 201,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClass": "Channel",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Summer Sale",
10 "type": "promotion"
11 },
12 "createdAt": "2026-07-13T09:05:00.000Z",
13 "updatedAt": "2026-07-13T09:05:00.000Z",
14 "eTag": "GhIjKlMnOpQrSt"
15 }
show all 16 linesGet channel
Returns a single channel by Id.
Method(s)
1pubnub.DataSync.GetChannel(GetChannelParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Channel identifier. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClass": "Channel",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Summer Sale",
10 "type": "promotion"
11 },
12 "createdAt": "2026-07-13T09:05:00.000Z",
13 "updatedAt": "2026-07-13T09:05:00.000Z",
14 "eTag": "GhIjKlMnOpQrSt"
15 }
show all 16 linesGet all channels
Returns a paginated list of channels. All parameters are optional, so you can call GetChannels with an empty parameters object. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.DataSync.GetChannels(GetChannelsParameters parameters)
| Parameter | Description |
|---|---|
EntityClassType: string Default: all channel classes | Channel class to list. Omit to list the Global Channel class and all of its subclasses. |
EntityClassVersionType: int Default: all versions | Channel class version to list. Omit to list channels across every version of the class. |
EntityClassLevelType: string Default: service default | Class hierarchy level of EntityClass, either Global for a class the service provides or SubKey for one defined on your keyset. Used to disambiguate a class name defined at both levels. |
CursorType: string Default: n/a | Opaque pagination cursor. Omit for the first page. |
LimitType: int Default: 20 | Maximum number of channels per page. Max 100. |
FilterFastType: string Default: n/a | Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. Accepts up to 10 conditions by default (raisable per keyset), over properties declared with filtering mode simple or full. Cannot be combined with Filter. |
FilterType: string Default: n/a | Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. Supports the full expression language, over properties declared with filtering mode full. Cannot be combined with FilterFast. |
SortType: string Default: n/a | Order results. Comma-separated fields, each optionally suffixed with :asc or :desc. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "channel-summer-sale",
6 "entityClass": "Channel",
7 "entityClassVersion": 1,
8 "entityClassLevel": "Global",
9 "payload": {
10 "name": "Summer Sale",
11 "type": "promotion"
12 },
13 "createdAt": "2026-07-13T09:05:00.000Z",
14 "updatedAt": "2026-07-13T09:05:00.000Z",
15 "eTag": "GhIjKlMnOpQrSt"
show all 23 linesOther examples
Filter with FilterFast
FilterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. It runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (raisable per keyset). Reference a declared property by its name, not its path. It shares the same expression language as Filter, so only one of the two can be sent per call.
1
Filter with Filter
Filter runs over properties declared with filtering mode full and is evaluated against eventually consistent storage, so a very recent write may not be matched yet. Reference a declared property by its name, not its path. It shares the same expression language as FilterFast, so only one of the two can be sent per call.
1
Page through results with Cursor
Pass no Cursor on the first call. Take Meta.NextCursor from the response and pass it back as Cursor on the next call. Stop when Meta.HasNext is false.
1
Set channel
Replaces a channel in full (PUT). Send the complete set of fields, any field you omit is cleared. EntityClass is immutable after creation and cannot be sent. Refer to optimistic concurrency with ETags for IfMatch. For a partial update, use Update channel.
Method(s)
1pubnub.DataSync.SetChannel(SetChannelParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Channel identifier. |
EntityClassVersion *Type: int Default: n/a | Version of the channel class schema. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
IfMatchType: string Default: n/a | The ETag from a prior read. The update succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClass": "Channel",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Summer Sale 2026",
10 "type": "promotion"
11 },
12 "createdAt": "2026-07-13T09:05:00.000Z",
13 "updatedAt": "2026-07-13T11:00:00.000Z",
14 "eTag": "IjKlMnOpQrStUv"
15 }
show all 16 linesUpdate channel
Applies a partial update to a channel with raw JSON Patch operations. Refer to partial update for the operation model.
Method(s)
1pubnub.DataSync.UpdateChannel(UpdateChannelParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Channel identifier. |
Operations *Type: List <JsonPatchOperation>Default: n/a | One or more JSON Patch operations. Must contain at least one item. |
IfMatchType: string Default: n/a | The ETag from a prior read. The patch succeeds only if it still matches, otherwise the server returns 412. |
Use a JSON Pointer that starts with /payload/ to target payload fields, or a root pointer (for example /status) to target a top-level field.
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClass": "Channel",
6 "entityClassVersion": 1,
7 "entityClassLevel": "Global",
8 "payload": {
9 "name": "Summer Sale 2026",
10 "type": "promotion"
11 },
12 "createdAt": "2026-07-13T09:05:00.000Z",
13 "updatedAt": "2026-07-13T11:05:00.000Z",
14 "eTag": "KlMnOpQrStUvWx"
15 }
show all 16 linesRemove channel
Deletes a channel by Id.
Method(s)
1pubnub.DataSync.DeleteChannel(DeleteChannelParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Channel identifier. |
IfMatchType: string Default: n/a | The ETag from a prior read. The delete succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200
3}
Memberships
A membership links a user to a channel and carries its own Payload. In the running example, Alice is a member of channel-summer-sale with the payload { "role": "viewer" }. Refer to memberships for the concept.
A membership is a relationship of the built-in Global Membership relationship class, whose two sides are surfaced as ChannelId and UserId. Every membership response includes both relationshipClass and relationshipClassVersion. The class is assigned by the service, so the CreateMembership and SetMembership methods take no class parameter.
Relationship classes don't support inheritance, and only the Global Membership class produces memberships, so relationshipClass is always Membership and relationshipClassVersion is the only part that varies.
Create membership
Creates a membership linking a user to a channel. The UserId/ChannelId pair must be unique for the membership class. A membership that duplicates an existing pair is rejected with a 409.
Method(s)
1pubnub.DataSync.CreateMembership(CreateMembershipParameters parameters)
| Parameter | Description |
|---|---|
IdType: string Default: server-generated | Membership identifier. Omit to let the server generate a UUID. Max 255 characters. |
ChannelId *Type: string Default: n/a | Identifier of the channel in the membership. |
UserId *Type: string Default: n/a | Identifier of the user in the membership. |
MembershipClassVersion *Type: int Default: n/a | Version of the membership class schema. Sent to the service as relationshipClassVersion. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
Sample code
Reference code
1
Response
The response already exposes friendly ChannelId and UserId properties, you don't need to translate from a relationship shape. Those property names are specific to CRUD responses (PNDataSyncMembershipResult). A real-time membership event carries the same two ids as RelationshipData.EntityAId and RelationshipData.EntityBId instead, refer to Add DataSync listener for details.
1{
2 "status": 201,
3 "data": {
4 "id": "membership-alice-summer-sale",
5 "channelId": "channel-summer-sale",
6 "userId": "user-alice",
7 "relationshipClass": "Membership",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "role": "viewer"
11 },
12 "createdAt": "2026-07-13T09:10:00.000Z",
13 "updatedAt": "2026-07-13T09:10:00.000Z",
14 "eTag": "MnOpQrStUvWxYz"
15 }
show all 16 linesGet membership
Returns a single membership by Id.
Method(s)
1pubnub.DataSync.GetMembership(GetMembershipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Membership identifier. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "membership-alice-summer-sale",
5 "channelId": "channel-summer-sale",
6 "userId": "user-alice",
7 "relationshipClass": "Membership",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "role": "viewer"
11 },
12 "createdAt": "2026-07-13T09:10:00.000Z",
13 "updatedAt": "2026-07-13T09:10:00.000Z",
14 "eTag": "MnOpQrStUvWxYz"
15 }
show all 16 linesGet all memberships
Returns a paginated list of memberships. All parameters are optional, so you can call GetMemberships with an empty parameters object. UserId and ChannelId can be set independently, together, or omitted entirely. Filter by UserId to list a user's memberships or by ChannelId to list a channel's members. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.DataSync.GetMemberships(GetMembershipsParameters parameters)
| Parameter | Description |
|---|---|
RelationshipClassVersionType: int Default: all versions | Membership class version to list. Omit to list memberships across every version of the class. |
CursorType: string Default: n/a | Opaque pagination cursor. Omit for the first page. |
LimitType: int Default: 20 | Maximum number of memberships per page. Max 100. |
FilterFastType: string Default: n/a | Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. Accepts up to 10 conditions by default (raisable per keyset), over properties declared with filtering mode simple or full. Cannot be combined with Filter. |
FilterType: string Default: n/a | Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. Supports the full expression language, over properties declared with filtering mode full. Cannot be combined with FilterFast. |
SortType: string Default: n/a | Order results. Comma-separated fields, each optionally suffixed with :asc or :desc. |
UserIdType: string Default: n/a | List only memberships for this user. |
ChannelIdType: string Default: n/a | List only memberships for this channel. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "membership-alice-summer-sale",
6 "channelId": "channel-summer-sale",
7 "userId": "user-alice",
8 "relationshipClass": "Membership",
9 "relationshipClassVersion": 1,
10 "payload": {
11 "role": "viewer"
12 },
13 "createdAt": "2026-07-13T09:10:00.000Z",
14 "updatedAt": "2026-07-13T09:10:00.000Z",
15 "eTag": "MnOpQrStUvWxYz"
show all 23 linesOther examples
List a channel's members with ChannelId
Pass ChannelId instead of UserId to list the members of a channel rather than a user's memberships.
1
Filter with FilterFast
FilterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. It runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (raisable per keyset). Reference a declared property by its name, not its path. It shares the same expression language as Filter, so only one of the two can be sent per call.
1
Filter with Filter
Filter runs over properties declared with filtering mode full and is evaluated against eventually consistent storage, so a very recent write may not be matched yet. Reference a declared property by its name, not its path. It shares the same expression language as FilterFast, so only one of the two can be sent per call.
1
Page through results with Cursor
Pass no Cursor on the first call. Take Meta.NextCursor from the response and pass it back as Cursor on the next call. Stop when Meta.HasNext is false.
1
Set membership
Replaces a membership in full (PUT). Send the complete set of fields, any field you omit is cleared. The linked user and channel are immutable, so UpdateMembershipParameters doesn't expose ChannelId/UserId at all, there's nothing to resend. Refer to optimistic concurrency with ETags for IfMatch. For a partial update, use Update membership.
Parameter class naming
Unlike users, channels, entities, and relationships, the membership parameter class names don't follow the Set<X>Parameters and Update<X>Parameters pattern. The full-replace method SetMembership takes UpdateMembershipParameters, and the partial-update method UpdateMembership takes PatchMembershipParameters. This is how the SDK is implemented, call the methods and parameter classes exactly as shown.
Method(s)
1pubnub.DataSync.SetMembership(UpdateMembershipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Membership identifier. |
RelationshipClassVersion *Type: int Default: n/a | Version of the membership class schema. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
IfMatchType: string Default: n/a | The ETag from a prior read. The update succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "membership-alice-summer-sale",
5 "channelId": "channel-summer-sale",
6 "userId": "user-alice",
7 "relationshipClass": "Membership",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "role": "moderator"
11 },
12 "createdAt": "2026-07-13T09:10:00.000Z",
13 "updatedAt": "2026-07-13T12:00:00.000Z",
14 "eTag": "OpQrStUvWxYzAb"
15 }
show all 16 linesUpdate membership
Applies a partial update to a membership with raw JSON Patch operations. Refer to partial update for the operation model. The parameter class differs from the method name, refer to the note on the full replace.
Method(s)
1pubnub.DataSync.UpdateMembership(PatchMembershipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Membership identifier. |
Operations *Type: List <JsonPatchOperation>Default: n/a | One or more JSON Patch operations. Must contain at least one item. |
IfMatchType: string Default: n/a | The ETag from a prior read. The patch succeeds only if it still matches, otherwise the server returns 412. |
Use a JSON Pointer that starts with /payload/ to target payload fields, or a root pointer (for example /status) to target a top-level field.
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "membership-alice-summer-sale",
5 "channelId": "channel-summer-sale",
6 "userId": "user-alice",
7 "relationshipClass": "Membership",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "role": "moderator"
11 },
12 "createdAt": "2026-07-13T09:10:00.000Z",
13 "updatedAt": "2026-07-13T12:05:00.000Z",
14 "eTag": "PqRsTuVwXyZaBc"
15 }
show all 16 linesRemove membership
Deletes a membership by Id.
Method(s)
1pubnub.DataSync.DeleteMembership(DeleteMembershipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Membership identifier. |
IfMatchType: string Default: n/a | The ETag from a prior read. The delete succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200
3}
Entities
Entities are instances of the custom entity classes you define on your keyset. In the running example, product is a class and product-sneaker-42 is an instance. Use Create a new entity class to declare a class, and Get entity class by ID to read the property, filtering, and projection declarations that govern its instances.
Entity classes can extend one another. Listing a class also returns the entities of its subclasses, so GetEntities with EntityClass = "product" returns every product plus every instance of a class that extends product.
Create entity
Creates an entity of a given class and version.
Method(s)
1pubnub.DataSync.CreateEntity(CreateEntityParameters parameters)
| Parameter | Description |
|---|---|
IdType: string Default: server-generated | Entity identifier. Omit to let the server generate a UUID. Max 255 characters. |
EntityClass *Type: string Default: n/a | Name of the entity class this instance belongs to. Set at creation and immutable afterward. |
EntityClassVersion *Type: int Default: n/a | Version of the entity class schema. |
EntityClassLevelType: string Default: service default | Class hierarchy level of EntityClass, either Global for a class the service provides or SubKey for one defined on your keyset. Used to disambiguate classes with the same name defined at different levels. Set at creation and immutable afterward. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
Sample code
Reference code
1
Response
1{
2 "status": 201,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "entityClassLevel": "SubKey",
8 "payload": {
9 "name": "Retro Sneaker",
10 "price": 89.99,
11 "stock": 12
12 },
13 "createdAt": "2026-07-13T09:15:00.000Z",
14 "updatedAt": "2026-07-13T09:15:00.000Z",
15 "eTag": "QrStUvWxYzAbCd"
show all 17 linesGet entity
Returns a single entity by Id.
Method(s)
1pubnub.DataSync.GetEntity(GetEntityParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Entity identifier. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "entityClassLevel": "SubKey",
8 "payload": {
9 "name": "Retro Sneaker",
10 "price": 89.99,
11 "stock": 12
12 },
13 "createdAt": "2026-07-13T09:15:00.000Z",
14 "updatedAt": "2026-07-13T09:15:00.000Z",
15 "eTag": "QrStUvWxYzAbCd"
show all 17 linesGet all entities
Returns a paginated list of entities within a class. The EntityClass parameter is required, entities are always listed within the context of their class. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.DataSync.GetEntities(GetEntitiesParameters parameters)
| Parameter | Description |
|---|---|
EntityClass *Type: string Default: n/a | Name of the entity class to list. |
EntityClassVersionType: int Default: all versions | Entity class version to list. Omit to list entities across every version of the class. |
EntityClassLevelType: string Default: service default | Class hierarchy level of EntityClass, either Global for a class the service provides or SubKey for one defined on your keyset. Used to disambiguate a class name defined at both levels. |
CursorType: string Default: n/a | Opaque pagination cursor. Omit for the first page. |
LimitType: int Default: 20 | Maximum number of entities per page. Max 100. |
FilterFastType: string Default: n/a | Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. Accepts up to 10 conditions by default (raisable per keyset), over properties declared with filtering mode simple or full. Cannot be combined with Filter. |
FilterType: string Default: n/a | Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. Supports the full expression language, over properties declared with filtering mode full. Cannot be combined with FilterFast. |
SortType: string Default: n/a | Order results. Comma-separated fields, each optionally suffixed with :asc or :desc. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "product-sneaker-42",
6 "entityClass": "product",
7 "entityClassVersion": 1,
8 "entityClassLevel": "SubKey",
9 "payload": {
10 "name": "Retro Sneaker",
11 "price": 89.99,
12 "stock": 12
13 },
14 "createdAt": "2026-07-13T09:15:00.000Z",
15 "updatedAt": "2026-07-13T09:15:00.000Z",
show all 24 linesOther examples
Filter with FilterFast
FilterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. It runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (raisable per keyset). Reference a declared property by its name, not its path, and combine conditions with && and ||. It shares the same expression language as Filter, so only one of the two can be sent per call.
1
Filter with Filter
Filter runs over properties declared with filtering mode full and is evaluated against eventually consistent storage, so a very recent write may not be matched yet. Reference a declared property by its name, not its path, and combine conditions with && and ||. It shares the same expression language as FilterFast, so only one of the two can be sent per call.
1
Page through results with Cursor
Pass no Cursor on the first call. Take Meta.NextCursor from the response and pass it back as Cursor on the next call. Stop when Meta.HasNext is false.
1
Set entity
Replaces an entity in full (PUT). Send the complete set of fields, any field you omit is cleared. EntityClass is immutable after creation and cannot be sent. Refer to optimistic concurrency with ETags for IfMatch. For a partial update, use Update entity.
Method(s)
1pubnub.DataSync.SetEntity(SetEntityParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Entity identifier. |
EntityClassVersion *Type: int Default: n/a | Version of the entity class schema. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
IfMatchType: string Default: n/a | The ETag from a prior read. The update succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "entityClassLevel": "SubKey",
8 "payload": {
9 "name": "Retro Sneaker",
10 "price": 79.99,
11 "stock": 8
12 },
13 "createdAt": "2026-07-13T09:15:00.000Z",
14 "updatedAt": "2026-07-13T13:00:00.000Z",
15 "eTag": "StUvWxYzAbCdEf"
show all 17 linesUpdate entity
Applies a partial update to an entity with raw JSON Patch operations. Refer to partial update for the operation model.
Method(s)
1pubnub.DataSync.UpdateEntity(UpdateEntityParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Entity identifier. |
Operations *Type: List <JsonPatchOperation>Default: n/a | One or more JSON Patch operations. Must contain at least one item. |
IfMatchType: string Default: n/a | The ETag from a prior read. The patch succeeds only if it still matches, otherwise the server returns 412. |
Use a JSON Pointer that starts with /payload/ to target payload fields, or a root pointer (for example /status) to target a top-level field.
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "entityClassLevel": "SubKey",
8 "payload": {
9 "name": "Retro Sneaker",
10 "price": 79.99,
11 "stock": 12
12 },
13 "createdAt": "2026-07-13T09:15:00.000Z",
14 "updatedAt": "2026-07-13T13:05:00.000Z",
15 "eTag": "UvWxYzAbCdEfGh"
show all 17 linesOther examples
Combine patch operations, and guard the write with IfMatch
A single UpdateEntity call can mix Add, Replace, Remove, Move, Copy, and Test, in one Operations list. All operations in the call apply together or not at all. Add IfMatch (the ETag from a prior read) to reject the patch with a 412 if the entity changed since you read it, instead of silently overwriting a concurrent change.
1
Remove entity
Deletes an entity by Id.
Method(s)
1pubnub.DataSync.DeleteEntity(DeleteEntityParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Entity identifier. |
IfMatchType: string Default: n/a | The ETag from a prior read. The delete succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200
3}
Relationships
A relationship links two entities and carries its own Payload. In the running example, the ProductOwner relationship links seller-bob to product-sneaker-42.
Relationships are instances of the relationship classes you define on your keyset. A relationship class declares the cardinality the service enforces (one-to-one, one-to-many, or many-to-many) and, optionally, which entity class each side must belong to. Use Create a new relationship class to declare a class, and Get relationship class by name and version to read it back.
Create relationship
Creates a relationship between two entities. The relationship class's cardinality (one-to-one, one-to-many, or many-to-many) is enforced on create. A relationship that violates its class's cardinality is rejected with a 409.
Method(s)
1pubnub.DataSync.CreateRelationship(CreateRelationshipParameters parameters)
| Parameter | Description |
|---|---|
IdType: string Default: server-generated | Relationship identifier. Omit to let the server generate a UUID. Max 255 characters. |
EntityAId *Type: string Default: n/a | Identifier of the first linked entity. Immutable after creation. |
EntityBId *Type: string Default: n/a | Identifier of the second linked entity. Immutable after creation. |
RelationshipClass *Type: string Default: n/a | Name of the relationship class this instance belongs to. Set at creation and immutable afterward. |
RelationshipClassVersion *Type: int Default: n/a | Version of the relationship class schema. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
Sample code
Reference code
1
Response
1{
2 "status": 201,
3 "data": {
4 "id": "rel-bob-owns-sneaker-42",
5 "entityAId": "seller-bob",
6 "entityBId": "product-sneaker-42",
7 "relationshipClass": "ProductOwner",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "since": "2026-07-13"
11 },
12 "createdAt": "2026-07-13T09:20:00.000Z",
13 "updatedAt": "2026-07-13T09:20:00.000Z",
14 "eTag": "WxYzAbCdEfGhIj"
15 }
show all 16 linesGet relationship
Returns a single relationship by Id.
Method(s)
1pubnub.DataSync.GetRelationship(GetRelationshipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Relationship identifier. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "rel-bob-owns-sneaker-42",
5 "entityAId": "seller-bob",
6 "entityBId": "product-sneaker-42",
7 "relationshipClass": "ProductOwner",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "since": "2026-07-13"
11 },
12 "createdAt": "2026-07-13T09:20:00.000Z",
13 "updatedAt": "2026-07-13T09:20:00.000Z",
14 "eTag": "WxYzAbCdEfGhIj"
15 }
show all 16 linesGet all relationships
Returns a paginated list of relationships within a class. The RelationshipClass parameter is required. Filter by EntityAId or EntityBId to list a specific entity's links. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.DataSync.GetRelationships(GetRelationshipsParameters parameters)
| Parameter | Description |
|---|---|
RelationshipClass *Type: string Default: n/a | Name of the relationship class to list. |
RelationshipClassVersionType: int Default: all versions | Relationship class version to list. Omit to list relationships across every version of the class. |
CursorType: string Default: n/a | Opaque pagination cursor. Omit for the first page. |
LimitType: int Default: 20 | Maximum number of relationships per page. Max 100. |
FilterFastType: string Default: n/a | Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. Accepts up to 10 conditions by default (raisable per keyset), over properties declared with filtering mode simple or full. Cannot be combined with Filter. |
FilterType: string Default: n/a | Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. Supports the full expression language, over properties declared with filtering mode full. Cannot be combined with FilterFast. |
SortType: string Default: n/a | Order results. Comma-separated fields, each optionally suffixed with :asc or :desc. |
EntityAIdType: string Default: n/a | List only relationships whose first entity is this id. |
EntityBIdType: string Default: n/a | List only relationships whose second entity is this id. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "rel-bob-owns-sneaker-42",
6 "entityAId": "seller-bob",
7 "entityBId": "product-sneaker-42",
8 "relationshipClass": "ProductOwner",
9 "relationshipClassVersion": 1,
10 "payload": {
11 "since": "2026-07-13"
12 },
13 "createdAt": "2026-07-13T09:20:00.000Z",
14 "updatedAt": "2026-07-13T09:20:00.000Z",
15 "eTag": "WxYzAbCdEfGhIj"
show all 23 linesOther examples
List an entity's incoming links with EntityBId
Pass EntityBId instead of EntityAId to list relationships where the entity is on the second side of the link.
1
Filter with FilterFast
FilterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. It runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (raisable per keyset). Reference a declared property by its name, not its path. It shares the same expression language as Filter, so only one of the two can be sent per call.
1
Filter with Filter
Filter runs over properties declared with filtering mode full and is evaluated against eventually consistent storage, so a very recent write may not be matched yet. Reference a declared property by its name, not its path. It shares the same expression language as FilterFast, so only one of the two can be sent per call.
1
Page through results with Cursor
Pass no Cursor on the first call. Take Meta.NextCursor from the response and pass it back as Cursor on the next call. Stop when Meta.HasNext is false.
1
Set relationship
Replaces a relationship in full (PUT). Send the complete set of fields, any field you omit is cleared. The linked entities are immutable, so SetRelationshipParameters doesn't expose EntityAId/EntityBId at all, there's nothing to resend. Refer to optimistic concurrency with ETags for IfMatch. For a partial update, use Update relationship.
Method(s)
1pubnub.DataSync.SetRelationship(SetRelationshipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Relationship identifier. |
RelationshipClassVersion *Type: int Default: n/a | Version of the relationship class schema. |
StatusType: string Default: n/a | Free-form lifecycle status. Max 100 characters. |
PayloadType: Dictionary <string, object>Default: n/a | Free-form JSON object holding your application data. |
IfMatchType: string Default: n/a | The ETag from a prior read. The update succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "rel-bob-owns-sneaker-42",
5 "entityAId": "seller-bob",
6 "entityBId": "product-sneaker-42",
7 "relationshipClass": "ProductOwner",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "since": "2026-07-13",
11 "tier": "gold"
12 },
13 "createdAt": "2026-07-13T09:20:00.000Z",
14 "updatedAt": "2026-07-13T14:00:00.000Z",
15 "eTag": "YzAbCdEfGhIjKl"
show all 17 linesUpdate relationship
Applies a partial update to a relationship with raw JSON Patch operations. Refer to partial update for the operation model.
Method(s)
1pubnub.DataSync.UpdateRelationship(UpdateRelationshipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Relationship identifier. |
Operations *Type: List <JsonPatchOperation>Default: n/a | One or more JSON Patch operations. Must contain at least one item. |
IfMatchType: string Default: n/a | The ETag from a prior read. The patch succeeds only if it still matches, otherwise the server returns 412. |
Use a JSON Pointer that starts with /payload/ to target payload fields, or a root pointer (for example /status) to target a top-level field.
Sample code
Reference code
1
Response
1{
2 "status": 200,
3 "data": {
4 "id": "rel-bob-owns-sneaker-42",
5 "entityAId": "seller-bob",
6 "entityBId": "product-sneaker-42",
7 "relationshipClass": "ProductOwner",
8 "relationshipClassVersion": 1,
9 "payload": {
10 "since": "2026-07-13",
11 "tier": "platinum"
12 },
13 "createdAt": "2026-07-13T09:20:00.000Z",
14 "updatedAt": "2026-07-13T14:05:00.000Z",
15 "eTag": "AbCdEfGhIjKlMn"
show all 17 linesRemove relationship
Deletes a relationship by Id.
Method(s)
1pubnub.DataSync.DeleteRelationship(DeleteRelationshipParameters parameters)
| Parameter | Description |
|---|---|
Id *Type: string Default: n/a | Relationship identifier. |
IfMatchType: string Default: n/a | The ETag from a prior read. The delete succeeds only if it still matches, otherwise the server returns 412. |
Sample code
Reference code
1
Response
1{
2 "status": 200
3}
Real-time updates
DataSync objects can publish create, update, and delete events that you receive in real time with a SubscribeCallbackListener and its onDataSync event. Subscribe to the object's data channel with a Channel SDK entity and attach the listener to the resulting Subscription, a SubscriptionSet, or the PubNub client, as described in Add DataSync listener.
1
Each event names the change in Event, identifies the object kind in Type (user, channel, membership, entity, or relationship), and carries the object state in EntityData or RelationshipData. For a delete event, neither is populated and the id arrives as Id on the event itself, alongside DeletedAt. The listener runs your handler on the Unity main thread, so you can touch GameObject and UI state from it directly.
Type names the object kind directly, while the state always arrives in one of the two containers:
| Change to | Type | State arrives in |
|---|---|---|
| A user | user | EntityData |
| A channel | channel | EntityData |
| An entity | entity | EntityData |
| A membership | membership | RelationshipData |
| A relationship | relationship | RelationshipData |
Dispatch on Type rather than on which container is populated, because EntityData is shared by three kinds and RelationshipData by two. ClassName tells you the specific class within a kind, for example which subclass of User an event belongs to.
Where each event is delivered
The channels that receive an event depend on the changed object. A relationship or membership never publishes on a channel named after its own id:
| Change to | On create | On update or delete |
|---|---|---|
| A user | The user's Id | The user's Id, plus the Id of every entity, user, or channel connected to it by a relationship or membership |
| A channel | The channel's Id | The channel's Id, plus the Id of every entity, user, or channel connected to it by a relationship or membership |
| An entity | The entity's Id | The entity's Id, plus the Id of every entity, user, or channel connected to it by a relationship or membership |
| A membership | Both the UserId and the ChannelId of the membership | Same as create |
| A relationship | Both the EntityAId and the EntityBId of the relationship | Same as create |
Update and delete also fan out to connected objects
An update or delete on a user, channel, or entity is also delivered on the Id channel of every other object connected to it by a relationship or membership, in either direction, at the time of the change. A client subscribed to a connected object's channel receives the event too, even though that object itself did not change. A create does not fan out this way, because nothing can be connected to a brand new object yet.
The connected channels are entity, user, and channel ids. Relationships and memberships never get an id channel of their own, so they never appear in this fan-out as a channel name.
So to see memberships appear and disappear for Alice, subscribe to user-alice rather than the membership id. A client subscribed to both sides of the same link receives the change twice, once per channel. Deduplicate create and update events on the object's Id and UpdatedAt, and delete events on Id and DeletedAt.
For a membership event, RelationshipData.EntityAId is the channel id and RelationshipData.EntityBId is the user id. The service sends these as channelId and userId, and the SDK maps them onto the A and B sides so that one result type serves both memberships and your own relationships.
Projection channels
Each projection declared on the class gets its own event, published to its own channel, and carrying only that projection's view of the payload:
| Projection | Channel | Payload |
|---|---|---|
__default__ (the base projection) | The object's own id, for example product-sneaker-42 | The fields tagged __default__ |
Any named projection, for example admin | __<projection>__<id>, for example __admin__product-sneaker-42 | The fields tagged with that projection |
A projection name must start with a letter or digit, so a leading __ marks a projection channel, with __default__ as the only exception.
Avoid ids that start with two underscores
A projection channel is named __<projection>__<id>, so an object id in that form can collide with another object's projection channel. The service doesn't reject such ids today, so avoid any id that starts with __.
Filtering applies to Payload and to Status: each is included in a given projection's event only if the class declares it under that projection, falling back to __default__ when the class never declares Status. Id, ETag, CreatedAt, UpdatedAt, and ExpiresAt are never filtered. Every projection's event carries them unchanged.
So one change to an object whose class declares an admin projection publishes two events, and a client subscribed only to product-sneaker-42 never sees the admin-only fields:
1
If the class declares no properties at all there is nothing to filter, so a single unfiltered event is published to the object's own id channel.
Projection channels need channel grants
Publishing to __<projection>__<id> is an ordinary channel publish, and it isn't gated by the DataSyncProjections entries in a token. Use Access Manager Channels grants to control who can subscribe to a projection channel. Anyone who can subscribe there receives the restricted fields. Refer to Grant token.
Delete events are never filtered by a projection.
Events are off by default and are enabled per class in the Admin Portal. Refer to enabling events for how to turn them on, and receiving events for the listener flow.