API call to get computers assigned user in Jamf Pro

Not applicable

I am looking for a way to query the API for the username of the Mac's assigned user in Jamf Pro.e6e3e96a044c4fb5b7d9f811c4b076e9

1 ACCEPTED SOLUTION

ShaunRMiller83
Contributor III

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}')

View solution in original post

3 REPLIES 3

ShaunRMiller83
Contributor III

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}')

Not applicable

Thank you, thank you, thank you! I am just starting with Jamf Pro, so I appreciate your help!

cbd4s
Contributor II

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")