Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding users to group API. for two groups I keep getting "Specified user does not exist or you do n

Mark J Cunningham
Contributor
August 17, 2023

I have site admin access, but for two groups they keep returning

"Specified user does not exist or you do not have required permissions" using Rest API

 

Currently the API works with adding users to other groups, but for some reason these two are not playing ball.

In Jira Automation

 

Web Request

Get

https://myinstance.atlassian.net/rest/api/3/user/search?query='{{Issue.Email}}'

user xxxxx:xxxx

Content-Type application/json

Authorization Basic xxxx

Accept application/json

This works

Status 200s returned and Account ID is then grabbed as a variable and recoded in audit to confirm it has been grabbed

 

Variable name* AccID
Access your variable in other actions by using {{AccID}}
Smart value*
{{WebResponse.body.accountId}}

 

Log message* {{AccID}}
Web Request

Post

https://myinstance.atlassian.net/rest/api/3/group/user?groupId=zzzzzzz

user xxxxx:xxxx

Content-Type application/json

Authorization Basic xxxx

Accept application/json

 

{
"accountId": "{{AccID}}"
}

 

 

For every other group bar two this works

But for 2 groups it returns either

400
{errorMessages=[Cannot add user. User is already a member of '{1}'], errors={}}

 

This is OK as means someone has manually put them in the relevant group

 

Or

404
{errorMessages=[Specified user does not exist or you do not have required permissions], errors={}}

 

But

- user exists as they were found via their email and the account ID returned, so that rules out Specified user does not exist part of the error

- I have the permissions as, 1) the user n Auth work on the Get and on other group adds, 2) I am site admin

 

So not sure why this is glitching on two of the groups.

 

 

1 answer

1 accepted

0 votes
Answer accepted
Jehan Bhathena
Community Champion
August 17, 2023

Hi @Mark J Cunningham ,

You an try debugging the AccID by using the "Log Action" to print out the {{AccID}} in the Log Action, and verify if the value fetched it correct.

If the value is correct and still not working, would recommend 2 approaches:

1. Try adding to that group manually, being a site admin it should work for your user

2. Use Postman to try out the same and then debug if there is some change in the syntax that needs to be capture

Hope this helps.

Mark J Cunningham
Contributor
August 18, 2023

Found it was an even odder quirk

 

For some user doing the get user from email string returned 2 or  3 account IDs for that email address, rather than one

Yep very odd

So the three were then trying to be fetched for the post to group

 

Fix was to split the automation down further (really wish you could branch a branch and the jira automation ran in series rather than parallel)

So ended with

WebRequest - get user via email

Check if 200 returns

create variable for AccountID

Branch - Split variable at ","

Then for each

Post to add to group


Like Jehan Bhathena likes this
Jehan Bhathena
Community Champion
August 18, 2023

Glad to know you found the solution.

If this thread helped would request you to mark this as the Accepted answer so that it can be referenced by others too.

Mark J Cunningham
Contributor
September 27, 2023

Better solution

double email search

Oddly:

  • Query only can return multiple users as it is a fuzzy search, so john.smith@acme.com would return results for
    • john.smith@acme.com
    • anyone named john
    • anyone named smith
  • search on email address only - fails
  • Combine the two - magic

in the Get

https://<your instance>.atlassian.net/rest/api/3/user/search?emailAddress={{Issue.Email}}&query={{Issue.Email}}

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events