What's the right value for user, when adding user to role in project, using REST API ?

Hello,
I'm currently building a small script that adds a user to a project's role, and I'm not sure about the user value.


I followed the documentation at https://docs.atlassian.com/jira/REST/cloud/#api/2/project/{projectIdOrKey}/role and in the Add Actors users, I currently provide the user key but the API keeps returning 404 (it works with groups !)


I've validated that the project existed, along with the role in the project (since the GET call returns fine & the POST failed with 404). I feel that I pass the wrong value in the user ({ "user" : ["admin"] })


Where should be the value & how could I get more info about the encountered error? (I call the API from Java using Jersey).


Thanks in advance,
Maxence VANBESIEN

1 answer

1 accepted

Hi Maxence,

This is working fine for me.
curl -u username:password -X POST --data '{"user" : ["admin"]}'  jiraurl/rest/api/2/project/projectkey/role/id -H'Content-type: application/json' -H'Accept: application/json'

Hello Swetha, 

I've tried and it also works for my for my admin & sysadmin... But not non-admin users...

Hi Maxcence,

It works for non admin users too for me. Can you paste the error here.

Nothing more than the 404..., when calling through Jersey (in Java)

When doing with cURL, I get the following 

{"errorMessages":["We can't find 'Maxence.Vanbesien' in any accessible user directory. Check they're still active and available, and try again."],"errors":{}}

While querying the user direclty https://.../jira/rest/api/2/user?username=Maxence.Vanbesien returns the right information ({"self":"https://kazan.atosworldline.com/jira/rest/api/2/user?username=Maxence.Vanbesien","key":"maxence.vanbesien","name":"Maxence.Vanbesien","emailAddress":"...","avatarUrls":{...},"displayName":"Maxence Vanbésien","active":true,"timeZone":"Europe/Paris","locale":"en_UK","groups":{"size":7,"items":[]},"applicationRoles":{"size":1,"items":[]},"expand":"groups,applicationRoles"})

Did you try with any other non-admin user other than maxence.vanbesien?

I think I found the solution...

The username should not be the name but the key (case is different in my case) and when using Jersey, we need to specify the type & the accept parameters (your cURL command gave me the clue)

(client.resource(roleURL).type("application/json").accept("application/json").post(element.toString()))

Good to hear that :)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

504 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you