App Context API for Kotlin SDK
Breaking changes in v9.0.0
PubNub Kotlin SDK version 9.0.0 unifies the codebases for Kotlin and Java SDKs, introduces a new way of instantiating the PubNub client, and changes asynchronous API callbacks and emitted status events. These changes can impact applications built with previous versions (< 9.0.0 ) of the Kotlin SDK.
For more details about what has changed, refer to Java/Kotlin SDK migration guide.
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 running your own databases.
PubNub also triggers events when object data changes: set, update, or removal. Setting the same data again doesn't trigger an event. Clients can receive these events in real time and update their front-end application accordingly.
Request execution
Most PubNub Kotlin SDK method invocations return an Endpoint object, which allows you to decide whether to perform the operation synchronously or asynchronously.
You must invoke the .sync() or .async() method on the Endpoint to execute the request, or the operation will not be performed.
1val channel = pubnub.channel("channelName")
2
3channel.publish("This SDK rules!").async { result ->
4 result.onFailure { exception ->
5 // Handle error
6 }.onSuccess { value ->
7 // Handle successful method result
8 }
9}
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 Kotlin SDK:
1pubnub.getAllUUIDMetadata(
2 filter: String? = null,
3 sort: Collection<PNSortKey<PNKey>> = listOf(),
4 page: PNPage? = null,
5 limit: Int? = null,
6 includeCustom: Boolean = false,
7 includeCount: Boolean = false
8).async { result -> }
| Parameter | Description |
|---|---|
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNKey>>Default: listOf() | Sort by ID, NAME, UPDATED, TYPE, STATUS with asc/desc for sort direction (for example, PNSortKey.asc(PNKey.STATUS)). |
pageType: PNPage?Default: null | Cursor-based pagination. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
includeCustomType: BooleanDefault: false | Whether to include the Custom object in the response. |
includeCountType: BooleanDefault: false | Whether to include the total count in the paginated response. Default is false. |
Sample code
Reference code
1
Response
1data class PNUUIDMetadataArrayResult(
2 val status: Int,
3 val data: Collection<PNUUIDMetadata>,
4 val totalCount: Int?,
5 val next: PNPage?,
6 val prev: PNPage?
7)
8
9data class PNUUIDMetadata(
10 val id: String,
11 val name: PatchValue<String?>? = null,
12 val externalId: PatchValue<String?>? = null,
13 val profileUrl: PatchValue<String?>? = null,
14 val email: PatchValue<String?>? = null,
15 val custom: PatchValue<Map<String, Any?>?>? = null,
show all 20 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 Kotlin SDK:
1pubnub.getUUIDMetadata(
2 uuid: String? = null,
3 includeCustom: Boolean = false
4).async { result -> }
| Parameter | Description |
|---|---|
uuidType: StringDefault: pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
includeCustomType: BooleanDefault: false | Whether to include the Custom object in the response. |
Sample code
1
Response
1data class PNUUIDMetadataResult(
2 val status: Int,
3 val data: PNUUIDMetadata?
4)
5
6data class PNUUIDMetadata(
7 val id: String,
8 val name: PatchValue<String?>? = null,
9 val externalId: PatchValue<String?>? = null,
10 val profileUrl: PatchValue<String?>? = null,
11 val email: PatchValue<String?>? = null,
12 val custom: PatchValue<Map<String, Any?>?>? = null,
13 val updated: PatchValue<String>? = null,
14 val eTag: PatchValue<String>? = null,
15 val type: PatchValue<String?>? = null,
show all 17 linesSet 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 Kotlin SDK:
1pubnub.setUUIDMetadata(
2 uuid: String? = null,
3 includeCustom: Boolean = false,
4 name: String? = null,
5 externalId: String? = null,
6 profileUrl: String? = null,
7 email: String? = null,
8 custom: Any? = null,
9 type: String?,
10 status: String?,
11 ifMatchesEtag: String?
12).async { result -> }
| Parameter | Description |
|---|---|
uuidType: StringDefault: pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
includeCustomType: BooleanDefault: false | Whether to include the custom field in the fetch response. |
nameType: String?Default: null | Display name for the user. |
externalIdType: String?Default: null | User's identifier in an external system |
profileUrlType: String?Default: null | The URL of the user's profile picture |
emailType: String?Default: null | The user's email address. |
typeType: String?Default: null | The custom type of the user. |
statusType: String?Default: null | The custom type of the user. |
customType: Any?Default: null | Any object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties. |
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. |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Sample code
1
Response
1data class PNUUIDMetadataResult(
2 val status: Int,
3 val data: PNUUIDMetadata?
4)
5
6data class PNUUIDMetadata(
7 val id: String,
8 val name: PatchValue<String?>? = null,
9 val externalId: PatchValue<String?>? = null,
10 val profileUrl: PatchValue<String?>? = null,
11 val email: PatchValue<String?>? = null,
12 val custom: PatchValue<Map<String, Any?>?>? = null,
13 val updated: PatchValue<String>? = null,
14 val eTag: PatchValue<String>? = null,
15 val type: PatchValue<String?>? = null,
show all 17 linesRemove user metadata
Removes the metadata from a specified UUID.
Method(s)
To Remove UUID Metadata you can use the following method(s) in the Kotlin SDK:
1pubnub.removeUUIDMetadata(
2 uuid: String? = null
3).async { result -> }
| Parameter | Description |
|---|---|
uuidType: StringDefault: pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
Sample code
1
Response
1data class PNRemoveMetadataResult(private val status: Int)
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 Kotlin SDK:
1pubnub.getAllChannelMetadata(
2 filter: String? = null,
3 sort: Collection<PNSortKey<PNKey>> = listOf(),
4 page: PNPage? = null,
5 limit: Int? = null,
6 includeCustom: Boolean = false,
7 includeCount: Boolean = false,
8).async { result -> }
| Parameter | Description |
|---|---|
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNKey>>Default: listOf() | List of properties to sort by. Available options are PNKey.ID, PNKey.NAME, PNKey.UPDATED, PNKey.TYPE, PNKey.STATUS. Use PNSortKey.asc or PNSortKey.desc to specify sort direction. For example: PNSortKey.asc(PNKey.STATUS) , PNSortKey.desc(PNKey.TYPE) |
pageType: PNPage?Default: null | The paging object used for pagination. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
includeCustomType: BooleanDefault: false | Whether to include the Custom field in the fetch response. |
includeCountType: BooleanDefault: false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
Sample code
1
Response
1data class PNChannelMetadataArrayResult(
2 val status: Int,
3 val data: Collection<PNChannelMetadata>,
4 val totalCount: Int?,
5 val next: PNPage?,
6 val prev: PNPage?
7)
8
9data class PNChannelMetadata(
10 val id: String,
11 val name: PatchValue<String?>? = null,
12 val description: PatchValue<String?>? = null,
13 val custom: PatchValue<Map<String, Any?>?>? = null,
14 val updated: PatchValue<String>? = null,
15 val eTag: PatchValue<String>? = null,
show all 18 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 Kotlin SDK:
1pubnub.getChannelMetadata(
2 channel: String,
3 includeCustom: Boolean = false
4).async { result -> }
| Parameter | Description |
|---|---|
channelType: StringDefault: n/a | Channel name. |
includeCustomType: BooleanDefault: false | Whether to include the custom field in the fetch response. |
Sample code
1
Response
1data class PNChannelMetadataResult(
2 val status: Int,
3 val data: PNChannelMetadata?
4)
5
6data class PNChannelMetadata(
7 val id: String,
8 val name: PatchValue<String?>? = null,
9 val description: PatchValue<String?>? = null,
10 val custom: PatchValue<Map<String, Any?>?>? = null,
11 val updated: PatchValue<String>? = null,
12 val eTag: PatchValue<String>? = null,
13 val type: PatchValue<String?>? = null,
14 val status: PatchValue<String?>? = null,
15)
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 Kotlin SDK:
1pubnub.setChannelMetadata(
2 channel: String,
3 includeCustom: Boolean = false,
4 name: String? = null,
5 description: String? = null,
6 custom: Any? = null
7 type: String?,
8 status: String?,
9 ifMatchesEtag: String?
10).async { result -> }
| Parameter | Description |
|---|---|
channelType: StringDefault: n/a | Channel name. |
includeCustomType: BooleanDefault: false | Whether to include the custom field in the fetch response. |
nameType: String?Default: null | Name for the channel. |
descriptionType: String?Default: null | Description of a channel. |
typeType: String?Default: null | The custom type of the channel. |
statusType: String?Default: null | The custom type of the channel. |
customType: Any?Default: null | Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn’t supported. |
ifMatchesEtagType: String Default: n/a | The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown. |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Sample code
1
Response
1data class PNChannelMetadataResult(
2 val status: Int,
3 val data: PNChannelMetadata?
4)
5
6data class PNChannelMetadata(
7 val id: String,
8 val name: PatchValue<String?>? = null,
9 val description: PatchValue<String?>? = null,
10 val custom: PatchValue<Map<String, Any?>?>? = null,
11 val updated: PatchValue<String>? = null,
12 val eTag: PatchValue<String>? = null,
13 val type: PatchValue<String?>? = null,
14 val status: PatchValue<String?>? = null,
15)
Other examples
Iteratively update existing metadata
1
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 Kotlin SDK:
1pubnub.removeChannelMetadata(
2 channel: String
3).async { result -> }
| Parameter | Description |
|---|---|
channelType: StringDefault: n/a | Channel name. |
Sample code
1
Response
1data class PNRemoveMetadataResult(private val status: Int)
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 Kotlin SDK:
1pubnub.getMemberships(
2 userId: String? = null,
3 limit: Int? = null,
4 page: PNPage? = null,
5 filter: String? = null,
6 sort: Collection<PNSortKey<PNMembershipKey>> = listOf(),
7 include: MembershipInclude = MembershipInclude(),
8).async { result -> }
| Parameter | Description |
|---|---|
userIdType: StringDefault: pubnub.configuration.userId.value | Unique User Metadata identifier. If not supplied, then userId from configuration will be used. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
pageType: PNPage?Default: null | The paging object used for pagination. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMembershipKey>>Default: listOf() | Sort by CHANNEL_ID, CHANNEL_NAME, CHANNEL_UPDATED, CHANNEL_STATUS, CHANNEL_TYPE, UPDATED, STATUS, TYPE with asc/desc for sort direction (for example, PNSortKey.PNAsc(PNMembershipKey.TYPE)). |
includeType: MembershipIncludeDefault: MembershipInclude() | Object holding the configuration for whether to include additional data in the response. |
Sample code
1
Response
1data class PNChannelMembershipArrayResult(
2 val status: Int,
3 val data: Collection<PNChannelMembership>,
4 val totalCount: Int?,
5 val next: PNPage?,
6 val prev: PNPage?
7)
8
9data class PNChannelMembership(
10 val channel: PNChannelMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>? = null,
15 val type: PatchValue<String?>? = null
show all 16 linesSet channel memberships
Set channel memberships for a User.
Method(s)
To Set Channel Memberships you can use the following method(s) in the Kotlin SDK:
1pubnub.setMemberships(
2 channels: List<ChannelMembershipInput>,
3 userId: String? = null,
4 limit: Int? = null,
5 page: PNPage? = null,
6 filter: String? = null,
7 sort: Collection<PNSortKey<PNMembershipKey>>, = listOf(),
8 include: MembershipInclude = MembershipInclude(),
9).async { result -> }
| Parameter | Description |
|---|---|
channelsDefault: n/a | List of ChannelMembershipInput to add to membership with optional custom metadata, like status or type. |
userIdType: StringDefault: pubnub.configuration.userId.value | Unique User Metadata identifier. If not supplied, then userId from configuration will be used. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
pageType: PNPage?Default: null | The paging object used for pagination. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMembershipKey>>Default: listOf() | List of properties to sort by. Available options are PNMembershipKey.CHANNEL_ID, PNMembershipKey.CHANNEL_NAME, PNMembershipKey.CHANNEL_UPDATED, PNMembershipKey.CHANNEL_STATUS, PNMembershipKey.CHANNEL_TYPE, PNMembershipKey.UPDATED, PNMembershipKey.STATUS and PNMembershipKey.TYPE. Use PNSortKey.PNAsc or PNSortKey.PNDesc to specify sort direction. For example: PNSortKey.PNAsc(PNMembershipKey.TYPE) or PNSortKey.PNDesc(PNMembershipKey.STATUS). |
includeType: MembershipIncludeDefault: MembershipInclude() | Object holding the configuration for whether to include additional data in the response. |
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
ChannelMembershipInput
| Parameter | Description |
|---|---|
channelType: String | The channel to add the membership to. |
customType: CustomObject | Additional information about the membership. |
typeType: String | The string description of the type of the membership. |
statusType: String | The string description of the status of the membership. |
Sample code
1
Response
1data class PNChannelMembershipArrayResult(
2 val status: Int,
3 val data: Collection<PNChannelMembership>,
4 val totalCount: Int?,
5 val next: PNPage?,
6 val prev: PNPage?
7)
8
9data class PNChannelMembership(
10 val channel: PNChannelMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>? = null,
15 val type: PatchValue<String?>? = null,
show all 16 linesRemove channel memberships
Remove channel memberships for a User.
Method(s)
To Remove Channel Memberships you can use the following method(s) in the Kotlin SDK:
1pubnub.removeMemberships(
2 channels: List<String>,
3 userId: String? = null,
4 limit: Int? = null,
5 page: PNPage? = null,
6 filter: String? = null,
7 sort: Collection<PNSortKey<PNMembershipKey>>, = listOf(),
8 include: MembershipInclude = MembershipInclude(),
9).async { result -> }
| Parameter | Description |
|---|---|
channelsType: List<String>Default: n/a | List of channels to remove from membership. |
userIdType: StringDefault: pubnub.configuration.userId.value | Unique User Metadata identifier. If not supplied, then userId from configuration will be used. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMembershipKey>>,Default: listOf() | Sort by CHANNEL_ID, CHANNEL_NAME, CHANNEL_UPDATED, CHANNEL_STATUS, CHANNEL_TYPE, UPDATED, STATUS, TYPE with asc/desc for sort direction (for example, PNSortKey.PNAsc(PNMembershipKey.TYPE)). |
pageType: PNPage?Default: null | Cursor-based pagination. |
limitType: IntDefault: 100 | Number of objects to return. Default/Max: 100. |
includeType: MembershipIncludeDefault: MembershipInclude() | Whether to include additional fields. |
Sample code
1
Response
1data class PNChannelMembershipArrayResult(
2 val status: Int,
3 val data: Collection<PNChannelMembership>,
4 val totalCount: Int?,
5 val next: PNPage?,
6 val prev: PNPage?
7)
8
9data class PNChannelMembership(
10 val channel: PNChannelMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>? = null,
15 val type: PatchValue<String?>? = null,
show all 16 linesManage channel memberships
Manage a user's channel memberships.
Method(s)
To Manage Memberships you can use the following method(s) in the Kotlin SDK:
1pubnub.manageMemberships(
2 channelsToSet: List<PNChannelWithCustom>,
3 channelsToRemove: List<String>,
4 userId: String? = null,
5 limit: Int? = null,
6 page: PNPage? = null,
7 filter: String? = null,
8 sort: Collection<PNSortKey<PNMembershipKey>>, = listOf(),
9 include: MembershipInclude = MembershipInclude(),
10).async { result -> }
| Parameter | Description |
|---|---|
channelsToSetType: List<PNChannelWithCustom>Default: n/a | List of PNChannelWithCustom to add to membership. |
channelsToRemoveType: List<String>Default: n/a | List of channels to remove from membership. |
userIdType: StringDefault: pubnub.configuration.userId.value | Unique User Metadata identifier. If not supplied, then userId from configuration will be used. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMembershipKey>>,Default: listOf() | List of properties to sort by. Available options are PNMembershipKey.CHANNEL_ID, PNMembershipKey.CHANNEL_NAME, PNMembershipKey.CHANNEL_UPDATED, PNMembershipKey.CHANNEL_STATUS, PNMembershipKey.CHANNEL_TYPE, PNMembershipKey.UPDATED, PNMembershipKey.STATUS and PNMembershipKey.TYPE. Use PNSortKey.PNAsc or PNSortKey.PNDesc to specify sort direction. For example: PNSortKey.PNAsc(PNMembershipKey.TYPE) or PNSortKey.PNDesc(PNMembershipKey.STATUS). |
pageType: PNPage?Default: null | The paging object used for pagination. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
includeType: MembershipIncludeDefault: MembershipInclude() | Object holding the configuration for whether to include additional data in the response. |
Sample code
1
Response
1data class PNChannelMembershipArrayResult(
2 val status: Int,
3 val data: Collection<PNChannelMembership>,
4 val totalCount: Int?,
5 val next: PNPage?,
6 val prev: PNPage?
7)
8
9data class PNChannelMembership(
10 val channel: PNChannelMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>? = null,
15 val type: PatchValue<String?>? = null,
show all 16 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 Kotlin SDK:
1pubnub.getChannelMembers(
2 channel: String,
3 limit: Int? = null,
4 page: PNPage? = null,
5 filter: String? = null,
6 sort: Collection<PNSortKey<PNMemberKey>> = listOf(),
7 include: MemberInclude = MemberInclude(),
8).async { result -> }
| Parameter | Description |
|---|---|
channelType: StringDefault: n/a | Channel name. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
pageType: PNPage?Default: null | The paging object used for pagination. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMemberKey>>Default: listOf() | List of properties to sort by. Available options are PNMemberKey.UUID_ID, PNMemberKey.UUID_NAME,PNMemberKey.UUID_UPDATED, PNMemberKey.UUID_NAME,PNMemberKey.UUID_TYPE, PNMemberKey.UPDATED,PNMemberKey.STATUS, PNMemberKey.TYPE. Use PNSortKey.PNAsc or PNSortKey.PNDesc to specify sort direction. For example: PNSortKey.PNAsc(PNMemberKey.TYPE) or PNSortKey.PNDesc(PNMemberKey.STATUS). |
includeType: MemberIncludeDefault: MemberInclude() | Object holding the configuration for whether to include additional data in the response. |
Sample code
1
Response
1data class PNMemberArrayResult(
2 val status: Int,
3 val data: Collection<PNMember>,
4 val totalCount: Int?,
5 val next: PNPage.PNNext?,
6 val prev: PNPage.PNPrev?
7)
8
9data class PNMember(
10 val uuid: PNUUIDMetadata?,
11 val custom: Any? = null,
12 val updated: Instant,
13 val eTag: String
14)
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 Kotlin SDK:
1pubnub.setChannelMembers(
2 channel: String,
3 users: List<PNMember.Partial>,
4 limit: Int? = null,
5 page: PNPage? = null,
6 filter: String? = null,
7 sort: Collection<PNSortKey<PNMemberKey>> = listOf(),
8 include: MemberInclude = MemberInclude(),
9).async { result, status ->
10 if (status.error) {
11 // handle error
12 } else if (result != null) {
13 // handle result
14 }
15}
| Parameter | Description |
|---|---|
channel *Type: StringDefault: n/a | Channel name. |
usersType: List<PNMember.Partial>Default: n/a | List of members PNMember.Partial to add to channel. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
pageType: PNPage?Default: null | The paging object used for pagination. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMemberKey>>Default: listOf() | List of properties to sort by. Available options are PNMemberKey.UUID_ID, PNMemberKey.UUID_NAME,PNMemberKey.UUID_UPDATED, PNMemberKey.UUID_NAME,PNMemberKey.UUID_TYPE, PNMemberKey.UPDATED,PNMemberKey.STATUS, PNMemberKey.TYPE. Use PNSortKey.PNAsc or PNSortKey.PNDesc to specify sort direction. For example: PNSortKey.PNAsc(PNMemberKey.TYPE) or PNSortKey.PNDesc(PNMemberKey.STATUS). |
includeType: MemberIncludeDefault: MemberInclude() | Object holding the configuration for whether to include additional data in the response. |
API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.
Sample code
1
Response
1data class PNMemberArrayResult(
2 val status: Int,
3 val data: Collection<PNMember>,
4 val totalCount: Int?,
5 val next: PNPage.PNNext?,
6 val prev: PNPage.PNPrev?
7)
8
9data class PNMember(
10 val uuid: PNUUIDMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>?,
15 val type: PatchValue<String?>?,
show all 16 linesRemove channel members
Remove members from a Channel.
Method(s)
To Remove Channel Members you can use the following method(s) in the Kotlin SDK:
1pubnub.removeChannelMembers(
2 userIds: List<String>,
3 channel: String,
4 limit: Int? = null,
5 page: PNPage? = null,
6 filter: String? = null,
7 sort: Collection<PNSortKey<PNMemberKey>> = listOf(),
8 include: MemberInclude = MemberInclude(),
9).async { result -> }
| Parameter | Description |
|---|---|
userIdsType: List<String>Default: n/a | List of members userIDs to remove from channel. |
channelType: StringDefault: n/a | Channel name. |
limitType: IntDefault: 100 | The number of objects to retrieve at a time. |
pageType: PNPage?Default: null | The paging object used for pagination. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMemberKey>>Default: listOf() | List of properties to sort by. Available options are PNMemberKey.UUID_ID, PNMemberKey.UUID_NAME,PNMemberKey.UUID_UPDATED, PNMemberKey.UUID_NAME,PNMemberKey.UUID_TYPE, PNMemberKey.UPDATED,PNMemberKey.STATUS, PNMemberKey.TYPE. Use PNSortKey.PNAsc or PNSortKey.PNDesc to specify sort direction. For example: PNSortKey.PNAsc(PNMemberKey.TYPE) or PNSortKey.PNDesc(PNMemberKey.STATUS). |
includeType: MemberIncludeDefault: MemberInclude() | Object holding the configuration for whether to include additional data in the response. |
Sample code
1
Response
1data class PNMemberArrayResult(
2 val status: Int,
3 val data: Collection<PNMember>,
4 val totalCount: Int?,
5 val next: PNPage.PNNext?,
6 val prev: PNPage.PNPrev?
7)
8
9data class PNMember(
10 val uuid: PNUUIDMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>?,
15 val type: PatchValue<String?>?,
show all 16 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 Kotlin SDK:
1pubnub.manageChannelMembers(
2 channel: String,
3 usersToSet: List<PNMember.Partial>,
4 userIdsToRemove: List<String>,
5 limit: Int? = null,
6 page: PNPage? = null,
7 filter: String? = null,
8 sort: Collection<PNSortKey<PNMemberKey>> = listOf(),
9 include: MemberInclude = MemberInclude(),
10).async { result, status ->
11 if (status.error) {
12 // Handle error
13 } else if (result != null) {
14 // Handle successful result
15 }
show all 16 lines| Parameter | Description |
|---|---|
channelType: StringDefault: n/a | Channel name. |
usersToSetType: List<PNMember.Partial>Default: n/a | List of members PNMember.Partial to add to the channel with optional custom metadata. |
userIdsToRemoveType: List<String>Default: n/a | List of members userIds to remove from the channel. |
limitType: Int?Default: 100 | The number of objects to retrieve at a time. |
pageType: PNPage?Default: null | The paging object used for pagination. |
filterType: String?Default: null | Filter expression. Only matching objects are returned. See filtering. |
sortType: Collection<PNSortKey<PNMemberKey>>Default: listOf() | List of properties to sort by. Available options are PNMemberKey.UUID_ID, PNMemberKey.UUID_NAME,PNMemberKey.UUID_UPDATED, PNMemberKey.UUID_NAME,PNMemberKey.UUID_TYPE, PNMemberKey.UPDATED,PNMemberKey.STATUS, PNMemberKey.TYPE. Use PNSortKey.PNAsc or PNSortKey.PNDesc to specify sort direction. For example: PNSortKey.PNAsc(PNMemberKey.TYPE) or PNSortKey.PNDesc(PNMemberKey.STATUS). |
includeType: MemberIncludeDefault: MemberInclude() | Object holding the configuration for whether to include additional data in the response. |
Sample code
1
Response
1data class PNMemberArrayResult(
2 val status: Int,
3 val data: Collection<PNMember>,
4 val totalCount: Int?,
5 val next: PNPage.PNNext?,
6 val prev: PNPage.PNPrev?
7)
8
9data class PNMember(
10 val uuid: PNUUIDMetadata,
11 val custom: PatchValue<Map<String, Any?>?>? = null,
12 val updated: String,
13 val eTag: String,
14 val status: PatchValue<String?>?,
15 val type: PatchValue<String?>?,
show all 16 lines