Cloudflare api v4 srv DNS creation failure in php


#1

Hello,

I am sending data as json with PHP Curl to create a dns record.

However, although I submit the data correctly, the CloudFlare API is returning a bug.

Example PHP SOURCE :

<?php

$ch2 = curl_init("https://api.cloudflare.com/client/v4/zones/".$zoneid."/dns_records");
		curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER,false);
		curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
		curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
		'X-Auth-Email: '.$email.'',
		'X-Auth-Key: '.$apikey.'',
		'Cache-Control: no-cache',
	    // 'Content-Type: multipart/form-data; charset=utf-8',
	    'Content-Type:application/json',
		'purge_everything: true'
		
		));
	
		// -d curl parametresi.
		$srvdata = array(
		
		// Object Tipi
		
		  "type" => "SRV",
		  "service" => "_ts3",
		  "proto" => "_udp",
		  "name" => "{$dnsadgeldi}",
		  "priority" => 1,
		  "weight" => 5,
		  "port" => "{$dnsportgeldi}",
		  "target" => "{$dnsadgeldi}.{$domain}"		
		);
		
		$srv_data_string = json_encode($srvdata);

		curl_setopt($ch2, CURLOPT_POST, true);
		curl_setopt($ch2, CURLOPT_POSTFIELDS, $srv_data_string);	

		$sonuc2 = curl_exec($ch2);		
		
		echo '<br> <h2> Error Log To Screen : 2 </h2> <br>';
		print_r($sonuc2);
		
		curl_close($ch2);	
?>

Error Log :

{"success":false,"errors":[{"code":1004,"message":"DNS Validation Error","error_chain":[{"code":9101,"message":"service is a required data field."}]}],"messages":[],"result":null}


#2

Is there anyone who can help solve this problem?

The service data already goes to the cloudflare API, but the API does not seem to see it.


#3

My eyes glazed over at the PHP. Can you echo the CURL command that’s going to the API? It looks like you included a service field, but that’s not what the error is saying.


#4

Firstly thank you for reply.

The above php code now runs the curl command I wrote here and sends the data to the CloudFlare in json format.

Sending curl command cloudflare api :

curl -X POST "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records" \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     -H "Content-Type: application/json" \
     --data '{"type":"SRV","service":"_ts3","proto":"_udp","name":"testdnsname","priority":1,"weight":5,"port":6000,"target":"testdnsname.domain.com",}'

The error is returned when I submit:


#5

The only issue I can see is a comma after the domain just before the }, but I don’t see that comma in your PHP source.

The only other thing I can suggest is to do it manually in the DNS settings page, and then check your Audit Log (Dashboard Home) and see what the Metadata looks like.


#6

I think the problem is in the CloudFlare itself.

I looked at the audit log and I get the same error when I send it in the same way.

New data in php :

	$srvdata = array(
	
    // Object Tipi || Veriler Alınıyor
	
	"zone_name" => "{$domain}",
	"zone_id" => "{$zoneid}",
	"type" => "SRV",
	"name" => "_ts3._udp.{$dnsadgeldi}.",
	"content" => "SRV 0 0 {$dnsportgeldi} {$dnsadgeldi}.{$domain}.",
	"priority" => 0,
	"weight" => 0,
	"port" => $dnsportgeldi,
	"target" => "{$dnsadgeldi}.{$domain}",
	"service" => "_ts3",
	"proto" => "_udp",
	"name" =>"{$dnsadgeldi}",
	"proxied" => false,
	"proxiable" => false,
	"ttl" => 1
	 			
	);

Error Log :

{"success":false,"errors":[{"code":1004,"message":"DNS Validation Error","error_chain":[{"code":9101,"message":"service is a required data field."}]}],"messages":[],"result":null}

Curl Data :

{"zone_name":"clants3.online","zone_id":"7040902b675a6e44233505615faaac01","type":"SRV","name":"zirve","content":"SRV 0 0 6000 zirve.clants3.online.","priority":0,"weight":0,"port":"6000","target":"zirve.clants3.online","service":"_ts3","proto":"_udp","proxied":false,"proxiable":false,"ttl":1}


#7

It looks like it’s time to open a Support ticket: support AT cloudflare DOT com


#8

Cloudflare support very slow, i fixed this issue. SRV Record need additionally data :slight_smile:

New Data in PHP :

	$srvdata = array(
	'type' => 'SRV',
	'data' => array(
	"name"=>"".$dnsadgeldi."",
	"ttl"=>120,
	"service"=>"_ts3",
	"proto"=>"_udp",
	"weight"=>5,
	"port"=>intval($dnsportgeldi),
	"priority"=>0,
	"target"=>"".$dnsadgeldi.".".$domain.""
	));