Last Update: 11.09.2009. By azarai in python
We are using Jira as an Issue and Bug tracker at work. Lately we had the need to access it from external systems. Luckily Jira itself does provide a remote API in form of XML-RPC and SOAP. And i did not have any language constraints, so i could use python ;-) After looking in the API docs i noticed they do also provide some python examle. Great, even they use SOAPPy. SOAPPy does not work in python >= 2.5 and seem to be dead anyways. Some googling later i found the new soap kid for python, suds. And its dead simple. Heres an example accessing the public jira with their tutorial users:
from suds.client import Client
client = Client('http://jira.atlassian.com/rpc/soap/jirasoapservice-v2?wsdl')
auth = client.service.login('soaptester', 'soaptester')
Import suds, create a Client object with the wsdl file you’d like t use and here you go. Suds does use the endpoint declared in the wsdl and does support also multiple endpoints. Each method of the webservice is exposed as a method on the clients service object with the exact name. So when accessing jira ones code will look a bit camelCased.
Jira users can create Filters for issue searches. With the getFavouriteFilters method these can be read by the api. Lets get them for our test user:
from suds.client import Client
client = Client('http://jira.atlassian.com/rpc/soap/jirasoapservice-v2?wsdl')
auth = client.service.login('soaptester', 'soaptester')
filters = client.service.getFavouriteFilters(auth)
print filters
for filter in filters.getFavouriteFiltersReturn:
print filter['name']
print filter['id']
Of course when we are done, we should logoff.
client.service.logout(auth)
Take a look at the jira api documentation for an overview of what can be done with the api. The most helpful info for coding is the javadoc of their service class as one cant understand the parameters when only using the wsdl....
Happy hacking.