2
votes

With the following code using Google's PHP API Client I am receiving this response.

Google_Service_Exception with message 'Error calling POST https://www.googleapis.com/dns/v1/projects/PROJECT-NAME/managedZones/DNSZONE/changes: (400) The 'entity.change' parameter is required but was missing.

Where PROJECT-NAME and DNSZONE are my project and zone.

$client_email = MYCLIENT;
$private_key = file_get_contents('config/credentials/KEY.p12');
$scopes = array('https://www.googleapis.com/auth/ndev.clouddns.readwrite');
$project = "PROJECT-NAME";
$managedZone = "DNSZONE";

$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 = "testing.DNSZONE.net.";
$resource->rrdatas[] = "testing.otherhost.com.";
$resource->ttl = 800;
$resource->type = "CNAME";

$dns = new Google_Service_Dns($client);
$change = new Google_Service_Dns_Change();
$change->kind = "dns#change";
$change->setAdditions($resource);

$dns->changes->create($project,$managedZone,$change);

I am a bit confused as to how to set this parameter. Or where I am even am to define it.

1
I figured it out - after 6 hours of fighting this - I realized that I needed to wrap my additions in an array. The error message was arcane and unhelpful.josh.chavanne
Is the rrdatas[ ] array that was throwing the error?user3547151
I needed to wrap my Google_Service_Dns_ResourceRecordSets in an array. I'll revise and an answer shortly.josh.chavanne

1 Answers

1
votes

Just for clarify what the answer is, setAdditions expects an array.

$change->setAdditions([ $resource ]);