Manage groups
Learn how to manage WhatsApp groups using Unipile API.
Manage group members
List members
To list all members of a group chat, use List all Chat Participants method and provide the chat ID.
const { data, error } = await messagingApi.getParticipantsList({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
},
query: {
limit: 20,
},
});participants = messaging_api.get_participants_list(
"chat_id",
"acc_123456789",
limit=20,
)curl --request GET \
--url https://api.unipile.com/v2/account_id/chats/chat_id/participants \
--header 'accept: application/json'Add a new member
To add a member to a group chat, use Add a Chat Participant method and provide the chat ID and the user ID to add. See Find User IDs.
Good to knowMake sure that the account owner has the Add other members permission in the group to perform this action. Otherwise, the request may succeed without the member being added.
const { data, error } = await messagingApi.addParticipant({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
},
body: {
user_id: "[email protected]",
},
});messaging_api.add_participant(
"chat_id",
"acc_123456789",
{"user_id": "[email protected]"},
)curl --request POST \
--url https://api.unipile.com/v2/account_id/chats/chat_id/participants \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"user_id": "[email protected]"
}
'Remove a member
To remove a member from a group, use Remove a Chat Participant method and provide the chat ID and the ID of the user to remove.
Good to knowMake sure the account owner is admin of the group to perform this action. Otherwise, the request may succeed without the member being removed.
const { data, error } = await messagingApi.removeParticipant({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
user_id: "[email protected]",
},
});messaging_api.remove_participant(
"chat_id",
"[email protected]",
"acc_123456789",
)curl --request DELETE \
--url https://api.unipile.com/v2/account_id/chats/chat_id/participants/334455667788%40s.whatsapp.net \
--header 'accept: application/json'Exit a group
To exit a group, use Remove a Chat Participant method and provide the user ID of the account owner.
const account = await accountsApi.getAccount({
path: {
account_id: "acc_123456789",
},
});
const self_user_id = account.data.user_id;
const { data, error } = await messagingApi.removeParticipant({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
user_id: self_user_id,
},
});account = accounts_api.get_account("acc_123456789")
self_user_id = account.user_id
if self_user_id:
messaging_api.remove_participant(
"chat_id",
self_user_id,
"acc_123456789",
)
Note on exited groupsWhen the account owner leaves a group, the
read_onlyproperty is set totrueon the Chat object. The chat will remain in the chat list, and its messages can still be retrieved — this reflects WhatsApp’s native behavior.If the owner selects Exit and delete for me or Delete chat from the WhatsApp app after leaving, the chat and its messages will be removed entirely and will no longer appear in API results.
Deleting a chat via Unipile is not supported.
Update group name
To change the name of Group Chats, use Update a Chat method.
const { data, error } = await messagingApi.updateChat({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
},
body: {
name: "Updated Chat Name",
},
});messaging_api.update_chat(
"chat_id",
"acc_123456789",
{"name": "Updated Chat Name"},
)Updated 2 days ago