Hello All,
Thanks for spending your time reading this.
I've been following the how to regarding the API interface for creating/modifying an Alias, that is located in https://docs.opnsense.org/manual/aliases.html.
Inside is stated that one can add an Alias like this:
curl \
--header "Content-Type: application/json" \
--basic \
--user "key:secret" \
--request POST \
--insecure \
--verbose \
--data '{"address":"10.0.0.2"}' \
https://opnsense.firewall/api/firewall/alias_util/add/MyAlias
So, i've built my script like this:
curl \
--header "Content-Type: application/json" \
--basic \
--user "XXXXX:YYYYYYY" \
--request POST \
--insecure \
--verbose \
--data '{"Ports":"512"}' \
https://172.16.0.20/api/firewall/alias_util/add/APP_FORWARD_PORTS
And i keep getting this error {"status":"failed"}.
I've tried to validate the script and credentials by using --data '{"address":"10.0.0.2"}' for the address and it works perfectly.
So it appears that my issue is related do "Ports".
I tried the script with Ports, Port, port, ports and nothing works.
Also, if i try to list ports from the API Alias it will not display any ports even those that exist:
curl -k -u "XXXXXXX":"YYYYYY" https://172.16.0.20/api/firewall/alias_util/list/EXISTING_PORT
i get:
{
"total": 0,
"rowCount": -1,
"current": 1,
"rows": []
}
If i try to export, i see the ports via API.
What is the syntax i should use? I don't see the ports directive being used in the manual. Is it not supported?
Thanks for your help.
Hi
afaik this api is intended only for adding addresses (and only) to an already existing alias
Oh... tks.
Is it slated on the roadmap for the foreseeable future?
Thanks again
sorry, can't say
You can always add, remove, create, edit existing aliases with the non-utility endpoint...
Cheers,
Franco
Hi Franco,
What non-utility endpoint? Can you please elaborate?
Thanks,
Nuno
Hi Nuno,
https://docs.opnsense.org/development/api/core/firewall.html#id1
Cheers,
Francp
Thanks!!
I am not a programmer, so i am trying to change a port on an alias. By any strech of luck do you have an example?
Again thanks for your reply!