Skip to content

Instantly share code, notes, and snippets.

@pirkla
Created September 10, 2021 13:30
Show Gist options
  • Save pirkla/609984fb737d5b5390de01728692c11e to your computer and use it in GitHub Desktop.
Save pirkla/609984fb737d5b5390de01728692c11e to your computer and use it in GitHub Desktop.
import json
import requests
################# REQUIRED USER DEFINED VARIABLES ############
# set network ID from https://url.jamfcloud.com/devices/enroll.html -> On device enrollment -> Network ID
networkId='yournetworkid'
# set api key from https://url.jamfcloud.com/configuration/api
apiKey='yourapikey'
# set base url for instance'
baseURL='https://yoururl.jamfcloud.com/api'
################ END REQUIRED VARIABLES
# set a dict for headers to set api version
headers={"X-Server-Protocol-Version":"1"}
# send a request to get users without an assigned device
params = {"hasDevice":False}
userRequest = requests.get(baseURL + "/users", headers=headers, auth=(networkId,apiKey),params=params)
# check that request worked
if (userRequest.status_code != 200):
print("There was an issue with the request, status code: " + str(userRequest.status_code) + " terminating" )
exit()
# load the response into a dict, then get the list of users
resultJson = json.loads(userRequest.text)
usersArray = resultJson["users"]
print("Found: " + str(len(usersArray)) + " users with no device assigned")
inputVal=input("Move users to trash? (Y/n):")
if inputVal != "Y":
print("You input: " + inputVal + " so I guess we're done here")
exit()
# delete the users
for user in usersArray:
deleteUserRequest = requests.delete(baseURL + "/users/" + str(user["id"]), auth=(networkId,apiKey))
print("Moved user: " + user["username"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment