This is an old revision of the document!
API
Get zones
curl -s -X GET -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" https://api.cloudflare.com/client/v4/zones
Purge Cache
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" https://api.cloudflare.com/client/v4/zones/$ZONE/purge_cache --data '{"purge_everything":true}'
Scripts
- file basic-auth.js
// CloudFront > Functions > Create function // CloudFront > Functions > FunctionName > Publish // CloudFront > Functions > FunctionName > Add association (Viewer request) // // echo -n 'user:password' | base64 // dXNlcjpwYXNzd29yZA== function handler(event) { var authHeaders = event.request.headers.authorization; var expected = "Basic dXNlcjpwYXNzd29yZA=="; if (authHeaders && authHeaders.value === expected) { return event.request; } var response = { statusCode: 401, statusDescription: "Unauthorized", headers: { "www-authenticate": { value: 'Basic realm="Enter credentials for this super secure site"', }, }, }; return response; }