Manage groups
Learn how to manage Instagram group conversations with 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.
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: "user_id",
},
});messaging_api.add_participant(
"chat_id",
"acc_123456789",
{"user_id": "user_id"},
)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": "user_id"
}
'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: "user_id",
},
});messaging_api.remove_participant(
"chat_id",
"user_id",
"acc_123456789",
)curl --request DELETE \
--url https://api.unipile.com/v2/account_id/chats/chat_id/participants/user_id \
--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 Instagram's native behavior.
Updated 9 days ago