I am looking for a way to query the API for the username of the Mac's assigned user in Jamf Pro.
Page 1 / 1
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}')
Thank you, thank you, thank you! I am just starting with Jamf Pro, so I appreciate your help!
Just a small note tr [A-Z] [a-z] didn't work for me, but tr "A-Z" "a-z" worked. Without the double quotes works too.
USERNAME=$(echo $USERINFO | /usr/bin/awk -F'<username>|</username>' '{print $2}' | tr "A-Z" "a-z")
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.