Skip to content

API Calls does not work #4656

Open
Open
@duczz

Description

@duczz

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)."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions