Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need an example for Add User to Group function in JIRA REST API 6.1

Malintha Amarasinghe January 27, 2014

I am developing an application that uses the JIRA 6.1 REST API. Can I know a sample JSON Object that I should use, to add a user to a given group in JIRA?

This is the relevant API call: https://docs.atlassian.com/jira/REST/latest/#d2e1694

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
Andrew Fisher March 14, 2014

I used a little trial and error (I guess this part of the API is currently experimental), but got it to work ok. My python code uses a post request (per the docs), passing in the groupname as a uri parameter, and the username inside the post request's json payload (but using the key "name"), e.g.

payload = json.dumps({"name":"myusername"});
r = requests.post(api_path + "group/user?groupname=inactive-users", headers=myheaders, data=payload, auth=myauth)

If anyone has any thoughts about the experimental nature of this particular post call (e.g. whether it's likely to change etc), I'd be interested.

Todd Beverly April 30, 2014

Confirmed that it works.

I tried "user", "users" and "username" but I didn't try "name" for the key.

Many thanks Andrew!

1 vote
JamesT
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2016

There was a similar question posted on StackOverflow, but the original answer there was about creating a user, not adding a user to a group.  I took the info here and the post from there, and combined it into a one-liner that does the job, at least for me:

curl --insecure -D- -u admin:password -X POST --data "{\"name\": \"username\"}" -H "Content-Type: application/json" https://myjiraserver.com/rest/api/2/group/user?groupname=mygroupname

  1. Replace password with the actual admin password.
  2. Replace username with the name of the user you're adding to the group.
  3. Replace myjiraserver.com with your JIRA server's FQDN.
  4. Replace mygroupname with the name of the group to which you are adding this user.

I added the --insecure option because of the private SSL certs used on my server. You may not need that, or you may not be using HTTPS at all (in which case edit the URL to use HTTP).

0 votes
Treethawat Thanawachiramate September 23, 2014

Hi Andrew,

 

Do you have an example for groovy?

 

Thanks,

Man

0 votes
JasonMuscat July 1, 2014

Thanks a bunch for this. Just killed a whole morning trying to figure this out.

Andrew DeFaria November 9, 2015

Yeah why is the documentation for this so bad?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events