App Context API for Dart SDK

Starting a new app? Use DataSync

DataSync is the successor to App Context. It covers the same users, channels, and memberships, and adds typed schemas, JSON Patch updates with ETags, field-level projections, and per-class expiry. Refer to the feature-by-feature comparison for details.

DataSync is currently available to new accounts and to accounts that are not actively using App Context. If your keysets already use App Context, keep using it for now. App Context remains fully supported.

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

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

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

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

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

1pubnub.objects.getAllUUIDMetadata(
2 {bool? includeCustomFields,
3 int? limit,
4 String? start,
5 String? end,
6 bool? includeCount,
7 bool includeStatus,
8 bool includeType,
9 String? filter,
10 Set<String>? sort,
11 Keyset? keyset,
12 String? using}
13)
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
limit#
Type: int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCount#
Type: bool
Default: true
Whether to include the total count in the paginated response. Default is false.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering guide.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1import 'package:pubnub/pubnub.dart';
2
3void main() async {
4 // Create PubNub instance with default keyset.
5 var pubnub = PubNub(
6 defaultKeyset: Keyset(
7 subscribeKey: 'demo',
8 publishKey: 'demo',
9 userId: UserId('myUniqueUserId'),
10 ),
11 );
12
13 // Get metadata for all users
14 try {
15 var result = await pubnub.objects.getAllUUIDMetadata(
show all 27 lines

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "id": "uuid-1",
6 "name": "John Doe",
7 "externalId": null,
8 "profileUrl": null,
9 "email": "johndoe@pubnub.com",
10 "custom": null,
11 "updated": "2019-02-20T23:11:20.893755",
12 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
13 },
14 {
15 "id": "uuid-2",
show all 27 lines

Get user metadata​

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

Method(s)​

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

1pubnub.objects.getUUIDMetadata(
2 {String? uuid,
3 Keyset? keyset,
4 String? using,
5 bool? includeCustomFields,
6 bool includeStatus,
7 bool includeType
8 }
9)
uuid#
Type: String
Default: defaultKeyset UUID
The UUID to get the metadata for.
If not supplied, the UUID from configuration will be used.
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.

Sample code​

1var result = await pubnub.objects.getUUIDMetadata();

Response​

1{
2 "status": 200,
3 "data": {
4 "id": "uuid-1",
5 "name": "John Doe",
6 "externalId": null,
7 "profileUrl": null,
8 "email": "johndoe@pubnub.com",
9 "updated": "2019-02-20T23:11:20.893755",
10 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
11 }
12}

Set user metadata​

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

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 Dart SDK:

1pubnub.objects.setUUIDMetadata(
2 UuidMetadataInput uuidMetadataInput,
3 {String? uuid,
4 bool? includeCustomFields,
5 bool includeStatus,
6 bool includeType,
7 String? ifMatchesEtag,
8 Keyset? keyset,
9 String? using}
10)
11
12class UuidMetadataInput {
13 String? name;
14 String? email;
15 dynamic custom;
show all 20 lines
required
uuidMetadataInput required#
Type: UuidMetadataInput
Default: no default
UUID metadata details. App Context filtering language doesn’t support filtering by custom properties.
uuid#
Type: String
Default: defaultKeyset UUID
UUID to set the metadata to.
If not supplied, the UUID from configuration will be used.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
ifMatchesEtag#
Type: String?
Default: no default
Use the eTag from an applicable get metadata call to ensure updates only apply if the object hasn’t changed. If the eTags differ, the server returns HTTP 412.
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.
API limits

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

Sample code​

1var uuidMetadataInput = UuidMetadataInput(
2 name: 'foo',
3 email: 'foo@example.domain',
4 profileUrl: 'http://sample.com');
5var result = await pubnub.objects.setUUIDMetadata(uuidMetadataInput);

Response​

1{
2 "status": 200,
3 "data": {
4 "id": "uuid-1",
5 "name": "John Doe",
6 "externalId": null,
7 "profileUrl": null,
8 "email": "johndoe@pubnub.com",
9 "updated": "2019-02-20T23:11:20.893755",
10 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
11 }
12}

Remove user metadata​

Removes the metadata from a specified UUID.

Method(s)​

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

1pubnub.objects.removeUUIDMetadata(
2 {String? uuid,
3 Keyset? keyset,
4 String? using}
5)
uuid#
Type: String
Unique UUID Metadata identifier.
If not supplied, the UUID from configuration will be used.
keyset#
Type: Keyset
Override for the PubNub default keyset configuration.
using#
Type: String
Keyset name from the keysetStore to be used for this method call.

Sample code​

1var result = await pubnub.objects.removeUUIDMetadata();

Response​

The removeUUIDMetadata() returns RemoveUuidMetadataResult which does not have actionable data. In case of an error, an exception with error details is thrown.

Channel​

Get metadata for all channels​

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

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

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

1pubnub.objects.getAllChannelMetadata(
2 {int? limit,
3 String? start,
4 String? end,
5 bool? includeCustomFields,
6 bool? includeCount,
7 bool includeStatus,
8 bool includeType,
9 String? filter,
10 Set<String>? sort,
11 Keyset? keyset,
12 String? using}
13)
limit#
Type: int
Default: 100
The number of objects to retrieve at a time.
start#
Type: String
Default: no default
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.
end#
Type: String
Default: no default
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 start parameter is supplied.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeCount#
Type: bool
Default: true
Whether to include the total count in the paginated response. Default is false.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1var result = await pubnub.objects.getAllChannelMetadata();

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "id": "my-channel",
6 "name": "My channel",
7 "description": "A channel that is mine",
8 "custom": null,
9 "updated": "2019-02-20T23:11:20.893755",
10 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
11 },
12 {
13 "id": "main",
14 "name": "Main channel",
15 "description": "The main channel",
show all 27 lines

Get channel metadata​

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

Method(s)​

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

1pubnub.objects.getChannelMetadata(
2 String channelId,
3 {Keyset? keyset,
4 String? using,
5 bool? includeCustomFields
6 bool includeStatus,
7 bool includeType}
8)
required
channelId required#
Type: String
Default: no default
Channel name.
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.

Sample code​

1var channelMetadata = await pubnub.objects.getChannelMetadata('my_channel');

Response​

1{
2 "status": 200,
3 "data": {
4 "id": "my-channel",
5 "name": "My channel",
6 "description": "A channel that is mine",
7 "updated": "2019-02-20T23:11:20.893755",
8 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
9 }
10}

Set channel metadata​

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

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 Dart SDK:

1pubnub.objects.setChannelMetadata(
2 String channelId,
3 ChannelMetadataInput channelMetadataInput,
4 {bool? includeCustomFields,
5 bool includeStatus,
6 bool includeType,
7 String? ifMatchesEtag,
8 Keyset? keyset,
9 String? using}
10)
11
12class ChannelMetadataInput {
13 String? name;
14 String? description;
15 dynamic custom;
show all 18 lines
required
channelId required#
Type: String
Default: no default
Channel name.
channelMetadataInput required#
Default: no default
Channel metadata details. Filtering by Custom isn’t supported.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom field in the fetch response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
ifMatchesEtag#
Type: String?
Default: no default
Use the eTag from an applicable get metadata call to ensure updates only apply if the object hasn’t changed. If the eTags differ, the server returns HTTP 412.
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.
API limits

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

Sample code​

1var channelMetadataInput = ChannelMetadataInput(
2 name: 'Channel name', description: 'A channel that is mine');
3
4var result = await pubnub.objects
5 .setChannelMetadata('my_channel', channelMetadataInput);

Response​

1{
2 "status": 200,
3 "data": {
4 "id": "my-channel",
5 "name": "My channel",
6 "description": "A channel that is mine",
7 "updated": "2019-02-20T23:11:20.893755",
8 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
9 }
10}

Other examples​

Iteratively update existing metadata​
1import 'dart:async';
2import 'package:pubnub/pubnub.dart';
3Future<void> main() async {
4 var keyset = Keyset(
5 publishKey: 'demo',
6 subscribeKey: 'demo',
7 userId: const UserId('example'));
8 var pubnub = PubNub(defaultKeyset: keyset);
9 var channel = 'main';
10 var name = 'Main Channel';
11 var description = 'This is the main channel.';
12 var custom = {'users': 10};
13
14 // Setting the basic channel info
15 var channelMetadataInput = ChannelMetadataInput(
show all 49 lines

Remove channel metadata​

Removes the metadata from a specified channel.

Method(s)​

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

1pubnub.objects.removeChannelMetadata(
2 String channelId,
3 {Keyset? keyset,
4 String? using}
5)
required
channelID required#
Type: String
Channel name.
keyset#
Type: Keyset
Override for the PubNub default keyset configuration.
using#
Type: String
Keyset name from the keysetStore to be used for this method call.

Sample code​

1var result = await pubnub.objects.removeChannelMetadata('my_channel');

Response​

The removeChannelMetadata() returns RemoveChannelMetadataResult which does not have actionable data. In case of an error, an exception with error details is thrown.

Channel memberships​

Get channel memberships​

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

Method(s)​

To Get Channel Memberships you can use the following method(s) in the Dart SDK:

1pubnub.objects.getMemberships(
2 {String? uuid,
3 int? limit,
4 String? start,
5 String? end,
6 bool? includeCustomFields,
7 bool? includeChannelFields,
8 bool? includeChannelCustomFields,
9 bool? includeChannelStatus,
10 bool? includeChannelType,
11 bool? includeCount = true,
12 String? filter,
13 Set<String>? sort,
14 Keyset? keyset,
15 String? using}
show all 16 lines
uuid#
Type: String
Default: defaultKeyset UUID
Unique UUID Metadata identifier.
If not supplied, then UUID from configuration will be used.
limit#
Type: Int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeChannelFields#
Type: bool
Default: false
Include fields for channels metadata.
includeCustomChannelFields#
Type: bool
Default: false
Include custom fields for channels metadata.
includeChannelStatus#
Type: bool
Default: true
Whether to include the channel status object in the response.
includeChannelType#
Type: bool
Default: true
Whether to include the channel type object in the response.
includeCount#
Type: bool
Default: false
Whether to include the total count in the paginated response. Default is false.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1  var memberships = await pubnub.objects.getMemberships();

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "channel": {
6 "id": "my-channel",
7 "name": "My channel",
8 "description": "A channel that is mine",
9 "custom": null,
10 "updated": "2019-02-20T23:11:20.893755",
11 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
12 },
13 "custom": {
14 "starred": false
15 },
show all 38 lines

Set channel memberships​

Set channel memberships for a UUID.

Method(s)​

To Set Channel Memberships you can use the following method(s) in the Dart SDK:

1pubnub.objects.setMemberships(
2 List<MembershipMetadataInput> setMetadata,
3 {String? uuid,
4 int? limit,
5 String? start,
6 String? end,
7 bool? includeCustomFields,
8 bool? includeChannelFields,
9 bool? includeChannelCustomFields,
10 bool includeChannelStatus,
11 bool includeChannelType,
12 bool includeStatus,
13 bool includeType,
14 bool? includeCount = true,
15 String? filter,
show all 24 lines
required
setMetadata required#
Type: List<MembershipMetadataInput>
Default: no default
The memberships to be set.
uuid#
Type: String
Default: defaultKeyset UUID
Unique UUID Metadata identifier.
If not supplied, then UUID from configuration will be used.
limit#
Type: Int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
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 start parameter is supplied.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom field in the fetch response.
includeChannelFields#
Type: bool
Default: false
Include fields for channels metadata.
includeCustomChannelFields#
Type: bool
Default: false
Include custom fields for channels metadata.
includeChannelStatus#
Type: bool
Default: true
Whether to include the channel status object in the response.
includeChannelType#
Type: bool
Default: true
Whether to include the channel type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Whether to include the total count in the paginated response. Default is false.
filter#
Type: String
Default: null
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined in the filtering reference.
sort#
Type: Set<String>
Default: no default
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction.
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.
API limits

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

Sample code​

1  var setMetadata = [
2 MembershipMetadataInput('my_channel', custom: {'starred': 'false'})
3 ];
4
5 var result = await pubnub.objects
6 .setMemberships(setMetadata, includeChannelFields: true);

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "channel": {
6 "id": "my-channel",
7 "name": "My channel",
8 "description": "A channel that is mine",
9 "custom": null,
10 "updated": "2019-02-20T23:11:20.893755",
11 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
12 },
13 "custom": {
14 "starred": false
15 },
show all 38 lines

Remove channel memberships​

Remove channel memberships for a UUID.

Method(s)​

To Remove Channel Memberships you can use the following method(s) in the Dart SDK:

1pubnub.objects.removeMemberships(
2 Set<String> channelIds,
3 {String? uuid,
4 int? limit,
5 String? start,
6 String? end,
7 bool? includeCustomFields,
8 bool? includeChannelFields,
9 bool? includeChannelCustomFields,
10 bool includeStatus,
11 bool includeType,
12 bool includeChannelStatus,
13 bool includeChannelType,
14 bool? includeCount = true,
15 String? filter,
show all 19 lines
required
channelIds required#
Type: Set<String>
Default: no default
List of channels to remove from membership.
uuid#
Type: String
Default: no default
Unique UUID Metadata identifier.
If not supplied, then UUID from configuration will be used.
limit#
Type: Int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom field in the fetch response.
includeChannelFields#
Type: bool
Default: false
Include fields for channels metadata.
includeCustomChannelFields#
Type: bool
Default: false
Include custom fields for channels metadata.
includeChannelStatus#
Type: bool
Default: true
Whether to include the channel status object in the response.
includeChannelType#
Type: bool
Default: true
Whether to include the channel type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Request IncludeCount to be included in paginated response. By default, includeCount is omitted.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1  var result = await pubnub.objects.removeMemberships({'my_channel', 'main_channel'});
2
3 // for other uuid
4 var result = await pubnub.objects.removeMemberships({'my_channel'}, uuid: 'uuid1');

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "channel": {
6 "id": "my-channel",
7 "name": "My channel",
8 "description": "A channel that is mine",
9 "custom": null,
10 "updated": "2019-02-20T23:11:20.893755",
11 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
12 },
13 "custom": {
14 "starred": false
15 },
show all 38 lines

Manage channel memberships​

Manage a user's channel memberships.

Method(s)​

To Manage Memberships you can use the following method(s) in the Dart SDK:

1pubnub.objects.manageMemberships(
2 List<MembershipMetadataInput> setMetadata,
3 Set<String> removeChannelIds,
4 {String? uuid,
5 int? limit,
6 String? start,
7 String? end,
8 bool? includeCustomFields,
9 bool? includeChannelFields,
10 bool? includeChannelCustomFields,
11 bool includeStatus,
12 bool includeType,
13 bool includeChannelStatus,
14 bool includeChannelType,
15 bool? includeCount,
show all 25 lines
required
setMetadata required#
Type: List<MembershipMetadataInput>
Default: no default
The memberships to be set.
channelIds required#
Type: Set<String>
Default: no default
List of channels to remove from membership.
uuid#
Type: String
Default: no default
Unique UUID Metadata identifier.
If not supplied, then UUID from configuration will be used.
limit#
Type: Int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeChannelFields#
Type: bool
Default: false
Include fields for channels metadata.
includeCustomChannelFields#
Type: bool
Default: false
Include custom fields for channels metadata.
includeChannelStatus#
Type: bool
Default: true
Whether to include the channel status object in the response.
includeChannelType#
Type: bool
Default: true
Whether to include the channel type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Request IncludeCount to be included in paginated response. By default, includeCount is omitted.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1  var setMetadata = [
2 MembershipMetadataInput('my_channel', custom: {'starred': 'false'})
3 ];
4 var result =
5 await pubnub.objects.manageMemberships(setMetadata, {'main_channel'});

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "channel": {
6 "id": "my-channel",
7 "name": "My channel",
8 "description": "A channel that is mine",
9 "custom": null,
10 "updated": "2019-02-20T23:11:20.893755",
11 "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
12 },
13 "custom": {
14 "starred": false
15 },
show all 38 lines

Channel members​

Get channel members​

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

Method(s)​

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

1pubnub.objects.getChannelMembers(
2 String channelId,
3 {int? limit,
4 String? start,
5 String? end,
6 bool? includeCustomFields,
7 bool? includeUUIDFields,
8 bool? includeUUIDCustomFields,
9 bool includeStatus,
10 bool includeType,
11 bool includeUUIDStatus,
12 bool includeUUIDType,
13 bool? includeCount = true,
14 String? filter,
15 Set<String>? sort,
show all 18 lines
channelId#
Type: String
Default: no default
Channel name.
limit#
Type: Int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeUUIDFields#
Type: Boolean
Default: false
Whether to include additional fields.
includeUUIDCustomFields#
Type: Boolean
Default: false
Whether to include additional fields.
includeUUIDStatus#
Type: bool
Default: true
Whether to include the user status object in the response.
includeUUIDType#
Type: bool
Default: true
Whether to include the user type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Whether to include the total count in the paginated response. Default is false.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1  var channelMembers = await pubnub.objects.getChannelMembers('my_channel');

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "uuid": {
6 "id": "uuid-1",
7 "name": "John Doe",
8 "externalId": null,
9 "profileUrl": null,
10 "email": "someone@pubnub.com",
11 "custom": null,
12 "updated": "2019-02-20T23:11:20.893755",
13 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
14 },
15 "custom": {
show all 41 lines

Set channel members​

This method sets members in a channel.

Method(s)​

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

1pubnub.objects.setChannelMembers(
2 String channelId,
3 List<ChannelMemberMetadataInput> setMetadata,
4 {int? limit,
5 String? start,
6 String? end,
7 bool? includeCustomFields,
8 bool? includeUUIDFields,
9 bool? includeUUIDCustomFields,
10 bool includeStatus,
11 bool includeType,
12 bool includeUUIDStatus,
13 bool includeUUIDType,
14 bool? includeCount,
15 String? filter,
show all 26 lines
required
channelId required#
Type: String
Default: no default
Channel name.
setMetadata required#
Default: no default
The metadata to be added.
limit#
Type: Int
Default: 100
Number of objects to return. Default/Max: 100.
start#
Type: String
Default: no default
Cursor-based pagination.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeUUIDFields#
Type: Boolean
Default: false
Whether to include additional fields.
includeUUIDCustomFields#
Type: Boolean
Default: false
Whether to include additional fields.
includeUUIDStatus#
Type: bool
Default: true
Whether to include the user status object in the response.
includeUUIDType#
Type: bool
Default: true
Whether to include the user type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Whether to include the total count in the paginated response. Default is false.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.
API limits

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

Sample code​

1  var setMetadata = [
2 ChannelMemberMetadataInput('myUUID', custom: {'role': 'admin'})
3 ];
4 var result =
5 await pubnub.objects.setChannelMembers('my_channel', setMetadata);

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "uuid": {
6 "id": "uuid-1",
7 "name": "John Doe",
8 "externalId": null,
9 "profileUrl": null,
10 "email": "johndoe@pubnub.com",
11 "custom": null,
12 "updated": "2019-02-20T23:11:20.893755",
13 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
14 },
15 "custom": {
show all 41 lines

Remove channel members​

Remove members from a Channel.

Method(s)​

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

1pubnub.objects.removeChannelMembers(
2 String channelId,
3 Set<String> uuids,
4 {int? limit,
5 String? start,
6 String? end,
7 bool? includeCustomFields,
8 bool? includeUUIDFields,
9 bool? includeUUIDCustomFields,
10 bool includeStatus,
11 bool includeType,
12 bool includeUUIDStatus,
13 bool includeUUIDType,
14 bool? includeCount,
15 String? filter,
show all 19 lines
required
channelId required#
Type: String
Default: no default
Channel name.
uuids required#
Type: Set<String>
Default: no default
UUIDs to remove from the channel.
limit#
Type: Int
Default: 100
The number of objects to retrieve at a time.
start#
Type: String
Default: no default
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.
end#
Type: String
Default: no default
Cursor-based pagination.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom object in the response.
includeUUIDFields#
Type: Boolean
Default: false
Whether to include additional fields.
includeUUIDCustomFields#
Type: Boolean
Default: false
Whether to include additional fields.
includeUUIDStatus#
Type: bool
Default: true
Whether to include the user status object in the response.
includeUUIDType#
Type: bool
Default: true
Whether to include the user type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Whether to include the total count in the paginated response. Default is false.
filter#
Type: String
Default: null
Filter expression. Only matching objects are returned. See filtering.
sort#
Type: Set<String>
Default: no default
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1  var result = await pubnub.objects
2 .removeChannelMembers('my_channel', {'uuid-1', 'uuid-2'});

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "uuid": {
6 "id": "uuid-1",
7 "name": "John Doe",
8 "externalId": null,
9 "profileUrl": null,
10 "email": "johndoe@pubnub.com",
11 "custom": null,
12 "updated": "2019-02-20T23:11:20.893755",
13 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
14 },
15 "custom": {
show all 41 lines

Manage channel members​

Set and Remove channel memberships for a user.

Method(s)​

To Manage Channel Members you can use the following method(s) in the Dart SDK:

1pubnub.objects.manageChannelMembers(
2 String channelId,
3 List<ChannelMemberMetadataInput> setMetadata,
4 Set<String> removeMemberUuids,
5 {int? limit,
6 String? start,
7 String? end,
8 bool? includeCustomFields,
9 bool? includeUUIDFields,
10 bool? includeUUIDCustomFields,
11 bool includeStatus,
12 bool includeType,
13 bool includeUUIDStatus,
14 bool includeUUIDType,
15 bool? includeCount = true,
show all 27 lines
required
channelId required#
Type: String
Default: no default
Channel name.
setMetadata required#
Default: no default
The metadata to set.
removeMemberUuids required#
Type: Set<String>
Default: no default
UUIDs to remove from the channel.
limit#
Type: Int
Default: 100
The number of objects to retrieve at a time.
start#
Type: String
Default: no default
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.
end#
Type: String
Default: no default
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 start parameter is supplied.
includeCustomFields#
Type: bool
Default: false
Whether to include the Custom field in the fetch response.
includeUUIDFields#
Type: Boolean
Default: false
Include fields for UUIDs metadata.
includeUUIDCustomFields#
Type: Boolean
Default: false
Include custom fields for UUIDs metadata.
includeUUIDStatus#
Type: bool
Default: true
Whether to include the user status object in the response.
includeUUIDType#
Type: bool
Default: true
Whether to include the user type object in the response.
includeStatus#
Type: bool
Default: true
Whether to include the status object in the response.
includeType#
Type: bool
Default: true
Whether to include the type object in the response.
includeCount#
Type: bool
Default: false
Request IncludeCount to be included in paginated response. By default, includeCount is omitted.
filter#
Type: String
Default: null
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined in the filtering reference.
sort#
Type: Set<String>
Default: no default
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction.
keyset#
Type: Keyset
Default: no default
Override for the PubNub default keyset configuration.
using#
Type: String
Default: no default
Keyset name from the keysetStore to be used for this method call.

Sample code​

1  var setMetadata = [
2 ChannelMemberMetadataInput('uuidToSet', custom: {'role': 'admin'})
3 ];
4 var result = await pubnub.objects
5 .manageChannelMembers('my_channel', setMetadata, {'uuidToRemove'});

Response​

1{
2 "status": 200,
3 "data": [
4 {
5 "uuid": {
6 "id": "uuid-1",
7 "name": "John Doe",
8 "externalId": null,
9 "profileUrl": null,
10 "email": "johndoe@pubnub.com",
11 "custom": null,
12 "updated": "2019-02-20T23:11:20.893755",
13 "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
14 },
15 "custom": {
show all 41 lines

Was this page useful?

Last updated on