Need recreate a firewall filtering rule via API.
I see it like this:
Delete rule and remember rule position.
Create rule and set position via place-before.
I will say right away, rule without a place-before parameter create successfully.
But if deleted rule and try crate rule with it position, I recive error: item referred by ‘place-before’ does not exist (11)
The problem can be simulated in the console. In CLI the problem can be resolved via command PRINT.
For example:
CLI
But /ip/firewall/filter/print doesn’t resolve the problem in API.
There is any solution?
I don´t think that it is really necessary, to recreate the rules.
What exactly are you trying to do?
place-before with numbers cannot be done with console or api
this would be possible: /ip firewall filter add chain=input comment=first place-before=[ find comment=“second” ]
But as stated, change of the existing rule should be ways better.
Main goal is check parameters of firewall rules.
If parameters are different from template, need set correct parameters.
I thought it was easier to remove and create a clean rule than to clean it up.
Sorry, nevertheless I think this is the wrong way. If you want to reset changed settings then you should reset it with set (like this):
/ip firewall raw set [find comment=“GENERATED: 001”] chain=prerouting disabled=no
This way you don´t loose counters, don´t have risk of disconnection between deleting and creating.
Furthermore in case you really want to delete a rule to replace it with a different one, you should first insert the new rule and then delete the existing one.