3030# _snipeit_custom_name_1234567890 = subset jamf_key
3131#
3232# A list of valid subsets are:
33- version = "1.0.4 "
33+ version = "1.0.5 "
3434
3535validsubset = [
3636 "general" ,
@@ -197,6 +197,7 @@ def request_jamf_token():
197197 global token_request_time
198198 global jamf_apiKey
199199 global jamfheaders
200+ global jamfxmlheaders
200201 global expires_time
201202 token_request_time = time .time ()
202203 logging .info ("Requesting a new token at {}." .format (token_request_time ))
@@ -223,6 +224,7 @@ def request_jamf_token():
223224 # The headers are also global, because they get used elsewhere.
224225 logging .info ("Setting new jamf headers with bearer token" )
225226 jamfheaders = {'Authorization' : 'Bearer {}' .format (jsonresponse ['token' ]),'Accept' : 'application/json' ,'Content-Type' :'application/json' }
227+ jamfxmlheaders = {'Authorization' : 'Bearer {}' .format (jsonresponse ['token' ]),'Accept' : 'application/xml' ,'Content-Type' :'application/xml' }
226228 logging .debug ('Request headers for JamfPro will be: {}\n Request headers for Snipe will be: {}' .format (jamfheaders , snipeheaders ))
227229 else :
228230 logging .error ("Could not obtain a token for use with Jamf's classic API. Please check your username and password." )
@@ -396,7 +398,7 @@ def update_jamf_asset_tag(jamf_id, asset_tag):
396398 api_url = "{}/JSSResource/computers/id/{}" .format (jamfpro_base , jamf_id )
397399 payload = """<?xml version="1.0" encoding="UTF-8"?><computer><general><id>{}</id><asset_tag>{}</asset_tag></general></computer>""" .format (jamf_id , asset_tag )
398400 logging .debug ('Making Get request against: {}\n Payload for the PUT request is: {}\n The username, password, and headers can be found near the beginning of the output.' .format (api_url , payload ))
399- response = requests .put (api_url , data = payload , headers = jamfheaders , verify = user_args .do_not_verify_ssl , hooks = {'response' : request_handler })
401+ response = requests .put (api_url , data = payload , headers = jamfxmlheaders , verify = user_args .do_not_verify_ssl , hooks = {'response' : request_handler })
400402 if response .status_code == 201 :
401403 logging .debug ("Got a 201 response. Returning: True" )
402404 return True
@@ -419,7 +421,7 @@ def update_jamf_mobiledevice_asset_tag(jamf_id, asset_tag):
419421 api_url = "{}/JSSResource/mobiledevices/id/{}" .format (jamfpro_base , jamf_id )
420422 payload = """<?xml version="1.0" encoding="UTF-8"?><mobile_device><general><id>{}</id><asset_tag>{}</asset_tag></general></mobile_device>""" .format (jamf_id , asset_tag )
421423 logging .debug ('Making Get request against: {}\n Payload for the PUT request is: {}\n The username, password, and headers can be found near the beginning of the output.' .format (api_url , payload ))
422- response = requests .put (api_url , data = payload , headers = jamfheaders , verify = user_args .do_not_verify_ssl , hooks = {'response' : request_handler })
424+ response = requests .put (api_url , data = payload , headers = jamfxmlheaders , verify = user_args .do_not_verify_ssl , hooks = {'response' : request_handler })
423425 if response .status_code == 201 :
424426 logging .debug ("Got a 201 response. Returning: True" )
425427 return True
0 commit comments