This morning Randy Saeks (@rsaeks) posed this question on Twitter:
Anyone using the JSS API to create an “add policy exclusion based on mobile device SN” ?
— Randy Saeks (@rsaeks) November 16, 2015
Which made me think this would be a great chance to use some of the new methods for group management available in the JSS API.
My recommendation was to create an exclusion group and add to the configuration profile. This way, he could add individual devices without having to edit the actually profile and have less risk of making an inadvertent modification that could risk breaking a know-working policy.
This post will look specifically at what is available for Mobile Device group management but the same principals will apply for Computer and User groups.
Previous Work Flow
In past versions of the API, if we wanted to update a static group we needed to know all devices that were in the group before performing our new PUT on the group. Otherwise we would erase all our previous work and replace it with the new data we had just submitted. In some cases, this was the desired effect. However, needing to make a small change (adding 1 new device) made using the API almost a non-starter. To make this work programmatically,we would always need to perform two API calls. One to GET the data, then a second to PUT the data back.
Luckily they have added two new options:
The API documentation states the following to introduce these to us:
PUT also works with a name. One or more mobile devices can be added by using <mobile_device_additions> instead of <mobile_devices>. One or more computers can be deleted by using <mobile_device_deletions> instead of <mobile_devices>
By reading this (brief) note, we know that we need to replace the mobile_devices element in our XML file with mobile_device_additions or mobile_device_deletions. In the samples below, notice the highlights where we replace mobile_devices and mobile_device_additions.
Typical Mobile Device Group Example
With the JSS API, we can usually strip down the XML to just what we need to submit. In this case, we can do the following:
Now, if I want to add the device above to my group, I just perform a PUT on the following URL and submit the abbreviated XML snippet above:
https://jss.url.com:8443/JSSResource/mobiledevicegroups/id/<ID of group we want to edit>
We could also do the same for the Static Group name:
https://jss.url.com:8443/JSSResource/mobiledevicegroups/name/<Name of group we want to edit>
Hopefully this can help you use these new features of the JSS API!
Update: All JSS group API resources have been updated to support this behavior. Full list below:
- Computer Groups
- Mobile Device Groups
- User Groups