Browse SDKs · WASM
SDKsWASM

Get user profiles

Query public application user profiles (PublicUserItem) in batches by userID.

Copy

Use getUsersInfo() to query application users' public profiles by userID. It is suitable for displaying friend candidates and profile cards for users who are not friends.

If your product searches users by nickname, phone number, organization, email, or another application field, perform the search and permission checks on the application backend first, then pass the returned userID values to getUsersInfo(). Administrator tokens must remain on a trusted backend, and user directory administration must also be performed by the backend.

Query public profiles

Call getUsersInfo() with an array of OpenIMSDK user IDs to retrieve their account-level public profiles. Deduplicate the IDs and limit the size of each request. Friend remarks belong to friendship data, while in-group nicknames and roles belong to group member data.

After the Promise succeeds, data contains the matched PublicUserItem[]. Commonly used fields are:

FieldTypeDescription
userIDstringOpenIMSDK user ID.
nicknamestringAccount-level public nickname.
faceURLstringAccount-level public avatar URL.
exstringAccount-level extension data whose format is defined by the application.

ex is read-only here. A browser cannot use the User API to change another account's public profile. Update the signed-in user's own extension data with setSelfInfo(); see setSelfInfo() for complete replacement semantics.

const userIDList = Array.from(new Set(['user_a', 'user_b']));

try {
  const response = await openimsdk.getUsersInfo(userIDList);
  const users = response.data ?? [];
  const usersByID = new Map(users.map((user) => [user.userID, user]));
} catch (error) {
  console.error('getUsersInfo failed', {
    error,
    userIDList,
  });
  throw error;
}

Results and profile refresh

After getUsersInfo() succeeds, use the returned PublicUserItem[] to update the current profile snapshot. Query again when opening a profile card, refreshing manually, reconnecting, or receiving a profile-change notification from your application backend. When a page displays several users, collect the visible userID values, deduplicate them, query them in one batch, and merge the results by userID.

The WASM SDK has no general change event for arbitrary public user profiles. CbEvents.OnSelfInfoUpdated carries only the signed-in user's SelfUserInfo; do not write it into another user's PublicUserItem cache. See Update your profile for reading, updating, and synchronizing the signed-in user's profile.

Search for users to add as friends

When searching for and adding friends, the application backend normally returns candidate userID values first. The browser then calls getUsersInfo() to display their public profiles. After the user confirms a target, continue to the friend application flow.

async function searchUsersForFriendRequest(keyword: string) {
  const { userIDs } = await searchUserIDsFromYourBackend(keyword);

  if (userIDs.length === 0) {
    return [];
  }

  try {
    const response = await openimsdk.getUsersInfo(userIDs);
    const users = response.data ?? [];

    return users.map((user) => ({
      userID: user.userID,
      displayName: user.nickname || user.userID,
      avatar: user.faceURL,
    }));
  } catch (error) {
    console.error('getUsersInfo failed', { error, userIDs });
    throw error;
  }
}

If your product supports only exact lookup by user ID, omit the backend search endpoint and pass the input directly to getUsersInfo() as a userID. For fuzzy search or sensitive fields, the backend must handle authorization, rate limiting, redaction, and auditing.

Choose display data by context

The same userID can have different display names and relationship data in different contexts. Choose the data source for the current context:

ContextPreferred type
Application user search or a profile card for a user who is not a friendPublicUserItem
Friend list, contacts, or friend remarksFriendUserItem
Group member list, in-group nicknames, or group rolesGroupMemberItem

Friend remarks and in-group nicknames come from friendship and group member data respectively. For friendships, see getFriendListPage() and getSpecifiedFriendsInfo(). For group members, see List group members.

Next steps