Why API? Using the REST API in an education environment.
Brad Schmidt Technical Services Operations Manager Hopkins Public Schools
Why API? Presentation agenda: Briefly - What is an API? What is the JSS API? How I ve used the API in my environment Lessons Learned, things to watch out for Resources Q&A
Let s talk to our JSS Copyright: Lucas Films - Thanks George/Disney?
What s an API? It stands for Application Programming Interface The JSS API lets us communicate with the JSS using a script or a program Safe(r) than going right to MySQL Eas(ier) than going right to MySQL
CRUD - Create, Read, Update, Delete Use HTTP to make the connection POST - Create objects GET - Read objects PUT - Update an existing object DELETE - Delete an object
Be careful what you say Copyright: Lucas Films - Thanks George/Disney?
Ways to communicate All methods use the HTTP protocol Python - requests, python-jss, httplib Bash/Shell - curl Ruby - jss-api gem Browser - https://dev.jss.com:8443/api
Python example using requests (tiny) >>> import requests >>> r = requests.get('https://jss.com:8443/jssresource/categories', auth=( user, pass )) >>> print r.text
Python example using requests >>> import requests >>> r = requests.get('https://jss.com:8443/jssresource/ categories', auth=( user, pass )) >>> print r.text
Bash example using requests (tiny) $ curl -u username:password https://jss.com:8443/jssresource/categories/
Bash example using requests $ curl -u username:password https://jss.com: 8443/JSSResource/categories
Example XML returned <categories> <category> <id>53</id> <name>brad s cool scripts</name> </category> <category> <id>40</id> <name>brad s cool packages</name> </category> </categories>
JSON and XML GET JSON and XML POST/PUT XML only Both are markup languages - Think HTML XML seems easier to work with in BASH JSON seems easier to work with in Python It comes down to personal preference
Acting on the data Now what? Get information from the JSS, work with the data in a script, send data back to the JSS. Import data into the JSS Export data from the JSS
Your logo here
Example 1 - Import Asset Tags Request: Have all the asset tags in the JSS CSV provided from vendors Obviously not going to hand enter No import function in the JSS
Example 1 - Import Asset Tags Solution: Script to import the tags using API Get a list of devices without asset tags Update the record with the asset tag Find the serial number in the CSV and return the asset tag
Example 1 - Import Asset Tags JSS:Advanced search API GET devices without asset tags The script takes each record and checks for it by serial number in the CSV. The script uses the API PUT command to update the device record with the found asset tag
Example 1 - Import Asset Tags Benefits: We now have asset tags in our JSS Helpful to do other cool things with the JSS.
Example 1 - Import Asset Tags
Example 2 - Wipe a $%# (lot) of ipads Request: We need to wipe 10,000+ ipads Option 1: Have techs do it one by one Option 2: Have students do it (My pref) Option 3: Create a script to wipe them Option 4: Wipe them all at once via API
Example 2 - Wipe a $%# (lot) of ipads Solution: Barcode Scanner + Script Create a bash script and present a GUI input window asking for the asset tag Use a barcode scanner to input the tag The script triggers a wipe command
Example 2 - Wipe a $%# (lot) of ipads Script launches a dialog window that asks for an asset tag Look up the device in the JSS and get the serial number. API GET Send an API PUT command with XML to trigger a wipe command, JSS issues the wipe
Example 2 - Wipe a $%# (lot) of ipads Benefits: The device is wiped on your terms The script triggers a wipe command Opens other options like processing repairs
Actual footage:
Example 3 - Process locked ipads Request: Exclude students from Config Profile Students get locked into Notes when they download a restricted app Security and training implications Existing workflow is a hassle
Example 3 - Process locked ipads Solution: Create an app to help process Written using Python and TKinter Anyone can use Uses the JSS match function
Example 3 - Process locked ipads Smart Group in JSS reads EA value. Smart Group is excluded from scope of CP GUI asks for search criteria, finds device and changes EA value on device Staff member removes restricted app. Presses update button in GUI An update inventory command is issued and the EA is cleared - API PUT JSS sends command to remove profile since the scope changed; restriction removed
Example 3 - Process locked ipads
Example 3 - Process locked ipads Benefits: Only certain staff members get access Not prone to error Much faster process
Example 4 - vshare Request: What is vshare? Get rid of it! A method to install pirated apps Apps can contain malware Installs as an in-house app with a provisioning profile
Example 4 - vshare Solution: Find them and wipe them Detect vshare E D I N D E Set an Extension Attribute Send the wipe command Send an email
Example 4 - vshare Advanced Search in the JSS looking for devices with vshare Script gets the list of devices in the using API GET Script sends an email Script changes an EA value so it falls out of the Advanced Search API PUT Script sends the remote command to wipe the device API PUT
Example 5 - Get to know your JSS Request: Identify the impact of a bug in the JSS Double and single quotes were being escaped in the advanced command field of policies Needed a list of policies since we had over 500
Example 5 - Get to know your JSS Solution: Bash script to get URLs of policies Used Curl to download all policies Used Bash to filter out polices with quotes Returned a list of policies and their URL, command, and policy name
Example 5 - Get to know your JSS Script to get a list of policies API GET Bash parses through list and returns the values I want
Example 6 - My latest creation Request: Key people need reports from the JSS Export/send these reports manually. Ugh! I could give them credentials to the JSS Link to another reporting system
Example 6 - My latest creation Solution: Use the Google Sheets API I developed a Python script to export any Advanced Search to a Google Sheet Downloads the data from JSS, uploads data to the Google Sheet
Example 6 - My latest creation Create any advanced device search in the JSS Script looks up the devices in advanced search API GET Script opens a connection to a Google Sheet Sheets API Script updates the Sheet with the headers and values of the search
Example 6 - My latest creation Benefits: I no longer need to run these reports manually No need to train users Least privilege Reports sent on time
Screenshot
Lessons Learned The road can be bumpy Come up with the logic, then script Have a development JSS with your prod data You can come across bugs in the API Use git/version control & test often!
Lessons Learned, cont. This stuff can be hard to share Some of my scripts have been very niche or you only need them once Genericizing scripts takes a lot of time
Resources https://your.jss.com:8443/api https://gist.github.com/kbareis https://bryson3gps.wordpress.com/the-unofficialjss-api-docs/ https://github.com/bradschm https://github.com/pixaranimationstudios/jss-apigem
Resources, cont. https://github.com/sheagcraig/python-jss https://github.com/burnash/gspread http://www.ofb.net/~egnor/xml2/ https://github.com/jamfit https://github.com/jamfsupport
Questions? Comments?
Thank you!