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 made changes -
            Resolution New: Timed out [ 10 ]
            Status Original: Gathering Impact [ 12072 ] New: Closed [ 6 ]

            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.
            SET Analytics Bot made changes -
            Support reference count Original: 2 New: 3

            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=
            SET Analytics Bot made changes -
            Support reference count Original: 1 New: 2
            SET Analytics Bot made changes -
            Support reference count New: 1

            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.
            Dishon Victor made changes -
            Component/s Original: JIRA [ 13891 ]
            Component/s New: Directory - Groups - Add / remove users [ 66395 ]
            Key Original: FEEDBACK-778182 New: ID-8004
            Symptom Severity New: Severity 3 - Minor [ 14432 ]
            Workflow Original: classic default workflow for Feedback Project [ 4288402 ] New: JAC Bug Workflow v3 [ 4288666 ]
            Project Original: Feedback [ 12310 ] New: Identity [ 16810 ]
            Status Original: Open [ 1 ] New: Gathering Impact [ 12072 ]
            Dishon Victor made changes -
            Description Original: h3. 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:
            "Cannot add user. User is already a member of '{1}'".

            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.

            h3. Steps to Reproduce

             # 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\).
             # Step 2 When the specified user is already a member of the specified group, the REST API call fails, as expected.

            h3. 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.

            h3. Actual Results

            * Error message which is not documented.
            {quote}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}'".(quote}

            The below exception is thrown in the xxxxxxx.log file:
            {noformat}
            ...
            {noformat}

            h3. Workaround

            Currently, there is no known workaround for this behavior. A workaround will be added here when available
            New: h3. 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\|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.

            h3. Steps to Reproduce
             # 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\|https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-user-post]).
             # Step 2 When the specified user is already a member of the specified group, the REST API call fails, as expected.

            h3. 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.

            h3. Actual Results
             * The error message is not documented.
            {quote}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}'".{quote}

            h3. Workaround

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

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

                Created:
                Updated:
                Resolved: