Page 1 of 1

Is there API endpoint to remove a user from a group?

Posted: Mon Apr 26, 2021 9:21 am
by skini
Is there any provision to remove a user from a group using the rest API?
According to the docs a POST request to users/{id}/groups/ can be used to add a user to a group. But I couldn't find any endpoint on /groups/ or /users/ to remove a user from a group.
Any help on the same would be great.

Re: Is there API endpoint to remove a user from a group?

Posted: Mon May 10, 2021 8:23 am
by michael
You can change the membership of a user by editing the 'groups pk list' attribute of the user via a PATCH of PUT request. This was done to provide a fast method to add or remove many groups in a single request but has the downside of not being intuitive.

For version 4.0, the API follows the container <- object layout, so now users are added to or removed from groups and not the other way around. Version 4.0 also includes specific API endpoints to perform these actions.

A read only endpoint is provided to get the list of groups a given user belongs to, but changes to that list are performed from the group point of view. This is slower when doing many group changes (work on bulk API requests is currently happening) but provides a better predictable and intuitive API layout.
2021-05-10_04-23_1.png (72.8 KiB) Viewed 22 times
2021-05-10_04-23.png (67.18 KiB) Viewed 22 times