DepNotify Script to query API and populate building and Department popup fields..

Valued Contributor



Does anyone have a DN script with a solution to the above??




Contributor III

I have this to get you started.  This will look up all the departments and store them in the Variable allDepartments. You would need to add this somewhere into the script, this will get all the sites, format them into a variable called setValues.  Then you would need to use setValues for the list of Departments, then do the same for Buildings.

# API information
jamfProURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)

# request auth token
authToken=$( /usr/bin/curl \
--request POST \
--silent \
--url "$jamfProURL/api/v1/auth/token" \
--user "$username:$password" )

echo "$authToken"

# parse auth token
token=$( /usr/bin/plutil \
-extract token raw - <<< "$authToken" )

tokenExpiration=$( /usr/bin/plutil \
-extract expires raw - <<< "$authToken" )

localTokenExpirationEpoch=$( TZ=GMT /bin/date -j \
-f "%Y-%m-%dT%T" "$tokenExpiration" \
+"%s" 2> /dev/null )

echo Token: "$token"
echo Expiration: "$tokenExpiration"
echo Expiration epoch: "$localTokenExpirationEpoch"

# get list of Departments
allDepartments=$( /usr/bin/curl \
--header "Accept: text/xml" \
--request GET \
--silent \
--url "$jamfProURL/JSSResource/departments" \
--header "Authorization: Bearer $token" )

setvalues=$(echo $allDepartments | xmllint --format - | grep "<name>" | sed -e 's/.*<name>//g' -e 's|</name>|, |g' | tr '\n' ' ' | sed -E -e 's/, +$//')

I will say I use this script for setting the Site of a device but I found calling it in the big DEPNotify script was a hassle so I opted to use siftDialog and call this as part of a policy. Let me know how it goes I'd be interested if I could use this in my DEPNotify script.