DataSync API for JavaScript SDK
The DataSync API of the PubNub JavaScript SDK stores application state as users, channels, memberships, entities, and relationships, and keeps connected clients 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 and gives you a scoped handle for subscribing and calling APIs. See SDK entities in Publish and subscribe.
The two meet in the DataSync SDK entities: 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.
A class definition decides three things for every object of that class. The definition decides which payload fields are filterable and sortable, which projection each field belongs to, and how long the object lives before it expires. See managing classes for details.
Every response includes the HTTP status. The remove* methods return the status on its own. Every other method adds a data key holding the object, or the array of objects for a list method. A response can also add a links object with the hypermedia URLs (HATEOAS) the service provides (self, and next where it applies). Every stored object carries its expiresAt auto-deletion timestamp (ISO 8601). A stored object also carries its free-form status when you set one.
The operations fall into six areas, and each operation has its own section:
- Users are entities of the built-in
Userclass. Start with Create user. - Channels are entities of the built-in
Channelclass. Start with Create channel. - Memberships link a user to a channel. Start with Create membership.
- Entities are instances of the custom entity classes you define. Start with Create entity.
- Relationships link two entities. Start with Create relationship.
- Real-time updates deliver change events to a
dataSynclistener. Start with Where each event is delivered.
#
DataSync pagination is forward-only, so there is no previous-page cursor. 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 with has_next, next_cursor, and limit. The meta object is optional, so guard the access when you read it, for example response.meta?.next_cursor.
To page forward, pass the returned next_cursor back as cursor on the next call, and stop when has_next is false. next_cursor is null on the last page. See sorting and pagination.
#
All list methods accept the two filter parameters filter and filterFast. The filter and filterFast parameters are mutually exclusive, and a request that carries both fails with a 400. The SDK sends whatever you pass, so the call reaches the server and fails there.
| 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 (configurable per keyset) |
filter | Eventually consistent, results can briefly lag writes | Filtering mode full only | Full expression language |
Use filterFast when the query has to see an object you just wrote. Use filter when you need the full expression language over a property with filtering mode full.
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. Earlier builds of the SDK named these filter and filterAdvanced respectively, so a filter expression written against an older build now runs on the other backing store. Rename filter to filterFast and filterAdvanced to filter when you upgrade.
Both parameters share one expression language of comparison, pattern (LIKE, SLIKE, ILIKE), and logical operators, described in filter expression syntax. Reference a property by its name, not its declared path. To filter on a nested payload property, declare it as a class property first, then filter by that property's name.
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
Filter expressions only work over properties declared on the class. The built-in fields id, createdAt, and updatedAt are always filterable without a declaration. The status field is filterable too, unless the class redeclares /status scoped to projections that your token cannot fully reach.
When you don't pass classVersion, a list includes items of every version, but filter, filterFast, and sort can only use properties declared on the latest version of the class. The service rejects a property that exists only in an older version with a 400. Pass classVersion to use properties declared on an older version. See filtering for the two filtering tiers, and property definitions for how properties are declared.
Use sort to order results. Pass an object mapping each field to a direction. A key's value is 'asc', 'desc', or null to apply the service default (ascending). Map multiple fields to sort by more than one, evaluated in the order the keys appear. The examples assume a class that declares type and price with a filtering mode other than none:
1sort: { price: 'desc' } // single field, descending
2sort: { type: 'asc', price: 'desc' } // type first, then price within each type
3sort: { createdAt: null } // explicit service default (ascending)
sort also accepts a raw string, which the SDK passes through unchanged. List the fields separated by commas, each a property name optionally suffixed with :desc. A bare name sorts ascending:
1sort: 'price:desc' // single field, descending
2sort: 'type,price:desc' // type ascending, then price descending
3sort: 'createdAt' // bare name, ascending
The +field and -field prefixes are not accepted.
Sorting alone or alongside filterFast works only on properties declared on the class with a filtering mode other than none. Sorting alongside filter also requires the field to be declared full. The built-in fields id, createdAt, and updatedAt are always sortable without a declaration. The status field is sortable too, unless the class redeclares /status scoped to projections that your token cannot fully reach.
The service rejects a sort field that the class does not declare. The rejection currently arrives as 403 Forbidden, not as a 400 that names the field.
#
Every stored object carries an eTag. When the stored object has changed since you read it, a write that carries the earlier eTag fails with a 412. Re-read the object and retry. See optimistic concurrency with ETags.
To guard against concurrent writes, pass the eTag you read earlier as ifMatchesEtag on set*, update*, and remove*. The SDK sends it as the If-Match request header.
#
The update* methods apply a partial update using JSON Patch (RFC 6902). They accept add, replace, and test (JSON Pointer key/value maps), remove (an array of JSON Pointers), and move and copy (arrays of { from, path } JSON Pointer pairs).
Each path is a full JSON Pointer (RFC 6901) from the document root. To target a field inside payload, include the /payload prefix, for example /payload/price. To target a top-level field, use a pointer such as /status.
The SDK sends each path as you write it and does not add a /payload prefix.
See partial update for details.
Correct patch forms:
1add: { '/payload/tags/0': 'featured' } // adds a value inside payload.tags
2replace: { '/payload/price': 79.99 } // replaces payload.price
3remove: ['/payload/tempFlag', '/payload/legacy/field'] // removes payload.tempFlag and payload.legacy.field
4move: [{ from: '/payload/legacyName', path: '/payload/displayName' }]
5copy: [{ from: '/payload/displayName', path: '/payload/previousName' }]
6test: { '/status': 'active' } // fails the patch if status is not "active"
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 service cannot patch the fields set at creation: entityClass and entityClassLevel on users, channels, and entities, relationshipClass, entityAId, and entityBId on relationships, and userId and channelId on memberships.
At least one of add, replace, remove, move, copy, or test must be provided. An empty object or array does not count. The SDK checks this before it sends anything and throws a PubNubError if nothing is provided.
#
An object's expiresAt is set once when the object is created, from its class TTL, and updates never refresh it. See data expiry for the default TTLs, the day rounding, and how relationships expire.
Supported and recommended asynchronous patterns
PubNub supports Callbacks, Promises, and Async/Await for asynchronous JS operations. The recommended pattern is Async/Await and all sample requests in this document are based on it. This pattern returns a status only on detecting an error. To receive the error status, you must add the try...catch syntax to your code.
Create user
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.createUser() creates a DataSync user through a PubNub client for JavaScript. The server generates the identifier unless the call supplies one.
Users have no top-level name or email fields. All application data lives in the free-form payload. See 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 properties, define a subclass of User with Create a new entity class and pass its name as class.
id#- Identifier of the new DataSync user. Omit it to let the server generate one. The identifier has at most 255 characters.
class#- Name of the entity class that this user belongs to. The class is set at creation and immutable afterward. Must be
Useror one of its subclasses. classLevel#- Class hierarchy level of
class, eitherGlobalfor a class the service provides orSubKeyfor one defined on your key set. The level is set at creation and immutable afterward. Omit it to let the service apply its default. datarequired#- The mutable user data.
- property of data:
classVersionrequired# - Version of the user class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
Sample code
Returns
pubnub.dataSync.createUser() resolves with the HTTP status and the created user.
Examples for Create user
Syntax
1pubnub.dataSync.createUser({
2 id: string,
3 class: string,
4 classLevel: string,
5 data: { classVersion: number, status: string, payload: object },
6}): Promise<DataSync.CreateUserResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Alice",
8 "type": "shopper"
9 },
10 "createdAt": "2026-07-13T09:00:00.000Z",
11 "updatedAt": "2026-07-13T09:00:00.000Z",
12 "eTag": "AbQdEfGhIjKlMn",
13 "expiresAt": "2026-08-12T09:00:00.000Z"
14 }
15}
Get user
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getUser() returns one DataSync user by identifier through a PubNub client for JavaScript.
idrequired#- Identifier of the user.
Sample code
Returns
pubnub.dataSync.getUser() resolves with the HTTP status and the requested user.
Examples for Get user
Syntax
1pubnub.dataSync.getUser({
2 id: string,
3}): Promise<DataSync.GetUserResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Alice",
8 "type": "shopper"
9 },
10 "createdAt": "2026-07-13T09:00:00.000Z",
11 "updatedAt": "2026-07-13T09:00:00.000Z",
12 "eTag": "AbQdEfGhIjKlMn",
13 "expiresAt": "2026-08-12T09:00:00.000Z"
14 }
15}
Get all users
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getUsers() returns a paginated list of DataSync users through a PubNub client for JavaScript.
getUsers() with no arguments.You can also pass a callback as the only argument.For pagination, filtering, and sorting, see sorting and pagination.class#- Name of the entity class to list. Omit it to list users of every user class.
classVersion#- Class version to list. Omit it to list users of every version of the class.
classLevel#- Class hierarchy level of
class, eitherGlobalfor a class the service provides orSubKeyfor one defined on your key set. Use it to disambiguate a class name defined at both levels. cursor#- Opaque pagination cursor from the previous page. Omit it to get the first page.
limit#- Maximum number of users to return in one page, up to 100.
filter#- Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. The parameter supports the full expression language over properties declared with filtering mode
full. A call cannot combine it withfilterFast. filterFast#- Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. The parameter accepts up to 10 conditions by default (configurable per keyset) over properties declared with filtering mode
simpleorfull. A call cannot combine it withfilter. sort#- Sort order of the returned users. An object that maps each field to
'asc','desc', ornull(service default), or a comma-separated string such as'createdAt:desc'.
Sample code
Returns
pubnub.dataSync.getUsers() resolves with the HTTP status, an array of users, and paging metadata.
Other examples
Examples for Get all users
Syntax
1pubnub.dataSync.getUsers({
2 class: string,
3 classVersion: number,
4 classLevel: string,
5 cursor: string,
6 limit: number,
7 filter: string,
8 filterFast: string,
9 sort: object | string,
10}): Promise<DataSync.GetUsersResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "user-alice",
6 "entityClassVersion": 1,
7 "payload": {
8 "name": "Alice",
9 "type": "shopper"
10 },
11 "createdAt": "2026-07-13T09:00:00.000Z",
12 "updatedAt": "2026-07-13T09:00:00.000Z",
13 "eTag": "AbQdEfGhIjKlMn",
14 "expiresAt": "2026-08-12T09:00:00.000Z"
15 }
show all 22 linesFilter with filter
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.
1
Filter with filterFast
Filter with filterFast
filterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. The expression runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (configurable per keyset). The two parameters share the expression language of filter, so a call can send only one of them.
1
Page through results with cursor
Page through results with cursor
Pass no cursor on the first call. Take meta.next_cursor from the response and pass it back as cursor on the next call. Stop when meta.has_next is false.
1
Set user
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.setUser() replaces a DataSync user in full through a PubNub client for JavaScript. The call clears a stored status or payload that it omits.
ifMatchesEtag. See optimistic concurrency with ETags.idrequired#- Identifier of the user.
datarequired#- The replacement user data.
- property of data:
classVersionrequired# - Version of the user class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
ifMatchesEtag#- The
eTagfrom a prior read. The update succeeds only if it still matches, otherwise the server returns412.
Sample code
Returns
pubnub.dataSync.setUser() resolves with the HTTP status and the stored user.
Examples for Set user
Syntax
1pubnub.dataSync.setUser({
2 id: string,
3 data: { classVersion: number, status: string, payload: object },
4 ifMatchesEtag: string,
5}): Promise<DataSync.SetUserResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Alice B.",
8 "type": "shopper"
9 },
10 "createdAt": "2026-07-13T09:00:00.000Z",
11 "updatedAt": "2026-07-13T10:15:00.000Z",
12 "eTag": "CdEfGhIjKlMnOp",
13 "expiresAt": "2026-08-12T09:00:00.000Z"
14 }
15}
Update user
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.updateUser() applies a JSON Patch (RFC 6902) partial update to a DataSync user through a PubNub client for JavaScript. The call needs at least one patch operation, and fields that no operation addresses stay unchanged.
idrequired#- Identifier of the user.
add#- Full JSON Pointers mapped to values to add.
replace#- Full JSON Pointers mapped to replacement values.
remove#- Full JSON Pointers to remove.
move#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis removed and re-added atpath. copy#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis duplicated topath. test#- Full JSON Pointers mapped to expected values. The patch fails if any value does not match.
ifMatchesEtag#- The
eTagfrom a prior read. The patch succeeds only if it still matches, otherwise the server returns412.
Paths can target fields inside payload or top-level stored fields. A JSON Pointer that starts with /payload/ targets a payload field, and a root pointer such as /status targets a top-level field. See partial update for the JSON Pointer rules.
At least one of add, replace, remove, move, copy, or test must be provided.
A single updateUser() call can mix add, replace, remove, move, copy, and test. The order you write the keys in does not matter. The SDK always sends the operations in the same order, with test last.
Sample code
Returns
pubnub.dataSync.updateUser() resolves with the HTTP status and the updated user.
Examples for Update user
Syntax
1pubnub.dataSync.updateUser({
2 id: string,
3 add: object,
4 replace: object,
5 remove: string[],
6 move: { from: string, path: string }[],
7 copy: { from: string, path: string }[],
8 test: object,
9 ifMatchesEtag: string,
10}): Promise<DataSync.UpdateUserResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "user-alice",
5 "entityClassVersion": 1,
6 "status": "active",
7 "payload": {
8 "name": "Alice B.",
9 "type": "shopper"
10 },
11 "createdAt": "2026-07-13T09:00:00.000Z",
12 "updatedAt": "2026-07-13T10:20:00.000Z",
13 "eTag": "EfGhIjKlMnOpQr",
14 "expiresAt": "2026-08-12T09:00:00.000Z"
15 }
show all 16 linesRemove user
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.removeUser() deletes a DataSync user by identifier through a PubNub client for JavaScript.
Sample code
Returns
pubnub.dataSync.removeUser() resolves with only the HTTP status.
Examples for Remove user
Syntax
1pubnub.dataSync.removeUser({
2 id: string,
3 ifMatchesEtag: string,
4}): Promise<DataSync.RemoveUserResponse>
Basic usage
1
Returns
1{
2 "status": 200
3}
Create channel
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.createChannel() creates a DataSync channel through a PubNub client for JavaScript. The server generates the identifier unless the call supplies one.
Channels work like users. They have no top-level name field, all application data lives in payload, and they support the same operations. See 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. To give your channels their own declared properties, define a subclass of Channel with Create a new entity class and pass its name as class.
id#- Identifier of the new DataSync channel. Omit it to let the server generate one. The identifier has at most 255 characters.
class#- Name of the entity class that this channel belongs to. The class is set at creation and immutable afterward. Must be
Channelor one of its subclasses. classLevel#- Class hierarchy level of
class, eitherGlobalfor a class the service provides orSubKeyfor one defined on your key set. The level is set at creation and immutable afterward. Omit it to let the service apply its default. datarequired#- The mutable channel data.
- property of data:
classVersionrequired# - Version of the channel class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
Sample code
Returns
pubnub.dataSync.createChannel() resolves with the HTTP status and the created channel.
Examples for Create channel
Syntax
1pubnub.dataSync.createChannel({
2 id: string,
3 class: string,
4 classLevel: string,
5 data: { classVersion: number, status: string, payload: object },
6}): Promise<DataSync.CreateChannelResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Summer Sale",
8 "type": "promotion"
9 },
10 "createdAt": "2026-07-13T09:05:00.000Z",
11 "updatedAt": "2026-07-13T09:05:00.000Z",
12 "eTag": "GhIjKlMnOpQrSt",
13 "expiresAt": "2026-08-12T09:05:00.000Z"
14 }
15}
Get channel
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getChannel() returns one DataSync channel by identifier through a PubNub client for JavaScript.
idrequired#- Identifier of the channel.
Sample code
Returns
pubnub.dataSync.getChannel() resolves with the HTTP status and the requested channel.
Examples for Get channel
Syntax
1pubnub.dataSync.getChannel({
2 id: string,
3}): Promise<DataSync.GetChannelResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Summer Sale",
8 "type": "promotion"
9 },
10 "createdAt": "2026-07-13T09:05:00.000Z",
11 "updatedAt": "2026-07-13T09:05:00.000Z",
12 "eTag": "GhIjKlMnOpQrSt",
13 "expiresAt": "2026-08-12T09:05:00.000Z"
14 }
15}
Get all channels
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getChannels() returns a paginated list of DataSync channels through a PubNub client for JavaScript.
getChannels() with no arguments.You can also pass a callback as the only argument.For pagination, filtering, and sorting, see sorting and pagination.class#- Name of the entity class to list. Omit it to list channels of every channel class.
classVersion#- Class version to list. Omit it to list channels of every version of the class.
classLevel#- Class hierarchy level of
class, eitherGlobalfor a class the service provides orSubKeyfor one defined on your key set. Use it to disambiguate a class name defined at both levels. cursor#- Opaque pagination cursor from the previous page. Omit it to get the first page.
limit#- Maximum number of channels to return in one page, up to 100.
filter#- Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. The parameter supports the full expression language over properties declared with filtering mode
full. A call cannot combine it withfilterFast. filterFast#- Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. The parameter accepts up to 10 conditions by default (configurable per keyset) over properties declared with filtering mode
simpleorfull. A call cannot combine it withfilter. sort#- Sort order of the returned channels. An object that maps each field to
'asc','desc', ornull(service default), or a comma-separated string such as'createdAt:desc'.
Sample code
Returns
pubnub.dataSync.getChannels() resolves with the HTTP status, an array of channels, and paging metadata.
Other examples
Examples for Get all channels
Syntax
1pubnub.dataSync.getChannels({
2 class: string,
3 classVersion: number,
4 classLevel: string,
5 cursor: string,
6 limit: number,
7 filter: string,
8 filterFast: string,
9 sort: object | string,
10}): Promise<DataSync.GetChannelsResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "channel-summer-sale",
6 "entityClassVersion": 1,
7 "payload": {
8 "name": "Summer Sale",
9 "type": "promotion"
10 },
11 "createdAt": "2026-07-13T09:05:00.000Z",
12 "updatedAt": "2026-07-13T09:05:00.000Z",
13 "eTag": "GhIjKlMnOpQrSt",
14 "expiresAt": "2026-08-12T09:05:00.000Z"
15 }
show all 22 linesFilter with filter
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.
1
Filter with filterFast
Filter with filterFast
filterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. The expression runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (configurable per keyset). The two parameters share the expression language of filter, so a call can send only one of them.
1
Page through results with cursor
Page through results with cursor
Pass no cursor on the first call. Take meta.next_cursor from the response and pass it back as cursor on the next call. Stop when meta.has_next is false.
1
Set channel
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.setChannel() replaces a DataSync channel in full through a PubNub client for JavaScript. The call clears a stored status or payload that it omits.
ifMatchesEtag. See optimistic concurrency with ETags.idrequired#- Identifier of the channel.
datarequired#- The replacement channel data.
- property of data:
classVersionrequired# - Version of the channel class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
ifMatchesEtag#- The
eTagfrom a prior read. The update succeeds only if it still matches, otherwise the server returns412.
Sample code
Returns
pubnub.dataSync.setChannel() resolves with the HTTP status and the stored channel.
Examples for Set channel
Syntax
1pubnub.dataSync.setChannel({
2 id: string,
3 data: { classVersion: number, status: string, payload: object },
4 ifMatchesEtag: string,
5}): Promise<DataSync.SetChannelResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Summer Sale 2026",
8 "type": "promotion"
9 },
10 "createdAt": "2026-07-13T09:05:00.000Z",
11 "updatedAt": "2026-07-13T11:00:00.000Z",
12 "eTag": "IjKlMnOpQrStUv",
13 "expiresAt": "2026-08-12T09:05:00.000Z"
14 }
15}
Update channel
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.updateChannel() applies a JSON Patch (RFC 6902) partial update to a DataSync channel through a PubNub client for JavaScript. The call needs at least one patch operation, and fields that no operation addresses stay unchanged.
idrequired#- Identifier of the channel.
add#- Full JSON Pointers mapped to values to add.
replace#- Full JSON Pointers mapped to replacement values.
remove#- Full JSON Pointers to remove.
move#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis removed and re-added atpath. copy#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis duplicated topath. test#- Full JSON Pointers mapped to expected values. The patch fails if any value does not match.
ifMatchesEtag#- The
eTagfrom a prior read. The patch succeeds only if it still matches, otherwise the server returns412.
Paths can target fields inside payload or top-level stored fields. A JSON Pointer that starts with /payload/ targets a payload field, and a root pointer such as /status targets a top-level field. See partial update for the JSON Pointer rules.
At least one of add, replace, remove, move, copy, or test must be provided.
A single updateChannel() call can mix add, replace, remove, move, copy, and test. The order you write the keys in does not matter. The SDK always sends the operations in the same order, with test last.
Sample code
Returns
pubnub.dataSync.updateChannel() resolves with the HTTP status and the updated channel.
Examples for Update channel
Syntax
1pubnub.dataSync.updateChannel({
2 id: string,
3 add: object,
4 replace: object,
5 remove: string[],
6 move: { from: string, path: string }[],
7 copy: { from: string, path: string }[],
8 test: object,
9 ifMatchesEtag: string,
10}): Promise<DataSync.UpdateChannelResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "channel-summer-sale",
5 "entityClassVersion": 1,
6 "payload": {
7 "name": "Summer Sale 2026",
8 "type": "promotion"
9 },
10 "createdAt": "2026-07-13T09:05:00.000Z",
11 "updatedAt": "2026-07-13T11:05:00.000Z",
12 "eTag": "KlMnOpQrStUvWx",
13 "expiresAt": "2026-08-12T09:05:00.000Z"
14 }
15}
Remove channel
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.removeChannel() deletes a DataSync channel by identifier through a PubNub client for JavaScript.
Sample code
Returns
pubnub.dataSync.removeChannel() resolves with only the HTTP status.
Examples for Remove channel
Syntax
1pubnub.dataSync.removeChannel({
2 id: string,
3 ifMatchesEtag: string,
4}): Promise<DataSync.RemoveChannelResponse>
Basic usage
1
Returns
1{
2 "status": 200
3}
Create membership
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.createMembership() creates a DataSync membership through a PubNub client for JavaScript. The server generates the identifier unless the call supplies one.
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" }. See 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.
The userId and channelId pair must be unique for the membership class. A membership that duplicates an existing pair is rejected with a 409.
id#- Identifier of the new DataSync membership. Omit it to let the server generate one. The identifier has at most 255 characters.
userIdrequired#- Identifier of the user in the membership.
channelIdrequired#- Identifier of the channel in the membership.
datarequired#- The mutable membership data.
- property of data:
classVersionrequired# - Version of the membership class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
Sample code
Returns
pubnub.dataSync.createMembership() resolves with the HTTP status and the created membership.
Examples for Create membership
Syntax
1pubnub.dataSync.createMembership({
2 id: string,
3 userId: string,
4 channelId: string,
5 data: { classVersion: number, status: string, payload: object },
6}): Promise<DataSync.CreateMembershipResponse>
Basic usage
1
Returns
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 "expiresAt": "2026-08-12T09:00:00.000Z"
show all 17 linesGet membership
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getMembership() returns one DataSync membership by identifier through a PubNub client for JavaScript.
idrequired#- Identifier of the membership.
Sample code
Returns
pubnub.dataSync.getMembership() resolves with the HTTP status and the requested membership.
Examples for Get membership
Syntax
1pubnub.dataSync.getMembership({
2 id: string,
3}): Promise<DataSync.GetMembershipResponse>
Basic usage
1
Returns
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 "expiresAt": "2026-08-12T09:00:00.000Z"
show all 17 linesGet all memberships
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getMemberships() returns a paginated list of DataSync memberships through a PubNub client for JavaScript.
All parameters are optional, so you can call getMemberships() with no arguments. You can also pass a callback as the only argument. Filter by userId to list a user's memberships or by channelId to list a channel's members. For pagination, filtering, and sorting, see sorting and pagination.
cursor#- Opaque pagination cursor from the previous page. Omit it to get the first page.
limit#- Maximum number of memberships to return in one page, up to 100.
filter#- Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. The parameter supports the full expression language over properties declared with filtering mode
full. A call cannot combine it withfilterFast. filterFast#- Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. The parameter accepts up to 10 conditions by default (configurable per keyset) over properties declared with filtering mode
simpleorfull. A call cannot combine it withfilter. sort#- Sort order of the returned memberships. An object that maps each field to
'asc','desc', ornull(service default), or a comma-separated string such as'createdAt:desc'. userId#- List only memberships of this user.
channelId#- List only memberships of this channel.
classVersion#- Class version to list. Omit it to list memberships of every version of the class.
Sample code
Returns
pubnub.dataSync.getMemberships() resolves with the HTTP status, an array of memberships, and paging metadata.
Other examples
Examples for Get all memberships
Syntax
1pubnub.dataSync.getMemberships({
2 cursor: string,
3 limit: number,
4 filter: string,
5 filterFast: string,
6 sort: object | string,
7 userId: string,
8 channelId: string,
9 classVersion: number,
10}): Promise<DataSync.GetMembershipsResponse>
Basic usage
1
Returns
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 24 linesList a channel's members with channelId
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 filter
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.
The Membership class declares no payload properties and you can't extend it, so a filter can't reference a field inside the membership payload. A membership is filterable on the built-in fields id, createdAt, updatedAt and status instead. This example lists the memberships of user-alice whose status starts with arch. A membership without a status doesn't match.
1
Filter with filterFast
Filter with filterFast
filterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. The expression runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (configurable per keyset). The two parameters share the expression language of filter, so a call can send only one of them.
This example lists the memberships of user-alice whose status is exactly archived, and it also sees a membership you just wrote. It filters on the same built-in status field as the previous example.
1
Page through results with cursor
Page through results with cursor
Pass no cursor on the first call. Take meta.next_cursor from the response and pass it back as cursor on the next call. Stop when meta.has_next is false.
1
Set membership
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.setMembership() replaces a DataSync membership in full through a PubNub client for JavaScript. The call clears a stored status or payload that it omits.
Resend userId, channelId, and classVersion along with the fields you want to keep. For a partial update, use Update membership. To guard against concurrent writes, pass ifMatchesEtag. See optimistic concurrency with ETags.
idrequired#- Identifier of the membership.
userIdrequired#- Identifier of the user in the membership.
channelIdrequired#- Identifier of the channel in the membership.
datarequired#- The replacement membership data.
- property of data:
classVersionrequired# - Version of the membership class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
ifMatchesEtag#- The
eTagfrom a prior read. The update succeeds only if it still matches, otherwise the server returns412.
Sample code
Returns
pubnub.dataSync.setMembership() resolves with the HTTP status and the stored membership.
Examples for Set membership
Syntax
1pubnub.dataSync.setMembership({
2 id: string,
3 userId: string,
4 channelId: string,
5 data: { classVersion: number, status: string, payload: object },
6 ifMatchesEtag: string,
7}): Promise<DataSync.SetMembershipResponse>
Basic usage
1
Returns
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 "expiresAt": "2026-08-12T09:00:00.000Z"
show all 17 linesUpdate membership
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.updateMembership() applies a JSON Patch (RFC 6902) partial update to a DataSync membership through a PubNub client for JavaScript. The call needs at least one patch operation, and fields that no operation addresses stay unchanged.
idrequired#- Identifier of the membership.
add#- Full JSON Pointers mapped to values to add.
replace#- Full JSON Pointers mapped to replacement values.
remove#- Full JSON Pointers to remove.
move#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis removed and re-added atpath. copy#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis duplicated topath. test#- Full JSON Pointers mapped to expected values. The patch fails if any value does not match.
ifMatchesEtag#- The
eTagfrom a prior read. The patch succeeds only if it still matches, otherwise the server returns412.
Paths can target fields inside payload or top-level stored fields. A JSON Pointer that starts with /payload/ targets a payload field, and a root pointer such as /status targets a top-level field. See partial update for the JSON Pointer rules.
At least one of add, replace, remove, move, copy, or test must be provided.
A single updateMembership() call can mix add, replace, remove, move, copy, and test. The order you write the keys in does not matter. The SDK always sends the operations in the same order, with test last.
Sample code
Returns
pubnub.dataSync.updateMembership() resolves with the HTTP status and the updated membership.
Examples for Update membership
Syntax
1pubnub.dataSync.updateMembership({
2 id: string,
3 add: object,
4 replace: object,
5 remove: string[],
6 move: { from: string, path: string }[],
7 copy: { from: string, path: string }[],
8 test: object,
9 ifMatchesEtag: string,
10}): Promise<DataSync.UpdateMembershipResponse>
Basic usage
1
Returns
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": "QrStUvWxYzAbCd",
15 "expiresAt": "2026-08-12T09:00:00.000Z"
show all 17 linesRemove membership
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.removeMembership() deletes a DataSync membership by identifier through a PubNub client for JavaScript.
Sample code
Returns
pubnub.dataSync.removeMembership() resolves with only the HTTP status.
Examples for Remove membership
Syntax
1pubnub.dataSync.removeMembership({
2 id: string,
3 ifMatchesEtag: string,
4}): Promise<DataSync.RemoveMembershipResponse>
Basic usage
1
Returns
1{
2 "status": 200
3}
Create entity
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.createEntity() creates a DataSync entity through a PubNub client for JavaScript. The server generates the identifier unless the call supplies one.
Entities are instances of the custom entity classes you define on your key set. 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.
id#- Identifier of the new DataSync entity. Omit it to let the server generate one. The identifier has at most 255 characters.
classrequired#- Name of the entity class that this instance belongs to. The class is set at creation and immutable afterward.
classLevel#- Class hierarchy level of
class, eitherGlobalfor a class the service provides orSubKeyfor one defined on your key set. The level is set at creation and immutable afterward. Omit it to let the service apply its default. datarequired#- The mutable entity data.
- property of data:
classVersionrequired# - Version of the entity class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
Sample code
Returns
pubnub.dataSync.createEntity() resolves with the HTTP status and the created entity.
Examples for Create entity
Syntax
1pubnub.dataSync.createEntity({
2 id: string,
3 class: string,
4 classLevel: string,
5 data: { classVersion: number, status: string, payload: object },
6}): Promise<DataSync.CreateEntityResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "payload": {
8 "name": "Retro Sneaker",
9 "price": 89.99,
10 "stock": 12
11 },
12 "createdAt": "2026-07-13T09:15:00.000Z",
13 "updatedAt": "2026-07-13T09:15:00.000Z",
14 "eTag": "QrStUvWxYzAbCd",
15 "expiresAt": "2026-08-13T09:15:00.000Z"
show all 17 linesGet entity
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getEntity() returns one DataSync entity by identifier through a PubNub client for JavaScript.
idrequired#- Identifier of the entity.
Sample code
Returns
pubnub.dataSync.getEntity() resolves with the HTTP status and the requested entity.
Examples for Get entity
Syntax
1pubnub.dataSync.getEntity({
2 id: string,
3}): Promise<DataSync.GetEntityResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "payload": {
8 "name": "Retro Sneaker",
9 "price": 89.99,
10 "stock": 12
11 },
12 "createdAt": "2026-07-13T09:15:00.000Z",
13 "updatedAt": "2026-07-13T09:15:00.000Z",
14 "eTag": "QrStUvWxYzAbCd",
15 "expiresAt": "2026-08-13T09:15:00.000Z"
show all 17 linesGet all entities
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getEntities() returns a paginated list of DataSync entities through a PubNub client for JavaScript.
The class parameter is required, entities are always listed within the context of their class. Listing a class also returns the entities of its subclasses, so getEntities({ class: 'product' }) returns every product plus every instance of a class that extends product. For pagination, filtering, and sorting, see sorting and pagination.
classrequired#- Name of the entity class to list. The
classparameter is required. classVersion#- Class version to list. Omit it to list entities of every version of the class.
classLevel#- Class hierarchy level of
class, eitherGlobalfor a class the service provides orSubKeyfor one defined on your key set. Use it to disambiguate a class name defined at both levels. cursor#- Opaque pagination cursor from the previous page. Omit it to get the first page.
limit#- Maximum number of entities to return in one page, up to 100.
filter#- Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. The parameter supports the full expression language over properties declared with filtering mode
full. A call cannot combine it withfilterFast. filterFast#- Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. The parameter accepts up to 10 conditions by default (configurable per keyset) over properties declared with filtering mode
simpleorfull. A call cannot combine it withfilter. sort#- Sort order of the returned entities. An object that maps each field to
'asc','desc', ornull(service default), or a comma-separated string such as'createdAt:desc'.
Sample code
Returns
pubnub.dataSync.getEntities() resolves with the HTTP status, an array of entities, and paging metadata.
Other examples
Examples for Get all entities
Syntax
1pubnub.dataSync.getEntities({
2 class: string,
3 classVersion: number,
4 classLevel: string,
5 cursor: string,
6 limit: number,
7 filter: string,
8 filterFast: string,
9 sort: object | string,
10}): Promise<DataSync.GetEntitiesResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": [
4 {
5 "id": "product-sneaker-42",
6 "entityClass": "product",
7 "entityClassVersion": 1,
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 24 linesFilter with filter
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. Combine conditions with && and ||.
1
Filter with filterFast
Filter with filterFast
filterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. The expression runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (configurable per keyset). The two parameters share the expression language of filter, so a call can send only one of them.
1
Page through results with cursor
Page through results with cursor
Pass no cursor on the first call. Take meta.next_cursor from the response and pass it back as cursor on the next call. Stop when meta.has_next is false.
1
Set entity
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.setEntity() replaces a DataSync entity in full through a PubNub client for JavaScript. The call clears a stored status or payload that it omits.
The entity class is immutable after creation and cannot be sent. To guard against concurrent writes, pass ifMatchesEtag. See optimistic concurrency with ETags.
idrequired#- Identifier of the entity.
datarequired#- The replacement entity data. The entity
classis immutable and cannot be included. - property of data:
classVersionrequired# - Version of the entity class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
ifMatchesEtag#- The
eTagfrom a prior read. The update succeeds only if it still matches, otherwise the server returns412.
Sample code
Returns
pubnub.dataSync.setEntity() resolves with the HTTP status and the stored entity.
Examples for Set entity
Syntax
1pubnub.dataSync.setEntity({
2 id: string,
3 data: { classVersion: number, status: string, payload: object },
4 ifMatchesEtag: string,
5}): Promise<DataSync.SetEntityResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "payload": {
8 "name": "Retro Sneaker",
9 "price": 79.99,
10 "stock": 8
11 },
12 "createdAt": "2026-07-13T09:15:00.000Z",
13 "updatedAt": "2026-07-13T13:00:00.000Z",
14 "eTag": "StUvWxYzAbCdEf",
15 "expiresAt": "2026-08-13T09:15:00.000Z"
show all 17 linesUpdate entity
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.updateEntity() applies a JSON Patch (RFC 6902) partial update to a DataSync entity through a PubNub client for JavaScript. The call needs at least one patch operation, and fields that no operation addresses stay unchanged.
idrequired#- Identifier of the entity.
add#- Full JSON Pointers mapped to values to add.
replace#- Full JSON Pointers mapped to replacement values.
remove#- Full JSON Pointers to remove.
move#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis removed and re-added atpath. copy#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis duplicated topath. test#- Full JSON Pointers mapped to expected values. The patch fails if any value does not match.
ifMatchesEtag#- The
eTagfrom a prior read. The patch succeeds only if it still matches, otherwise the server returns412.
Paths can target fields inside payload or top-level stored fields. A JSON Pointer that starts with /payload/ targets a payload field, and a root pointer such as /status targets a top-level field. See partial update for the JSON Pointer rules.
At least one of add, replace, remove, move, copy, or test must be provided.
A single updateEntity() call can mix add, replace, remove, move, copy, and test. The order you write the keys in does not matter. The SDK always sends the operations in the same order, with test last.
Sample code
Returns
pubnub.dataSync.updateEntity() resolves with the HTTP status and the updated entity.
Other examples
Examples for Update entity
Syntax
1pubnub.dataSync.updateEntity({
2 id: string,
3 add: object,
4 replace: object,
5 remove: string[],
6 move: { from: string, path: string }[],
7 copy: { from: string, path: string }[],
8 test: object,
9 ifMatchesEtag: string,
10}): Promise<DataSync.UpdateEntityResponse>
Basic usage
1
Returns
1{
2 "status": 200,
3 "data": {
4 "id": "product-sneaker-42",
5 "entityClass": "product",
6 "entityClassVersion": 1,
7 "payload": {
8 "name": "Retro Sneaker",
9 "price": 79.99,
10 "stock": 12
11 },
12 "createdAt": "2026-07-13T09:15:00.000Z",
13 "updatedAt": "2026-07-13T13:05:00.000Z",
14 "eTag": "UvWxYzAbCdEfGh",
15 "expiresAt": "2026-08-13T09:15:00.000Z"
show all 17 linesCombine patch operations, and guard the write with ifMatchesEtag
Combine patch operations, and guard the write with ifMatchesEtag
updateEntity() call can mix add, replace, remove, move, copy, and test. The order you write the keys in does not matter. The SDK always sends the operations in the same order, with test last.Add ifMatchesEtag (the eTag from a prior read) to reject the patch with a 412 if the entity changed since you read it, instead of overwriting a concurrent change.1
Remove entity
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.removeEntity() deletes a DataSync entity by identifier through a PubNub client for JavaScript.
Sample code
Returns
pubnub.dataSync.removeEntity() resolves with only the HTTP status.
Examples for Remove entity
Syntax
1pubnub.dataSync.removeEntity({
2 id: string,
3 ifMatchesEtag: string,
4}): Promise<DataSync.RemoveEntityResponse>
Basic usage
1
Returns
1{
2 "status": 200
3}
Create relationship
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.createRelationship() creates a DataSync relationship through a PubNub client for JavaScript. The server generates the identifier unless the call supplies one.
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 key set. 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.
The relationship class's cardinality is enforced on create. A relationship that violates its class's cardinality is rejected with a 409.
id#- Identifier of the new DataSync relationship. Omit it to let the server generate one. The identifier has at most 255 characters.
classrequired#- Name of the relationship class that this instance belongs to. The class is set at creation and immutable afterward.
entityAIdrequired#- Identifier of the first linked entity. Immutable after creation.
entityBIdrequired#- Identifier of the second linked entity. Immutable after creation.
datarequired#- The mutable relationship data.
- property of data:
classVersionrequired# - Version of the relationship class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
Sample code
Returns
pubnub.dataSync.createRelationship() resolves with the HTTP status and the created relationship.
Examples for Create relationship
Syntax
1pubnub.dataSync.createRelationship({
2 id: string,
3 class: string,
4 entityAId: string,
5 entityBId: string,
6 data: { classVersion: number, status: string, payload: object },
7}): Promise<DataSync.CreateRelationshipResponse>
Basic usage
1
Returns
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 "expiresAt": "2026-08-12T09:00:00.000Z"
show all 17 linesGet relationship
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getRelationship() returns one DataSync relationship by identifier through a PubNub client for JavaScript.
idrequired#- Identifier of the relationship.
Sample code
Returns
pubnub.dataSync.getRelationship() resolves with the HTTP status and the requested relationship.
Examples for Get relationship
Syntax
1pubnub.dataSync.getRelationship({
2 id: string,
3}): Promise<DataSync.GetRelationshipResponse>
Basic usage
1
Returns
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 "expiresAt": "2026-08-12T09:00:00.000Z"
show all 17 linesGet all relationships
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.getRelationships() returns a paginated list of DataSync relationships through a PubNub client for JavaScript.
The class parameter is required. Filter by entityAId or entityBId to list a specific entity's links. For pagination, filtering, and sorting, see sorting and pagination.
classrequired#- Name of the relationship class to list. The
classparameter is required. classVersion#- Class version to list. Omit it to list relationships of every version of the class.
entityAId#- List only relationships whose first entity has this identifier.
entityBId#- List only relationships whose second entity has this identifier.
cursor#- Opaque pagination cursor from the previous page. Omit it to get the first page.
limit#- Maximum number of relationships to return in one page, up to 100.
filter#- Filter expression evaluated against eventually consistent storage, so results can briefly lag writes. The parameter supports the full expression language over properties declared with filtering mode
full. A call cannot combine it withfilterFast. filterFast#- Filter expression evaluated against strongly consistent storage, so it reflects the latest writes. The parameter accepts up to 10 conditions by default (configurable per keyset) over properties declared with filtering mode
simpleorfull. A call cannot combine it withfilter. sort#- Sort order of the returned relationships. An object that maps each field to
'asc','desc', ornull(service default), or a comma-separated string such as'createdAt:desc'.
Sample code
Returns
pubnub.dataSync.getRelationships() resolves with the HTTP status, an array of relationships, and paging metadata.
Other examples
Examples for Get all relationships
Syntax
1pubnub.dataSync.getRelationships({
2 class: string,
3 classVersion: number,
4 entityAId: string,
5 entityBId: string,
6 cursor: string,
7 limit: number,
8 filter: string,
9 filterFast: string,
10 sort: object | string,
11}): Promise<DataSync.GetRelationshipsResponse>
Basic usage
1
Returns
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 24 linesList an entity's incoming links with entityBId
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 filter
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.
1
Filter with filterFast
Filter with filterFast
filterFast is evaluated against strongly consistent storage, so it matches an object you just wrote. The expression runs over properties declared with filtering mode simple or full and accepts up to 10 conditions by default (configurable per keyset). The two parameters share the expression language of filter, so a call can send only one of them.
1
Page through results with cursor
Page through results with cursor
Pass no cursor on the first call. Take meta.next_cursor from the response and pass it back as cursor on the next call. Stop when meta.has_next is false.
1
Set relationship
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.setRelationship() replaces a DataSync relationship in full through a PubNub client for JavaScript. The call clears a stored status or payload that it omits.
The linked entity identifiers are immutable, so resend the same entityAId and entityBId. To guard against concurrent writes, pass ifMatchesEtag. See optimistic concurrency with ETags.
idrequired#- Identifier of the relationship.
entityAIdrequired#- Identifier of the first linked entity. Must match the value set at creation.
entityBIdrequired#- Identifier of the second linked entity. Must match the value set at creation.
datarequired#- The replacement relationship data. The relationship
classis immutable and cannot be included. - property of data:
classVersionrequired# - Version of the relationship class schema.
- property of data:
status# - Free-form lifecycle status. The maximum length is 100 characters.
- property of data:
payload# - Free-form JSON object holding your application data.
ifMatchesEtag#- The
eTagfrom a prior read. The update succeeds only if it still matches, otherwise the server returns412.
Sample code
Returns
pubnub.dataSync.setRelationship() resolves with the HTTP status and the stored relationship.
Examples for Set relationship
Syntax
1pubnub.dataSync.setRelationship({
2 id: string,
3 entityAId: string,
4 entityBId: string,
5 data: { classVersion: number, status: string, payload: object },
6 ifMatchesEtag: string,
7}): Promise<DataSync.SetRelationshipResponse>
Basic usage
1
Returns
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 18 linesUpdate relationship
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.updateRelationship() applies a JSON Patch (RFC 6902) partial update to a DataSync relationship through a PubNub client for JavaScript. The call needs at least one patch operation, and fields that no operation addresses stay unchanged.
idrequired#- Identifier of the relationship.
add#- Full JSON Pointers mapped to values to add.
replace#- Full JSON Pointers mapped to replacement values.
remove#- Full JSON Pointers to remove.
move#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis removed and re-added atpath. copy#- Pairs of JSON Pointers, each with a
fromand apath. The value atfromis duplicated topath. test#- Full JSON Pointers mapped to expected values. The patch fails if any value does not match.
ifMatchesEtag#- The
eTagfrom a prior read. The patch succeeds only if it still matches, otherwise the server returns412.
Paths can target fields inside payload or top-level stored fields. A JSON Pointer that starts with /payload/ targets a payload field, and a root pointer such as /status targets a top-level field. See partial update for the JSON Pointer rules.
At least one of add, replace, remove, move, copy, or test must be provided.
A single updateRelationship() call can mix add, replace, remove, move, copy, and test. The order you write the keys in does not matter. The SDK always sends the operations in the same order, with test last.
Sample code
Returns
pubnub.dataSync.updateRelationship() resolves with the HTTP status and the updated relationship.
Examples for Update relationship
Syntax
1pubnub.dataSync.updateRelationship({
2 id: string,
3 add: object,
4 replace: object,
5 remove: string[],
6 move: { from: string, path: string }[],
7 copy: { from: string, path: string }[],
8 test: object,
9 ifMatchesEtag: string,
10}): Promise<DataSync.UpdateRelationshipResponse>
Basic usage
1
Returns
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 18 linesRemove relationship
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
pubnub.dataSync.removeRelationship() deletes a DataSync relationship by identifier through a PubNub client for JavaScript.
Sample code
Returns
pubnub.dataSync.removeRelationship() resolves with only the HTTP status.
Examples for Remove relationship
Syntax
1pubnub.dataSync.removeRelationship({
2 id: string,
3 ifMatchesEtag: string,
4}): Promise<DataSync.RemoveRelationshipResponse>
Basic usage
1
Returns
1{
2 "status": 200
3}
Where each event is delivered
Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal.
DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal.
Requires Access Manager add-on
This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
Requires DataSync add-on
This method requires that the DataSync add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
The PubNub JavaScript SDK receives a DataSync change event on every channel whose name matches the identifier of an object that the change affects.
DataSync objects can publish create, update, and delete events that you receive in real time with a dataSync listener. Create a DataSync SDK entity for the object, subscribe to it, and attach the listener, described in the Add DataSync listener section of Publish and subscribe.
Each event names the change in event, identifies the object kind in objectType (user, channel, membership, entity, or relationship), and carries the object state in data. For a delete event, data holds only the id and, when the service reports it, deletedAt.
A relationship or membership change is delivered on the ids of the two objects it links, and never on a channel named after the relationship or membership id. A create for a user, channel, or entity is delivered only on its own id. An update or delete for a user, channel, or entity is also delivered on the id of every object connected to it at the time of the change. The connection can be a relationship or membership, in either direction.
The table shows the mapping for each kind of change.
| Change to | create delivered on | update / delete delivered on |
|---|---|---|
| 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 | Both the userId and the channelId of the membership |
| A relationship | Both the entityAId and the entityBId of the relationship | Both the entityAId and the entityBId of the relationship |
So to see memberships appear and disappear for Alice, observe user-alice rather than the membership id. Unlike entity/user/channel events, a membership or relationship create is delivered on both linked ids too, the same as its update/delete. A client observing both sides of the same link receives the change twice, once per channel. Deduplicate create and update events on data.id and data.updatedAt, and delete events on data.id and data.deletedAt.
DataSync events are off by default. You enable event publishing for each class in the Admin Portal. See enabling DataSync events. See receiving events for the listener flow.
Sample code
Examples for Where each event is delivered
Basic usage
1