Created
July 15, 2020 22:14
-
-
Save pirkla/ce95ebc3597b7fe7abc9a59f7231b3a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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='networkidhere' | |
# set api key from https://url.jamfcloud.com/configuration/api | |
apiKey='apikeyhere' | |
# set base url for instance' | |
baseURL='https://url.jamfcloud.com/api' | |
################ END REQUIRED VARIABLES | |
# set a dict for headers to set api version | |
headers={"X-Server-Protocol-Version":"3"} | |
# send a request to get a list of classes. Basic authorization is handled by requests auth argument | |
r=requests.get(baseURL +"/classes", headers=headers, auth=(networkId,apiKey)) | |
# use the json module to parse the request into a dict | |
classJson = json.loads(r.text) | |
# get the classes value from the dict | |
classArray = classJson["classes"] | |
# declare a dictionary and add class uuid's with names as keys | |
parsedDict=dict() | |
print("class names: ") | |
for x in classArray: | |
parsedDict[x["name"]] = x["uuid"] | |
print(x["name"]) | |
# prompt for a class name | |
inputVal=input("Enter a class name: ") | |
# get the uuid of the entered class name | |
pickedClass = parsedDict.get(inputVal) | |
# make sure the class name entered actually exists | |
if (pickedClass == None): | |
print(inputVal + " could not be found") | |
exit() | |
print("Picked Class: " + inputVal + " with uuid: " + pickedClass) | |
# send a request to get class details for the given uuid | |
r2 = requests.get(baseURL + "/classes/" + pickedClass, headers=headers, auth=(networkId,apiKey)) | |
# load the response into a dict, then get the list of teachers and students in the dict | |
resultJson = json.loads(r2.text) | |
teachers = resultJson["class"]["teachers"] | |
students = resultJson["class"]["students"] | |
# declare an empty array to append emails to | |
emailList = [] | |
# loop over all teachers and students, adding their email to the email list | |
for x in teachers: | |
emailList.append(x["email"]) | |
for x in students: | |
emailList.append(x["email"]) | |
# declare a separator | |
s= "," | |
# join the email list with the separator | |
emails= s.join(emailList) | |
# print the emails | |
print(emails) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment