PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›API Reference

nodeJS

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Access Manager
    • Channel Groups
    • Message Persistence
    • Mobile Push
    • Objects
    • Files
    • Message Actions
    • Miscellaneous
  • Status Events
  • Troubleshooting
  • Change Log
  • Feature Support
  • Platform Support

Metadata API for PubNub Node.js SDK

This page describes the new Objects v2. To upgrade from Objects v1, refer to the migration guide.

Objects provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use Objects 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.

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 Node.js V4 SDK:

  1. pubnub.objects.getAllUUIDMetadata( {Object include, String filter, Object sort, Number limit, Object page}, Function callback )
    
    ParameterTypeRequiredDefaultsDescription
    includeObjectOptionalInclude respective additional fields in the response.
    totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
    customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
    filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
    sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {name: 'asc'}
    limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
    pageObjectOptionalUse for pagination.
    nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
    prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.getAllUUIDMetadata();

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",
            "name": "Bob Cat",
            "externalId": null,
            "profileUrl": null,
            "email": "bobc@example.com",
            "custom": {
                "phone": "999-999-9999"
            },
            "updated": "2019-02-21T03:29:00.173452",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        }
    ]
}

Get 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 Node.js V4 SDK:

  1. pubnub.objects.getUUIDMetadata( {String uuid, Object include}, Function callback )
    
    ParameterTypeRequiredDefaultsDescription
    uuidStringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
    includeObjectOptionalInclude respective additional fields in the response.
    customFieldsBooleanOptionaltrueWhether to fetch custom fields or not.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

// using UUID from the config
pubnub.objects.getUUIDMetadata();

// using passed in UUID
pubnub.objects.getUUIDMetadata({
    uuid: 'myUuid',
});

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 Node.js V4 SDK:

pubnub.objects.setUUIDMetadata( {String uuid, Object data, Object include}, Function callback )
ParameterTypeRequiredDefaultsDescription
uuidStringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
dataObjectYesJSON object with uuid metadata to set.
nameStringOptionalDisplay name for the user. Maximum 200 characters.
externalIdStringOptionalUser's identifier in an external system
profileUrlStringOptionalThe URL of the user's profile picture
emailStringOptionalThe user's email address. Maximum 80 characters.
customObjectOptionalJSON object of key-value pairs with supported data types. Objects filtering language doesn’t support filtering by custom properties.
includeObjectOptionalInclude respective additional fields in the response.
customFieldsBooleanOptionaltrueWhether to fetch custom fields or not.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

// using UUID from the config
pubnub.objects.setUUIDMetadata({
    data: {
        name: 'John Doe'
    }
});

// using passed in UUID
pubnub.objects.setUUIDMetadata({
    uuid: 'myUuid',
    data: {}
});

Response

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

Remove User Metadata

Description

Removes the metadata from a specified UUID.

Method(s)

To Remove UUID Metadata you can use the following method(s) in the Node.js V4 SDK:

  1. pubnub.objects.removeUUIDMetadata( {String uuid}, Function callback )
    
    ParameterTypeRequiredDefaultsDescription
    uuidStringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

// using UUID from the config
pubnub.objects.removeUUIDMetadata();

// using passed in UUID
pubnub.objects.removeUUIDMetadata({
    uuid: 'myUuid'
});

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 Node.js V4 SDK:

pubnub.objects.getAllChannelMetadata( {Object include, String filter, Object sort, Number limit, Object page}, Function callback )
ParameterTypeRequiredDefaultsDescription
includeObjectOptionalInclude respective additional fields in the response.
totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {name: 'asc'}
limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageObjectOptionalUse for pagination.
nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.getAllChannelMetadata({
    include: {
        totalCount: true
    }
});

Response

{
    "status": 200,
    "data": [
        {
            "id": "my-channel",
            "name": "My channel",
            "description": "A channel that is mine",
            "custom": null,
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
        },
        {
            "id": "main",
            "name": "Main channel",
            "description": "The main channel",
            "custom": {
                "public": true,
                "motd": "Always check your spelling!"
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
        }
    ],
    "totalCount": 9,
    "next": "MUIwQTAwMUItQkRBRC00NDkyLTgyMEMtODg2OUU1N0REMTNBCg==",
    "prev": "M0FFODRENzMtNjY2Qy00RUExLTk4QzktNkY1Q0I2MUJFNDRCCg=="
}

Get 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 Node.js V4 SDK:

pubnub.objects.getChannelMetadata({String channel, Object include},Function callback)
ParameterTypeRequiredDefaultsDescription
channelStringYesChannel name.
includeObjectOptionalInclude respective additional fields in the response.
customFieldsBooleanOptionaltrueWhether to fetch custom fields or not.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.getChannelMetadata({
    channel: 'myChannel',
});

Response

{
    "status": 200,
    "data": {
        "id": "my-channel",
        "name": "My channel",
        "description": "A channel that is mine",
        "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 Node.js V4 SDK:

pubnub.objects.setChannelMetadata({String channel, Object data, Object include},Function callback)
ParameterTypeRequiredDefaultsDescription
channelStringYesChannel name.
dataObjectYesJSON object with channel metadata to set.
nameStringOptionalName of a channel.
descriptionStringOptionalDescription of a channel.
customObjectOptionalJSON object of key-value pairs with supported data types. Objects filtering language doesn’t support filtering by custom properties.
includeObjectOptionalInclude respective additional fields in the response.
customFieldsBooleanOptionaltrueWhether to fetch custom fields or not.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.setChannelMetadata({
    channel: 'myChannel',
    data: {
        name: 'Channel Name'
    }
});

Response

{
    "status": 200,
    "data": {
        "id": "my-channel",
        "name": "My channel",
        "description": "A channel that is mine",
        "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 Node.js V4 SDK:

  1. pubnub.objects.removeChannelMetadata({String channel},Function callback)
    
    ParameterTypeRequiredDefaultsDescription
    channelStringYesChannel name.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.removeChannelMetadata({
    channel: 'myChannel'
});

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 Node.js V4 SDK:

pubnub.objects.getMemberships({String uuid, Object include, String filter, Object sort, Number limit, Object page},Function callback)
ParameterTypeRequiredDefaultsDescription
uuidStringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
includeObjectOptionalInclude respective additional fields in the response.
totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
channelFieldsBooleanOptionalfalseInclude fields for channels metadata.
customChannelFieldsBooleanOptionalfalseInclude custom fields for channels metadata.
filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, channel.id, channel.name, and channel.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {channel.name: 'asc'}
limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageObjectOptionalUse for pagination.
nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

// using UUID from the config
pubnub.objects.getMemberships();

// using passed in UUID
pubnub.objects.getMemberships({
    uuid: 'myUuid',
    include: {
        channelFields: true
    }
});

Response

{
    "status": 200,
    "data": [
        {
            "channel": {
                "id": "my-channel",
                "name": "My channel",
                "description": "A channel that is mine",
                "custom": null,
                "updated": "2019-02-20T23:11:20.893755",
                "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "custom": {
                "starred": false
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        },
        {
            "channel": {
                "id": "main",
                "name": "Main channel",
                "description": "The main channel",
                "custom": {
                    "public": true,
                    "motd": "Always check your spelling!"
                },
                "updated": "2019-02-20T23:11:20.893755",
                "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        }
    ],
    "totalCount": 7,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}

Set Channel Memberships

Description

Set channel memberships for a UUID.

Method(s)

To Set Memberships you can use the following method(s) in the Node.js V4 SDK:

pubnub.objects.setMemberships({String uuid, Array channels, Object include, String filter, Object sort, Number limit, Object page},Function callback)
ParameterTypeRequiredDefaultsDescription
uuidStringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
channelsArrayYesArray of channels to add to membership. Array can contain strings (channel-name only) or objects (which can include custom data).
includeObjectOptionalInclude respective additional fields in the response.
totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
channelFieldsBooleanOptionalfalseInclude fields for channels metadata.
customChannelFieldsBooleanOptionalfalseInclude custom fields for channels metadata.
filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, channel.id, channel.name, and channel.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {channel.name: 'asc'}
limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageObjectOptionalUse for pagination.
nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

// using UUID from the config
pubnub.objects.setMemberships({
    channels: ['ch-1', 'ch-2']
});

// using passed in UUID
pubnub.objects.setMemberships({
 uuid: 'my-uuid',
 channels: [
   "my-channel-1",
   { id: "my-channel-2" },
   { id: "my-channel-3", custom: { hello: "world" } },
   include: {
        // To include channel fields in response
        channelFields: true
    }
 ]
});

Response

{
    "status": 200,
    "data": [
        {
            "channel": {
              "id": "my-channel",
              "name": "My channel",
              "description": "A channel that is mine",
              "custom": null,
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "custom": {
                "starred": false
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        },
        {
          "channel": {
              "id": "main",
              "name": "Main channel",
              "description": "The main channel",
              "custom": {
                  "public": true,
                  "motd": "Always check your spelling!"
              },
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
          },
          "updated": "2019-02-20T23:11:20.893755",
          "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        }
    ],
    "totalCount": 7,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}

Remove Channel Memberships

Description

Remove channel memberships for a UUID.

Method(s)

To Remove Memberships you can use the following method(s) in the Node.js V4 SDK:

  1. pubnub.objects.removeMemberships({String uuid, String[] channels, Object include, String filter, Object sort, Number limit, Object page},Function callback)
    
    ParameterTypeRequiredDefaultsDescription
    uuidStringOptionalcurrent uuidUnique user identifier. If not supplied then current user's uuid is used.
    channelsString[]YesChannels to remove from membership.
    includeObjectOptionalInclude respective additional fields in the response.
    totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
    customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
    channelFieldsBooleanOptionalfalseInclude fields for channels metadata.
    customChannelFieldsBooleanOptionalfalseInclude custom fields for channels metadata.
    filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
    sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, channel.id, channel.name, and channel.updated. Use asc or desc to specify sort direction., or specify null to take the default sort direction (ascending). For example: {channel.name: 'asc'}
    limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
    pageObjectOptionalUse for pagination.
    nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
    prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

// using UUID from the config
pubnub.objects.removeMemberships({
    channels: ['ch-1', 'ch-2'],
});

// using passed in UUID
pubnub.objects.removeMemberships({
    uuid: 'myUuid',
    channels: ['ch-1', 'ch-2'],
});

Response

{
    "status": 200,
    "data": [
        {
            "channel": {
              "id": "my-channel",
              "name": "My channel",
              "description": "A channel that is mine",
              "custom": null,
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "custom": {
                "starred": false
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        },
        {
            "channel": {
              "id": "main",
              "name": "Main channel",
              "description": "The main channel",
              "custom": {
                  "public": true,
                  "motd": "Always check your spelling!"
              },
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        }
    ],
    "totalCount": 7,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}

Channel 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 Node.js V4 SDK:

  1. pubnub.objects.getChannelMembers({String channel, Object include, String filter, Object sort, Number limit, Object page},Function callback)
    
    ParameterTypeRequiredDefaultsDescription
    channelStringYesChannel name.
    includeObjectOptionalInclude respective additional fields in the response.
    totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
    customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
    UUIDFieldsBooleanOptionalfalseInclude fields for UUIDs metadata.
    customUUIDFieldsBooleanOptionalfalseInclude custom fields for UUIDs metadata.
    filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
    sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {uuid.name: 'asc'}
    limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
    pageObjectOptionalUse for pagination.
    nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
    prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.getChannelMembers({
    channel: 'myChannel',
    include: {
        UUIDFields: true
    }
});

Response

{
  "status": 200,
  "data": [
    {
      "uuid": {
        "id": "uuid-1",
        "name": "John Doe",
        "externalId": null,
        "profileUrl": null,
        "email": "jack@twitter.com",
        "custom": null,
        "updated": "2019-02-20T23:11:20.893755",
        "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
      },
      "custom": {
        "role": "admin"
      },
      "updated": "2019-02-20T23:11:20.893755",
      "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
    },
    {
      "uuid": {
        "id": "uuid-2",
        "name": "Bob Cat",
        "externalId": null,
        "profileUrl": null,
        "email": "bobc@example.com",
        "custom": {
          "phone": "999-999-9999"
        },
        "updated": "2019-02-21T03:29:00.173452",
        "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
      },
      "updated": "2019-02-20T23:11:20.893755",
      "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
    }
  ],
  "totalCount": 37,
  "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
  "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}

Set 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 Node.js V4 SDK:

pubnub.objects.setChannelMembers({String channel, Array uuids, Object include, String filter, Object sort, Number limit, Object page},Function callback)
ParameterTypeRequiredDefaultsDescription
channelStringYesChannel name.
uuidsArrayYesArray of members to add to the channel. Array can contain strings (uuid only) or objects (which can include custom data).
includeObjectOptionalInclude respective additional fields in the response.
totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
UUIDFieldsBooleanOptionalfalseInclude fields for UUIDs metadata.
customUUIDFieldsBooleanOptionalfalseInclude custom fields for UUIDs metadata.
filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {uuid.name: 'asc'}
limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
pageObjectOptionalUse for pagination.
nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.setChannelMembers({
    channel: 'myChannel',
    uuids: ['uuid-1', 'uuid-2'],
});

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": {
                "role": "admin"
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        },
        {
            "uuid": {
                "id": "uuid-2",
                "name": "Bob Cat",
                "externalId": null,
                "profileUrl": null,
                "email": "bobc@example.com",
                "custom": {
                    "phone": "999-999-9999"
                },
                "updated": "2019-02-21T03:29:00.173452",
                "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        }
    ],
    "totalCount": 37,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}

Remove Channel Members

Description

Remove members from a Channel.

Method(s)

To Remove Channel Members you can use the following method(s) in the Node.js V4 SDK:

  1. pubnub.objects.removeChannelMembers({String channel, String[] uuids, Object include, String filter, Object sort, Number limit, Object page},Function callback)
    
    ParameterTypeRequiredDefaultsDescription
    channelStringYesChannel name.
    uuidsString[]YesMembers to remove from channel.
    includeObjectOptionalInclude respective additional fields in the response.
    totalCountBooleanOptionalfalseRequest totalCount to be included in paginated response. By default, totalCount is omitted.
    customFieldsBooleanOptionalfalseWhether to fetch custom fields or not.
    UUIDFieldsBooleanOptionalfalseInclude fields for UUIDs metadata.
    customUUIDFieldsBooleanOptionalfalseInclude custom fields for UUIDs metadata.
    filterStringOptionalExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here
    sortObjectOptionalKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {uuid.name: 'asc'}
    limitNumberOptional100Number of objects to return in response. Default is 100, which is also the maximum value.
    pageObjectOptionalUse for pagination.
    nextStringOptionalPreviously-returned cursor bookmark for fetching the next page.
    prevStringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    callback(result) => voidOptionalCallback to the function. If not passed, the function will return a Promise instead.

Basic Usage

pubnub.objects.removeChannelMembers({
    channel: 'myChannel',
    uuids: ['uuid-1', 'uuid-2'],
});

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": {
                "role": "admin"
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        },
        {
            "uuid": {
                "id": "uuid-2",
                "name": "Bob Cat",
                "externalId": null,
                "profileUrl": null,
                "email": "bobc@example.com",
                "custom": {
                    "phone": "999-999-9999"
                },
                "updated": "2019-02-21T03:29:00.173452",
                "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        }
    ],
    "totalCount": 37,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}

Objects Filtering Language Definition

The filtering language for Objects 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, in order 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>
                            | "'" ( "\" "'" | "\" <special_char>
                            | "\" "u" <hex_digit> <hex_digit> <hex_digit> <hex_digit>
                            | <unicode_char> - "'" - "\" )* "'"
<number>               ::= ( "+" | "-" )? ( <digit> )* ( "." )? <digit> ( <digit> )*
                            ( "e" | "E" ( "+" | "-" )? <digit> ( <digit> )* )?
<letter>               ::= Unicode Letter (category; any kind of letter from any language)
<digit>                ::= "0" .. "9"
<hex_digit>            ::= <digit> | "A" .. "F"
<double_quote>         ::= the " character
<unicode_char>         ::= any character in the Unicode range from U+0020 to U+10FFFF inclusive
<special_char>         ::= "\" | "/" | "b" | "f" | "n" | "r" | "t"

Sample object filtering operations

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

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

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

name LIKE 'X*'

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

name LIKE '*\\**'
← Mobile PushFiles →
  • User
    • Get Metadata for All Users
    • Get User Metadata
    • Set User Metadata
    • Remove User Metadata
  • Channel
    • Get Metadata for All Channels
    • Get Channel Metadata
    • Set Channel Metadata
    • Remove Channel Metadata
  • Channel Memberships
    • Get Channel Memberships
    • Set Channel Memberships
    • Remove Channel Memberships
  • Channel Members
    • Get Channel Members
    • Set Channel Members
    • Remove Channel Members
  • Objects Filtering Language Definition
    • Sample object filtering operations
© PubNub Inc. - Privacy Policy