Let's try to ask DNS record for CloudFlare API.
Replace the "API Token" at auth_key by the API Token you get, the "Zone ID" can be found in Cloudflare Dashboard, logged in the Cloudflare Dashboard, check the Domain page, "Zone ID" information will appearance at API block, right hand side.
import json
import requests
cloudflare_api = "https://api.cloudflare.com/client/v4/"
zone_id = "278035ad7a9d983bc54a990b43ef7eb0"
auth_key = "API Token"
headers = {'Authorization': 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)
If the request send successfully, the result will print.
Ok
Then, the JSON data(dns_data) it respon will be like this:
{'result': [{'id': '3f7a9d18e117a65860dc5e2f2abdd191',
'zone_id': '278035ad7a9d983bc54a990b43ef7eb0',
'zone_name': 'lewd.dream',
'name': 'lewd.dream',
'type': 'A',
'content': '114.514.19.19',
'proxiable': True,
'proxied': True,
'ttl': 1,
'locked': False,
'meta': {'auto_added': False,
'managed_by_apps': False,
'managed_by_argo_tunnel': False,
'source': 'primary'},
'created_on': '2020-08-24T03:30:28.114514Z',
'modified_on': '2020-08-24T03:30:28.114514Z'},
{'id': 'ec8b33016fccf46dc8969316578974d7',
'zone_id': '278035ad7a9d983bc54a990b43ef7eb0',
'zone_name': 'lewd.dream',
'name': 'midsummer-s.lewd.dream',
'type': 'AAAA',
'content': '8930:8100:1145:141:919:36:114:514',
'proxiable': True,
'proxied': False,
'ttl': 1,
'locked': False,
'meta': {'auto_added': False,
'managed_by_apps': False,
'managed_by_argo_tunnel': False,
'source': 'primary'},
'created_on': '2020-08-24T03:43:46.114514Z',
'modified_on': '2020-08-24T03:43:46.114514Z'}],
'success': True,
'errors': [],
'messages': [],
'result_info': {'page': 1,
'per_page': 20,
'count': 2,
'total_count': 2,
'total_pages': 1}}
doesn't work, it throws
{"success":false,"errors":[{"code":9106,"message":"Missing X-Auth-Key, X-Auth-Email or Authorization headers"}]}