Problem - Confluence new REST API for groups / membership

Hello.
Just trying to make new API work in Python here.
Removing groups works fine as nothing seems to be required in arguments.
Adding groups always pops with a message saying that ‘type’ is missing ? I can’t see in the docs anything mentioned about another parameter to mention other than the group name.
Detailed error :
HTTPError: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property ‘type’ that is to contain type id (for class com.atlassian.confluence.api.model.people.Group)
at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@64b4bfdd; line: 1, column: 22]
Removing or adding users to a group also fails. Bad request or something about null… I use the correct PUT / DELETE method and URL. Authentication is fine as the remove_group works fine and so are all other functions.
Here’s the code of my functions :

    def create_group(self, name):
        """
        Create a group by given group parameter

        :param name: str
        :return: New group params
        """
        url = "rest/api/admin/group"
        data = {"name": name}
        return self.post(url, data=data)

    def remove_group(self, name):
        """
        Delete a group by given group parameter
        If you delete a group and content is restricted to that group, the content will be hidden from all users

        :param name: str
        :return:
        """
        log.warning("Removing group...")
        url = "rest/api/admin/group/{groupName}".format(groupName=name)

        try:
            response = self.delete(url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no group with the given name, "
                    "or the calling user does not have permission to delete it",
                    reason=e,
                )
            raise

        return response

    def add_user_to_group(self, username, group_name):
        """
        Add given user to a group

        :param username: str
        :param group_name: str
        :return: Current state of the group
        """
        url = "rest/api/user/{username}/group/{groupName}".format(username=username, groupName=group_name)
        return self.put(url)

    def remove_user_from_group(self, username, group_name):
        """
        Remove given user from a group

        :param username: str
        :param group_name: str
        :return:
        """
        log.warning("Removing user from a group...")
        url = "rest/api/user/{username}/group/{groupName}".format(username=username, groupName=group_name)
        try:
            response = self.delete(url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no group with the given name, "
                    "or the calling user does not have permission",
                    reason=e,
                )
            raise

        return response

Anyone here made it work my any chance ?
Thx :slight_smile:

Hi @anon49427038. Welcome to the developer community!

What version of Confluence Data Center are you running? I believe that group management REST APIs were only recently added to Confluence Data Center 8.2 based on the release notes. If you’re running the latest version, perhaps you could try staging the API call using a REST client like Postman first to insure that it’s not an issue with your client library.

The problem is the bad documentation of the API endpoint.
If the documentation was made giving all details of the input and output, it would work on the first try.
Take exemple here : https://it-lab.atlassian.net/wiki/spaces/RAEC/pages/89852793/REST+API+-+Groups#RESTAPI-Groups-Addgroups
For the group creation, you don’t need to only specify the group_name, but also an additional parameter ‘type’: ‘group’ for it to work.
I guess I’ll find something similar for the 2 others by trial and error instead of based on the poor documentation.
Thx anyway.

Can I know the REST API to fetch all group names ?