Automating IP blocking in firewall rules

Is there any API which we can use to automate blocking of IPs in firewall rules.

Yes. There’s a separate “Filters” API for this: