App Context API for PubNub JavaScript SDK

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.

PubNub also triggers events when object data is set or removed from the database. Clients can receive these events in real time and update their front-end application accordingly.

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.

User

Get Metadata for All Users

Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All UUID Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.getAllUUIDMetadata({
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
includeanyOptionalInclude respective additional fields in the response.
   totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
filterstringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {name: 'asc'}
limitnumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextStringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevStringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Basic Usage

// Get all UUIDs
try {
const result = await pubnub.objects.getAllUUIDMetadata();
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Get all UUIDs with the custom type "doctor"
try {
const result = await pubnub.objects.getAllUUIDMetadata({
filter: 'custom.type == "doctor"',
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 200,
"data": [
{
"id": "uuid-1",
"name": "John Doe",
"externalId": null,
"profileUrl": null,
"email": "johndoe@pubnub.com",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
},
{
"id": "uuid-2",
show all 27 lines

Get User Metadata

Returns metadata for the specified UUID, optionally including the custom data object for each.

Method(s)

To Get UUID Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.getUUIDMetadata({
uuid: string,
include: any
})
ParameterTypeRequiredDefaultDescription
uuidstringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
includeanyOptionalInclude respective additional fields in the response.
   customFieldsBooleanOptionaltrueWhether to fetch custom fields or not.

Basic Usage

// Using UUID from the config
try {
const result = await pubnub.objects.getUUIDMetadata();
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Using the passed in UUID
try {
const result = await pubnub.objects.getUUIDMetadata({
uuid: "myUuid",
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 200,
"data": {
"id": "uuid-1",
"name": "John Doe",
"externalId": null,
"profileUrl": null,
"email": "johndoe@pubnub.com",
"updated": "2019-02-20T23:11:20.893755",
"eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
}
}

Set User Metadata

Set metadata for a UUID in the database, optionally including the custom data object for each.

Method(s)

To Set UUID Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.setUUIDMetadata({
uuid: string,
data: any,
include: any
})
ParameterTypeRequiredDefaultDescription
uuidstringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
dataanyYesJSON object with uuid metadata to set.
   namestringOptionalDisplay name for the user.
   externalIdstringOptionalUser's identifier in an external system
   profileUrlstringOptionalThe URL of the user's profile picture
   emailstringOptionalThe user's email address.
   customanyOptionalJSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties.
includeanyOptionalInclude respective additional fields in the response.
   customFieldsbooleanOptionaltrueWhether to fetch custom fields or not.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Basic Usage

// Using UUID from the config
try {
const result = await pubnub.objects.setUUIDMetadata({
data: {
name: "John Doe",
},
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Using the passed in UUID
try {
const result = await pubnub.objects.setUUIDMetadata({
uuid: "myUuid",
show all 20 lines

Response

{
"status": 200,
"data": {
"id": "uuid-1",
"name": "John Doe",
"externalId": null,
"profileUrl": null,
"email": "johndoe@pubnub.com",
"updated": "2019-02-20T23:11:20.893755",
"eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
}
}

Remove User Metadata

Removes the metadata from a specified UUID.

Method(s)

To Remove UUID Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.removeUUIDMetadata({
uuid: string
})
ParameterTypeRequiredDefaultDescription
uuidstringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.

Basic Usage

// Using UUID from the config
try {
const result = await pubnub.objects.removeUUIDMetadata();
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Using the passed in UUID
try {
const result = await pubnub.objects.removeUUIDMetadata({
uuid: "myUuid",
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 0,
"data": {}
}

Channel

Get Metadata for All Channels

Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All Channel Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.getAllChannelMetadata({
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
includeanyOptionalInclude respective additional fields in the response.
   totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
filterstringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {name: 'asc'}
limitnumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Basic Usage

// Get the total number of channels
try {
const result = await pubnub.objects.getAllChannelMetadata({
include: {
totalCount: true,
},
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Get all channels that have IDs starting with "pro."
try {
const result = await pubnub.objects.getAllChannelMetadata({
filter: 'name LIKE "*Team"',
show all 19 lines

Response

{
"status": 200,
"data": [
{
"id": "team.blue",
"name": "Blue Team",
"description": "The channel for Blue team and no other teams.",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
},
{
"id": "team.red",
"name": "Red Team",
"description": "The channel for Red team and no other teams.",
show all 35 lines

Get Channel Metadata

Returns metadata for the specified Channel, optionally including the custom data object for each.

Method(s)

To Get Channel Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.getChannelMetadata({
channel: string,
include: any
})
ParameterTypeRequiredDefaultDescription
channelstringYesChannel name.
includeanyOptionalInclude respective additional fields in the response.
   customFieldsBooleanOptionaltrueWhether to fetch custom fields or not.

Basic Usage

try {
const result = await pubnub.objects.getChannelMetadata({
// `channel` is the `id` in the _metadata_, not `name`
channel: "team.blue",
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 200,
"data": {
"id": "team.blue",
"name": "Blue Team",
"description": "The channel for Blue team and no other teams.",
"updated": "2019-02-20T23:11:20.893755",
"eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
}
}

Set Channel Metadata

Set metadata for a Channel in the database, optionally including the custom data object for each.

Method(s)

To Set Channel Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.setChannelMetadata({
channel: string,
data: any,
include: any
})
ParameterTypeRequiredDefaultDescription
channelstringYesChannel name.
dataanyYesJSON object with channel metadata to set.
   namestringOptionalName of a channel.
   descriptionstringOptionalDescription of a channel.
   customanyOptionalJSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties.
includeanyOptionalInclude respective additional fields in the response.
   customFieldsbooleanOptionaltrueWhether to fetch custom fields or not.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Basic Usage

try {
const result = await pubnub.objects.setChannelMetadata({
channel: "team.red",
data: {
name: "Red Team",
description: "The channel for Red team and no other teams.",
custom: {
owner: "Red Leader",
},
},
include: {
customFields: false,
},
});
} catch (status) {
show all 17 lines

Response

{
"status": 200,
"data": {
"id": "team.red",
"name": "Red Team",
"description": "The channel for Blue team and no other teams.",
"updated": "2019-02-20T23:11:20.893755",
"eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
}
}

Remove Channel Metadata

Removes the metadata from a specified channel.

Method(s)

To Remove Channel Metadata, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.removeChannelMetadata({
channel: string
})
ParameterTypeRequiredDefaultDescription
channelStringYesChannel name.

Basic Usage

try {
const result = await pubnub.objects.removeChannelMetadata({
channel: "team.red",
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 0,
"data": {}
}

Channel Memberships

Get Channel Memberships

The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.

Method(s)

To Get Memberships, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.getMemberships({
uuid: string,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
uuidstringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
includeanyOptionalInclude respective additional fields in the response.
   totalCountbooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsbooleanOptionalfalseWhether to include custom fields in the response.
   channelFieldsbooleanOptionalfalseWhether to include fields for channel metadata in the response.
   customChannelFieldsbooleanOptionalfalseWhether to include custom fields for channel metadata in the response.
   statusFieldbooleanOptionalfalseWhether to include the membership's status field in the response.
   channelStatusFieldbooleanOptionalfalseWhether to include the channel's status field in the response.
   channelTypeFieldbooleanOptionalfalseWhether to include channel's type fields in the response.
filterstringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, channel.id, channel.name, and channel.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {channel.name: 'asc'}
limitnumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Basic Usage

// Using UUID from the config
try {
const result = await pubnub.objects.getMemberships();
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Using the passed in UUID
try {
const result = await pubnub.objects.getMemberships({
uuid: "myUuid",
include: {
channelFields: true,
},
});
show all 28 lines

Response

{
"status": 200,
"data": [
{
"channel": {
"id": "my-channel",
"name": "My channel",
"description": "A channel that is mine",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
},
"custom": {
"starred": false
},
show all 38 lines

Set Channel Memberships

Set channel memberships for a UUID.

Method(s)

To Set Memberships, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.setMemberships({
uuid: string,
channels: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
uuidstringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
channelsArray<string>YesArray of channels to add to membership. Array can contain strings (channel-name only) or objects which can include custom data, for example: { id: "my-channel-3", custom: { owner: "PubNubUser" } }.
includeanyOptionalInclude respective additional fields in the response.
   totalCountbooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsbooleanOptionalfalseWhether to fetch custom fields or not.
   channelFieldsbooleanOptionalfalseInclude fields for channels metadata.
   customChannelFieldsbooleanOptionalfalseInclude custom fields for channels metadata.
filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, channel.id, channel.name, and channel.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {channel.name: 'asc'}
limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.
API limits

To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.

Basic Usage

// Using UUID from the config
try {
const result = await pubnub.objects.setMemberships({
channels: ["ch-1", "ch-2"],
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Using the passed in UUID
try {
const result = await pubnub.objects.setMemberships({
uuid: "my-uuid",
channels: [
"my-channel",
show all 26 lines

Response

{
"status": 200,
"data": [
{
"channel": {
"id": "my-channel",
"name": "My channel",
"description": "A channel that is mine",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
},
"custom": {
"starred": false
},
show all 38 lines

Remove Channel Memberships

Remove channel memberships for a UUID.

Method(s)

To Remove Memberships, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.removeMemberships({
uuid: string,
channels: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
uuidstringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
channelsArray<string>YesChannels to remove from membership.
includeanyOptionalInclude respective additional fields in the response.
   totalCountbooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsbooleanOptionalfalseWhether to fetch custom fields or not.
   channelFieldsbooleanOptionalfalseInclude fields for channels metadata.
   customChannelFieldsbooleanOptionalfalseInclude custom fields for channels metadata.
filterstringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, channel.id, channel.name, and channel.updated. Use asc or desc to specify sort direction., or specify null to take the default sort direction (ascending). For example: {channel.name: 'asc'}
limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Basic Usage

// Using UUID from the config
try {
const result = await pubnub.objects.removeMemberships({
channels: ["ch-1", "ch-2"],
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Using the passed in UUID
try {
const result = await pubnub.objects.removeMemberships({
uuid: "myUuid",
channels: ["ch-1", "ch-2"],
});
show all 18 lines

Response

{
"status": 200,
"data": [
{
"channel": {
"id": "my-channel",
"name": "My channel",
"description": "A channel that is mine",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
},
"custom": {
"starred": false
},
show all 38 lines

Channel Members

Get Channel Members

The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.

Method(s)

To Get Channel Members, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.getChannelMembers({
channel: string,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
channelstringYesChannel name.
includeanyOptionalInclude respective additional fields in the response.
   totalCountbooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsbooleanOptionalfalseWhether to fetch custom fields
   UUIDFieldsbooleanOptionalfalseWhether to include fields for UUIDs metadata.
   customUUIDFieldsbooleanOptionalfalseWhether to include custom fields for UUIDs metadata.
   statusFieldbooleanOptionalfalseWhether to include the member's status field in the response.
   UUIDStatusFieldbooleanOptionalfalseWhether to include the member's status field in the response.
   UUIDTypeFieldbooleanOptionalfalseWhether to include member's type fields in the response.
filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {uuid.name: 'asc'}
limitnumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Basic Usage

try {
const result = await pubnub.objects.getChannelMembers({
channel: "myChannel",
include: {
UUIDFields: true,
},
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

// Get all channel members with the "admin" role
try {
const result = await pubnub.objects.getChannelMembers({
channel: "myChannel",
show all 20 lines

Response

{
"status": 200,
"data": [
{
"uuid": {
"id": "uuid-1",
"name": "John Doe",
"externalId": null,
"profileUrl": null,
"email": "jack@twitter.com",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
},
"custom": {
show all 41 lines

Set Channel Members

This method sets members in a channel.

Method(s)

To Set Channel Members, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.setChannelMembers({
channel: string,
uuids: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
channelstringYesChannel name.
uuidsArrayYesArray of members to add to the channel. Array can contain strings (uuid only) or objects which can include custom data, for example: { id: "uuid-3", custom: { role: "Super Admin" } }.
includeanyOptionalInclude respective additional fields in the response.
   totalCountbooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsbooleanOptionalfalseWhether to fetch custom fields or not.
   UUIDFieldsbooleanOptionalfalseInclude fields for UUIDs metadata.
   customUUIDFieldsbooleanOptionalfalseInclude custom fields for UUIDs metadata.
filterstringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {uuid.name: 'asc'}
limitnumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.
API limits

To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.

Basic Usage

try {
const result = await pubnub.objects.setChannelMembers({
channel: "myChannel",
uuids: [
"uuid-1",
"uuid-2",
{ id: "uuid-3", custom: { role: "Super Admin" } },
],
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 200,
"data": [
{
"uuid": {
"id": "uuid-1",
"name": "John Doe",
"externalId": null,
"profileUrl": null,
"email": "johndoe@pubnub.com",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
},
"custom": {
show all 41 lines

Remove Channel Members

Remove members from a Channel.

Method(s)

To Remove Channel Members, you can use the following method(s) in the JavaScript SDK:

pubnub.objects.removeChannelMembers({
channel: string,
uuids: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
ParameterTypeRequiredDefaultDescription
channelstringYesChannel name.
uuidsString[]YesMembers to remove from channel.
includeanyOptionalInclude respective additional fields in the response.
   totalCountbooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
   customFieldsbooleanOptionalfalseWhether to fetch custom fields or not.
   UUIDFieldsbooleanOptionalfalseInclude fields for UUIDs metadata.
   customUUIDFieldsbooleanOptionalfalseInclude custom fields for UUIDs metadata.
filterstringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortanyOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {uuid.name: 'asc'}
limitnumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageanyOptionalUse for pagination.
   nextstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   prevstringOptionalRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Basic Usage

try {
const result = await pubnub.objects.removeChannelMembers({
channel: "myChannel",
uuids: ["uuid-1", "uuid-2"],
});
} catch (status) {
console.log("operation failed w/ error:", status);
}

Response

{
"status": 200,
"data": [
{
"uuid": {
"id": "uuid-1",
"name": "John Doe",
"externalId": null,
"profileUrl": null,
"email": "johndoe@pubnub.com",
"custom": null,
"updated": "2019-02-20T23:11:20.893755",
"eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
},
"custom": {
show all 41 lines

App Context Filtering Language Definition

The filtering language for App Context is similar to the stream filtering language.

Note the following:

  • Date/time properties, such as updated, must be compared to valid date/time strings formatted according to ISO 8601.

  • The LIKE operator supports wildcards denoted by the * character. A wildcard matches any sequence of arbitrary Unicode characters, including the empty sequence. The literal asterisk is matched when escaped using the backslash (\) character.

  • Values used with LIKE must be properly encoded just like any other string value. Thus, to escape an asterisk, the raw value must contain \\*.

  • The entire expression must be properly URL-encoded when used in the query string.

Custom property filtering

You can't filter by custom properties.

<expression>           ::= <and_expression> ( "||" <and_expression> )*
<and_expression> ::= <binary_condition> ( "&&" <binary_condition> )*
<binary_condition> ::= "!" <binary_condition> | "(" <expression> ")" | <relational_condition>
<relational_condition> ::= <property_path> <relational_operator> <value>
<property_path> ::= <property_name> ( "." <property_name> )*
<property_name> ::= <identifier> | "[" <string> "]"
<value> ::= <string> | <number> | "true" | "false" | "null"

Tokens

<identifier> ::= <letter> | "$" | "_" ( <letter> | "$" | "_" | <digit> )*
<relational_operator> ::= "==" | "!=" | "<=" | ">=" | "<" | ">" | "LIKE"
<string> ::= <double_quote> ( "\" <double_quote> | "\" <special_char>
| "\" "u" <hex_digit> <hex_digit> <hex_digit> <hex_digit>
| <unicode_char> - <double_quote> - "\" )* <double_quote>
show all 26 lines

Sample object filtering operations

The following date/time comparison returns results that were modified on or after August 31st, 2019 (UTC):

updated >= "2019-08-31T00:00:00Z"

The following wildcard expression returns results whose name starts with the letter X:

name LIKE 'X*'

The following escaped wildcard expression returns results whose name contains an asterisk:

name LIKE '*\\**'
Last updated on