The external control API (default 127.0.0.1:9090) makes every UI action scriptable. Below are ready-to-run examples - plain PowerShell, nothing to install.
Example 1: query and switch nodes
# state of the group named "Select"
Invoke-RestMethod "http://127.0.0.1:9090/proxies/Select"
# switch it to a specific node
Invoke-RestMethod -Method Put -Uri "http://127.0.0.1:9090/proxies/Select" -Body '{"name":"HK 01"}' -ContentType "application/json"
Example 2: auto-pick the lowest-latency node
$group = "Select"
$info = Invoke-RestMethod "http://127.0.0.1:9090/proxies/$group"
$best = $null; $bestDelay = [int]::MaxValue
foreach ($name in $info.all) {
try {
$r = Invoke-RestMethod ("http://127.0.0.1:9090/proxies/$name/delay?timeout=3000&url=" +
[uri]::EscapeDataString("http://www.gstatic.com/generate_204"))
if ($r.delay -lt $bestDelay) { $bestDelay = $r.delay; $best = $name }
} catch {}
}
if ($best) {
Invoke-RestMethod -Method Put -Uri "http://127.0.0.1:9090/proxies/$group" -Body (@{name=$best} | ConvertTo-Json) -ContentType "application/json"
"switched to $best ($bestDelay ms)"
}
Save as .ps1 and schedule hourly with Task Scheduler - a more controllable auto-selector than url-test (e.g. active only during certain hours).
Example 3: close all connections
Invoke-RestMethod -Method Delete "http://127.0.0.1:9090/connections"
Forces every connection to rebuild after a switch - same as the UI's broom button.
Example 4: change the outbound mode
Invoke-RestMethod -Method Patch -Uri "http://127.0.0.1:9090/configs" -Body '{"mode":"Global"}' -ContentType "application/json"
Notes
- With a
secretset, add-Headers @{Authorization = "Bearer your-secret"}to every call. - The endpoint catalog is in the API introduction.
- The API changes runtime state; a profile reload restores config-file values.
GET /traffic and GET /connections endpoints instead of polling.