PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

Users API for PubNub Kotlin SDK

A User is a human, a device, or a control system that can access PubNub APIs. The Users of your system interact with each other using multiple clients on which your application is installed. Depending on the User type, you can enforce different rules, for example the ability for a single User to connect from multiple clients.

Calling Kotlin methods

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 choose one of these or the operation will not be performed at all.

For example, the following code is valid and will compile, but the publish won't be performed:

pubnub.publish(
    message = "this sdk rules!",
    spaceId = "my_space"
)

To successfully publish a message, you must follow the actual method invocation with whether to perform it synchronously or asynchronously, for example:

pubnub.publish(
    message = "this sdk rules!",
    spaceId = "my_space"
).async { result, status ->
    if (status.error) {
        // handle error
    } else {
        // handle successful method result
    }
}

Fetch Users

Returns a paginated list of Users, optionally including custom fields for each.

Method(s)

pubnub.fetchUsers(
    limit: Int? = null,
    page: PNPage? = null,
    filter: String? = null,
    sort: Collection<PNSortKey> = listOf(),
    includeCount: Boolean = false,
    includeCustom: Boolean = false
).async { result, status -> }
ParameterTypeRequiredDefaultDescription
limitIntOptional100The number of objects to retrieve at a time.
pagePNPage?OptionalnullThe paging object used for pagination.
filterString?OptionalnullExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortList<PNSortKey>OptionallistOf()List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
includeCountBooleanOptionalfalseRequest IncludeCount to be included in paginated response. By default, IncludeCount is omitted.
includeCustomBooleanOptionalfalseWhether to include the Custom field in the fetch response.

Basic Usage

pubnub.fetchUsers()
        .async { result, status ->
            if (status.error) {
                //handle error
            } else if (result != null) {
                //handle result
            }
        }

Response

data class PNUserArrayResult(
    val status: Int,
    val data: Collection<PNUser>,
    val totalCount: Int?,
    val next: PNPage?,
    val prev: PNPage?
)

data class PNUser(
    val id: String,
    val name: String?,
    val externalId: String?,
    val profileUrl: String?,
    val email: String?,
    val custom: Any?,
    val updated: String?,
    val eTag: String?
)

Fetch User

Returns metadata for the specified User, optionally including custom fields for each.

Method(s)

pubnub.fetchUser(
    userId: String? = null,
    includeCustom: Boolean = false
).async { result, status -> }
ParameterTypeRequiredDefaultDescription
userIdStringOptionalpubnub.configuration.uuidUnique User identifier.
If not supplied, then UUID from configuration will be used.
includeCustomBooleanOptionalfalseWhether to include the custom field in the fetch response.

Basic Usage

pubnub.fetchUser()
        .async { result, status ->
            if (status.error) {
                //handle error
            } else if (result != null) {
                //handle result
            }
        }

Response

data class PNUserResult(
    val status: Int,
    val data: PNUser?
)

data class PNUser(
    val id: String,
    val name: String?,
    val externalId: String?,
    val profileUrl: String?,
    val email: String?,
    val custom: Any?,
    val updated: String?,
    val eTag: String?
)

Create User

Create metadata for a User in the database, optionally including custom fields for each.

Method(s)

pubnub.createUser(
    userId: String? = null,
    name: String? = null,
    externalId: String? = null,
    profileUrl: String? = null,
    email: String? = null,
    custom: Any? = null,
    includeCustom: Boolean = false
).async { result, status -> }
ParameterTypeRequiredDefaultDescription
userIdStringOptionalpubnub.configuration.uuidUnique User identifier.
If not supplied, then UUID from configuration will be used.
nameString?OptionalnullDisplay name for the user. Maximum 200 characters.
externalIdString?OptionalnullUser's identifier in an external system.
profileUrlString?OptionalnullThe URL of the user's profile picture.
emailString?OptionalnullThe user's email address. Maximum 80 characters.
customAny?OptionalnullAny object of key-value pairs with supported data types. Objects filtering language doesn’t support filtering by custom properties.
includeCustomBooleanOptionalfalseWhether to include the custom field in the fetch response.

Basic Usage

pubnub.createUser()
        .async { result, status ->
            if (status.error) {
                //handle error
            } else if (result != null) {
                //handle result
            }
        }

Response

data class PNUserResult(
    val status: Int,
    val data: PNUser?
)

data class PNUser(
    val id: String,
    val name: String?,
    val externalId: String?,
    val profileUrl: String?,
    val email: String?,
    val custom: Any?,
    val updated: String?,
    val eTag: String?
)

Update User

Update existing metadata for a User in the database, optionally including custom fields for each.

Method(s)

pubnub.updateUser(
    userId: String? = null,
    name: String? = null,
    externalId: String? = null,
    profileUrl: String? = null,
    email: String? = null,
    custom: Any? = null,
    includeCustom: Boolean = false
).async { result, status -> }
ParameterTypeRequiredDefaultDescription
userIdStringOptionalpubnub.configuration.uuidUnique User identifier.
If not supplied, then UUID from configuration will be used.
nameString?OptionalnullDisplay name for the user. Maximum 200 characters.
externalIdString?OptionalnullUser's identifier in an external system.
profileUrlString?OptionalnullThe URL of the user's profile picture.
emailString?OptionalnullThe user's email address. Maximum 80 characters.
customAny?OptionalnullAny object of key-value pairs with supported data types. Objects filtering language doesn’t support filtering by custom properties.
includeCustomBooleanOptionalfalseWhether to include the custom field in the fetch response.

Basic Usage

pubnub.updateUser()
        .async { result, status ->
            if (status.error) {
                //handle error
            } else if (result != null) {
                //handle result
            }
        }

Response

data class PNUserResult(
    val status: Int,
    val data: PNUser?
)

data class PNUser(
    val id: String,
    val name: String?,
    val externalId: String?,
    val profileUrl: String?,
    val email: String?,
    val custom: Any?,
    val updated: String?,
    val eTag: String?
)

Remove User

Removes the metadata from a specified User.

Method(s)

pubnub.removeUser(
    userId: String? = null
).async { result, status -> }
ParameterTypeRequiredDefaultDescription
userIdStringOptionalpubnub.configuration.uuidUnique User identifier.
If not supplied, then UUID from configuration will be used.

Basic Usage

pubnub.removeUser()
        .async { result, status ->
            if (status.error) {
                //handle error
            } else if (result != null) {
                //handle result
            }
        }

Response

data class PNRemoveUserResult(val status: Int)
  • Fetch Users
  • Fetch User
  • Create User
  • Update User
  • Remove User
© PubNub Inc. - Privacy Policy