Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create group

Create a new chat group and configure initial administrators and regular members.

Copy

Supply initial group properties along with separate arrays of administrator and regular member user IDs. The current creator becomes the owner automatically, indicated by ownerUserID on the returned group object:

Code example

import sdk, { CreateGroupReq, CreateGroupResp } from '@openimsdk/imsdk';

const request: CreateGroupReq = {
  groupName: 'Project Discussion',
  faceURL: 'https://example.com/group.png',
  adminUserIDs: ['user_002'],
  memberUserIDs: ['user_003', 'user_004'],
};
const response: CreateGroupResp = await sdk.createGroup(request);
openGroupPage(response.groupInfo.groupID);

Parameters

ParameterTypeRequiredDescription
groupNamestringYesDisplay name for the new group.
adminUserIDsstring[]YesInitial administrator user IDs. Pass an empty array if none.
memberUserIDsstring[]YesInitial regular member user IDs. Pass an empty array if none.
groupIDstringNoExplicit group identifier pre-allocated by the backend. Usually omitted for auto-generation.
notificationstringNoInitial group announcement text.
introductionstringNoInitial group introduction description.
faceURLstringNoGroup avatar image URL.
needVerificationGroupNeedVerificationNoGroup join verification policy.
lookMemberInfoGroupLookMemberInfoNoMember profile visibility permission.
applyMemberFriendGroupApplyMemberFriendNoMember-to-member friend addition permission.
exstringNoCustom metadata extension string.

Deduplicate all user IDs, and ensure that adminUserIDs and memberUserIDs do not contain overlapping accounts or the creator's ID.

Return value

Returns a Promise that resolves to a CreateGroupResp object containing groupInfo: IMGroup.

State changes after the call

Resolving the Promise yields the newly created IMGroup record. Connected clients receive EventOnJoinedGroupAdded; merge the new group into your joined groups list keyed by groupID. For event listeners, see Group overview.