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
})
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 | Random 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. | |
prev | String | Optional | Random 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 name "John"
try {
const result = await pubnub.objects.getAllUUIDMetadata({
filter: 'name == "John"',
});
} 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
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
})
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
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
})
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. | |
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. | |
custom | any | Optional | JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs. | |
include | any | Optional | Include respective additional fields in the response. | |
customFields | boolean | Optional | true | Whether 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 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
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
})
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
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
})
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 | Random 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. | |
prev | string | Optional | Random 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 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
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
})
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
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
})
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. |
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 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
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
})
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
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
})
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 include custom fields in the response. |
channelFields | boolean | Optional | false | Whether to include fields for channel metadata in the response. |
customChannelFields | boolean | Optional | false | Whether to include custom fields for channel metadata in the response. |
statusField | boolean | Optional | false | Whether to include the membership's status field in the response. |
channelStatusField | boolean | Optional | false | Whether to include the channel's status field in the response. |
channelTypeField | boolean | Optional | false | Whether to include channel's type fields in the response. |
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 | Random 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. | |
prev | string | Optional | Random 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 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
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
})
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 | Random 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. | |
prev | string | Optional | Random 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 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
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
})
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 | Random 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. | |
prev | string | Optional | Random 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 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
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
})
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 |
UUIDFields | boolean | Optional | false | Whether to include fields for UUIDs metadata. |
customUUIDFields | boolean | Optional | false | Whether to include custom fields for UUIDs metadata. |
statusField | boolean | Optional | false | Whether to include the member's status field in the response. |
UUIDStatusField | boolean | Optional | false | Whether to include the member's status field in the response. |
UUIDTypeField | boolean | Optional | false | Whether to include member's type fields in the response. |
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 | Random 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. | |
prev | string | Optional | Random 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 "admin" in the description
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
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
})
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 | Random 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. | |
prev | string | Optional | Random 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 linesRemove 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
})
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 | Random 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. | |
prev | string | Optional | Random 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