Hi,
Has anyone here created a policy via the API before? I've made other script to create objects via the API (buildings, departments, etc.) but these are my first attempts at creating a policy and it isn't working.
My goal is to have a script I can run against a client server that will make a policy to cache all of their packages. I plan to use a custom trigger. I'm not even trying to scope it in this, just create a policy that contains all the packages with an action to cache them. Then I can go in and and scope to a test machine.
I'm including my code below in case someone sees an obvious error, or if any of it is of value to someone else's efforts.
#!/bin/bash
jamfurl="https://xxx.jamfcloud.com"
jamfuser="APIUSER"
jamfpass="APIPASS"
packageList=$(curl -ksu "${jamfuser}:${jamfpass}" -H "Accept: text/xml" "${jamfurl}/JSSResource/packages")
packageCount=$(echo ${packageList} | xmllint --xpath '/packages/size/text()' -)
packageIDs=$(echo ${packageList} | xmllint --format - | awk -F'[<>]' '/<id>/{print $3}')
for packageID in $packageIDs; do
package=$(curl -ksu "${jamfuser}:${jamfpass}" -H "Accept: text/xml" "${jamfurl}/JSSResource/packages/id/${packageID}")
packageNumber=$(echo $package | xmllint --xpath '/package/id/text()' -)
packageName=$(echo $package | xmllint --xpath '/package/name/text()' -)
packageBlob="<package><id>${packageNumber}</id><name>${packageName}</name><action>Cache</action></package>"
packagesXML="${packagesXML}${packageBlob}"
done
uploadXML="<policy><general><name>Download Packages</name><enabled>true</enabled><trigger>EVENT</trigger><trigger_other>downloadTest</trigger_other><frequency>Ongoing</frequency></general><scope><all_computers>true</all_computers></scope><package_configuration><packages><size>${packageCount}</size>${packagesXML}</packages></package_configuration></policy>"
curl -ksu "${jamfuser}:${jamfpass}" -H "Content-Type: text/xml" "${jamfurl}/JSSResource/policies/id/0" -X POST -d ${uploadXML}
