API Calls does not work
Hey Guys,
i found a bug on NPM. I control my hosts via API and the problem is that when i disable the host via API the host shows as disabled in the NPM GUI but is still reachable, to really disable the host i need to disable via mouse in the GUI.
Can this fix someone? On bottom i post a test api script for enable disable via api so the devoloper can test this
Powershell Test Script:
##Host deaktivieren
$Token = Invoke-RestMethod -Uri http://192.168.178.100:81/api/tokens -Method POST -ContentType "application/json" -Body '{"identity":"[email protected]","secret":"Password"}'
$Token.Token
##Host-ID abfragen
$token = $Token.Token
$baseUrl = "http://192.168.178.100:81/api/nginx/proxy-hosts"
$headers = @{ Authorization = "Bearer $token" }
# Hosts abrufen
$response = Invoke-RestMethod -Uri $baseUrl -Headers $headers -Method Get
# Host-ID deaktivieren
$hostId = 5
# Alle Hosts abrufen
$response = Invoke-RestMethod -Uri $baseUrl -Headers $headers -Method Get
# Gewünschten Host auswählen
$host2 = $response | Where-Object { $_.id -eq $hostId }
# Neues Objekt mit nur erlaubten Feldern zusammenbauen
$updateHost = [PSCustomObject]@{
enabled = 0 # deaktivieren
#enabled = 1 # aktivieren
}
# PUT-URL für den Host
$putUrl = "$baseUrl/$hostId"
# JSON erzeugen
$jsonBody = $updateHost | ConvertTo-Json -Depth 10
# PUT Request senden
Invoke-RestMethod -Uri $putUrl -Headers $headers -Method Put -ContentType "application/json" -Body $jsonBody
Write-Output "Host ID $hostId wurde deaktiviert (enabled=0)."
I am having the same issue using bash shell in Linux. API runs, updates on screen, but does not really enable or disable the proxy. When I use the GUI to enable or disable, it works as expected, but via shell it seems to just change the displayed status of enabled or disabled without actually disabling the proxy.
Yep correctly