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 auth_key.
import json
import requests
cloudflare_verify = "https://api.cloudflare.com/client/v4/user/tokens/verify"
auth_key = "API Token"
headers = {'Authorization': auth_key, '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.
Ok
Then, 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}]}