Posted on 10-18-2018 04:36 AM
So running this to add and exclusion to a manged preference:
>>
apiUser="apifulluser"
apiPass="iovobinospoisigehecm"
jssURL="https://jss.arts.ac.uk:8443"
POLICYIDS=(362)
function update_Managed_Preference ()
{
echo "Editing Managed Preference ID: $ID"
cat << EOD > /tmp/$ID.xml
<managed_preference_profile><scope>
<exclusions>
<computer_groups/>
<computer_group>
<id>599</id>
<name>OS Version: All 10.13</name>
<is_smart>true</is_smart>
<site>
<id>-1</id>
<name>None</name>
</site>
</computer_group>
</exclusions>
</scope></managed_preference_profile>
EOD
/usr/bin/curl -sfku "${apiUser}:${apiPass}" "${jssURL}/JSSResource/managedpreferenceprofiles/id/$ID" -T /tmp/$ID.xml -X PUT
if [ $? == 0 ]; then
echo -e "
Managed Preference $ID edited successfully"
rm /tmp/$ID.xml
else
echo -e "
Managed Preference $ID could not be edited"
rm /tmp/$ID.xml
fi
}
while read ID; do
update_Managed_Preference
done < <(printf '%s
' "${POLICYIDS[@]}")
The output of the script:
Editing Managed Preference ID: 362
<?xml version="1.0" encoding="UTF-8"?><managed_preference_profile><id>362</id></managed_preference_profile>
Managed Preference 362 edited successfully
On checking back with the JSS, I can see no addition to the exclusion...
Anyone??
Posted on 10-18-2018 04:58 AM
It may be totally unrelated but the API does seem glitchy today as less than 50% of the GET requests for my reporting dashboard are returning values.
Posted on 10-18-2018 06:03 AM
@kerouak Your XML is not valid from what I can tell. You are closing the computer_groups element, then trying to add an element into it. I can't validate this but it is a step in the right direction I think.
<?xml version="1.0" encoding="UTF-8"?>
<managed_preference_profile>
<scope>
<exclusions>
<computer_groups> <!-- you were closing this element, don't do that -->
<computer_group>
<id>599</id>
<name>OS Version: All 10.13</name>
<is_smart>true</is_smart>
<site>
<id>-1</id>
<name>None</name>
</site>
</computer_group>
</computer_groups> <!--you need to add this to close the element in the proper place -->
</exclusions>
</scope>
</managed_preference_profile>
Posted on 10-18-2018 06:19 AM
@ryan.ball is correct. @kerouak - I'd suggest changing the password on your api account. Also, I generally just use the id, and not name, when updating. Something like:
<managed_preference_profile><scope><exclusions><computer_groups><computer_group><id>599</id><site><id>-1</id></site></computer_group></computer_groups></exclusions></scope></managed_preference_profile>