Python 2 code
Python 2 code
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' Create XML file in same directory as script ''' import urllib2 import sys import base64 import urllib JIRA_URL = "http://localhost:2990/jira/plugins/servlet/jirauserexport/admin/xml" BASIC_AUTH = "Basic " + base64.b64encode("admin:admin") HEADERS = {"Content-Type": "application/x-www-form-urlencoded","Authorization": BASIC_AUTH} FILE_NAME = "jira-users.xml" def call_endpoint(data, headers, method): try: request = urllib2.Request(JIRA_URL, data, headers) request.get_method = lambda: method contents = urllib2.urlopen(request).read() assert contents with open(FILE_NAME, 'a') as xml_file: xml_file.write(contents) except urllib2.HTTPError as e: print "HTTP error: " + str(e.code) print "Exiting..." sys.exit(1) post_data = urllib.urlencode({"userexport_searchstring":"","userexport_activeUsers":"true","userexport_inactiveUsers":"true"}) call_endpoint(data=post_data, headers=HEADERS, method="POST")
cURL example
cURL command
# Call XML export curl -vk -u admin:admin -H "Content-Type: application/x-www-form-urlencoded" \ "http://localhost:2990/jira/plugins/servlet/jirauserexport/admin/xml" \ -d "userexport_searchstring=&userexport_activeUsers=true&userexport_inactiveUsers=true" >> jira-users.xml