Posted on 12-01-2021 07:17 AM
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:
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
Solved! Go to Solution.
Posted on 12-01-2021 09:14 AM
This was resolved by adding single quotes around the variable in the xpath command: "//extension_attribute[name='$eaName']".
Posted on 12-01-2021 09:14 AM
This was resolved by adding single quotes around the variable in the xpath command: "//extension_attribute[name='$eaName']".