4

I want to pull a list of users in the jira-users group. as i understand it, it can be done with Python using restkit.

Does anyone have any examples or links that give an example of this?

thanks.

1
  • I am stuck with same problem, can anyone throw some light on this.? Commented Mar 10, 2015 at 8:29

3 Answers 3

5

If somebody still need a solution, you can install JIRA rest api lib https://pypi.python.org/pypi/jira/. Just a simple example for your question:

from jira.client import JIRA

jira_server = "http://yourjiraserver.com"
jira_user = "login"
jira_password = "pass"

jira_server = {'server': jira_server}
jira = JIRA(options=jira_server, basic_auth=(jira_user, jira_password))

group = jira.group_members("jira-users")
for users in group:
    print users
Sign up to request clarification or add additional context in comments.

Comments

4

Jira has a REST API for external queries, it's using HTTP protocol for request and responses and the response content is formed as JSON. So you can use python's urllib and json packages to run request and then parse results.

This is Atlassian's document for Jira REST API: http://docs.atlassian.com/jira/REST/latest/ and for example check the users API: http://docs.atlassian.com/jira/REST/latest/#id120322

Consider that you should do authentication before send your request, you can find necessary information in the document.

4 Comments

I don't see the method that returns this information in that REST API, do you? I see a way to get all the groups a given user is in, but not where to get the members of a given group.
No, You are right, I can't find this API too. But It's not impossible, you can get information of all users by user get API - /rest/api/2/user - and then search them for a group.
True, I can't get a list of users but it was helpful nonetheless. not for getting that list of users but for other tasks i need to perform. so, this was still helpful to me. It looks like to get a list of jira users i will need to to q SQL query. i'm not sure there is another option. so, I'm looking at doing that with a python script.
I will try the get API( /rest/api/2/user ) if I have dificulties with the python script.
0
import urllib2, base64
import requests
import ssl
import json
import os
from pprint import pprint
import getpass

UserName = raw_input("Ener UserName: ")
pswd = getpass.getpass('Password:')

# Total number of users or licenses used in JIRA. REST api of jira can take values of 50 incremental
ListStartAt = [0,50,100,150,200,250,300]
counter = 0
for i in ListStartAt:
    request = urllib2.Request("https://jiraserver.com/rest/api/2/group/member?groupname=GROUPNAME&startAt=%s" %i)

    base64string = base64.encodestring('%s:%s' % (UserName, pswd)).replace('\n', '')
    request.add_header("Authorization", "Basic %s" % base64string) 
    gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
    result = urllib2.urlopen(request, context=gcontext)

    JsonGroupdata = result.read()
    jsonToPython = json.loads(JsonGroupdata)

    try:
        for i in range (0,50):
            print jsonToPython["values"][i]["key"]
            counter = counter+1
    except Exception as e:
        pass
print counter

3 Comments

Enter the group name you are looking to pull the information in the api "GRO\UPNAME"
You can edit your answer, to include more informations, by clicking the edit link under it. You don't have to comment the additional info. Also, don't just paste some code explaint it too.
Thanks.... FYI... That code is written by me. It will ping the rest api given by JIRA (Atlassian). We need to provide the group name. It will give all the list of users belonging to that group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.