App Context API for Dart SDK
This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.
App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to 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.
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)
| Parameter | Description |
|---|---|
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
limitType: intDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCountType: boolDefault: true | Whether to include the total count in the paginated response. Default is false. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering guide. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | Keyset name from the keysetStore to be used for this method call. |
Sample code
Reference 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 linesResponse
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 linesGet user metadata
Returns metadata for the specified UUID, optionally including the custom data object for each.
Method(s)
To Get UUID Metadata you can use the following method(s) in the 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)
| Parameter | Description |
|---|---|
uuidType: StringDefault: defaultKeyset UUID | The UUID to get the metadata for. If not supplied, the UUID from configuration will be used. |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | Keyset name from the keysetStore to be used for this method call. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: 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:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- 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| Parameter | Description |
|---|---|
uuidMetadataInput *Type: UuidMetadataInputDefault: n/a | UUID metadata details. App Context filtering language doesn’t support filtering by custom properties. |
uuidType: StringDefault: defaultKeyset UUID | UUID to set the metadata to. If not supplied, the UUID from configuration will be used. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
ifMatchesEtagType: String? Default: n/a | 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. |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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)
| Parameter | Description |
|---|---|
uuidType: String | Unique UUID Metadata identifier. If not supplied, the UUID from configuration will be used. |
keysetType: Keyset | Override for the PubNub default keyset configuration. |
usingType: 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.
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)
| Parameter | Description |
|---|---|
limitType: intDefault: 100 | The number of objects to retrieve at a time. |
startType: StringDefault: 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. |
endType: StringDefault: 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 start parameter is supplied. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeCountType: boolDefault: true | Whether to include the total count in the paginated response. Default is false. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesGet channel metadata
Returns metadata for the specified Channel, optionally including the custom data object for each.
Method(s)
To Get Channel Metadata you can use the following method(s) in the Dart SDK:
1pubnub.objects.getChannelMetadata(
2 String channelId,
3 {Keyset? keyset,
4 String? using,
5 bool? includeCustomFields
6 bool includeStatus,
7 bool includeType}
8)
| Parameter | Description |
|---|---|
channelId *Type: StringDefault: n/a | Channel name. |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | Keyset name from the keysetStore to be used for this method call. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: 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:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- 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| Parameter | Description |
|---|---|
channelId *Type: StringDefault: n/a | Channel name. |
channelMetadataInput *Type: ChannelMetadataInputDefault: n/a | Channel metadata details. Filtering by Custom isn’t supported. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom field in the fetch response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
ifMatchesEtagType: String? Default: n/a | 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. |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesRemove 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)
| Parameter | Description |
|---|---|
channelID *Type: String | Channel name. |
keysetType: Keyset | Override for the PubNub default keyset configuration. |
usingType: 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| Parameter | Description |
|---|---|
uuidType: StringDefault: defaultKeyset UUID | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeChannelFieldsType: boolDefault: false | Include fields for channels metadata. |
includeCustomChannelFieldsType: boolDefault: false | Include custom fields for channels metadata. |
includeChannelStatusType: boolDefault: true | Whether to include the channel status object in the response. |
includeChannelTypeType: boolDefault: true | Whether to include the channel type object in the response. |
includeCountType: boolDefault: false | Whether to include the total count in the paginated response. Default is false. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesSet 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| Parameter | Description |
|---|---|
setMetadata *Type: List<MembershipMetadataInput>Default: n/a | The memberships to be set. |
uuidType: StringDefault: defaultKeyset UUID | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: 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 start parameter is supplied. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom field in the fetch response. |
includeChannelFieldsType: boolDefault: false | Include fields for channels metadata. |
includeCustomChannelFieldsType: boolDefault: false | Include custom fields for channels metadata. |
includeChannelStatusType: boolDefault: true | Whether to include the channel status object in the response. |
includeChannelTypeType: boolDefault: true | Whether to include the channel type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Whether to include the total count in the paginated response. Default is false. |
filterType: StringDefault: null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Set<String>Default: n/a | List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesRemove 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| Parameter | Description |
|---|---|
channelIds *Type: Set<String>Default: n/a | List of channels to remove from membership. |
uuidType: StringDefault: n/a | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom field in the fetch response. |
includeChannelFieldsType: boolDefault: false | Include fields for channels metadata. |
includeCustomChannelFieldsType: boolDefault: false | Include custom fields for channels metadata. |
includeChannelStatusType: boolDefault: true | Whether to include the channel status object in the response. |
includeChannelTypeType: boolDefault: true | Whether to include the channel type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Request IncludeCount to be included in paginated response. By default, includeCount is omitted. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesManage 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| Parameter | Description |
|---|---|
setMetadata *Type: List<MembershipMetadataInput>Default: n/a | The memberships to be set. |
channelIds *Type: Set<String>Default: n/a | List of channels to remove from membership. |
uuidType: StringDefault: n/a | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeChannelFieldsType: boolDefault: false | Include fields for channels metadata. |
includeCustomChannelFieldsType: boolDefault: false | Include custom fields for channels metadata. |
includeChannelStatusType: boolDefault: true | Whether to include the channel status object in the response. |
includeChannelTypeType: boolDefault: true | Whether to include the channel type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Request IncludeCount to be included in paginated response. By default, includeCount is omitted. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesChannel members
Get channel members
The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.
Method(s)
To Get Channel Members you can use the following method(s) in the 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| Parameter | Description |
|---|---|
channelIdType: StringDefault: n/a | Channel name. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeUUIDFieldsType: Boolean Default: false | Whether to include additional fields. |
includeUUIDCustomFieldsType: Boolean Default: false | Whether to include additional fields. |
includeUUIDStatusType: boolDefault: true | Whether to include the user status object in the response. |
includeUUIDTypeType: boolDefault: true | Whether to include the user type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Whether to include the total count in the paginated response. Default is false. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesSet channel members
This method sets members in a channel.
Method(s)
To Set Channel Members you can use the following method(s) in the 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| Parameter | Description |
|---|---|
channelId *Type: StringDefault: n/a | Channel name. |
setMetadata *Default: n/a | The metadata to be added. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
startType: StringDefault: n/a | Cursor-based pagination. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeUUIDFieldsType: Boolean Default: false | Whether to include additional fields. |
includeUUIDCustomFieldsType: Boolean Default: false | Whether to include additional fields. |
includeUUIDStatusType: boolDefault: true | Whether to include the user status object in the response. |
includeUUIDTypeType: boolDefault: true | Whether to include the user type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Whether to include the total count in the paginated response. Default is false. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesRemove 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| Parameter | Description |
|---|---|
channelId *Type: StringDefault: n/a | Channel name. |
uuids *Type: Set<String>Default: n/a | UUIDs to remove from the channel. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
startType: StringDefault: 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. |
endType: StringDefault: n/a | Cursor-based pagination. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom object in the response. |
includeUUIDFieldsType: Boolean Default: false | Whether to include additional fields. |
includeUUIDCustomFieldsType: Boolean Default: false | Whether to include additional fields. |
includeUUIDStatusType: boolDefault: true | Whether to include the user status object in the response. |
includeUUIDTypeType: boolDefault: true | Whether to include the user type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Whether to include the total count in the paginated response. Default is false. |
filterType: StringDefault: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Set<String>Default: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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 linesManage 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| Parameter | Description |
|---|---|
channelId *Type: StringDefault: n/a | Channel name. |
setMetadata *Default: n/a | The metadata to set. |
removeMemberUuids *Type: Set<String>Default: n/a | UUIDs to remove from the channel. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
startType: StringDefault: 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. |
endType: StringDefault: 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 start parameter is supplied. |
includeCustomFieldsType: boolDefault: false | Whether to include the Custom field in the fetch response. |
includeUUIDFieldsType: Boolean Default: false | Include fields for UUIDs metadata. |
includeUUIDCustomFieldsType: Boolean Default: false | Include custom fields for UUIDs metadata. |
includeUUIDStatusType: boolDefault: true | Whether to include the user status object in the response. |
includeUUIDTypeType: boolDefault: true | Whether to include the user type object in the response. |
includeStatusType: boolDefault: true | Whether to include the status object in the response. |
includeTypeType: boolDefault: true | Whether to include the type object in the response. |
includeCountType: boolDefault: false | Request IncludeCount to be included in paginated response. By default, includeCount is omitted. |
filterType: StringDefault: null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Set<String>Default: n/a | List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. |
keysetType: KeysetDefault: n/a | Override for the PubNub default keyset configuration. |
usingType: StringDefault: n/a | 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