I am looking for a way to query the API for the username of the Mac's assigned user in Jamf Pro.
Solved
API call to get computers assigned user in Jamf Pro
Best answer by ShaunRMiller83
Here is a code snippet to get that info.
I use this snippet as part of a larger system renamer script.
#!/bin/sh
# Variables
jssURL="https://jamf.domain.com:8443/"
apiUser="apiuser"
apiPass="apipassword"
SERIAL=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}')
USERINFO=$(curl -k ${jssURL}JSSResource/computers/serialnumber/${SERIAL}/subset/location -H "Accept: application/xml" --user "${apiUser}:${apiPass}")
USERNAME=$(echo $USERINFO | /usr/bin/awk -F'<username>|</username>' '{print $2}' | tr [A-Z] [a-z])
first2user=$(echo ${USERNAME:0:2})
DEVICEINFO=$(curl -k ${jssURL}JSSResource/computers/serialnumber/${SERIAL}/subset/hardware -H "Accept: application/xml" --user "${apiUser}:${apiPass}")
MODEL=$(echo $DEVICEINFO | /usr/bin/awk -F'<model_identifier>|</model_identifier>' '{print $2}')Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
