I am trying to set a fixed IP in a Unifi environment (UDMPRO) with Powershell. I can connect, and list connected clients, but when I try the PUT command I get
Invoke-Restmethod : {"error":{"code":403,"message":"Forbidden"}}
This is my code:
$Mac = "94:9f:3e:b1:27:3c"
[String]$Controller = "https://192.168.1.1"
$cred = Get-Credential
$credentials = "`{`"username`":`"$($cred.username)`",`"password`":`"$($cred.GetNetworkCredential().password)`"`}"
# Ignore self-signed certificates
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$LoginURI="$Controller/api/auth/login"
$Session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$results = Invoke-Restmethod -Uri $LoginURI -method post -body $credentials -ContentType "application/json; charset=utf-8" -WebSession $Session -TimeoutSec 600
$name = 'default'
$URI = "$controller/proxy/network/api/s/$name/stat/sta"
$request = Invoke-RestMethod -Uri $URI -WebSession $Session
$Client = $request.data | where { $_.mac -eq $Mac }
$ClientId = $Client._id
$Ip = $Client.last_ip
$FixedIP = @{
"use_fixedip" = $True
"fixed_ip" = $Ip
}
$FixedIPJson = $FixedIP | ConvertTo-Json
$URI = "$controller/proxy/network/api/s/$name/rest/user/$ClientId"
$header = @{"accept" = "application/json","text/plain"}
$Fixedresult = Invoke-Restmethod -Uri $URI -method PUT -Headers $header -Body $FixedIPJson -ContentType "application/json; charset=utf-8" -WebSession $Session
$Fixedresult
Does anyone have an idea what I am doing wrong?