Skip to main content
Solved

API call to get computers assigned user in Jamf Pro

  • October 12, 2018
  • 3 replies
  • 52 views

I am looking for a way to query the API for the username of the Mac's 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}')

3 replies

Forum|alt.badge.img+11
  • Valued Contributor
  • Answer
  • October 12, 2018

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

  • October 12, 2018

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


Forum|alt.badge.img+7
  • Valued Contributor
  • May 25, 2020

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