Home
Help
Search
Login
Register
OPNsense Forum
»
Archive
»
21.7 Legacy Series
»
Issues with API using example from docs.opnsense.org
« previous
next »
Print
Pages: [
1
]
Author
Topic: Issues with API using example from docs.opnsense.org (Read 4050 times)
xupetas
Jr. Member
Posts: 55
Karma: 5
Issues with API using example from docs.opnsense.org
«
on:
July 29, 2021, 12:08:12 pm »
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.
«
Last Edit: July 29, 2021, 12:55:01 pm by xupetas
»
Logged
Fright
Hero Member
Posts: 1777
Karma: 164
Re: Issues with API using example from docs.opnsense.org
«
Reply #1 on:
July 29, 2021, 02:16:06 pm »
Hi
afaik this api is intended only for
adding addresses
(and only) to an already
existing alias
Logged
xupetas
Jr. Member
Posts: 55
Karma: 5
Re: Issues with API using example from docs.opnsense.org
«
Reply #2 on:
July 29, 2021, 02:30:20 pm »
Oh... tks.
Is it slated on the roadmap for the foreseeable future?
Thanks again
Logged
Fright
Hero Member
Posts: 1777
Karma: 164
Re: Issues with API using example from docs.opnsense.org
«
Reply #3 on:
July 29, 2021, 05:56:49 pm »
sorry, can't say
Logged
franco
Administrator
Hero Member
Posts: 17661
Karma: 1611
Re: Issues with API using example from docs.opnsense.org
«
Reply #4 on:
July 30, 2021, 01:59:50 pm »
You can always add, remove, create, edit existing aliases with the non-utility endpoint...
Cheers,
Franco
Logged
xupetas
Jr. Member
Posts: 55
Karma: 5
Re: Issues with API using example from docs.opnsense.org
«
Reply #5 on:
July 30, 2021, 02:16:43 pm »
Hi Franco,
What non-utility endpoint? Can you please elaborate?
Thanks,
Nuno
Logged
franco
Administrator
Hero Member
Posts: 17661
Karma: 1611
Re: Issues with API using example from docs.opnsense.org
«
Reply #6 on:
July 30, 2021, 02:18:31 pm »
Hi Nuno,
https://docs.opnsense.org/development/api/core/firewall.html#id1
Cheers,
Francp
Logged
xupetas
Jr. Member
Posts: 55
Karma: 5
Re: Issues with API using example from docs.opnsense.org
«
Reply #7 on:
July 30, 2021, 05:28:40 pm »
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!
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
Archive
»
21.7 Legacy Series
»
Issues with API using example from docs.opnsense.org