Uploaded image for project: 'Identity'
  1. Identity
  2. ID-8004

Using REST API to add a user to a group to which it already belongs, error code is misleading

      Issue Summary

      I am using the REST API call to add a user to a group (here: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-user-post\). When the specified user is already a member of the specified group, the REST API call fails, as expected. However, the returned HTTP error is 400, and the HTTP response contains one error message that is not documented.

      So there are two problems here:
      1. The group name is not present in the error message
      2. The documentation for the 400 error says that it happens if:

      • group name is not provided.
      • accountId is missing.

      Steps to Reproduce

      1. Step 1 Use the REST API call to add a user to a group (here: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-user-post\).
      2. Step 2 When the specified user is already a member of the specified group, the REST API call fails, as expected.

      Expected Results

      • The error message should be the group name instead of the group ID on which the user already exists.
      • The error that happened to me is not documented which should have been documented.

      Actual Results

      • The error message is not documented.

        However, the returned HTTP error is 400, and the HTTP response contains one error message:
        "Cannot add user. User is already a member of '{1}'".

      Workaround

      Currently, there is no known workaround for this behavior. A workaround will be added here when available

            [ID-8004] Using REST API to add a user to a group to which it already belongs, error code is misleading

            Kat N added a comment -

            Hi everyone,
            Thank you for watching, following, and providing valuable feedback for our teams. Due to inactivity, we will be closing this bug as "Timed Out", but if this is still affecting your team, let us know so we can potentially re-evaluate.

            Kat N added a comment - Hi everyone, Thank you for watching, following, and providing valuable feedback for our teams. Due to inactivity, we will be closing this bug as "Timed Out", but if this is still affecting your team, let us know so we can potentially re-evaluate.

            There is another minor issue with the "add member to group api" in that if you use the Confluence API you can add users to group and it does not return an error versus using the Jira API it will return the HTPP 400 mentioned above. Granted the Jira API is on V3 while the Confluence API is on V1 (V2 dosen't appear to support adding users to groups) but they are still inconsistent.

            API Endpoints:

            domain.atlassian.net/wiki/rest/api/group/userByGroupId?groupId=

            domain.atlassian.net/rest/api/3/group/user?groupId=

            paul.thorburn added a comment - There is another minor issue with the "add member to group api" in that if you use the Confluence API you can add users to group and it does not return an error versus using the Jira API it will return the HTPP 400 mentioned above. Granted the Jira API is on V3 while the Confluence API is on V1 (V2 dosen't appear to support adding users to groups) but they are still inconsistent. API Endpoints: domain.atlassian.net/wiki/rest/api/group/userByGroupId?groupId= domain.atlassian.net/rest/api/3/group/user?groupId=

            By mistake I added the comment above using my private mail instead of work mail...

            Amir Katz (Outseer) added a comment - By mistake I added the comment above using my private mail instead of work mail...

            I am the one who reported this.

            My sort-of workaround is this:

            If returned error is 400, check the response. If the error message starts with 'Cannot add user. User is already a member of ', you can be pretty sure that this means the user is already in the group.

            If I were the developer, I would return error 409 ("conflict") which, IMO, better reflects the problem.

            Amir on Gmail added a comment - I am the one who reported this. My sort-of workaround is this: If returned error is 400, check the response. If the error message starts with 'Cannot add user. User is already a member of ', you can be pretty sure that this means the user is already in the group. If I were the developer, I would return error 409 ("conflict") which, IMO, better reflects the problem.

              Unassigned Unassigned
              6ddbd1c1e1be Dishon Victor
              Affected customers:
              5 This affects my team
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: