Skip to content

Instantly share code, notes, and snippets.

@sprocktech
Last active August 29, 2024 14:01
Show Gist options
  • Save sprocktech/d0a122c64924c786e3588d620179c0d7 to your computer and use it in GitHub Desktop.
Save sprocktech/d0a122c64924c786e3588d620179c0d7 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This is an example script to force provision a UniFi network device using the controller API
# If you are running this externally then replace localhost with the hostname
baseurl=https://localhost:8443
# I would make a dedicated admin user for this
username=<username_here>
password=<password_here>
# If you want to make this re-usable for multiple sites/devices then use argument varibles ${1} and ${2}
# Site is typically just 'default' but could also be an eight character string found in the controller URL
site=<site_here>
mac=<mac_here>
cookie=$(mktemp)
# If you have a valid cert then remove --insecure
curl_cmd="curl --cookie ${cookie} --cookie-jar ${cookie} --insecure"
${curl_cmd} --data "{\"username\": \"${username}\", \"password\": \"${password}\"}" ${baseurl}/api/login
${curl_cmd} --data "{\"mac\": \"${mac}\", \"cmd\": \"force-provision\"}" ${baseurl}/api/s/${site}/cmd/devmgr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment