PubNub Module
The pubnub module provides PubNub client API methods.
Execution boundaries
- You can chain up to
3hops from one Function to another usingpublishorfire. - Within one Function execution, you can perform up to
3combined operations:KV store,XHRs,publish, orfire.
The pubnub module is made available via the following require() statement:
1const pubnub = require('pubnub');
Publish
Publish
Use the publish() method to send a message to subscribers and Functions.
Usage
1publish({ message, channel })
| Parameter | Description |
|---|---|
message *Type: Object | The message to send. |
channel *Type: String | The channel to publish to. |
1pubnub.publish({
2 "channel": "hello_universe",
3 "message": request.message
4}).then((publishResponse) => {
5 console.log(`Publish Status: ${publishResponse[0]}:${publishResponse[1]} with TT ${publishResponse[2]}`);
6});
JSON requirement
Published payloads must be valid JSON. Strings won't trigger Functions.
Fire
Use the fire() method to trigger Functions without delivering to subscribers.
Usage
1fire({ message, channel })
| Parameter | Description |
|---|---|
message *Type: Object | JavaScript object to be sent to PubNub. |
channel *Type: String | The channel to publish to. |
1pubnub.fire({
2 "channel": "hello_universe",
3 "message": request.message
4}).then((publishResponse) => {
5 console.log(`Publish Status: ${publishResponse[0]}:${publishResponse[1]} with TT ${publishResponse[2]}`);
6});
Signal
To send a signal to PubNub Subscribers and Functions, use the signal() method.
By default, signals are limited to a message payload size of 64 bytes. This limit applies only to the payload and not to the URI or headers. If you require a larger payload size, contact support.
Usage
1signal({ message, channel })
| Parameter | Description |
|---|---|
message *Type: Object | JavaScript object to be sent to PubNub. |
channel *Type: String | The channel to publish to. |
1pubnub.signal({
2 "channel": "hello_universe",
3 "message": request.message // must be smaller than 64 bytes
4}).then((signalResponse) => {
5 console.log(`Signal Status: ${signalResponse[0]}:${signalResponse[1]} with TT ${signalResponse[2]}`);
6});
JSON requirement
Payload that is published via signal requires a valid JSON. Strings won't trigger Functions.
File sharing
At present, the main use case for Functions is to construct the URL and integrate with external services, for example, for image moderation or logging. To upload and download files, you need to use a PubNub client SDK.
List files in channel
Retrieve the list of files uploaded to a channel.
Usage
listFiles accepts a single argument — a Javascript object with the following properties:
1listFiles({ channel, limit, next })
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Retrieve list of files for this channel. |
limitType: Number Default: 100 | Number of files to return. |
nextType: String Default: n/a | String token to get the next batch of files. |
1const pubnub = require('pubnub');
2
3return pubnub.listFiles({
4 channel: 'my_channel',
5 limit: 2,
6 next: '10rX15WW7pyYsbwPY2h3ZlPfP1vSFl_3M6rCappuuCSULLIQb3MWOOba7xouJDxxs8yS9Ql6mxdz-1FmMdeiUE53GPMjNLmrUtefZdhoaswVwat7Z0Q6YzXi4FQYclt7pW_nQlOaC-vzaGSaeSB4QeQS2vlmjyiDVFYPQvSz6g39X7__1H73-XgogHZqqI-jnWMonp2fpgcQ',
7}).then((res) => {
8 console.log(res);
9}).catch((err) => {
10 // handle error
11});
Returns
Returns a promise that resolves to an object with the following format:
1{
2 status: number,
3 data: Array<{
4 name: string,
5 id: string,
6 size: number,
7 created: string
8 }>,
9 next: string,
10 count: number,
11}
For example:
1{
2 status: 200,
3 data: [
4 {
5 name: 'cat_picture.jpg',
6 id: '0936618c-94f9-4e96-bd9c-aa4fd8719c28',
7 size: 31,
8 created: '2020-08-13T19:05:30Z'
9 },
10 {
11 name: 'my_other_file.jpg',
12 id: '2afb0f85-8eb3-43bf-84f9-5b4c7e031f8f',
13 size: 23,
14 created: '2020-08-13T19:07:22Z'
15 },
show all 19 linesGet file URL
Get a file's direct download URL. This method doesn't make any API calls, and won't decrypt an encrypted file.
Usage
getFileUrl accepts a single argument — a Javascript object with the following properties:
1getFileUrl({ channel, id, name })
| Parameter | Description |
|---|---|
channel *Type: String | Channel that the file was sent to. |
id *Type: String | The file's unique identifier. |
name *Type: String | Name of the file. |
1const pubnub = require('pubnub');
2
3const url = pubnub.getFileUrl({
4 channel: 'my_channel',
5 id: '12345678-1234-5678-123456789012',
6 name: 'cat_picture.jpg',
7});
8
9console.log(url);
Returns
Returns a string with the following format:
1'https://ps.pndsn.com/v1/files/my-subkey/channels/my_channel/files/12345678-1234-5678-123456789012/cat_picture.jpg'
Delete file
Deletes a file from the specified channel.
Usage
deleteFile accepts a single argument — a Javascript object with the following properties:
1deleteFile({ channel, id, name })
| Parameter | Description |
|---|---|
channel *Type: String | Channel that the file was sent to. |
id *Type: String | The file's unique identifier. |
name *Type: String | Name of the file. |
1const pubnub = require('pubnub');
2
3return pubnub.deleteFile({
4 channel: 'my_channel',
5 id: '12345678-1234-5678-123456789012',
6 name: 'cat_picture.jpg' ,
7}).then((res) => {
8 console.log(res);
9}).catch((err) => {
10 // handle error
11});
Returns
Returns a promise that resolves to an object with the following format:
1{
2 status: 200,
3}
Publish file message
Manually publish information about a previously uploaded file.
Usage
publishFile accepts a single argument — a Javascript object with the following properties:
1publishFile({ message, channel, fileId, fileName, storeInHistory, ttl, meta })
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Channel on which to send the file message. |
fileId *Type: String Default: n/a | The file's unique identifier. |
fileName *Type: String Default: n/a | Name of the file. |
messageType: Object Default: n/a | Message to attach to the file. The message can be any value that can be JSON-stringified. |
storeInHistoryType: Boolean Default: true | Whether published file messages should be stored in the channel's history. If storeInHistory isn't specified, then the history configuration on the key is used. |
ttlType: Number Default: n/a | How long the message should be stored in the channel's history, in hours. If not specified, defaults to the keyset's retention value. |
metaType: Object Default: n/a | Additional metadata published with the message. |
1const pubnub = require('pubnub');
2
3return pubnub.publishFile({
4 channel: 'my_channel',
5 fileId: '12345678-1234-5678-123456789012',
6 fileName: 'cat_picture.jpg',
7 message: {
8 someField: 'someValue',
9 },
10}).then((res) => {
11 console.log(res);
12}).catch((err) => {
13 // handle error
14});
Returns
Returns a promise that resolves to an object with the following format:
1[ 1, "Sent", "15973568884237770" ]
Presence
Requires Presence
This method requires that the Presence add-on is enabled for your key in the Admin Portal.
For information on how to receive presence events and what those events are, refer to Presence Events.
Here now
To fetch Here Now, use the hereNow() method.
Usage
1hereNow({ channels, channelGroups, includeUUIDs, includeState })
| Parameter | Description |
|---|---|
channelsType: Array | channels is an array which specifies the channels to return occupancy results. |
channelGroupsType: Array | channelGroups is an array which specifies the channelGroup to return occupancy results. |
includeUUIDsType: Boolean | Setting includeUUIDs to false disables the return of UUIDs. |
includeStateType: Boolean | Setting includeState to true enables the return of subscriber state information. |
1pubnub.hereNow({
2 channels: ["ch1"],
3 channelGroups : ["cg1"],
4 includeUUIDs: true,
5 includeState: true
6}).then((response) => {
7 console.log(response)
8}).catch((error) => {
9 // handle error
10});
Where now
To fetch Where Now, use the whereNow() method.
Usage
1whereNow({ uuid })
| Parameter | Description |
|---|---|
uuidType: String | uuid specifies the UUID to return channel list for. |
1pubnub.whereNow({
2 uuid: "uuid"
3}).then((response) => {
4 console.log(response)
5}).catch((error) => {
6 // handle error
7});
Global here now
To fetch Global Here Now, use the hereNow() method.
Usage
1hereNow({ includeUUIDs, includeState })
| Parameter | Description |
|---|---|
includeUUIDsType: Boolean | Setting includeUUIDs to false disables the return of UUIDs. |
includeStateType: Boolean | Setting includeState to true enables the return of subscriber state information. |
1pubnub.hereNow({
2 includeUUIDs: true,
3 includeState: true
4}).then((response) => {
5 console.log(response)
6}).catch((error) => {
7 // handle error
8});
Set state
To fetch Set State, use the setState() method.
Usage
1setState({ channels, channelGroups, state, uuid })
| Parameter | Description |
|---|---|
channelsType: Array | Specifies the channels to get the state. Either channels or channelGroups should be provided. |
channelGroupsType: Array | Specifies the channelGroups to get the state. Either channels or channelGroups should be provided. |
stateType: Object | state is a JSON object of key/value pairs with supported data-types of int, float, and string. Nesting of key/values is not permitted and key names beginning with the pn prefix are reserved. |
uuidType: String | uuid to set the current state. |
1pubnub.setState({
2 channels: ['ch1'],
3 channelGroups: ['cg1'],
4 state: newState,
5 uuid: "uuid"
6}).then((response) => {
7 console.log(response)
8}).catch((error) => {
9 // handle error
10});
Get state
To fetch Set State, use the getState() method.
Usage
1getState({ uuid, channels, channelGroups })
| Parameter | Description |
|---|---|
uuidType: String | uuid is the subscriber UUID to get the current state. |
channelsType: Array | Specifies the channels to get the state. Either channels or channelGroups should be provided. |
channelGroupsType: Array | Specifies the channelGroups to get the state. Either channels or channelGroups should be provided. |
1pubnub.getState({
2 uuid: "uuid",
3 channels: ['ch1'],
4 channelGroups: ['cg1']
5}).then((response) => {
6 console.log(response)
7}).catch((error) => {
8 // handle error
9});
Access Manager
Requires Access Manager
This method requires that Access Manager is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Grant
To grant permissions in Access Manager v2, use the grant() method.
Required secret key
Only server-side instances with a valid secret key can grant permissions to PubNub resources.
Usage
1grant({ channels, channelGroups, uuids, authKeys, ttl, read, write, manage, delete, get, update, join})
| Parameter | Description |
|---|---|
channelsType: Array | Array which specifies the channel(s) to grant permissions to. |
channelGroupsType: Array | Array which specifies the channel group(s) to grant permissions to. |
uuidsType: Array | Array which specifies the UUID(s) to grant permissions to. You can't grant permissions to channels or channel groups in the same request if you decide to use uuids. This parameter does not support wildcards. |
authKeysType: Array | Array which specifies the authorization credentials that should be granted access to selected resources. authKeys are required for user-level grants. If you don't specify this parameter, the permissions will apply to all clients on the channel-level or application-level. |
ttl *Type: Number | Time in minutes for which granted permissions are valid. The default value is 1440 (24hrs) and the allowed values range from 1 to 525600. If you set ttl to 0, it will apply the grant indefinitely. |
readType: Boolean | Set to true to grant read permissions. Set to false to remove permissions. |
writeType: Boolean | Set to true to grant write permissions. Set to false to remove permissions. |
manageType: Boolean | Set to true to grant manage permissions. Set to false to remove permissions. |
deleteType: Boolean | Set to true to grant delete permissions. Set to false to remove permissions. |
getType: Boolean | Set to true to grant get permissions. Set to false to remove permissions. |
updateType: Boolean | Set to true to grant update permissions. Set to false to remove permissions. |
joinType: Boolean | Set to true to grant join permissions. Set to false to remove permissions. |
Max number of resources
There is a limit of up to 200 resources of the same type that you can request access to in a single grant API call.
1pubnub.grant({
2 channels: [ch1, ch2],
3 channelGroups: [cg1, cg2],
4 authKeys: [key1, key2],
5 ttl: 12313,
6 read: true,
7 write: true,
8 manage: true
9}).then((response) => {
10 console.log(response)
11}).catch((error) => {
12 // handle error
13});
Grant token
To grant channel, channel group, and UUID permissions in Access Manager v3, use the grantToken() method.
Required secret key
Only server-side instances with a valid secret key can grant permissions to PubNub resources.
Usage
1grantToken({ ttl, authorizedUuid, resources, patterns, meta })
| Parameter | Description |
|---|---|
ttl *Type: Number | Total number of minutes for which the token is valid.
|
authorizedUuidType: String | Single uuid which is authorized to use the token to make API requests to PubNub. |
resourcesType: Object | Object containing resource permissions. |
resources.uuidsType: Object | Object containing uuid metadata permissions. For example, {"uuid-1": {get: true, update: true, delete: true},"uuid-2": {...}}. |
resources.channelsType: Object | Object containing channel permissions. For example, {"channel-id-1": {read: true, write: true, manage: true, delete: true, get: true, update: true, join: true},"channel-id-2": {...}}. |
resources.groupsType: Object | Object containing channel group permissions. For example, {"group-id-1": {read: true, manage: true},"group-id-2": {...}}. |
patternsType: Object | Object containing permissions to multiple resources specified by a RegEx pattern. |
patterns.uuidsType: Object | Object containing uuid metadata permissions to apply to all uuids matching the RegEx pattern. For example, {"uuid-pattern-1": {get: true, update: true, delete: true},"uuid-pattern-2": {...}}. |
patterns.channelsType: Object | Object containing channel permissions to apply to all channels matching the RegEx pattern. For example, {"channel-pattern-1": {read: true, write: true, manage: true, delete: true, get: true, update: true, join: true}, "channel-pattern-2": {...}}. |
patterns.groupsType: Object | Object containing channel group permissions to apply to all channel groups matching the pattern. For example, {"group-pattern-1": {read: true, manage: true}, "group-pattern-2": {...}}. |
metaType: Object | Extra metadata to be published with the request. Values must be scalar only; arrays or objects aren't supported. |
Required key/value mappings
For a successful grant request, you must specify permissions for at least one uuid, channel, or group, either as a resource sequence (resources) or as a regular expression (patterns).
1pubnub.grantToken(
2 {
3 ttl: 15,
4 authorizedUuid: "my-authorized-uuid",
5 resources: {
6 channels: {
7 "channel-a": {
8 read: true
9 },
10 "channel-b": {
11 read: true,
12 write: true
13 },
14 "channel-c": {
15 read: true,
show all 48 linesRevoke token
The revokeToken() method is used by the server to revoke access to PubNub resources previously granted using the grantToken() method.
This method only applies to Access Manager v3.
Required secret key
Only server-side instances with a valid secret key can revoke permissions to PubNub resources.
Usage
1revokeToken(token)
| Parameter | Description |
|---|---|
token *Type: String | Current token with embedded permissions. |
1pubnub.revokeToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
Parse token
The parseToken() method decodes an existing token and returns the object containing permissions embedded in that token. The client can use this method for debugging to check the permissions to the resources or find out the token's ttl details.
This method only applies to Access Manager v3.
Usage
1parseToken(token)
| Parameter | Description |
|---|---|
token *Type: String | Current token with embedded permissions. |
1pubnub.parseToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
Set token
The setToken() method is used by the client devices to update the authentication token granted by the server.
This method only applies to Access Manager v3.
Usage
1setToken(token)
| Parameter | Description |
|---|---|
token *Type: String | Current token with embedded permissions. |
1pubnub.setToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
Channel groups
Requires Stream Controller
This method requires that Stream Controller is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Add channels
To add channels to a channel group, use channelGroups.addChannels().
Maximum number of channels
200 channels can be added to the channel group per one API call.
Usage
1channelGroups.addChannels({ channels, channelGroup })
| Parameter | Description |
|---|---|
channels *Type: Array | channels is an array that specifies channels to be added to a channel group. |
channelGroup *Type: String | channelGroup is a string that specifies the channel group to which you can add channels. |
1pubnub.channelGroups.addChannels({
2 channels: ['ch1', 'ch2'],
3 channelGroup: 'myChannelGroup'
4}).then((response) => {
5 console.log(response)
6}).catch((error) => {
7 // handle error
8});
List channels
To list all the channels of the channel group, use channelGroups.listChannels().
Usage
1channelGroups.listChannels({ channels })
| Parameter | Description |
|---|---|
channelGroup *Type: String | channelGroup is a string that specifies the channel group from which you want to list the channel(s). |
1pubnub.channelGroups.listChannels({
2 channelGroup: 'myChannelGroup'
3}).then((response) => {
4 console.log(response)
5}).catch((error) => {
6 // handle error
7});
Remove channels
To remove the channels from the channel group, use channelGroups.removeChannels().
Usage
1channelGroups.removeChannels({ channels, channelGroup })
| Parameter | Description |
|---|---|
channels *Type: Array | channels is an array that specifies channels to remove from the channel group. |
channelGroup *Type: String | channelGroup is a string that specifies the channel group from which you want to remove channels. |
1pubnub.channelGroups.removeChannels({
2 channels: ['ch1'],
3 channelGroup: 'myChannelGroup'
4}).then((response) => {
5 console.log(response)
6}).catch((error) => {
7 // handle error
8});
Delete channel group
To remove the channel group, use channelGroups.deleteGroup().
Usage
1channelGroups.deleteGroup({ channelGroup })
| Parameter | Description |
|---|---|
channelGroup *Type: String | channelGroup is a string that specifies the channel group to remove. |
1pubnub.channelGroups.deleteGroup({
2 channelGroup: 'myChannelGroup'
3}).then((response) => {
4 console.log(response)
5}).catch((error) => {
6 // handle error
7});
Message persistence
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
History
To fetch History, use the history() method.
Usage
1history({ channel, reverse, count, stringifiedTimeToken, start, end })
| Parameter | Description |
|---|---|
channel *Type: String | Specifies channel to return history messages from. |
reverseType: Boolean | Setting to true will traverse the timeline in reverse starting with the oldest message first. If both start and end arguments are provided, reverse is ignored and messages are returned starting from the newest message. |
countType: Number | Specifies the number of historical messages to return. |
stringifiedTimeTokenType: Boolean | If stringifiedTimeToken is specified as true, the SDK will return timetoken values as strings instead of integers. This setting is encouraged in JavaScript environments which perform round-up/down on large integers. |
startType: String | Timetoken delimiting the start of time slice (exclusive) to pull messages from. |
endType: String | Timetoken delimiting the end of time slice (inclusive) to pull messages from. |
1export default (request) => {
2 var pubnub = require('pubnub');
3
4 return pubnub.history({
5 'channel' : 'my_channel',
6 'count' : 3,
7 'stringifiedTimeToken' : true,
8 'reverse' : true,
9 }).then((response) => {
10 console.log("startTT", response.startTimeToken);
11 console.log("endTT", response.endTimeToken);
12 response['messages'].forEach((value, index) => {
13 console.log("message:", value.entry, "timetoken:", value.timetoken);
14 });
15 return request.ok();
show all 17 linesBatch history
To fetch History from multiple channels, use the fetchMessages() method.
Usage
1fetchMessages({ channels, count, start, end, stringifiedTimeToken })
| Parameter | Description |
|---|---|
channels *Type: Array | Specifies channels to return history messages from. |
countType: Number | Specifies the number of historical messages to return per channel. |
startType: String | Timetoken delimiting the start of time slice (exclusive) to pull messages from. |
endType: String | Timetoken delimiting the end of time slice (inclusive) to pull messages from. |
stringifiedTimeTokenType: Boolean | If stringifiedTimeToken is specified as true, the SDK will return timetoken values as a strings instead of integers. |
1pubnub.fetchMessages({
2 'channels' : ['my_channel', 'my_other_channel'],
3 'count' : 8,
4 'start' : '15343325214676133',
5 'end' : '15343325004275466',
6 'stringifiedTimeToken' : true,
7}).then((status, response) => {
8 console.log(status);
9 console.log(response);
10});
Delete messages from history
To delete messages from the history, use the deleteMessages() method.
Required setting
There is a setting to accept delete from history requests for a key, which you must enable by checking the Enable Delete-From-History checkbox in the key settings for your key in the Admin Portal.
Requires Initialization with a secret key.
Usage
1deleteMessages({ channel, start, end })
| Parameter | Description |
|---|---|
channel *Type: String | Specifies channel messages to be deleted from history. |
startType: String | Timetoken delimiting the start of time slice (inclusive) to delete messages from. |
endType: String | Timetoken delimiting the end of time slice (exclusive) to delete messages from. |
1pubnub.deleteMessages({
2 'channel' : 'my_channel',
3 'start': '15088506076921021',
4 'end': '15088532035597390',
5}).then((result) => {
6 console.log(result);
7});
Message counts
Specifies the number of historical messages to return per channel. The returned count is the number of messages in history with a timetoken value greater than the passed value in the channelTimetokens parameter.
Usage
1messageCounts({ channels, channelTimetokens })
| Parameter | Description |
|---|---|
channels *Type: Array | The channels to fetch the message count. |
channelTimetokens *Type: Array | List of timetokens in the order of the channels list. Specify a single timetoken to apply it to all channels. Otherwise, the list of timetokens must be the same length as the list of channels, or the Function returns a PNStatus with an error flag. |
1pubnub.messageCounts({
2 'channels' : ['my_channel', 'my_other_channel'],
3 'channelTimetokens' : ['my_timetoken', 'my_other_timetoken'],
4}).then((status, results) => {
5 console.log(status);
6 console.log(results);
7});
Mobile push
Requires Mobile Push Notifications
This method requires that Mobile Push Notifications is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Add device to channel
To enable mobile push notifications on a provided set of channels, use push.addChannels().
Usage
1push.addChannels({ channels, device, pushGateway })
| Parameter | Description |
|---|---|
channels *Type: Array | Specifies channels to associate with mobile push notifications. |
device *Type: String | The device ID to associate with mobile push notifications. |
pushGateway *Type: String | apns, mpns or gcm |
1pubnub.push.addChannels({
2 channels: ['my_channel', 'my_other_channel'],
3 device: 'nice_device',
4 pushGateway: 'apns'
5}).then((response) => {
6 console.log(response)
7}).catch((error) => {
8 // handle error
9});
List channels for device
To request all channels on which push notifications were enabled, use push.listChannels().
Usage
1push.listChannels({ device, pushGateway })
| Parameter | Description |
|---|---|
device *Type: String | The device ID to associate with mobile push notifications. |
pushGateway *Type: String | apns, mpns or gcm |
1pubnub.push.listChannels({
2 device: 'nice_device',
3 pushGateway: 'apns'
4}).then((response) => {
5 console.log(response)
6}).catch((error) => {
7 // handle error
8});
Remove device from channel
To disable mobile push notifications on a provided set of channels, use push.removeChannels().
Usage
1push.removeChannels({ channels, device, pushGateway })
| Parameter | Description |
|---|---|
channels *Type: Array | Specifies channels to associate with mobile push notifications. |
device *Type: String | The device ID to associate with mobile push notifications. |
pushGateway *Type: String | apns, mpns or gcm |
1pubnub.push.removeChannels({
2 channels: ['my_channel', 'my_other_channel'],
3 device: 'nice_device',
4 pushGateway: 'apns'
5}).then((response) => {
6 console.log(response)
7}).catch((error) => {
8 // handle error
9});
Remove all mobile push notifications
To disable mobile push notifications from all channels which are registered with a specified pushToken, use push.deleteDevice().
Usage
1push.deleteDevice({ device, pushGateway })
| Parameter | Description |
|---|---|
device *Type: String | The device ID to associate with mobile push notifications. |
pushGateway *Type: String | apns, mpns or gcm |
1pubnub.push.deleteDevice({
2 device: 'nice_device',
3 pushGateway: 'apns'
4}).then((response) => {
5 console.log(response)
6}).catch((error) => {
7 // handle error
8});
App Context
Get metadata for all users
Returns a paginated list of UUID metadata objects, optionally including the custom data object for each.
Usage
1getAllUUIDMetadata({include, filter, sort, limit, page})
| Parameter | Description |
|---|---|
includeType: Object Default: n/a | Include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getAllUUIDMetadata({
5 limit: 1,
6 include: {
7 customFields: true,
8 },
9 })
10 .then((resp) => {
11 console.log(resp);
12 return event.ok('Fetched uuid metadata successfully.');
13 })
14 .catch((error) => {
15 console.log(err);
show all 18 linesResponse
1{
2 "status" : 200,
3 "data" : [
4 {
5 "name" : "my-name",
6 "updated" : "2020-07-16T21:10:38.770048Z",
7 "id" : "my-uuid",
8 "email" : "me@email.com",
9 "custom" : {
10 "foo" : "bar"
11 },
12 "externalId" : null,
13 "eTag" : "AePWsMnEl9m23wE",
14 "profileUrl" : null
15 }
show all 18 linesOther examples
Get the next page of the results.
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getAllUUIDMetadata({
5 limit: 1,
6 include: {
7 customFields: true,
8 },
9 page: {
10 next: "Mg", // from previous response
11 },
12 })
13 .then((resp) => {
14 console.log(resp);
15 return event.ok('Fetched uuid metadata successfully.');
show all 21 linesResponse
1{
2 "status": 200,
3 "data": [
4 {
5 "created": "2020-03-10T18:45:49.460388Z",
6 "eTag": "Ad+6yqHMr6TYxgE",
7 "email": null,
8 "externalId": null,
9 "id": "my-other-uuid",
10 "name": "my-other-name",
11 "profileUrl": null,
12 "updated": "2020-03-10T18:45:49.460388Z"
13 }
14 ],
15 "next": "MQ",
show all 17 linesGet user metadata
Returns metadata for the specified UUID, optionally including the custom data object for each.
Usage
1getUUIDMetadata({uuid, include})
| Parameter | Description |
|---|---|
uuid *Type: String Default: n/a | Unique UUID identifier. |
includeType: Object Default: n/a | Specifies whether to include the UUID's custom data field. |
customFieldsType: Boolean Default: true | Whether to fetch custom fields. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getUUIDMetadata({
5 uuid: 'my-uuid',
6 include: {
7 customFields: false,
8 },
9 })
10 .then((resp) => {
11 console.log(resp);
12 return event.ok('Fetched UUID metadata successfully.');
13 })
14 .catch((err) => {
15 console.log(err);
show all 18 linesResponse
1{
2 "status" : 200,
3 "data" : {
4 "email" : "me@email.com",
5 "profileUrl" : null,
6 "externalId" : null,
7 "updated" : "2020-07-16T21:10:38.770048Z",
8 "name" : "my-name",
9 "eTag" : "AePWsMnEl9m23wE",
10 "id" : "my-uuid"
11 }
12}
Set user metadata
Set metadata for a UUID in the database, optionally including the custom data object for each.
Usage
1setUUIDMetadata({ uuid, data, include })
| Parameter | Description |
|---|---|
uuid *Type: String Default: n/a | Unique UUID identifier. |
data *Type: Object Default: n/a | Object with UUID metadata to set. |
nameType: String Default: n/a | Display name for the UUID, maximum 200 characters. |
externalIdType: String Default: n/a | UUID's identifier in an external system. |
profileUrlType: String Default: n/a | The URL of the UUID's profile picture. |
emailType: String Default: n/a | The UUID's email address, maximum 80 characters. |
customType: Object Default: n/a | JSON object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported. |
includeType: Object Default: n/a | Include additional fields in the response. |
customFieldsType: Boolean Default: true | Whether to fetch custom fields. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.setUUIDMetadata({
5 uuid: 'my-uuid',
6 data: {
7 name: 'my-name',
8 email: 'me@email.com',
9 custom: {
10 foo: 'bar',
11 },
12 },
13 include: {
14 customFields: false,
15 },
show all 25 linesResponse
1{
2 "status" : 200,
3 "data" : {
4 "email" : "me@email.com",
5 "profileUrl" : null,
6 "externalId" : null,
7 "updated" : "2020-07-16T21:10:38.770048Z",
8 "name" : "my-name",
9 "eTag" : "AePWsMnEl9m23wE",
10 "id" : "my-uuid"
11 }
12}
Remove user metadata
Removes the metadata from a specified UUID.
Usage
1removeUUIDMetadata({ uuid })
| Parameter | Description |
|---|---|
uuid *Type: String | Unique UUID identifier. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.removeUUIDMetadata({
5 uuid: 'my-uuid',
6 })
7 .then((resp) => {
8 console.log(resp);
9 return event.ok('Removed UUID successfully.');
10 })
11 .catch((error) => {
12 console.log(err);
13 return event.abort('Failed to remove UUID metadata');
14 });
15};
Response
1{
2 "status": 200,
3 "data": null
4}
Get metadata for all channels
Returns a paginated list of channel metadata objects, optionally including the custom data object for each.
Usage
1getAllChannelMetadata({include, filter, sort, limit, page})
| Parameter | Description |
|---|---|
includeType: Object Default: n/a | Include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getAllChannelMetadata({
5 limit: 1,
6 include: {
7 totalCount: true,
8 },
9 })
10 .then((resp) => {
11 console.log(resp);
12 return event.ok('Fetched channel metadata successfully.');
13 })
14 .catch((error) => {
15 console.log(err);
show all 18 linesResponse
1{
2 "status" : 200,
3 "data" : [
4 {
5 "name" : "channel-name",
6 "description" : "What a great channel",
7 "updated" : "2020-07-16T21:18:12.156794Z",
8 "eTag" : "AeWFs+b3rMH4Dw",
9 "id" : "my-channel"
10 }
11 ],
12 "totalCount" : 2,
13 "next" : "MQ"
14}
Other examples
Get the next page of the results.
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getAllChannelMetadata({
5 limit: 1,
6 page: {
7 next: "MQ", // from previous response
8 },
9 })
10 .then((resp) => {
11 console.log(resp);
12 return event.ok('Fetched channel metadata successfully.');
13 })
14 .catch((error) => {
15 console.log(err);
show all 18 linesResponse
1{
2 "status" : 200,
3 "data" : [
4 {
5 "updated" : "2020-07-16T21:19:28.735177Z",
6 "eTag" : "AeDH5/ixi/7lZw",
7 "id" : "my-other-channel",
8 "description" : "What another great channel",
9 "name" : "other-channel-name"
10 }
11 ],
12 "prev" : "MQ",
13 "next" : "Mg"
14}
Get channel metadata
Returns metadata for the specified channel, optionally including the custom data object for each.
Usage
1getChannelMetadata({channel, include})
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique channel identifier. |
includeType: Object Default: n/a | Specifies whether to include the channel's custom data field. |
customFieldsType: Boolean Default: true | Whether to fetch custom fields. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getChannelMetadata({
5 channel: 'my-channel',
6 })
7 .then((resp) => {
8 console.log(resp);
9 return event.ok('Fetched channel metadata successfully.');
10 })
11 .catch((error) => {
12 console.log(err);
13 return event.abort('Failed to fetch channel metadata');
14 });
15};
Response
1{
2 "status" : 200,
3 "data" : {
4 "description" : "What a great channel",
5 "eTag" : "AeWFs+b3rMH4Dw",
6 "id" : "my-channel",
7 "updated" : "2020-07-16T21:18:12.156794Z",
8 "custom" : {
9 "foo" : "bar"
10 },
11 "name" : "channel-name"
12 }
13}
Set channel metadata
Set metadata for a channel in the database, optionally including the custom data object for each.
Usage
1setChannelMetadata({ channel, data, include })
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique channel identifier. |
data *Type: Object Default: n/a | Object with channel metadata to set. |
nameType: String Default: n/a | Name of the channel. |
descriptionType: String Default: n/a | Description of the channel. |
customType: Object Default: n/a | JSON object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported. |
includeType: Object Default: n/a | Include additional fields in the response. |
customFieldsType: Boolean Default: true | Whether to fetch custom fields. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.setChannelMetadata({
5 channel: 'my-channel',
6 data: {
7 name: 'channel-name',
8 description: 'What a great channel',
9 custom: {
10 foo: 'bar',
11 },
12 },
13 include: {
14 customFields: false,
15 },
show all 25 linesResponse
1{
2 "status" : 200,
3 "data" : {
4 "eTag" : "AeWFs+b3rMH4Dw",
5 "id" : "my-channel",
6 "name" : "channel-name",
7 "description" : "What a great channel",
8 "updated" : "2020-07-16T21:18:12.156794Z"
9 }
10}
Remove channel metadata
Removes the metadata from a specified channel.
Usage
1removeChannelMetadata({ channel })
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique channel identifier. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.removeChannelMetadata({
5 channel: 'my-channel',
6 })
7 .then((resp) => {
8 console.log(resp);
9 return event.ok('Removed channel successfully');
10 })
11 .catch((error) => {
12 console.log(err);
13 return event.abort('Failed to remove channel metadata');
14 });
15};
Response
1{
2 "data": null,
3 "status": 200
4}
Get channel memberships
The method returns a list of channel memberships for a user. This method doesn't return user's subscriptions.
Usage
1getMemberships({uuid, include, limit, page, filter, sort})
| Parameter | Description |
|---|---|
uuid *Type: String Default: n/a | UUID whose memberships you wish to retrieve. |
includeType: Object Default: n/a | Specifies whether to include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
channelFieldsType: Boolean Default: false | Whether to include fields for channel metadata. |
customChannelFieldsType: Boolean Default: false | Whether to include custom fields for channel metadata. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getMemberships({
5 uuid: "my-uuid",
6 limit: 2,
7 })
8 .then((resp) => {
9 console.log(resp);
10 return event.ok('Fetched uuid memberships successfully.');
11 })
12 .catch((error) => {
13 console.log(err);
14 return event.abort('Failed to fetch memberships');
15 });
show all 16 linesResponse
1{
2 "status" : 200,
3 "data" : [
4 {
5 "updated" : "2020-07-16T21:28:58.702287Z",
6 "channel" : {
7 "id" : "my-channel"
8 },
9 "eTag" : "AY39mJKK//C0VA"
10 },
11 {
12 "eTag" : "AY39mJKK//C0VA",
13 "updated" : "2020-07-16T21:28:21.992673Z",
14 "channel" : {
15 "id" : "my-other-channel"
show all 20 linesSet channel memberships
Set channel memberships for a UUID.
Usage
1setMemberships({uuid, channels, include, limit, page, filter, sort})
| Parameter | Description |
|---|---|
uuid *Type: String Default: n/a | UUID whose memberships you wish to set. |
channels *Type: Array Default: n/a | Array of channels to set membership. Array can contain strings (channel-name only) or objects (which can include custom data). |
includeType: Object Default: n/a | Specifies whether to include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
channelFieldsType: Boolean Default: false | Whether to include fields for channel metadata. |
customChannelFieldsType: Boolean Default: false | Whether to include custom fields for channel metadata. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.setMemberships({
5 uuid: "my-uuid",
6 channels: [
7 "my-channel",
8 { id: "my-other-channel", custom: { hello: "world" } },
9 ],
10 include: {
11 channelFields: true,
12 customChannelFields: true,
13 customFields: true,
14 totalCount: true,
15 },
show all 25 linesResponse
1{
2 "status" : 200,
3 "data" : [
4 {
5 "channel" : {
6 "id" : "my-channel"
7 },
8 "eTag" : "AY39mJKK//C0VA",
9 "custom" : null,
10 "updated" : "2020-07-16T21:28:58.702287Z"
11 },
12 {
13 "updated" : "2020-07-16T21:28:58.693461Z",
14 "custom" : {
15 "hello" : "world"
show all 32 linesRemove channel memberships
Remove channel memberships for a UUID.
Usage
1removeMemberships({uuid, channels, include, limit, page, filter, sort})
| Parameter | Description |
|---|---|
uuid *Type: String Default: n/a | UUID from which to remove memberships. |
channels *Type: Array Default: n/a | Array of channels to remove from uuid memberships. |
includeType: Object Default: n/a | Specifies whether to include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
channelFieldsType: Boolean Default: false | Whether to include fields for channel metadata. |
customChannelFieldsType: Boolean Default: false | Whether to include custom fields for channel metadata. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.removeMemberships({
5 uuid: "my-uuid",
6 channels: [ "my-channel", "my-other-channel" ],
7 })
8 .then((resp) => {
9 console.log(resp);
10 return event.ok('Removed uuid memberships successfully.');
11 })
12 .catch((error) => {
13 console.log(err);
14 return event.abort('Failed to remove memberships');
15 });
show all 16 linesResponse
1{
2 "status": 200,
3 "data": []
4}
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.
Usage
1getChannelMembers({channel, include, limit, page, filter, sort})
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Channel for which to retrieve members. |
includeType: Object Default: n/a | Specifies whether to include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
UUIDFieldsType: Boolean Default: false | Whether to include fields for uuid metadata. |
customUUIDFieldsType: Boolean Default: false | Whether to include custom fields for uuid metadata. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.getChannelMembers({
5 channel: "my-channel",
6 include: {
7 UUIDFields: true,
8 },
9 })
10 .then((resp) => {
11 console.log(resp);
12 return event.ok('Fetched channel members successfully.');
13 })
14 .catch((error) => {
15 console.log(err);
show all 18 linesResponse
1{
2 "status" : 200,
3 "next" : "Mg",
4 "data" : [
5 {
6 "eTag" : "AbGV6rSh8LS/eg",
7 "uuid" : {
8 "id" : "my-other-uuid"
9 },
10 "updated" : "2020-07-16T21:40:48.367305Z"
11 },
12 {
13 "eTag" : "AY39mJKK//C0VA",
14 "uuid" : {
15 "profileUrl" : null,
show all 26 linesSet channel members
This method sets members in a channel.
Usage
1setChannelMembers({channel, uuids, include, limit, page, filter, sort})
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Channel for which to set members. |
uuids *Type: Array Default: n/a | Array of UUIDs to set as members. Array can contain strings (uuid-name only) or objects (which can include custom data). |
includeType: Object Default: n/a | Specifies whether to include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
UUIDFieldsType: Boolean Default: false | Whether to include fields for uuid metadata. |
customUUIDFieldsType: Boolean Default: false | Whether to include custom fields for uuid metadata. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.setChannelMembers({
5 channel: "my-channel",
6 uuids: [
7 "my-uuid",
8 { id: "my-other-uuid", custom: { hello: "world" } },
9 ],
10 })
11 .then((resp) => {
12 console.log(resp);
13 return event.ok('Set channel members successfully.');
14 })
15 .catch((error) => {
show all 19 linesResponse
1{
2 "status" : 200,
3 "data" : [
4 {
5 "updated" : "2020-07-16T21:40:48.367305Z",
6 "eTag" : "AbGV6rSh8LS/eg",
7 "uuid" : {
8 "id" : "my-other-uuid"
9 }
10 },
11 {
12 "uuid" : {
13 "id" : "my-uuid"
14 },
15 "eTag" : "AY39mJKK//C0VA",
show all 20 linesRemove channel members
Remove members from a channel.
Usage
1removeChannelMembers({channel, uuids, include, limit, page, filter, sort})
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Channe` from which to remove members. |
uuids *Type: Array Default: n/a | Array of UUIDs to remove from channel members. |
includeType: Object Default: n/a | Specifies whether to include additional fields in the response. |
customFieldsType: Boolean Default: false | Whether to fetch custom fields. |
UUIDFieldsType: Boolean Default: false | Whether to include fields for uuid metadata. |
customUUIDFieldsType: Boolean Default: false | Whether to include custom fields for uuid metadata. |
totalCountType: Boolean Default: false | Whether to include totalCount in response. |
limitType: Number Default: 100 | Maximum number of results to return per page. |
pageType: Object Default: n/a | Use for pagination. |
nextType: String Default: n/a | 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. |
prevType: String Default: n/a | 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. |
filterType: String Default: n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Object Default: n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Sort directions are asc (ascending), desc (descending). For example, { name: 'asc' }. |
1export default (event) => {
2 const pubnub = require('pubnub');
3
4 return pubnub.objects.removeChannelMembers({
5 channel: "my-channel",
6 uuids: [ "my-uuid", "my-other-uuid" ],
7 })
8 .then((resp) => {
9 console.log(resp);
10 return event.ok('Removed channel members successfully.');
11 })
12 .catch((error) => {
13 console.log(err);
14 return event.abort('Failed to remove members');
15 });
show all 16 linesResponse
1{
2 "status": 200,
3 "data": []
4}
Message Reactions
Add Message Reaction
Add an action on a published message.
Usage
1addMessageAction({channel, messageTimetoken, action:{type, value}, uuid})
| Parameter | Description |
|---|---|
channel *Type: String | Name of a channel which stores the message for which an action should be added. |
messageTimetoken *Type: String | Timetoken of message for which action should be added. |
action *Type: Hash | Message reaction information. |
action.type *Type: String | What feature this message reaction represents. |
action.value *Type: String | Value which should be stored along with a message reaction. |
uuid *Type: String | The UUID associated with the reaction. |
1pubnub.addMessageAction({
2 channel: 'channel1'
3 messageTimetoken: '15610547826970040',
4 action: {
5 type: 'reaction',
6 value: 'smiley_face',
7 },
8 uuid: 'uuid'
9}).then((response) => {
10 console.log(response)
11}).catch((error) => {
12 // handle error
13});
Remove Message Reaction
Remove a peviously added action on a published message.
Usage
1removeMessageAction({channel, messageTimetoken, actionTimetoken, uuid})
| Parameter | Description |
|---|---|
channel *Type: String | Name of a channel which stores the message for which an action should be removed. |
messageTimetoken *Type: String | Timetoken of a message for which an action should be removed. |
actionTimetoken *Type: String | Action addition timetoken. |
uuid *Type: String | UUID associated with the action. |
1pubnub.removeMessageAction({
2 channel: 'channel1'
3 messageTimetoken: '15610547826970040',
4 actionTimetoken: '15610547826970040',
5 uuid: 'uuid'
6}).then((response) => {
7 console.log(response)
8}).catch((error) => {
9 // handle error
10});
Get Message Reactions
Get a list of message reactions in a channel.
Usage
1getMessageActions({channel, start, end, limit})
| Parameter | Description |
|---|---|
channel *Type: String | Name of a channel from which a list of messages actions should be retrieved. |
startType: String | Message reaction timetoken denoting the start of the range requested. Return values will be less than start. |
endType: String | Message reaction timetoken denoting the end of the range requested. Return values will be greater than or equal to end. |
limitType: Number | Number of message reactions to return in response. |
1pubnub.getMessageActions({
2 channel: 'channel1',
3 start: '15610547826970041',
4 end: '15610547826970040',
5 limit: 100,
6}).then((response) => {
7 console.log(response)
8}).catch((error) => {
9 // handle error
10});
Functions support
Functions provides a rich set of tools, and this documentation does not cover all of the potential situations you may encounter. If you need help with a situation not covered by the documentation, please contact PubNub Support