OPNsense Forum

Archive => 22.7 Legacy Series => Topic started by: JamesElstone on September 18, 2022, 06:14:03 PM

Title: Firewall API to manage Destination based NAT Port Forwarding
Post by: JamesElstone on September 18, 2022, 06:14:03 PM
Hi OPNsense Forum,

I have read up on the both the Core API and the "Firewall" plugin API, and can only find the controller for  "source_nat" that is documented.

I am wanting to dynamically control the the NAT -> Port Forward table via the API.

Also when I call the /api/firewall/filter_base/get API, it returns an API exception error: [internal function]: Phalcon\\Di\\Di->get('OPNsense\\\\Firewa...', NULL)

Has someone any domain knowledge in this area or can help me with this please?
Title: Re: Firewall API to manage Destination based NAT Port Forwarding
Post by: JamesElstone on September 18, 2022, 08:03:27 PM
For those who find this post and are having difficulty calling an OPNsense API, below is a full curl command posting data for reference:

curl \
-XPOST \
-H "Content-Type: application/json" \
-d '{"host": {"enabled":"1","hostname":"test","domain":"example.com","rr":"A","server":"1.2.3.4","description":"A test"}}' \
-k \
-u "yourAPIkey":"yourAPIsecret" \
https://opnsense.ip.address.or.dns.name/api/unbound/settings/addHostOverride/


The response you should get states:
{
  "result":"saved",
  "uuid":"guid_id_of_object_created"
}


Lots of people refer to it, but never in its full form in this forum. Hopefully will help others over time.
Title: Re: Firewall API to manage Destination based NAT Port Forwarding
Post by: ansibleguy on September 20, 2022, 09:02:19 PM
Hi.

FYI: If you have trouble using some OPNSense API - I've implemented many of the available ones in my project => https://github.com/ansibleguy/collection_opnsense

One could use the Ansible modules directly or read into (the code) how to use the APIs.  :D

- AnsibleGuy