Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
24.1 Legacy Series
»
Using API to create nested aliases
« previous
next »
Print
Pages: [
1
]
Author
Topic: Using API to create nested aliases (Read 83 times)
Quinten
Newbie
Posts: 1
Karma: 0
Using API to create nested aliases
«
on:
October 14, 2024, 05:09:07 pm »
Dear Forum!
We are trying to automate the creation of aliases using github actions with hosted runners. In powershell.
So far we have managed to create a blank alias.
$key='ourkey'
$secret='oursecret'
$credPair = "$($key):$($secret)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
$BasicAuthHeader = @{ Authorization = "Basic $encodedCredentials" }
$body = @{
alias = @{
enabled = 1
name = "Alias1"
type = "host"
description = "testing"
content = "1.1.1.1`n2.2.2.2"
}
} | ConvertTo-Json -Depth 100 -Compress
$apiUri="/api/firewall/alias/additem"
$baseUri="
http://1.2.3.4:80
"
$uri=$baseUri+$apiUri
$method="post"
$result=Invoke-RestMethod -Uri $uri -Method $method -Headers $BasicAuthHeader -Body $body -UseBasicParsing -ContentType "application/json"
$result
result uuid
------ ----
saved 39873aaf-e467-484c-a13a-8c506489ecfa
This worked.
Through the GUI aliases can be added to other aliases.
The GUI version uses the /api/firewall/alias/setItem/UUID endpoint
The UUID can be retrieved for an alias name using "/api/firewall/alias/getAliasUUID/$aliasName" endpoint.
This is the payload we captured with the web browser, when using the GUI to add an alias to another alias.
{"alias":{"enabled":"1","name":"MainAlias","type":"host","proto":"","categories":"","updatefreq":"","content":"testalias\nAlias1","interface":"","counters":"0","description":""},"network_content":"Alias1,testalais","authgroup_content":""}
When we attempted to add into alias "MainAlias" the content "Alias1" to replicate what the GUI does, we receive
result
------
failed
Does anyone know how to do this using the API?
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
24.1 Legacy Series
»
Using API to create nested aliases