I’m trying to programatically purge urls but can’t get it to work. It seems to work and the API returns a success message, but I believe the page isn’t actually being purged.
Doing this in Python and it is roughly like this:
# get the cloudflare api url
cloudflare_api_url = 'https://api.cloudflare.com/client/v4/zones/' + \
zones_list[domain]['zoneid'] + '/purge_cache'
# set the headers for the email and the api_key
headers = {'X-Auth-Email': email, 'X-Auth-Key': key}
# set the data for the request to purge just this url
data = {'files': [clearcloudflare_url_list_by_domain]}
# make the request
r = uncached_session.post(cloudflare_api_url, headers=headers, json=data)
if r.status_code != 200:
print('\nCloudFlare purge request failed for {} : {}'.format(domain,r.text))
exit(1)
else:
if verbose:
print('\nCloudFlare purge request for {} successful'.format(domain))
print('\n')
After doing this when I load the URL it is still “hit” and shows the old content.
I understand from the documentation (https://developers.cloudflare.com/cache/how-to/purge-cache/) that there are cases where this won’t work due to headers and cache keys, but I’m not sure how this applies. These are Wordpress pages and I am not explicitly setting any special headers or keys.
How/where should I like to troubleshoot this? Is there a way to find the headers/keys that may be preventing it from working? I understand that I’ll need to pass the url/headers to the purge in such a case.
Thanks.