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

Maxence.Vanbesien August 28, 2017

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

2 answers

1 accepted

1 vote
Answer accepted
Deleted user August 29, 2017

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'

Maxence.Vanbesien August 29, 2017

Hello Swetha, 

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

Deleted user August 29, 2017

Hi Maxcence,

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

Maxence.Vanbesien August 29, 2017

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"})

Deleted user August 29, 2017

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

Maxence.Vanbesien August 29, 2017

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()))

Deleted user August 29, 2017

Good to hear that :)

0 votes
Powpow Shen June 15, 2020

This is more like a documentation issue.

In jira official document, username should be used. But user key is the one actually accepted. Username and user key can be the same most time but different sometimes. JIRA also provides a rest api for getting user info. You can use that API to see if that is your case.

mvanbesien June 15, 2020

Thanks for your reply !

Onuche Akor Idoko October 2, 2020

Thanks very much. This works also with the project role services for this action.

Suggest an answer

Log in or Sign up to answer