Hi,
I seem to be unable to access the https://api.cloudflare.com/client/v4/zones/‘.$myzone.’/snippets/snippet_rules’; endpoint.
I have enabled user permissions for ‘Snippet [edit]’ and I am using the same Zone ID that i’m using for my custom purge code that seems ok.
Is there another permission that needs to be added other than Snippet?
Here is a simple example of the code I am running:
PHP CURL:
$firewallrules=array();
$firewallrules[]='{"enabled": false, "expression": "", "snippet_name": "test"}';
$token='Bearer my token';
$myzone='my zone ID'; //must retrieve through API. ($urlcf='https://api.cloudflare.com/client/v4/zones)
$urlcf='https://api.cloudflare.com/client/v4/zones/'.$myzone.'/snippets/snippet_rules';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $urlcf);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: $token", "Content-Type: application/json"));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"new_value": ['.implode($firewallrules, ',').']}');
$html=curl_exec($curl);
echo $html;
{“success”:false,“errors”:[{“code”:10000,“message”:“POST method not allowed for the api_token authentication scheme”}]}
But it should be… any help would be awesome!!
The EXACT same code works when I replace $urlcf with
$urlcf='https://api.cloudflare.com/client/v4/zones/'.$myzone.'/purge_cache';
AND
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"files": ["https://www.infinitesweeps.com/"]}');
Giving me {"success":true,........
Making me believe this is some “bug”.
Thank you for looking!