JIRA 4.3 : Creating a SOAP Client
This page last changed on Feb 23, 2011 by mdoar.
JIRA ships with the RPC plugin which enables remote access through XML-RPC and SOAP. This document contains notes on how to perform various operations (e.g. creating issues) via a Java SOAP client. Remotely exposed operations.Before you begin, check out the javadoc for the RPC plugin, specifically JiraSoapService, which has information on all the methods available through SOAP and and XML-RPC. Also check the list of RPC bugs, listed on the RPC plugin page, to see that none will affect you.
Enable the RPC pluginTo invoke JIRA operations remotely, you should ensure that the RPC plugin is enabled on the JIRA installation you are targeting. If you simply want to create a client to http://jira.atlassian.com/ then you can skip this step. First you need to check if the Accept Remote API Calls has been enabled in 'General Configuration' under 'Global Settings' in the left-hand menu: Then you need to enable the JIRA RPC Plugin in 'Plugins' under 'System' in the left-hand menu:
Your server should now be ready to accept remote procedure calls. WSDL descriptor
Regardless of the language or SOAP API used, you will need the WSDL descriptor for your JIRA installation. This is found at http://your_installation/rpc/soap/jirasoapservice-v2?wsdl. For instance, http://jira.atlassian.com's WSDL file is: http://jira.atlassian.com/rpc/soap/jirasoapservice-v2?wsdl Sample Java SOAP clientCheck out the latest demo SOAP client distribution from the Atlassian public repository. This contains a Maven 2 project configured to use Apache Axis, and a sample Java SOAP client which creates test issues in http://jira.atlassian.com. To give you an idea of what a Java SOAP client looks like, here is the sample client's code for creating issues: The various external classes (JiraSoapService etc) are the classes generated automatically from WSDL by the Maven Axis plugin. Python (SOAPPy) clientThe following code demonstrates how to create an issue and comment (on http://jira.atlassian.com) using python: #!/usr/bin/python # Sample Python client accessing JIRA via SOAP. By default, accesses # http://jira.atlassian.com with a public account. Methods requiring # more than basic user-level access are commented out. Change the URL # and project/issue details for local testing. # # Note: This Python client only works with JIRA 3.3.1 and above (see # http://jira.atlassian.com/browse/JRA-7321) # # Refer to the SOAP Javadoc to see what calls are available: # http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/JiraSoapService.html import SOAPpy import SOAPpy.Types import getpass, import datetime import time soap = SOAPpy.WSDL.Proxy('http://jira.atlassian.com/rpc/soap/jirasoapservice-v2?wsdl') #soap = SOAPpy.WSDL.Proxy('http://localhost:8090/jira/rpc/soap/jirasoapservice-v2?wsdl') #jirauser = raw_input("Username for jira [fred]: ") #if jirauser == "": # jirauser = "fred" # #passwd = getpass.getpass("Password for %s: " % jirauser) #passwd="fredspassword" jirauser='soaptester' passwd='soaptester' # This prints available methods, but the WSDL doesn't include argument # names so its fairly useless. Refer to the Javadoc URL above instead #print 'Available methods: ', soap.methods.keys() def listSOAPmethods(): for key in soap.methods.keys(): print key, ': ' for param in soap.methods[key].inparams: print '\t', param.name.ljust(10), param.type for param in soap.methods[key].outparams: print '\tOut: ', param.name.ljust(10), param.type auth = soap.login(jirauser, passwd) issue = soap.getIssue(auth, 'TST-3410') print "Retrieved issue:", issue print baseurl = soap.getServerInfo(auth)['baseUrl'] newissue = soap.createIssue(auth, {'project': 'TST', 'type': '1', 'summary': 'Issue created with Python!'}) print "Created %s/browse/%s" % (baseurl, newissue['key']) print "Adding comment.." soap.addComment(auth, newissue['key'], {'body': 'Comment added with SOAP'}) print 'Updating issue..' soap.updateIssue(auth, newissue['key'], [ {"id": "summary", "values": ['[Updated] Issue created with Python'] }, # Change issue type to 'New feature' {"id":"issuetype", "values":'2'}, # Setting a custom field. The id (10010) is discoverable from # the database or URLs in the admin section {"id": "customfield_10010", "values": ["Random text set in updateIssue method"] }, {"id":"fixVersions", "values":['10331']}, # Demonstrate setting a cascading selectlist. See # http://confluence.atlassian.com/display/JIRA/Frequently+Asked+RPC+Questions+and+Known+Issues#FrequentlyAskedRPCQuestionsandKnownIssues-Settingthevalueofcascadingselectcustomfield {"id": "customfield_10061", "values": ["10098"]}, {"id": "customfield_10061:1", "values": ["10105"]}, {"id": "duedate", "values": datetime.date.today().strftime("%d-%b-%y")} ]) print 'Resolving issue..' # Note: all fields prompted for in the transition (eg. assignee) need to # be set, or they will become blank. soap.progressWorkflowAction(auth, newissue['key'], '2', [ {"id": "assignee", "values": "jefft" }, {"id":"fixVersions", "values":['10331']}, {"id": "resolution", "values": "2" } ]) # Re. 'assignee' above, see http://jira.atlassian.com/browse/JRA-9018 # This works if you have the right permissions #user = soap.createUser(auth, "testuser2", "testuser2", "SOAP-created user", "newuser@localhost") #print "Created user ", user #group = soap.getGroup(auth, "jira-developers") # Adding a user to a group. Naming the parameters may be required (see # http://jira.atlassian.com/browse/JRA-7971). You may experience other # problems (see http://jira.atlassian.com/browse/JRA-7920). #soap.addUserToGroup(token=auth, group=group, user=user) # Adding a version to a project. dateObj = SOAPpy.Types.dateTimeType((int(2011), int(1), int(10), int(time.timezone/3600), 0, 0)) soap.addVersion(auth, "TST", remoteVersion = {'name': 'Version 1', 'releaseDate': dateObj}) print "Done!" # vim set textwidth=1000:
Ruby clientBen Walding (Codehaus) reports:
There is a JIRA4R sample Ruby script available in the samples (thanks Jonathan Zhang). If you have any Ruby samples to share, please let us know so we can include them into the repository as well. See also |
![]() |
Document generated by Confluence on Mar 27, 2011 18:54 |