Cloudflare Apiv4 Issue [{"code":9020,"message":"Invalid DNS record type"}]}]


#1

I am having issue while using cloudflare APIv4. I am trying to update a dns record and receiving following error:

{"success":false,"errors":[{"code":1004,"message":"DNS Validation Error","error_chain":[{"code":9020,"message":"Invalid DNS record type"}]}],"messages":,"result":null}

Following is the PHP function:

   function updateCloudflareDNS($zone_id,$dns_id){
   $updatedata = '[{"name":"e.example.com"},{"type":"A"},{"ttl":"1"},{"content":"4.4.4.4"}, 
   {"proxied":"true"}]';
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, 
  "https://api.cloudflare.com/client/v4/zones/".$zone_id."/dns_records/".$dns_id);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json; charset=utf-8',
    'X-Auth-Email: **********',
    'X-Auth-Key: ***********'
    ));    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $updatedata);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    
    $response = curl_exec($ch);
    curl_close($ch);
   return $response;
 }

Also, I am putting record type “A” correctly as mentioned on the Cloudflare API documentation

Could someone help me out with this issue?

Thanks


#2

Check your JSON string. It does not match the example in your link.


#3

Stupid mistake… Thanks