Skip to content

Instantly share code, notes, and snippets.

@pirkla
Last active November 19, 2021 15:23
Show Gist options
  • Save pirkla/b298e29d17703b8a3c2874c4ce569f98 to your computer and use it in GitHub Desktop.
Save pirkla/b298e29d17703b8a3c2874c4ce569f98 to your computer and use it in GitHub Desktop.
import json
import requests
# Set all users' passwords in a group to 1234
################# REQUIRED USER DEFINED VARIABLES ############
# set network ID from https://url.jamfcloud.com/devices/enroll.html -> On device enrollment -> Network ID
networkId='networkidhere'
# set api key from https://url.jamfcloud.com/configuration/api
apiKey='apikeyhere'
# set base url for instance'
baseURL='https://yourdomain.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 a list of groups. Basic authorization is handled by requests auth argument
r=requests.get(baseURL +"/users/groups", headers=headers, auth=(networkId,apiKey))
# use the json module to parse the request into a dict
groupJson = json.loads(r.text)
# get the groups value from the dict
groupArray = groupJson["groups"]
# declare a dictionary and add group id's with names as keys
parsedDict=dict()
print("group names: ")
for x in groupArray:
parsedDict[x["name"]] = x["id"]
print(x["name"])
# prompt for a group name
inputVal=input("Enter a group name: ")
# get the uuid of the entered group name
pickedGroup = parsedDict.get(inputVal)
# make sure the group name entered actually exists
if (pickedGroup == None):
print(inputVal + " could not be found")
exit()
print("Picked Group: " + inputVal + " with id: " + str(pickedGroup))
# send a request to get users that are part of the group by filtering list users by picked group id
params = {"memberOf":pickedGroup}
r2 = requests.get(baseURL + "/users", headers=headers, auth=(networkId,apiKey),params=params)
# load the response into a dict, then get the list of users
resultJson = json.loads(r2.text)
usersArray = resultJson["users"]
# set the post data to set the password
newPasswordDict = { "password":"1234"}
for user in usersArray:
r3 = requests.put(baseURL + "/users/"+str(user["id"]), headers=headers, auth=(networkId,apiKey),data=newPasswordDict)
print("updated user: " + user["username"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment