Hi, I’ve create this piece of code to create a new DNS Record in my cloudflare domain
function createDNSRecord($zoneID, $apiKey, $recordName, $recordType, $recordContent, $recordTTL = 3600) {
$apiEndpoint = "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records";
$data = array(
"content" => $recordContent,
"name" => $recordName,
"type" => $recordType,
"ttl" => $recordTTL
);
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer $apiKey"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiEndpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
return "cURL Error: $error";
} else {
$responseData = json_decode($response, true);
if (isset($responseData['success']) && $responseData['success']) {
return "DNS record created successfully.";
} else {
return "Failed to create DNS record. Error: " . print_r($responseData['errors'], true);
}
}
}
I’ve putted my email, api key (created here and my zone id but it return me the error 10000 (Authentication error)
Why?