Get IP Access Rules out of Cloudlare with API - help

Okay, so I’m not familiar with this.
I need to figure out a way to get all of the “IP access rules” out of Cloudflare, the IPs we have manually blocked under Firewall > Tools > IP Access Rules. All the posts I found on this topic say “use the API” except, I’m not familiar with this. The labeling of some items is not clear.

Any chance someone can provide an example of how to do this that I can wrap my MS-riddled head around?

If so, thanks, you’re my hero!

I’m trying to read the docs and find out which kind of tokens I need to create, stuck on step one. Which of these relates to the one I want?

Edit: Also I’m assuming the curl commands are going into ssh?

Edit: Tried connecting, success, valid and active.
Edit: Okay so I think I need?:

https://api.cloudflare.com/#user-level-firewall-access-rule-list-access-rules

Authentication error.

The documentation says:
API Key X-Auth-Key API key generated on the “My Account” page

First of all there is no “My Account” page
And I tried the Global API Key there, no success.
I’m a privileged user on another account, maybe this is the issue?

Edit: Was finally able to connect (using primary account and his global key) and it spit out empty information… which can’t be the case because we have more than 12 pages of blocks…

Edit: I’m using this:
curl -X GET “https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules?page=1&per_page=20&mode=block
-H “X-Auth-Email: [email protected]
-H “X-Auth-Key: redacted”
-H “Content-Type: application/json”

Any help on if I’m using the right one? Pretty please?

Overall your approach looks alright, however these rules are located on four individual layers

  1. https://api.cloudflare.com/#user-level-firewall-access-rule-list-access-rules
  2. https://api.cloudflare.com/#account-level-firewall-access-rule-list-access-rules
  3. https://api.cloudflare.com/#organization-level-firewall-access-rule-list-access-rules
  4. https://api.cloudflare.com/#firewall-access-rule-for-a-zone-list-access-rules

In your example you are only accessing layer one, you’ll most likely be (also) looking for layer four.

Can you post a screenshot of your access rules?

1 Like