Skip to content

Instantly share code, notes, and snippets.

@kongakong
Created April 23, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kongakong/85b3972c479e42cfb726884eb83adb19 to your computer and use it in GitHub Desktop.
Save kongakong/85b3972c479e42cfb726884eb83adb19 to your computer and use it in GitHub Desktop.
Print out page rules on Cloudflare
import requests
import pprint
import os
TOKEN=os.environ['TOKEN']
ZONE=os.environ['ZONE']
EMAIL="your email"
def get_all_rules():
headers = {
"X-Auth-Email": EMAIL,
"X-Auth-Key": TOKEN,
"Content-Type": "application/json"
}
url ="https://api.cloudflare.com/client/v4/zones/%s/pagerules?status=active&order=status&direction=desc&match=all"
r = requests.get(url % ZONE, headers=headers)
response = r.json()
for result in response['result']:
print "=" * 10
pprint.pprint(result)
if __name__ == '__main__':
get_all_rules()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment