API Python Script for Web Help Desk WHD custom connection

GabeShack
Valued Contributor III

Hey all,
We had some problems recently with our JSS and one of the suggestions was turning off a custom API tie in that one of my colleagues built to see if it was causing issues. Well we fixed the outstanding issues on the JSS but now I'm looking to turn this script back on.

If anyone familiar enough with the Jamf API could just take a quick look at the below python script I'd really appreciate it. The script is a custom connection for Web Help Desk that gathers both computers and mobile devices as well as extension attributes so we can sync all the fields that Jamf Pro has to WHD.

Thanks to anyone who can give some input and or feedback!

Gabe Shackney
Princeton Public Schools

#Python 3.4 - Need to run this command to install requests: pip install requests
import requests
import warnings
import time

warnings.filterwarnings('ignore')
print ("PPS XML Exporter for Casper Start")
print ("")
print ("Mobile1")
print ("")
#Open URL
#Using the URL, UserName, Password, and turning off the certificate verification since the certificate is self signed
# URL API: https://jssURL:8443/api/index.htm
url = "https://jssURL:8443/JSSResource/mobiledevices"
head = {"content-type": "text/xml", "Accept": "application/xml"}
r = requests.get(url, auth=(' XXXXXXXX', 'XXXXXXXX!'), headers=head, verify=False)
xml = r.content.decode(encoding='UTF-8')
#Open URL

#File
#Creates a connection to an output file and write out the XML data and close the file
file = open("mobile1.xml", 'w')
file.write(xml)
file.close()
#File
print ("")
print ("Mobile2")
print ("")
#Over Write File
#This needs to be done since the file is appended in the loop
file = open("mobile2.xml", 'w')                  
xml = ""
file.write(xml)
file.close()
#Over Write File
#Mobile 2 - More detail report
for count in range(1,20000):
                x = str(count)
                url = "https://jssURL:8443/JSSResource/mobiledevices/id/" + x + "/subset/General%26Location%26Purchasing"
                head = {"content-type": "text/xml", "Accept": "application/xml"}
                r = requests.get(url, auth=(' XXXXXXXX ', ' XXXXXXXX '), headers=head, verify=False)
                xml = r.content.decode(encoding='UTF-8')
                xml = xml + "
"
                print ("MobileDetail" + x)
                if xml[:5] == "<?xml":
                                file = open("mobile2.xml", 'a', encoding='utf-8')
                                file.write(xml)
                                #time.sleep(10)
                                file.close()
#Mobile 2 - More detail report
print ("")
print ("Computer1")
print ("")
#Open URL
#Using the URL, UserName, Password, and turning off the certificate verification since the certificate is self signed
# URL API: https://jssURL:8443/api/index.htm
url = "https://jssURL:8443/JSSResource/computers/subset/basic"
head = {"content-type": "text/xml", "Accept": "application/xml"}
r = requests.get(url, auth=(' XXXXXXXX ', ' XXXXXXXX '), headers=head, verify=False)
xml = r.content.decode(encoding='UTF-8')
#Open URL

#File
#Creates a connection to an output file and write out the XML data and close the file
file = open("computer1.xml", 'w', encoding='utf-8')
file.write(xml)
file.close()
#File
print ("")
print ("Computer2")
print ("")
#Over Write File
#This needs to be done since the file is appended in the loop
file = open("computer2.xml", 'w', encoding='utf-8')                         
xml = ""
file.write(xml)
file.close()
#Over Write File
#Computer 2 - More detail report
for count in range(1,20000):
                x = str(count)
                url = "https://jssURL:8443/JSSResource/computers/id/" + x + "/subset/General%26Location%26Purchasing%26Hardware%26Extension_attributes"
                head = {"content-type": "text/xml", "Accept": "application/xml"}
                r = requests.get(url, auth=('XXXXXXXX', 'XXXXXXXX'), headers=head, verify=False)
                xml = r.content.decode(encoding='UTF-8')
                xml = xml + "
"
                print ("ComputerDetail" + x)
                if xml[:5] == "<?xml":
                                file = open("Computer2.xml", 'a', encoding='utf-8')
                                file.write(xml)
                                #time.sleep(10)
                                file.close()
#Computer 2 - More detail report
print ("PPS XML Exporter for Casper Finished")
Gabe Shackney
Princeton Public Schools
0 REPLIES 0