I’ve been using Cloudflare API for some time now uploading images, but now am trying to figure out how I can purge cache via API and am having issues with authentication. My code below (Python):
import requests
from configs.credentials import cloudflare
cf_url_cache = "https://api.cloudflare.com/client/v4/zones/{}/purge_cache".format(
cloudflare["zone_id"])
def clear_cloudflare_cache(url):
payload = {
"files": [url]
}
purge = requests.post(cf_url_cache, data=payload, headers={
"Content-Type": "application/json",
"X-Auth-Email": "{my_email}",
"X-Auth-Key": cloudflare["api_key"]
})
if purge.ok:
print("successfully purged URL cache")
else:
print("Purging Cloudflare cache request didn't succeed: {}".format(purge.content))
url = "https://my_url"
clear_cloudflare_cache(url)
I tried using Bearer Token and Email and Key - both result in the same error.
Bearer Token auth method works fine with the image upload endpoint.
Anybody could give me a hand?