Posted on 12-29-2015 09:33 AM
Hey All!
I'm fairly comfortable with Casper's API manipulation but I've been wracking my brain trying to figure out this issue (maybe it's post vacation brain?).
I have an extension attribute that's of type Pop-Up Menu. I've already populated the values for Pop-Up Menu.
I'm basically just trying to update the Pop-Up value for each machine via the API. Except every time I try, I get a 409 - Conflict error.
I'm updating the extension attribute by doing the following:
#!/bin/sh
JSSHostname="$JSSURL/JSSResource/computers/serialnumber/$1/subset/extensionattributes"
XMLTOWRITE="<computer><extension_attributes><extension_attribute><name>Deskside Support By</name><value>$2</value></extension_attribute></extension_attributes></computer>"
completeCurlCommand=`curl -s -f -k -u $APIUser:$APIPassword -X PUT -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$XMLTOWRITE" $JSSHostname --verbose`
I have no issues using the code above to update other extension attributes. It just seems to be when the extension attribute is of type Pop-Up menu and I try to change the Pop-Up value from one value to another that I get this issue. I have verified that the updated value I'm trying to insert does already exist in the Pop-Up menu values.
Any thoughts would be greatly appreciated! JSS version 9.81.
Solved! Go to Solution.
Posted on 12-29-2015 10:40 AM
I was able to figure this out with the major help of Bryson Tyrrell.
I removed the -f flag so I could see any errors and echoed out the completeCurlCommand variable to see what the JSS was echoing back for HTML. I found out it was actually an API permissions error. The account I had did not have permissions to update user based extension attributes which is where I specified the extension attribute to live in the JSS. Added a few extra permissions and all is well now :)
Thanks again Bryson!
Posted on 12-29-2015 10:40 AM
I was able to figure this out with the major help of Bryson Tyrrell.
I removed the -f flag so I could see any errors and echoed out the completeCurlCommand variable to see what the JSS was echoing back for HTML. I found out it was actually an API permissions error. The account I had did not have permissions to update user based extension attributes which is where I specified the extension attribute to live in the JSS. Added a few extra permissions and all is well now :)
Thanks again Bryson!
Posted on 10-03-2017 12:13 PM
@seansb Can you post the full script? I am trying to do the same thing to update the pop up EA but I am running into issues as well. Thanks!
Posted on 10-03-2017 06:59 PM
I actually got it working thanks to this post:
https://www.jamf.com/jamf-nation/discussions/24804/ea-via-curl-put
@davidacland's suggestion worked for me, thanks David!
Here is the completed script in case anyone wants to use it. I used encrypted string parameters as well.
#!/bin/bash
function DecryptString() {
echo "${1}" | /usr/bin/openssl enc -aes256 -d -a -A -S "${2}" -k "${3}"
}
username=$(DecryptString $4 'xxxxxxxxx' 'xxxxxxxxxx')
password=$(DecryptString $5 'xxxxxxxxx' 'xxxxxxxxxx')
jssURL=$(DecryptString $6 'xxxxxxxxx' 'xxxxxxxxxx')
ea_name="Name of EA"
ea_value="Value of EA"
serial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
# Create xml
cat << EOF > /private/tmp/ea.xml
<computer>
<extension_attributes>
<extension_attribute>
<name>$ea_name</name>
<value>$ea_value</value>
</extension_attribute>
</extension_attributes>
</computer>
EOF
## Upload the xml file
curl -sfku "${username}":"${password}" "${jssURL}/JSSResource/computers/serialnumber/${serial}" -T /private/tmp/ea.xml -X PUT
exit 0
Posted on 07-20-2018 08:55 AM
The XML portion of this script seems to be problematic for me. I tried to put this info into a function in my DEP script so I could update an extension attribute during initial setup, but the 'cat' command seems to confuse text editors and ultimately causes my script to fail to update the computer record.
I've also tried removing all of the white space and using an 'echo' to the xml file, but when I test locally, I'm getting
>Bad Request</p> <p>Error in XML file</p>
Is there another way to accomplish this?
Posted on 07-20-2018 09:01 AM
@mwilkerson Are you able to post the XML file contents here so we can see what it looks like? The cat << EOF >
method should work fine to generate the file, so I'm not sure why you'd be seeing that error. It's possible some of the strings, like for name or value, in the final XML file are using some illegal characters for an XML file or something.
Posted on 07-20-2018 09:44 AM
@mm2270, do you ever rest?? :)
I actually used the OP's method and it worked perfectly... I'm still not sure how the
cat << EOF >
method was failing, but I spent almost 2 days trying to take it apart. At this point, I'm good to go!