We need to use API to identify if a computer is a member of one of five existing Static Computer Groups (StCG), on the client side, using an API script. The value is used locally to feed other non-JSS related workflows.
The StCG names would look like these:
- MyGroup_01
- MyGroup_02
- MyGroup_03
- MyGroup_04
- MyGroup_05
We typically use UUID to find the computer, and this API call seems to work:
staticComputerGroup=$( /usr/bin/curl -s -k -u ${apiUser}:${apiPass} ${jssURL}/JSSResource/computers/udid/${uuid} | /usr/bin/xpath '/computer/groups_accounts/computer_group_memberships[1]' 2>/dev/null | /usr/bin/sed -e 's/<group>//g;s/</group>/++/g' | /usr/bin/tr '++' '
' | /usr/bin/sed '/^$/d' | /usr/bin/grep MyGroup )
After wrestling with this for a couple hours, I wonder if the above is as convoluted as it seems. I created a few other API scripts that were easier and less of an eye sore:
assignedUser=$( /usr/bin/curl -s -k -u ${apiUser}:${apiPass} ${jssURL}/JSSResource/computers/udid/${uuid} | /usr/bin/xpath '/computer/location/username/text()' 2>/dev/null )
mgmtAccount=$( /usr/bin/curl -s -k -u ${apiUser}:${apiPass} ${jssURL}/JSSResource/computers/udid/${uuid} | /usr/bin/xpath '/computer/general/remote_management/management_username/text()' 2>/dev/null )
siteName=$( /usr/bin/curl -s -k -u ${apiUser}:${apiPass} ${jssURL}/JSSResource/computers/udid/${udid} | /usr/bin/xpath '/computer/general/site/name/text()' 2>/dev/null )
I'm ok with leaving the first API command the way it is, if necessary, but was hoping maybe I'm missing an easier way to do it.