What is the best way to remove a user from all the groups and add a new member in place of the same user?

We have a flow where we need to delete a user from all the groups that user is part of and add a new user to all the groups.

Right now I am looping each and every channel to delete the user using (/Leave api) and looping again and adding a new user.

We are calling the api multiple times and might get into the throttling. Is there any way that I can do better to reduce the api calls.

And moreover the swapping is happening by another user who is head of both these users.

Hello @BCH Welcome to the Sendbird community!

The best way to remove a user from all group channels and add a new member is by using our update a user API: User | Chat Platform API | Sendbird Docs and
by using ‘leave_all_when_deactivated’ parameter

PUT https://api-{application_id}.sendbird.com/v3/users/my-user-id
  1. Update this user ID and send:
    {
    “user_id”: “my-user-id”,
    “is_active”: false,
    “leave_all_when_deactivated”: true
    }
  2. After receiving a response for this call, you activate this user again:
    {
    “user_id”: “my-user-id”,
    “is_active”: true
    }

Let me know if this helps.

Thank you so much for the reply.

I will definitely try and confirm here.

Hi @Chinmaya_Gupta ,

The step2 meaning
After receiving a response for this call, you activate this user again:
{
“user_id”: “my-user-id”,
“is_active”: true
}

PUT https://api-{application_id}.sendbird.com/v3/users/my-user-id (FromUserID)
{
“user_id”: “new-user-id”,
“is_active”: true
}

I have to activate the new User… Am i right?

@BCH Absolutely, as step 1 will disable it.

Please let me know if this helps.

Hi @Chinmaya_Gupta

Step1: FromUser is successfully deleted from all the group channels…

Step2: Second scenario Adding a different user to the groups not working.

I also tried executing step2 first and step1 next, also not helped.

FromUserID = 100;
ToUserID = 101;

PUT https://api-{application_id}.sendbird.com/v3/users/100

{
“user_id”: “100”,
“is_active”: false,
“leave_all_when_deactivated”: true
}

Successful.

PUT https://api-{application_id}.sendbird.com/v3/users/100
{
“user_id”: “101”,
“is_active”: true
}

The user 101 is not added to the list of groups that 100 belonged to.

Please let me know where I am missing.

@Chinmaya_Gupta Can you please help me on this?

@BCH Oh, I got your point here. Unfortunately, we do not have any way to do this. We have only for leaving automatically and that’s what I thought initially.

Let me know if have any questions.