Skip to main content
Quick Reference for AI Agents & Developers
  • Create user: CometChat.createUser(user:apiKey:onSuccess:onError:)
  • Get user: CometChat.getUser(UID:onSuccess:onError:)
  • List users: UsersRequest.UsersRequestBuilder().build()usersRequest.fetchNext(onSuccess:onError:)
  • Block/unblock: CometChat.blockUsers(_:onSuccess:onError:), CometChat.unblockUsers(_:onSuccess:onError:)
  • Related: User Management · Retrieve Users · Block Users
The primary aim for our users’ functionality is to allow you to quickly retrieve and add users to CometChat. You can begin with user management to sync your users to CometChat. Once that is done, you can retrieve users and display them in your app.

User Data Model

The User class represents a CometChat user with all their profile information.

Creating a User Object

// Basic user creation
let user = User(uid: "user123", name: "John Doe")

// Set optional properties
user.avatar = "https://example.com/avatar.png"
user.link = "https://example.com/profile/user123"
user.role = "default"
user.metadata = ["department": "engineering", "level": 5]
user.tags = ["premium", "verified"]

User Properties

ParameterTypeEditableDescription
uidString?No*Unique user identifier. Must be alphanumeric with underscore/hyphen only. Required for user creation.
nameString?YesDisplay name of the user. Required for user creation.
avatarString?YesURL to the user’s avatar/profile image.
linkString?YesURL to the user’s profile page or external link.
roleString?YesRole assigned to the user for role-based access control.
metadata[String: Any]?YesCustom metadata dictionary for storing additional user information.
statusUserStatusNoCurrent online status of the user: .online or .offline.
statusMessageString?YesCustom status message set by the user.
lastActiveAtDoubleNoUnix timestamp of the user’s last activity.
hasBlockedMeBoolNoIndicates if this user has blocked the logged-in user.
blockedByMeBoolNoIndicates if the logged-in user has blocked this user.
deactivatedAtDoubleNoUnix timestamp when user was deactivated. Value is 0.0 if user is active.
tags[String]YesArray of tags for categorizing and filtering users.
* uid is specified on user creation and not editable after that
ParameterTypeDescription
uidString?Unique identifier of the user. Example: "user123"
nameString?Display name of the user. Example: "John Doe"
avatarString?URL to the user’s avatar image. Example: "https://example.com/avatar.png"
linkString?URL to the user’s profile page. Example: "https://example.com/profile/user123"
roleString?Role assigned to the user for access control. Example: "default"
statusUserStatusCurrent online status of the user. Example: .online
statusMessageString?Custom status message set by the user. Example: "Available"
lastActiveAtDoubleUnix timestamp of the user’s last activity. Example: 1699900000.0
hasBlockedMeBoolIndicates if this user has blocked the logged-in user. Example: false
blockedByMeBoolIndicates if the logged-in user has blocked this user. Example: false
deactivatedAtDoubleUnix timestamp when user was deactivated (0 if active). Example: 0.0
tags[String]Array of tags associated with the user. Example: ["premium", "verified"]
metadata[String: Any]?Custom metadata dictionary for additional user info. Example: ["department": "engineering", "level": 5]
metadata.departmentStringDepartment the user belongs to (nested in metadata). Example: "engineering"
metadata.levelIntUser’s level or rank (nested in metadata). Example: 5

UserStatus Enum

ValueRaw ValueDescription
.online0User is currently online and active in the application.
.offline1User is currently offline or not connected.

UID Requirements

RuleDescription
AlphanumericLetters (a-z, A-Z) and numbers (0-9) are allowed
UnderscoreUnderscore character _ is allowed
HyphenHyphen character - is allowed
SpacesSpaces are NOT allowed in UID
PunctuationPunctuation marks (., !, ?, etc.) are NOT allowed
Special charactersSpecial characters (@, #, $, %, etc.) are NOT allowed

Common Error Codes

Error CodeDescriptionResolution
ERR_UID_NOT_FOUNDUser with specified UID does not exist in CometChatVerify the UID is correct and the user has been created
ERR_USER_DEACTIVATEDUser account has been deactivatedContact admin to reactivate the user account
ERR_NOT_LOGGED_INNo user is currently logged in to CometChatCall CometChat.login() before performing this operation
ERR_UID_ALREADY_EXISTSUser with specified UID already existsUse a different unique UID for the new user
ERR_INVALID_API_KEYThe provided API key is invalid or expiredVerify API key from CometChat Dashboard
ERR_INVALID_UIDUID contains invalid charactersUse only alphanumeric characters, underscore, and hyphen
ERR_EMPTY_UIDUID is empty or nullProvide a valid non-empty UID
ERR_EMPTY_NAMEName is empty or nullProvide a valid non-empty name
ERR_INVALID_LIMITInvalid limit value provided for paginationUse a limit value between 1 and 100