Get all members of Jira _not_ in a particular group

My overarching task is to get all members of Jira _except those_ in a particular group, but I think I need some intermediary help before I can get there. I'm using jira-python, and I've gotten so far as to sort of get the group I need:

print jira.groups(query='jira-developers')

gives me

{u'header': u'Showing 1 of 1 matching groups', u'total': 1, u'groups': [{u'html': u'<b>jira-developers</b>', u'name': u'jira-developers'}]}

which was not the format I expected, but fine. I can't get the members of that group. The documentation seems to suggest that jira.group_members(group) should work, but I get the error that jira has no attribute group_members. Either the docs are lying or I'm an idiot, which are at least equally likely.

4 answers

1 accepted

This works fine for me:

from jira.client import JIRA

options = {'server': 'http://localhost:8080'}
basic_auth = ('admin', 'password')
jira = JIRA(options, basic_auth)

users = jira.group_members('jira-developers')
print users

N.B. You must be authenticated and have permission to run these queries.
If you're not the output of this script will give you a clue:

  • HTTP 401 "Client must be authenticated to access this resource".
    This means you're not logged in.
    Supply your credentials in 'basic_auth'.
  • HTTP 403 "You are not authorised to perform this action. Administrator privileges are required."
    The user account you used to login doesn't have the 'Browse User' permission.

Your original quest to get all user which are not in a particular group will require some scripting.
I assume all your users are in the group 'jira-users'.

  • Retrieve the members of 'jira-users' and store them in a list.
  • Retrieve the members of the group you want to exclude.
  • Delete all members of the excluded group from the jira-users list.
  • The remaining users in the list are users which are not a member of the particular group.

I'm still getting `AttributeError: 'JIRA' object has no attribute 'group_members'` from your code (obviously with my server, username and password substituted)

No, it's called something else. I created the script within sublime and I'm running it from there. Does that matter?

Wild guess: did you call your script ""?
If so, rename it to something else, delete the "jira.pyc" file, and try again.

Edit: scratch that, you would get another error.

Sorry, I don't know.
It could be a problem with your jira_python installation, but that's just a guess.

It shouldn't, but that's easy enough to try out by running the script from the commandline.

No help. Also tried typing in the same commands directly in the python prompt. Same error message: AttributeError: 'JIRA' object has no attribute 'group_members'

I have no clue.

Can you try installing Python and jira_python in a clean environment (VM or another PC) to see if that works?
If that works it proves your own installation has some problems.

It's already in a virtual environment. What was the command for getting group_members pre-6?

I'm not a regular user of jira-python, so I don't know. Have just installed and tested it for this problem.

I'm not a regular user of jira-python, so I don't know. Have just installed and tested it for this problem.

I retried, installing jira-python from scratch in a virtualenv, and everything just works out of the box.
It looks like your problem is related to your environment, but I have no clue what it could be :(

Suggest an answer

Log in or Join to answer
Community showcase
Louis De Jaeger
Posted Thursday in Off-topic

Friday fun: your best joke

Hi all Lets make this Friday fun really fun and post one (or more) of your best jokes! The joke can be about an Atlassian product, or just a really fun joke you want to share! I’m not the best j...

189 views 12 3
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot