First, logged in the Cloudflare Dashboard, and go to User Profile, choice API Tokens, generated API Token.
Then, once successfully generated, the token secret is only shown once. Make sure to copy the secret to a secure place. Replace the API Token at BearerAuth.
import json
import requests
cloudflare_verify = "https://api.cloudflare.com/client/v4/user/tokens/verify"
BearerAuth = "API Token"
AuthMail = "Auth Mail"
headers = {"Authorization":BearerAuth, "X-Auth-Email":AuthMail, "Content-Type":"application/json"}
cloudflare_respon = requests.get(cloudflare_verify, headers=headers)
if cloudflare_respon.status_code == 200:
print("Ok")
else:
print(cloudflare_respon.status_code)
json_data = json.loads(cloudflare_respon.text)If the API Token activated successfully, the result will print.
OkThen, the JSON data(json_data) it respon will be like this:
{'result': {'id': 'c995e0fb6f249ac0e9a7ed90fc678e4b', 'status': 'active'},
'success': True,
'errors': [],
'messages': [{'code': 10000,
'message': 'This API Token is valid and active',
'type': None}]}
Should use
instead
link