OPNsense Forum

English Forums => 26.1 Series => Topic started by: opn_minded on February 07, 2026, 06:42:31 PM

Title: API - toggle firewall rule doesn't work
Post by: opn_minded on February 07, 2026, 06:42:31 PM
Hi,

my use-case is relatively simple, I would like to toggle a (LAN-) rule via API.

Based on https://docs.opnsense.org/development/how-tos/api.html#id4, I'm able to connect - but as soon as I try to use the toggle_rule endpoint (https://docs.opnsense.org/development/api/core/firewall.html#id6) I receive the following error;

{'result': 'failed'}
This is the endpoint I'm using (<RULE-UUID> based on the corresponding entry in the config.xml);

https://<OPNSENSE>/api/firewall/filter/toggle_rule/<RULE-UUID>
The request itself;

api_response = requests.post(opnsense_api_url, auth=(opnsense_api_key, opnsense_api_secret), verify=False)
Can you please tell me what I'm missing? Thanks for your time!
Title: Re: API - toggle firewall rule doesn't work
Post by: keeka on February 07, 2026, 08:11:35 PM
AIUI It needs to be sent as a POST request, with uuid as part of the json payload.
Title: Re: API - toggle firewall rule doesn't work
Post by: opn_minded on February 07, 2026, 10:14:53 PM
Hi,

tried it with and without payload, same effect.

api_response = requests.post(opnsense_api_url, auth=(opnsense_api_key, opnsense_api_secret), verify=False)
has the same effect as

json_payload = { 'uuid': <UUID> }
api_response = requests.post(opnsense_api_url, auth=(opnsense_api_key, opnsense_api_secret), verify=False, json=json_payload)

I also tried several different "command" nodes (toggle_rule, toggleRule), together with /1 at the end and without.. always the same result ({'result': 'failed'})

https://<OPNSENSE>/api/firewall/filter/toggle_rule/<UUID>/1
https://<OPNSENSE>/api/firewall/filter/toggleRule/<UUID>/1
https://<OPNSENSE>/api/firewall/filter/toggle_rule/<UUID>
https://<OPNSENSE>/api/firewall/filter/toggleRule/<UUID>

Reading further at https://docs.opnsense.org/development/api/core/firewall.html#id6... "Rules not visible in the web interface (Firewall ‣ Automation) will not be returned by the API either." -> I don't have such a menu entry on 26.1.1. Does that mean that API endpoint isn't working for "standard" (non-automation) rules?
Title: Re: API - toggle firewall rule doesn't work
Post by: meyergru on February 07, 2026, 10:17:39 PM
Correct. Only "new rules" will be visible over the API.
Title: Re: API - toggle firewall rule doesn't work
Post by: opn_minded on February 08, 2026, 09:14:38 AM
That did the trick! I've not migrated my "old rules" to "new rules", so I created a simple test "new rule".

Running my Python-script works like a charm, so many thanks again for taking your time and responding!

If anyone is interested;