The time has come in our deployment of iOS devices where we need to delete a large chunk of devices from the JSS. Of course, we could go through and “unmanage” each device from the JSS, but for approximately 250 devices, that is a fair amount of clicking. We could also go the route of deleting the profile from the mobile device, but that required even more tapping. How can we do this programmatically? That is where the JSS API comes to the rescue!
The JSS API provides a method for coding HTTP RESTful commands in a way that is very efficient and fast. Luckily, I’ve had some experience with the API while working on Casper Ally. If you are interested in the steps used to outline the app, read the paragraph below. If you just want to see the requirements skip the next paragraph.
My undergrad work was in engineering and one skill that I still use from that in my daily life is breaking larger projects down into smaller parts. In my mind, the process diagram from that consists of a bunch of boxes with question marks on them where what happens in code doesn’t really matter too much and everything is a series of inputs and outputs. (TTL logic gates, anyone) The process broke down into the following steps:
The resulting code is on github here
Once we download the command we will make sure it is executable (chmod +x the file) and run it with three parameters:
./delMobileDevice.sh serialnumbers.txt username password
The first parameter is the path to a text file containing the serial numbers of the device you wish to delete. The second is your jss username and the third is your jss password. That’s all!
The script does need a few modifications on your part (your JSS URL & port) as well as commenting out the line associated with deleting mobile devices or computers. Also, there is a section in the while loop where you can generate output to show what commands will be run and these allow you to test the code on one device before inputting in the entire serial number list. As always, please make sure to have a backup of your JSS database or snapshot the VM before running.