Creating SRV record with PHP


#1

Hello,
When i tried to create SRV record, getting an error.

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch2, CURLOPT_VERBOSE, 1);
$headers = array(
	'X-Auth-Email: '.$email,
	'X-Auth-Key: '.$authkey,
	'Content-Type: application/json',
);
$data2 = array(
	"type" => "SRV",
	"data" => "{
	'name' : '_ts3._udp.testsrv.',
	'content' : 'SRV 0 5 11 testsrv.domain.com.',
	'service' : '_ts3',
	'ttl' : '120'
	}
	"
);
$json2 = json_encode($data2);
curl_setopt($ch2, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/".$zoneid."/dns_records");
curl_setopt($ch2, CURLOPT_POSTFIELDS, $json2);
curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch2);
echo "<br />";
$toarray = json_decode(trim($result), TRUE);
print_r($toarray);
curl_close($ch2);

Also i tried with different array type

$data2 = array(
	"type" => "SRV",
	"data" => "{
	'service' : '_ts3',
	'protocol' : '_udp',
	'name' : 'testsrv',
	'priority' : '0',
	'weight' : '5',
	'port' : '11',
	'target' : 'testsrv.domain.com',
	'ttl' : '120'
	}"
);

But still i’m getting Invalid service value error. Error :

Array ( [success] => [errors] => Array ( [0] => Array ( [code] => 1004 [message] => DNS Validation Error [error_chain] => Array ( [0] => Array ( [code] => 9011 [message] => Invalid service value ) ) ) ) [messages] => Array ( ) [result] => )

How can i insert valid service value ? I can add SRV record with _ts3 via cloudflare dashboard.

Thank you


#2

Hello,
I solved the problem. The data value must also be sent as an array.

$data2 = array(
	'type' => 'SRV',
	'data' => array(
	"name"=>"testsrv",
	"ttl"=>120,
	"service"=>"_ts3",
	"proto"=>"_udp",
	"weight"=>5,
	"port"=>11,
	"priority"=>0,
	"target"=>"testsrv.domain.com"
	)