item referred by 'place-before' does not exist (11)

Hello.

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.

Something more to read:
http://forum.mikrotik.com/t/trouble-with-the-place-before-option-in-ip-firewall-nat/60923/1

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.

I will try change paramters instead of deleting.

Marting thank you for solution. It fit me.

It is a pity that cannot set the sequence number as in Cisco.

You can (should) use place-before with .id value in API:

/ip/firewall/filter/print
=.proplist=.id
!re.=.id=*37
!re.=.id=*1
!re.=.id=*2
!done
/ip/firewall/filter/add
=chain=input
=dst-address=192.168.1.1
=protocol=tcp
=dst-port=81
=comment=TESTING PLACE BEFORE
=place-before=*37
!done
=ret=*38
/quit

explorer_2019-09-27_08-06-56.png

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.

Nescafe2002 it’s a wonderful solution!
Your solution works and in CLI.

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.