OPNsense Forum

Archive => 21.7 Legacy Series => Topic started by: xupetas on July 29, 2021, 12:08:12 pm

Title: Issues with API using example from docs.opnsense.org
Post by: xupetas 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.


Title: Re: Issues with API using example from docs.opnsense.org
Post by: Fright 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
Title: Re: Issues with API using example from docs.opnsense.org
Post by: xupetas on July 29, 2021, 02:30:20 pm
Oh... tks.

Is it slated on the roadmap for the foreseeable future?

Thanks again
Title: Re: Issues with API using example from docs.opnsense.org
Post by: Fright on July 29, 2021, 05:56:49 pm
sorry, can't say
Title: Re: Issues with API using example from docs.opnsense.org
Post by: franco on July 30, 2021, 01:59:50 pm
You can always add, remove, create, edit existing aliases with the non-utility endpoint...


Cheers,
Franco
Title: Re: Issues with API using example from docs.opnsense.org
Post by: xupetas on July 30, 2021, 02:16:43 pm
Hi Franco,

What non-utility endpoint? Can you please elaborate?

Thanks,
Nuno
Title: Re: Issues with API using example from docs.opnsense.org
Post by: franco on July 30, 2021, 02:18:31 pm
Hi Nuno,

https://docs.opnsense.org/development/api/core/firewall.html#id1


Cheers,
Francp
Title: Re: Issues with API using example from docs.opnsense.org
Post by: xupetas 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!