API call on extension attribute name field is not returning results

bhardawa
New Contributor III

I am somewhat new to making API calls. I am trying understand why the following API call won't return the value held by the "name" field of an extension attribute. However, running the same call, but targeting the "id" field does return the expected value.

Things to note:

  • Permissions are correct on the API user account.
  • I am able to return the raw XML via curl using the API user account.
  • Running on Big Sur & Monterey, and the xpath command is adjusted to reflect syntax changes beginning with Big Sur.
  • I am able to retrieve all nodes on the name field using "//extension_attribute[name()]".

Can someone more experienced with API calls throw me a bone?

 

apiUser="username"
apiPass="password"
apiURL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's|/$||')
udid=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID:/ { print $3 }')
eaName=""insert EA name string value""
eaID=""insert EA ID numeric value""

fromName=$(curl -s -f -u $apiUser:$apiPass -H "Accept: application/xml" $apiURL/JSSResource/computers/udid/$udid/subset/extension_attributes | xpath -e "//extension_attribute[name=$eaName]" 2>&1 | awk -F'<value>|</value>' '{print $2}' | tail -n +1)

fromID=$(curl -s -f -u $apiUser:$apiPass -H "Accept: application/xml" $apiURL/JSSResource/computers/udid/$udid/subset/extension_attributes | xpath -e "//extension_attribute[id=$eaID]" 2>&1 | awk -F'<value>|</value>' '{print $2}' | tail -n +1)

echo $fromName
echo $fromID

 

 

1 ACCEPTED SOLUTION

bhardawa
New Contributor III

This was resolved by adding single quotes around the variable in the xpath command: "//extension_attribute[name='$eaName']".

 

View solution in original post

1 REPLY 1

bhardawa
New Contributor III

This was resolved by adding single quotes around the variable in the xpath command: "//extension_attribute[name='$eaName']".