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
Description
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 V4 SDK:
pubnub.objects.getAllUUIDMetadata({
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
include | any | Optional | Include respective additional fields in the response. | |
totalCount | Boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | Boolean | Optional | false | Whether to fetch custom fields or not. |
filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | String | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | String | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesGet User Metadata
Description
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 V4 SDK:
pubnub.objects.getUUIDMetadata({
uuid: string,
include: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Optional | current uuid | Unique user identifier. If not supplied then current user's uuid is used. |
include | any | Optional | Include respective additional fields in the response. | |
customFields | Boolean | Optional | true | Whether 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
Description
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 V4 SDK:
pubnub.objects.setUUIDMetadata({
uuid: string,
data: any,
include: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Optional | current uuid | Unique user identifier. If not supplied then current user's uuid is used. |
data | any | Yes | JSON object with uuid metadata to set. | |
name | string | Optional | Display name for the user. Maximum 200 characters. | |
externalId | string | Optional | User's identifier in an external system | |
profileUrl | string | Optional | The URL of the user's profile picture | |
email | string | Optional | The user's email address. Maximum 80 characters. | |
custom | any | Optional | JSON 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. | |
include | any | Optional | Include respective additional fields in the response. | |
customFields | boolean | Optional | true | Whether to fetch custom fields or not. |
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 linesResponse
{
"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
Description
Removes the metadata from a specified UUID.
Method(s)
To Remove UUID Metadata
, you can use the following method(s) in the JavaScript V4 SDK:
pubnub.objects.removeUUIDMetadata({
uuid: string
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Optional | current uuid | Unique 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
Description
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 V4 SDK:
pubnub.objects.getAllChannelMetadata({
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
include | any | Optional | Include respective additional fields in the response. | |
totalCount | Boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | Boolean | Optional | false | Whether to fetch custom fields or not. |
filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesResponse
{
"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 linesGet Channel Metadata
Description
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 V4 SDK:
pubnub.objects.getChannelMetadata({
channel: string,
include: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | string | Yes | Channel name. | |
include | any | Optional | Include respective additional fields in the response. | |
customFields | Boolean | Optional | true | Whether 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
Description
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 V4 SDK:
pubnub.objects.setChannelMetadata({
channel: string,
data: any,
include: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | string | Yes | Channel name. | |
data | any | Yes | JSON object with channel metadata to set. | |
name | string | Optional | Name of a channel. | |
description | string | Optional | Description of a channel. | |
custom | any | Optional | JSON 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. | |
include | any | Optional | Include respective additional fields in the response. | |
customFields | boolean | Optional | true | Whether to fetch custom fields or not. |
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 linesResponse
{
"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
Description
Removes the metadata from a specified channel.
Method(s)
To Remove Channel Metadata
, you can use the following method(s) in the JavaScript V4 SDK:
pubnub.objects.removeChannelMetadata({
channel: string
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Channel 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
Description
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 V4 SDK:
pubnub.objects.getMemberships({
uuid: string,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Optional | current uuid | Unique user identifier. If not supplied then current user's uuid is used. |
include | any | Optional | Include respective additional fields in the response. | |
totalCount | boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | boolean | Optional | false | Whether to fetch custom fields or not. |
channelFields | boolean | Optional | false | Include fields for channels metadata. |
customChannelFields | boolean | Optional | false | Include custom fields for channels metadata. |
filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesResponse
{
"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 linesSet Channel Memberships
Description
Set channel memberships for a UUID.
Method(s)
To Set Memberships
, you can use the following method(s) in the JavaScript V4 SDK:
pubnub.objects.setMemberships({
uuid: string,
channels: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Optional | current uuid | Unique user identifier. If not supplied then current user's uuid is used. |
channels | Array<string> | Yes | Array 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" } } . | |
include | any | Optional | Include respective additional fields in the response. | |
totalCount | boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | boolean | Optional | false | Whether to fetch custom fields or not. |
channelFields | boolean | Optional | false | Include fields for channels metadata. |
customChannelFields | boolean | Optional | false | Include custom fields for channels metadata. |
filter | String | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | Number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesResponse
{
"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 linesRemove Channel Memberships
Description
Remove channel memberships for a UUID.
Method(s)
To Remove Memberships
, you can use the following method(s) in the JavaScript V4 SDK:
pubnub.objects.removeMemberships({
uuid: string,
channels: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Optional | current uuid | Unique user identifier. If not supplied then current user's uuid is used. |
channels | Array<string> | Yes | Channels to remove from membership. | |
include | any | Optional | Include respective additional fields in the response. | |
totalCount | boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | boolean | Optional | false | Whether to fetch custom fields or not. |
channelFields | boolean | Optional | false | Include fields for channels metadata. |
customChannelFields | boolean | Optional | false | Include custom fields for channels metadata. |
filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | Number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesResponse
{
"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 linesChannel Members
Get Channel Members
Description
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 V4 SDK:
pubnub.objects.getChannelMembers({
channel: string,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | string | Yes | Channel name. | |
include | any | Optional | Include respective additional fields in the response. | |
totalCount | boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | boolean | Optional | false | Whether to fetch custom fields or not. |
UUIDFields | boolean | Optional | false | Include fields for UUIDs metadata. |
customUUIDFields | boolean | Optional | false | Include custom fields for UUIDs metadata. |
filter | String | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesResponse
{
"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 linesSet Channel Members
Description
This method sets members in a channel.
Method(s)
To Set Channel Members
, you can use the following method(s) in the JavaScript V4 SDK:
pubnub.objects.setChannelMembers({
channel: string,
uuids: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | string | Yes | Channel name. | |
uuids | Array | Yes | Array 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" } } . | |
include | any | Optional | Include respective additional fields in the response. | |
totalCount | boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | boolean | Optional | false | Whether to fetch custom fields or not. |
UUIDFields | boolean | Optional | false | Include fields for UUIDs metadata. |
customUUIDFields | boolean | Optional | false | Include custom fields for UUIDs metadata. |
filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesRemove Channel Members
Description
Remove members from a Channel.
Method(s)
To Remove Channel Members
, you can use the following method(s) in the JavaScript V4 SDK:
pubnub.objects.removeChannelMembers({
channel: string,
uuids: Array<string>,
include: any,
filter: string,
sort: any,
limit: number,
page: any
})
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | string | Yes | Channel name. | |
uuids | String[] | Yes | Members to remove from channel. | |
include | any | Optional | Include respective additional fields in the response. | |
totalCount | boolean | Optional | false | Request totalCount to be included in paginated response. By default, totalCount is omitted. |
customFields | boolean | Optional | false | Whether to fetch custom fields or not. |
UUIDFields | boolean | Optional | false | Include fields for UUIDs metadata. |
customUUIDFields | boolean | Optional | false | Include custom fields for UUIDs metadata. |
filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. | |
sort | any | Optional | Key-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'} | |
limit | number | Optional | 100 | Number of objects to return in response. Default is 100 , which is also the maximum value. |
page | any | Optional | Use for pagination. | |
next | string | Optional | Previously-returned cursor bookmark for fetching the next page. | |
prev | string | Optional | Previously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. |
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 linesApp 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 linesSample 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 '*\\**'