Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents

Python

...

3 code using requests library

Code Block
title
languagepy
themeRDark
Python 2 code
linenumberstrue
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Create XML file in same directory as script
'''
import urllib2requests
import sys
import base64
import
urllib

JIRA_URL = "http://localhost:2990/jira/plugins/servlet/jirauserexport/admin/xml"
BASIC_AUTH = "Basic " + base64.b64encode(b"admin:admin").decode("utf-8")
HEADERS = {"Content-Typetype": "application/x-www-form-urlencoded", "Authorization": BASIC_AUTH}
FILE_NAME = "jira-users.xml"


def call_export_endpoint(dataurl, headerspayload, methodheaders):
    try:
        request r = urllib2requests.Request(JIRA_URLpost(url=url, data=payload, headers=headers)
    print("Response    request.get_method = lambdastatus code: method"         contents = urllib2.urlopen(request).read(+ str(r.status_code))
    return r._content


assert contents
   def write_to_file(file_data, file_name):
    with open(FILEfile_NAMEname, 'aw') as xml_file:
   
        xml_file.write(contentsfile_data.decode("utf-8"))
    except urllib2.HTTPError as e:
   print("File " + file_name + " was written to disk!")


if  print "HTTP error: " + str(e.code)__name__ == "__main__":
    body = {
        print"userexport_searchstring": "Exiting..."admin",
        "userexport_activeUsers": True,
    sys.exit(1)  post_data = urllib.urlencode({"userexport_searchstringinactiveUsers": True,
        "userexport_download": True,
        "userexport_activeUsersgroup": "true",
        "userexport_inactiveUsersapplication": "true"})
    final_result = call_export_endpoint(dataurl=post_dataJIRA_URL, payload=body, headers=HEADERS, method="POST")

...

)
    write_to_file(file_data=final_result, file_name=FILE_NAME)


cURL example

cURL command
Code Block
languagebash
themeRDark
titlecURL command
linenumberstrue
# 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

...