i would like to add additonal cname records to google cloud dns using the php api. cname records already exist for sub1.example.com and sub2.example.com added through the web console. but im getting an error
The resource record set 'entity.change.additions[0]' is invalid because the DNS name 'example.com.' may have either one CNAME resource record set or resource record sets of other types, but not both.
<?php
require '../autoload.php';
$client_email = CEMAIL;
$private_key = file_get_contents(PKEY);
$scopes = array('https://www.googleapis.com/auth/ndev.clouddns.readwrite');
$project = PNAME;
$managedZone = "example-com";
$creds = new Google_Auth_AssertionCredentials($client_email,$scopes,$private_key);
$client = new Google_Client();
$client->setAssertionCredentials($creds);
$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "example.com.";
$resource->rrdatas[] = "sub3.example.com.";
$resource->ttl = 300;
$resource->type = "CNAME";
$dns = new Google_Service_Dns($client);
$change = new Google_Service_Dns_Change();
$change->kind = "dns#change";
$change->setAdditions([$resource]);
$r=$dns->changes->create($project,$managedZone,$change);
echo '<pre>'.print_r($r,true).'</pre>';
?>
also i could not find a way to list the existsing cname records using the php api as this would have given me a clue to the answer here. Does anyone know how to retreive these, so far the code
<?php
//include details from above
$dns = new Google_Service_Dns($client);
$r=$dns->managedZones->listManagedZones($project);
echo '<pre>'.print_r($r,true).'</pre>';
$r=$dns->managedZones->get($project,$managedZone);
echo '<pre>'.print_r($r,true).'</pre>';
?>
does not list these cname records, although the methods, get and listManagedZones take an additional optional parameter i cannot find documentation on it
source : https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Dns.php line:416, 395
follow on from article : Google Cloud DNS Services - entity.change parameter is required but missing
-
https://developers.google.com/api-client-library/php/
https://developers.google.com/apis-explorer/#p/dns/v1/
https://support.google.com/cloud/answer/6158849?hl=en
https://cloud.google.com/dns/api/v1/resourceRecordSets#resource