DataSync API for Java 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 the Channel SDK entity.
The two meet in the DataSync SDK entities (DataSyncUser, DataSyncChannel, and DataSyncEntity): SDK entities whose only job is to subscribe to a DataSync object's 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.
A successful call yields a result object whose getStatus() returns the HTTP status. The remove* methods return the status on its own, every other method adds a getData() accessor holding the object, or the list of objects for a list method. A list method also adds a getNext() accessor holding the pagination state. The SDK does not surface the HATEOAS links the service sends. A stored object carries its free-form status and its expiresAt auto-deletion timestamp (ISO 8601) whenever those are set on it. A failed call surfaces as a PubNubException whose getStatusCode() is the HTTP status, for example 412, and whose getPubnubError() is a DATASYNC_* category chosen from that status. Read the DS- error code with DataSyncErrors.firstCode(exception), or every error item with DataSyncErrors.from(exception). The raw response body stays in getErrorMessage() and getJso(). A response that carries no DS- code keeps the generic HTTP_ERROR category. You pass payload as a Map<String, Object>, and read it back as the same type from getPayload().
- 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 setToken().
DataSync pagination is forward-only. There is no previous-page cursor, and PNDataSyncPage exposes no getPrevCursor() or isHasPrev(). 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 return a result whose getNext() is a PNDataSyncPage with isHasNext(), getCursor(), and getLimit(). The getNext() accessor never returns null, it is an empty page when the server sends no pagination details, so read isHasNext() rather than checking getNext() for null.
To page forward, pass the returned getNext().getCursor() back as cursor on the next call, and stop when getNext().isHasNext() is false. getCursor() returns 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:
1.filterFast("price < 100") // strongly consistent, single condition
2.filterFast("(price < 100 && stock > 0) || price > 500") // strongly consistent, grouped conditions
3.filter("name LIKE \"*sneaker*\"") // eventually consistent, needs filtering mode "full"
4.filter("!(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. When you don't pass classVersion, the list includes items of every version, but filter, filterFast, and sort can only use properties declared on the latest version of the class. A property that exists only in an older version is rejected with a 400. Pass classVersion to use properties declared on an older version. Refer to filtering for the two filtering tiers, and property definitions for how properties are declared.
Use sort to order results. Pass a List<PNDataSyncSortField> in priority order, where each PNDataSyncSortField names a property and sets ascending (default true). The SDK joins the list into a comma-separated request value and appends :desc to each descending field. A bare name sorts ascending:
1.sort(Arrays.asList(new PNDataSyncSortField("price", false))) // single field, descending
2.sort(Arrays.asList(new PNDataSyncSortField("type"), new PNDataSyncSortField("price", false))) // type ascending, then price descending
3.sort(Arrays.asList(new PNDataSyncSortField("createdAt", true))) // explicit ascending
The +field and -field prefixes are not accepted. A leading - is read as part of the property name, so new PNDataSyncSortField("-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. The only local checks are a blank sort property on any list method, a blank className (on createEntity, getEntities, createRelationship, and getRelationships, or on createUser, getUsers, createChannel, and getChannels when you pass one), and a blank resource id. These fail with a PubNubException before anything is sent. The exception is thrown by sync() and delivered to the failure callback by async().
Every stored object carries an eTag. To guard against concurrent writes, pass the eTag you read earlier as ifMatch on set*, update*, and remove* 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). Pass a List<PNJsonPatchOperation>. Each PNJsonPatchOperation has an op (add, remove, replace, move, copy, or test, written as a string), a path (a full JSON Pointer, for example /status or /payload/price), and, depending on the operation, a value or a from. Build one with PNJsonPatchOperation.builder().
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:
1PNJsonPatchOperation.builder().op("add").path("/payload/tags").value("sale").build() // adds a value inside payload.tags
2PNJsonPatchOperation.builder().op("replace").path("/payload/price").value(79.99).build() // replaces payload.price
3PNJsonPatchOperation.builder().op("remove").path("/payload/tempFlag").build() // removes payload.tempFlag
4PNJsonPatchOperation.builder().op("move").from("/payload/oldTag").path("/payload/tag").build()
5PNJsonPatchOperation.builder().op("copy").from("/payload/price").path("/payload/msrp").build()
6PNJsonPatchOperation.builder().op("test").path("/status").value("active").build() // 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 fails the call with a PubNubException carrying JSON_PATCH_OPERATIONS_MISSING if the list is empty. The exception is thrown by sync() and delivered to the failure callback by async().
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.
Request execution
Every DataSync method returns an endpoint object, and nothing is sent until you call sync() or async() on it. Required parameters go in the method call, and optional ones are set by chaining setters on the returned endpoint object.
sync() blocks and returns the result, or throws a PubNubException. async() takes a callback that receives a Result, so you handle success and failure inside the callback. Use async() on any thread you cannot block.
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 fields, 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 className.
Create user
Creates a user. Supply a userId to control the identifier, or omit it to let the server generate one.
Method(s)
1pubnub.dataSync().createUser(int classVersion)
2 .userId(String)
3 .className(String)
4 .classLevel(PNDataSyncClassLevel)
5 .status(String)
6 .payload(Map<String, Object>)
| Parameter | Description |
|---|---|
classVersion *Type: int Default: n/a | Version of the user class schema. |
userIdType: String Default: server-generated | User identifier. Omit to let the server generate a UUID. Max 255 characters. |
classNameType: 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. |
classLevelType: PNDataSyncClassLevel Default: service default | Class hierarchy level of className, 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: Map <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": { "name": "Alice", "type": "shopper" },
9 "createdAt": "2026-07-13T09:00:00.000Z",
10 "updatedAt": "2026-07-13T09:00:00.000Z",
11 "eTag": "AbCdEfGhIjKlMn"
12 }
13}
Get user
Returns a single user by userId.
Method(s)
1pubnub.dataSync().getUser(String userId)
| Parameter | Description |
|---|---|
userId *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": { "name": "Alice", "type": "shopper" },
9 "createdAt": "2026-07-13T09:00:00.000Z",
10 "updatedAt": "2026-07-13T09:00:00.000Z",
11 "eTag": "AbCdEfGhIjKlMn"
12 }
13}
Get all users
Returns a paginated list of users. All parameters are optional, so you can call getUsers() without setting any of them. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.dataSync().getUsers()
2 .className(String)
3 .classVersion(Integer)
4 .classLevel(PNDataSyncClassLevel)
5 .filterFast(String)
6 .filter(String)
7 .sort(List<PNDataSyncSortField>)
8 .limit(Integer)
9 .cursor(String)
| Parameter | Description |
|---|---|
classNameType: String Default: all user classes | User class to list. Omit to list the Global User class and all of its subclasses. |
classVersionType: Integer Default: all versions | User class version to list. Omit to list users across every version of the class. |
classLevelType: PNDataSyncClassLevel Default: service default | Class hierarchy level of className, 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. |
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: List <PNDataSyncSortField>Default: n/a | Order results. Each entry names a property and a direction, for example new PNDataSyncSortField("createdAt", false). |
limitType: Integer Default: 20 | Maximum number of users per page. Max 100. |
cursorType: String Default: n/a | Opaque pagination cursor. Omit for the first page. |
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": { "name": "Alice", "type": "shopper" },
10 "createdAt": "2026-07-13T09:00:00.000Z",
11 "updatedAt": "2026-07-13T09:00:00.000Z",
12 "eTag": "AbCdEfGhIjKlMn"
13 }
14 ],
15 "meta": {
show all 20 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. The built-in User class declares only name and type, so those, plus the built-in id, createdAt, updatedAt, and status fields, are what you can filter on. To filter on other payload fields, such as email, define a subclass of User that declares them and pass it as className.
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 getNext().getCursor() from the result and pass it back as cursor on the next call. Stop when getNext().isHasNext() is false.
1
Set user
Replaces a user in full (PUT). Send the complete set of fields, any field you omit is cleared. className 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(String userId, int classVersion)
2 .status(String)
3 .payload(Map<String, Object>)
4 .ifMatch(String)
| Parameter | Description |
|---|---|
userId *Type: String Default: n/a | User identifier. |
classVersion *Type: int Default: n/a | Version of the user class schema. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "name": "Alice B.", "type": "shopper" },
9 "createdAt": "2026-07-13T09:00:00.000Z",
10 "updatedAt": "2026-07-13T10:15:00.000Z",
11 "eTag": "CdEfGhIjKlMnOp"
12 }
13}
Update 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(String userId, List<PNJsonPatchOperation> operations)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
userId *Type: String Default: n/a | User identifier. |
operations *Type: List <PNJsonPatchOperation>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 "status": "active",
6 "entityClass": "User",
7 "entityClassVersion": 1,
8 "entityClassLevel": "Global",
9 "payload": { "name": "Alice B.", "type": "shopper" },
10 "createdAt": "2026-07-13T09:00:00.000Z",
11 "updatedAt": "2026-07-13T10:20:00.000Z",
12 "eTag": "EfGhIjKlMnOpQr"
13 }
14}
Remove user
Deletes a user by userId.
Method(s)
1pubnub.dataSync().removeUser(String userId)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
userId *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 field, 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 className.
Create channel
Creates a channel. Supply a channelId to control the identifier, or omit it to let the server generate one.
Method(s)
1pubnub.dataSync().createChannel(int classVersion)
2 .channelId(String)
3 .className(String)
4 .classLevel(PNDataSyncClassLevel)
5 .status(String)
6 .payload(Map<String, Object>)
| Parameter | Description |
|---|---|
classVersion *Type: int Default: n/a | Version of the channel class schema. |
channelIdType: String Default: server-generated | Channel identifier. Omit to let the server generate a UUID. Max 255 characters. |
classNameType: 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. |
classLevelType: PNDataSyncClassLevel Default: service default | Class hierarchy level of className, 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: Map <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": { "name": "Summer Sale", "type": "promotion" },
9 "createdAt": "2026-07-13T09:05:00.000Z",
10 "updatedAt": "2026-07-13T09:05:00.000Z",
11 "eTag": "GhIjKlMnOpQrSt"
12 }
13}
Get channel
Returns a single channel by channelId.
Method(s)
1pubnub.dataSync().getChannel(String channelId)
| Parameter | Description |
|---|---|
channelId *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": { "name": "Summer Sale", "type": "promotion" },
9 "createdAt": "2026-07-13T09:05:00.000Z",
10 "updatedAt": "2026-07-13T09:05:00.000Z",
11 "eTag": "GhIjKlMnOpQrSt"
12 }
13}
Get all channels
Returns a paginated list of channels. All parameters are optional, so you can call getChannels() without setting any of them. For pagination, filtering, and sorting, refer to sorting and pagination.
Method(s)
1pubnub.dataSync().getChannels()
2 .className(String)
3 .classVersion(Integer)
4 .classLevel(PNDataSyncClassLevel)
5 .filterFast(String)
6 .filter(String)
7 .sort(List<PNDataSyncSortField>)
8 .limit(Integer)
9 .cursor(String)
| Parameter | Description |
|---|---|
classNameType: String Default: all channel classes | Channel class to list. Omit to list the Global Channel class and all of its subclasses. |
classVersionType: Integer Default: all versions | Channel class version to list. Omit to list channels across every version of the class. |
classLevelType: PNDataSyncClassLevel Default: service default | Class hierarchy level of className, 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. |
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: List <PNDataSyncSortField>Default: n/a | Order results. Each entry names a property and a direction. |
limitType: Integer Default: 20 | Maximum number of channels per page. Max 100. |
cursorType: String Default: n/a | Opaque pagination cursor. Omit for the first page. |
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": { "name": "Summer Sale", "type": "promotion" },
10 "createdAt": "2026-07-13T09:05:00.000Z",
11 "updatedAt": "2026-07-13T09:05:00.000Z",
12 "eTag": "GhIjKlMnOpQrSt"
13 }
14 ],
15 "meta": {
show all 20 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. The built-in Channel class declares only name and type, so those, plus the built-in id, createdAt, updatedAt, and status fields, are what you can filter on. To filter on other payload fields, such as region, define a subclass of Channel that declares them and pass it as className.
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 getNext().getCursor() from the result and pass it back as cursor on the next call. Stop when getNext().isHasNext() is false.
1
Set channel
Replaces a channel in full (PUT). Send the complete set of fields, any field you omit is cleared. className 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(String channelId, int classVersion)
2 .status(String)
3 .payload(Map<String, Object>)
4 .ifMatch(String)
| Parameter | Description |
|---|---|
channelId *Type: String Default: n/a | Channel identifier. |
classVersion *Type: int Default: n/a | Version of the channel class schema. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "name": "Summer Sale 2026", "type": "promotion" },
9 "createdAt": "2026-07-13T09:05:00.000Z",
10 "updatedAt": "2026-07-13T11:00:00.000Z",
11 "eTag": "IjKlMnOpQrStUv"
12 }
13}
Update 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(String channelId, List<PNJsonPatchOperation> operations)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
channelId *Type: String Default: n/a | Channel identifier. |
operations *Type: List <PNJsonPatchOperation>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 "status": "active",
6 "entityClass": "Channel",
7 "entityClassVersion": 1,
8 "entityClassLevel": "Global",
9 "payload": { "name": "Summer Sale 2026", "type": "promotion" },
10 "createdAt": "2026-07-13T09:05:00.000Z",
11 "updatedAt": "2026-07-13T11:05:00.000Z",
12 "eTag": "KlMnOpQrStUvWx"
13 }
14}
Remove channel
Deletes a channel by channelId.
Method(s)
1pubnub.dataSync().removeChannel(String channelId)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
channelId *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(String channelId, String userId, int classVersion)
2 .membershipId(String)
3 .status(String)
4 .payload(Map<String, Object>)
| Parameter | Description |
|---|---|
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. |
classVersion *Type: int Default: n/a | Version of the Membership relationship class schema. |
membershipIdType: String Default: server-generated | Membership identifier. Omit to let the server generate a UUID. Max 255 characters. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": "membership-alice-summer-sale",
5 "channelId": "channel-summer-sale",
6 "userId": "user-alice",
7 "relationshipClass": "Membership",
8 "relationshipClassVersion": 1,
9 "payload": { "role": "viewer" },
10 "createdAt": "2026-07-13T09:10:00.000Z",
11 "updatedAt": "2026-07-13T09:10:00.000Z",
12 "eTag": "MnOpQrStUvWxYz"
13 }
14}
Get membership
Returns a single membership by membershipId.
Method(s)
1pubnub.dataSync().getMembership(String membershipId)
| Parameter | Description |
|---|---|
membershipId *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": { "role": "viewer" },
10 "createdAt": "2026-07-13T09:10:00.000Z",
11 "updatedAt": "2026-07-13T09:10:00.000Z",
12 "eTag": "MnOpQrStUvWxYz"
13 }
14}
Get all memberships
Returns a paginated list of memberships. All parameters are optional, so you can call getMemberships() without setting any of them. 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()
2 .channelId(String)
3 .userId(String)
4 .classVersion(Integer)
5 .filterFast(String)
6 .filter(String)
7 .sort(List<PNDataSyncSortField>)
8 .limit(Integer)
9 .cursor(String)
| Parameter | Description |
|---|---|
channelIdType: String Default: n/a | List only memberships for this channel. |
userIdType: String Default: n/a | List only memberships for this user. |
classVersionType: Integer Default: all versions | Membership class version to list. Omit to list memberships across every version of the class. |
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: List <PNDataSyncSortField>Default: n/a | Order results. Each entry names a property and a direction. |
limitType: Integer Default: 20 | Maximum number of memberships per page. Max 100. |
cursorType: String Default: n/a | Opaque pagination cursor. Omit for the first page. |
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": { "role": "viewer" },
11 "createdAt": "2026-07-13T09:10:00.000Z",
12 "updatedAt": "2026-07-13T09:10:00.000Z",
13 "eTag": "MnOpQrStUvWxYz"
14 }
15 ],
show all 21 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 getNext().getCursor() from the result and pass it back as cursor on the next call. Stop when getNext().isHasNext() 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 setMembership 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.
Method(s)
1pubnub.dataSync().setMembership(String membershipId, int classVersion)
2 .status(String)
3 .payload(Map<String, Object>)
4 .ifMatch(String)
| Parameter | Description |
|---|---|
membershipId *Type: String Default: n/a | Membership identifier. |
classVersion *Type: int Default: n/a | Version of the Membership relationship class schema. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "role": "moderator" },
10 "createdAt": "2026-07-13T09:10:00.000Z",
11 "updatedAt": "2026-07-13T12:00:00.000Z",
12 "eTag": "OpQrStUvWxYzAb"
13 }
14}
Update membership
Applies a partial update to a membership with raw JSON Patch operations. Refer to partial update for the operation model.
Method(s)
1pubnub.dataSync().updateMembership(String membershipId, List<PNJsonPatchOperation> operations)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
membershipId *Type: String Default: n/a | Membership identifier. |
operations *Type: List <PNJsonPatchOperation>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 "status": "active",
6 "channelId": "channel-summer-sale",
7 "userId": "user-alice",
8 "relationshipClass": "Membership",
9 "relationshipClassVersion": 1,
10 "payload": { "role": "moderator" },
11 "createdAt": "2026-07-13T09:10:00.000Z",
12 "updatedAt": "2026-07-13T12:05:00.000Z",
13 "eTag": "QrStUvWxYzAbCd"
14 }
15}
Remove membership
Deletes a membership by membershipId.
Method(s)
1pubnub.dataSync().removeMembership(String membershipId)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
membershipId *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("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(String className, int classVersion)
2 .entityId(String)
3 .classLevel(PNDataSyncClassLevel)
4 .status(String)
5 .payload(Map<String, Object>)
| Parameter | Description |
|---|---|
className *Type: String Default: n/a | Name of the entity class this instance belongs to. Set at creation and immutable afterward. |
classVersion *Type: int Default: n/a | Version of the entity class schema. |
classLevelType: PNDataSyncClassLevel Default: service default | Class hierarchy level of className, 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. |
entityIdType: String Default: server-generated | Entity identifier. Omit to let the server generate a UUID. Max 255 characters. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "name": "Retro Sneaker", "price": 89.99, "stock": 12 },
9 "createdAt": "2026-07-13T09:15:00.000Z",
10 "updatedAt": "2026-07-13T09:15:00.000Z",
11 "eTag": "StUvWxYzAbCdEf"
12 }
13}
Get entity
Returns a single entity by entityId.
Method(s)
1pubnub.dataSync().getEntity(String entityId)
| Parameter | Description |
|---|---|
entityId *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": { "name": "Retro Sneaker", "price": 89.99, "stock": 12 },
9 "createdAt": "2026-07-13T09:15:00.000Z",
10 "updatedAt": "2026-07-13T09:15:00.000Z",
11 "eTag": "StUvWxYzAbCdEf"
12 }
13}
Get all entities
Returns a paginated list of entities within a class. The className 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(String className)
2 .classVersion(Integer)
3 .classLevel(PNDataSyncClassLevel)
4 .filterFast(String)
5 .filter(String)
6 .sort(List<PNDataSyncSortField>)
7 .limit(Integer)
8 .cursor(String)
| Parameter | Description |
|---|---|
className *Type: String Default: n/a | Name of the entity class to list. |
classVersionType: Integer Default: all versions | Entity class version to list. Omit to list entities across every version of the class. |
classLevelType: PNDataSyncClassLevel Default: service default | Class hierarchy level of className, 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. |
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: List <PNDataSyncSortField>Default: n/a | Order results. Each entry names a property and a direction. |
limitType: Integer Default: 20 | Maximum number of entities per page. Max 100. |
cursorType: String Default: n/a | Opaque pagination cursor. Omit for the first page. |
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": { "name": "Retro Sneaker", "price": 89.99, "stock": 12 },
10 "createdAt": "2026-07-13T09:15:00.000Z",
11 "updatedAt": "2026-07-13T09:15:00.000Z",
12 "eTag": "StUvWxYzAbCdEf"
13 }
14 ],
15 "meta": {
show all 20 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 getNext().getCursor() from the result and pass it back as cursor on the next call. Stop when getNext().isHasNext() is false.
1
Set entity
Replaces an entity in full (PUT). Send the complete set of fields, any field you omit is cleared. className 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(String entityId, int classVersion)
2 .status(String)
3 .payload(Map<String, Object>)
4 .ifMatch(String)
| Parameter | Description |
|---|---|
entityId *Type: String Default: n/a | Entity identifier. |
classVersion *Type: int Default: n/a | Version of the entity class schema. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "name": "Retro Sneaker", "price": 79.99, "stock": 12 },
9 "createdAt": "2026-07-13T09:15:00.000Z",
10 "updatedAt": "2026-07-13T13:00:00.000Z",
11 "eTag": "UvWxYzAbCdEfGh"
12 }
13}
Update 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(String entityId, List<PNJsonPatchOperation> operations)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
entityId *Type: String Default: n/a | Entity identifier. |
operations *Type: List <PNJsonPatchOperation>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": { "name": "Retro Sneaker", "price": 79.99, "stock": 8 },
9 "createdAt": "2026-07-13T09:15:00.000Z",
10 "updatedAt": "2026-07-13T13:05:00.000Z",
11 "eTag": "WxYzAbCdEfGhIj"
12 }
13}
Other examples
Combine patch operations, and guard the write with ifMatch
A single updateEntity call can mix add, replace, remove, move, copy, and test operations 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 entityId.
Method(s)
1pubnub.dataSync().removeEntity(String entityId)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
entityId *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(String entityAId, String entityBId, String className, int classVersion)
2 .relationshipId(String)
3 .status(String)
4 .payload(Map<String, Object>)
| Parameter | Description |
|---|---|
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. |
className *Type: String Default: n/a | Name of the relationship class this instance belongs to. Set at creation and immutable afterward. |
classVersion *Type: int Default: n/a | Version of the relationship class schema. |
relationshipIdType: String Default: server-generated | Relationship identifier. Omit to let the server generate a UUID. Max 255 characters. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "since": "2026-07-13" },
10 "createdAt": "2026-07-13T09:20:00.000Z",
11 "updatedAt": "2026-07-13T09:20:00.000Z",
12 "eTag": "YzAbCdEfGhIjKl"
13 }
14}
Get relationship
Returns a single relationship by relationshipId.
Method(s)
1pubnub.dataSync().getRelationship(String relationshipId)
| Parameter | Description |
|---|---|
relationshipId *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": { "since": "2026-07-13" },
10 "createdAt": "2026-07-13T09:20:00.000Z",
11 "updatedAt": "2026-07-13T09:20:00.000Z",
12 "eTag": "YzAbCdEfGhIjKl"
13 }
14}
Get all relationships
Returns a paginated list of relationships within a class. The className 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(String className)
2 .entityAId(String)
3 .entityBId(String)
4 .classVersion(Integer)
5 .filterFast(String)
6 .filter(String)
7 .sort(List<PNDataSyncSortField>)
8 .limit(Integer)
9 .cursor(String)
| Parameter | Description |
|---|---|
className *Type: String Default: n/a | Name of the relationship class to list. |
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. |
classVersionType: Integer Default: all versions | Relationship class version to list. Omit to list relationships across every version of the class. |
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: List <PNDataSyncSortField>Default: n/a | Order results. Each entry names a property and a direction. |
limitType: Integer Default: 20 | Maximum number of relationships per page. Max 100. |
cursorType: String Default: n/a | Opaque pagination cursor. Omit for the first page. |
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": { "since": "2026-07-13" },
11 "createdAt": "2026-07-13T09:20:00.000Z",
12 "updatedAt": "2026-07-13T09:20:00.000Z",
13 "eTag": "YzAbCdEfGhIjKl"
14 }
15 ],
show all 21 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 getNext().getCursor() from the result and pass it back as cursor on the next call. Stop when getNext().isHasNext() is false.
1
Set relationship
Replaces a relationship in full (PUT). Send the complete set of fields, any field you omit is cleared. className is immutable after creation and cannot be sent, and the linked entity ids are immutable too, so setRelationship 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(String relationshipId, int classVersion)
2 .status(String)
3 .payload(Map<String, Object>)
4 .ifMatch(String)
| Parameter | Description |
|---|---|
relationshipId *Type: String Default: n/a | Relationship identifier. |
classVersion *Type: int Default: n/a | Version of the relationship class schema. |
statusType: String Default: n/a | Free-form lifecycle status. Max 100 characters. |
payloadType: Map <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": { "since": "2026-07-13", "tier": "gold" },
10 "createdAt": "2026-07-13T09:20:00.000Z",
11 "updatedAt": "2026-07-13T14:00:00.000Z",
12 "eTag": "AbCdEfGhIjKlMn"
13 }
14}
Update 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(String relationshipId, List<PNJsonPatchOperation> operations)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
relationshipId *Type: String Default: n/a | Relationship identifier. |
operations *Type: List <PNJsonPatchOperation>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": { "since": "2026-07-13", "tier": "platinum" },
10 "createdAt": "2026-07-13T09:20:00.000Z",
11 "updatedAt": "2026-07-13T14:05:00.000Z",
12 "eTag": "CdEfGhIjKlMnOp"
13 }
14}
Remove relationship
Deletes a relationship by relationshipId.
Method(s)
1pubnub.dataSync().removeRelationship(String relationshipId)
2 .ifMatch(String)
| Parameter | Description |
|---|---|
relationshipId *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 DataSync listener on a Subscription, a SubscriptionSet, or the PubNub client. Create a DataSync SDK entity for the object (DataSyncUser, DataSyncChannel, or DataSyncEntity), subscribe to it, and attach the listener, as described in Add DataSync listener.
1
Each event arrives as a PNDataSyncEventResult. Its getExtractedMessage() names the object kind in getType() (user, channel, membership, entity, or relationship) and carries the object state in getData(). A create or update event is a PNSetDataSync*EventMessage whose getEvent() is CREATE or UPDATE. For a delete event, a PNDeleteDataSync*EventMessage carries only the getId() and the getDeletedAt() timestamp.
getType() names the object kind directly, while the message class tells you which typed state container the event carries:
| Change to | getType() | On create or update | On delete |
|---|---|---|---|
| A user | user | PNSetDataSyncUserEventMessage with PNDataSyncUserData | PNDeleteDataSyncUserEventMessage |
| A channel | channel | PNSetDataSyncChannelEventMessage with PNDataSyncChannelData | PNDeleteDataSyncChannelEventMessage |
| An entity | entity | PNSetDataSyncEntityEventMessage with PNDataSyncEntityData | PNDeleteDataSyncEntityEventMessage |
| A membership | membership | PNSetDataSyncMembershipEventMessage with PNDataSyncMembershipData | PNDeleteDataSyncMembershipEventMessage |
| A relationship | relationship | PNSetDataSyncRelationshipEventMessage with PNDataSyncRelationshipData | PNDeleteDataSyncRelationshipEventMessage |
Branch on the message class with instanceof checks, and always add a final else branch, because an event the SDK does not recognize arrives as a PNUnknownDataSyncEventMessage that keeps the raw getType(), getEvent(), getMetadata(), and getData(). getClassName() 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 getId() and getUpdatedAt(), and delete events on getId() and getDeletedAt().
For a membership event, PNDataSyncMembershipData carries getChannelId() and getUserId() directly, so you don't map them onto generic A and B sides. A relationship event carries getEntityAId() and getEntityBId().
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 |
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 projection assignments in a token. Use Access Manager channel 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.