-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepartmentlist.py
36 lines (25 loc) · 909 Bytes
/
departmentlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
import urllib2
import base64
import json
import sys
import ssl
import urllib
requestURL ="https://myjamfpro:8443/JSSResource/departments"
#build the request
request = urllib2.Request(requestURL)
_create_unverified_https_context = ssl._create_unverified_context
ssl._create_default_https_context = _create_unverified_https_context
request.add_header('Accept', 'application/json')
request.add_header('Authorization', 'Basic ' + base64.b64encode('USERNAME' + ':' + 'PASSWORD'))
#request the json data
response = urllib2.urlopen(request)
response_data = json.loads(response.read())
#set the layer we're looking into
departmentinfo = response_data['departments']
fulldepartment = ""
#loops for every instance of mapped printers
for ea in departmentinfo:
departmentname = ea['name']
fulldepartment = fulldepartment + departmentname + '\" \"'
print '\"' + fulldepartment