API PUT not updating in JSS ..

kerouak
Valued Contributor

So running this to add and exclusion to a manged preference:

>>

!/bin/bash

Set the API credentials and JSS URL here. API account must have permissions to edit policies

apiUser="apifulluser"
apiPass="iovobinospoisigehecm"
jssURL="https://jss.arts.ac.uk:8443"

Edit this array to include the actual policy JSS IDs

POLICYIDS=(362)

function update_Managed_Preference ()
{

echo "Editing Managed Preference ID: $ID"

Generate a temp xml file with the new custom trigger name

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

Upload the new policy data to update the policy

/usr/bin/curl -sfku "${apiUser}:${apiPass}" "${jssURL}/JSSResource/managedpreferenceprofiles/id/$ID" -T /tmp/$ID.xml -X PUT

Check the exit status of the PUT command

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

}

Loop over array, running the above function on each ID

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??

3 REPLIES 3

jsherwood
Contributor

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.

ryan_ball
Valued Contributor

@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>

leslie
Contributor II
Contributor II

@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>