Accounts API Endpoint v4 fails to authenticate


#1

Looking to create a tool that will allow me to create IP blocks for my domains on the fly, but I’m getting stuck just trying to authenticate against the API.

I’m using php on my side, but I can’t see where I could be passing bad data.

Hoping someone could take a look at what I have and provide some guidance:

IP = _REQUEST[‘ip’];
$url =“https://api.cloudflare.com/client/v4/accounts/01a7362d577a6c3019a474fd6f485823/firewall/access_rules/rules”;

$fields = array(
‘mode’=>‘block’,
‘configuration’=>array(
‘target’=>‘ip’,
‘value’=>$IP
),
‘notes’=>'Blocked for suspected abuse on '.date(“m/d/y”)
);

$blockData = json_encode($fields);

$headers = [
‘X-Auth-Email:XXaccount_emailXX’,
‘X-Auth-Key:XXglobal_apiXX’,
‘Content-Type:application/json’
];

$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_POSTFIELDS,$blockData);
$result     = curl_exec($ch);

when I print the results, I always receive the same error:

{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]}

I have confirmed multiple times that I am using the correct account email and the correct global key (reset the key twice to be sure) and I’m still getting an “Authentication error”. The total lack of description is a little frustrating.

Hoping someone has seen this before and I’m just missing something obvious.

Thanks for any insight you can provide!