Help with firewall rules using api

Good day.

I’m not sure if i found a problem with the api.
I can create firewall rules using the api no problem.
If i delete the rules using the UI, i can create the firewall rules again using api and works fine.
When i delete the firewall rules using api, i cannot create firewall rules again for that domain using the api. I can still manually create them using UI.
When trying to create them with api i get this -
“code”: 10202,
“message”: “filter at index (0) conflicts with an existing filter”,
“source”: {
“pointer”: “/0/filter”

but if i check there are no filter or firewall rules.
Any ideas would help thanks.
If it helps the method I used to delete the rules was the individual firewall rule because that was the only one that worked for me. If I use this method - DELETE zones/:zone_identifier/firewall/rules then I get this error - [{‘message’: ‘invalid param size, min: 1, max: 25’, ‘source’: {‘parameter’: ‘id’}}]

This is a BIG ISSUE. i have tried another way, and i still get the same message. when you delete firewall rules using the api, you cannot add rules back using the api on the same domain.
zones.firewall.rules.post 10202 filter at index (0) conflicts with an existing filter - api call failed
Would purging help with this or purging is only for website content ?

Have you checked for the amount of allowed Firewall rules you can have for your domain (depending on the Plan)?

Have you checked does the filter already exists?

Are you using JSON or maybe, depending on the programming languge, flarectl?

For firewall/rules, have you identified which one or you delete all of them?

Good day,

I have checked and there are no firewall rules before i run the python code.
I’m not sure if it has anything to do with if you delete a zone/domain from the UI on the site, when you create the same domain again, it remembers some of the settings from before. So deleting does not actually wipe out everything related to that domain or zone. So when testing api in python and i am using requests.post/get/patch/put/delete and i have also tried the main python wrapper library too but still same error message, i’ testing deleting and recreating domains. I find it would be easier to delete a whole site and start from scratch.So currently if I have a site that has old firewall rules, it would be easier to delete them and create new ones using api but currently can’t do that.
Why the Api because i need to automate some behind the scenes work for work.

Besides native api calls which is what i used first, i also tried using this library - https://github.com/cloudflare/python-cloudflare.
The other strange thing is i can’t delete a firewall rule using the main delete method which is - DELETE zones/:zone_identifier/firewall/rules, but i use requests not curl.
This method gives me a param error of min and max-25 - it show param:id. i have check and the id for the firewall is correct, the one i use in the data part.
The only time i can currently delete a firewall using the api is using the delete individual rule - DELETE zones/:zone_identifier/firewall/rules/:id and im not sure if this delete is causing my issues. I’m not sure if purging the site will help or if that is only for website cached content ?

curl -X DELETE "[https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules](https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules)" \
     -H "X-Auth-Email: [[email protected]](mailto:[email protected])" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     -H "Content-Type: application/json" \ 

–data ‘{“id”:“372e67954025e0ba6aaa6d586b9e0b60”}’

Hi again,

Everything is on free plan for now while testing and i can see that it says before i try and add the firewall rules 0 out of 5 rules used.
Please tell me too if and when enable bot fight mode will be added to the api ?

Regards
Greg

Hi i delete all of them and try and re add them again.

Having the same problem. And i solved it.

https://developers.cloudflare.com/firewall/api/cf-firewall-rules/delete
Read note:

DELETE does not delete any filter related to the firewall rule. To delete the filter, it’s necessary to call the /filters API.

Deleting the firewall rule you should also delete the filter:
https://developers.cloudflare.com/firewall/api/cf-filters/delete