Get DNS ID in Cloudflare

import json
import requests

cloudflare_api = "https://api.cloudflare.com/client/v4/"
zone_id = "XXXX"
auth_key = "XXXX"
headers = {'Authorization': 'Bearer '+ auth_key, 'Content-Type':'application/json'}

cloudflare_dns = cloudflare_api + "zones/" + zone_id + "/dns_records"  

cloudflare_dns_respon = requests.get(cloudflare_dns, headers=headers)

if cloudflare_dns_respon.status_code == 200:
    print("Ok")
else:
    print(cloudflare_dns_respon.status_code)    

dns_data = json.loads(cloudflare_dns_respon.text)

print(json.dumps(dns_data, indent=4))

with open('dns_data.json', 'w') as json_file:
    json.dump(dns_data, json_file, indent=4)

print("DNS data has been saved to dns_data.json")

Last updated