0

I setup billing and whatnot in Google Developer console, and enabled the Cloud DNS APi, however it is very confusing, and the documentation seems to be taking me in circles with no real examples.

I would like an example on how to use the Google Cloud DNS API using the google-api-php-client script from Github to add a DNS entry, remove a DNS entry, and update a DNS entry.

I am also unsure as to what credentials I am supposed to use for this as there doesn't seem to be any way to generate credentials -- only a unique app id (which can't be changed) for this billable service.

Their documentation points to stackoverflow for any questions regarding the use of this library.

Thanks in advance.

Kraang Prime
  • 9,981
  • 10
  • 58
  • 124

1 Answers1

2

I haven't used Cloud DNS, but the API seems to follow the same format of the other services, so I'll try to give you an idea of how it might work.

The documentation for the PHP library isn't the best, but looking at the source code and comments you can understand what should be done.

I'm not sure if you have used the library before, but the first step is to create and authenticate a Google_Client object. There are examples on Github.

You create credentials at the Developers Console. Select the project and then on the sidebar choose APIs & auth / Credentials.

The code below is obviously just a draft, check the library's source too see all the methods and options available.

<?php

// Assuming $client is a Google_Client instance that
// is already authenticated

$dns = new Google_Service_Dns($client);

$change = new Google_Service_Dns_Change();

$addition1 = new Google_Service_Dns_ResourceRecordSet();
// configure $addition1, check the methods on the lib

$deletion1 = new Google_Service_Dns_ResourceRecordSet();
// configure $deletion1, check the methods on the lib

$additions = array($addition1, ..., $additionN);
$deletions = array($deletion1, ..., $deletionN);

$change->setAdditions($additions);
$change->setDeletions($deletions);
// other settings on $change, check the lib

$dns->changes->create($project, $managedZone, $change);
Vinicius Braz Pinto
  • 8,209
  • 3
  • 42
  • 60
  • 1
    I am looking for a simple call list -- aka $dns->AddDomain($domain); $dns->CreateARecord($domain, $ip); $dns->CreateMXRecord($domain, $host, $priotity); etc. Their documentation is horrid, and reading through thousands of lines of code to find the specific function calls by guessing ---- there has got to be a better way. – Kraang Prime Nov 07 '14 at 01:22
  • 1
    This REALLY was helpful. I looked at this example and refactored my code to no avail until I realized that setAdditions was accepting a single Google_Service_Dns_ResourceRecordSet but should have required me to wrap it in an array - with the most unhelpful error message "The 'entity.change' parameter is required but was missing." after wrapping my additions in an array it all worked out! – josh.chavanne Aug 21 '15 at 04:45
  • Hi @josh.chavanne , can you please share that array format. I am also facing the same issue. Not able to debug the same. – Sreenath Aug 23 '15 at 11:47
  • @Sreenath I just initialized an array and added all my additions to that similar to the code example above. I was just pushing in one record into Google_Service_Dns_Change::setAdditions and was passing in one Google_Service_Dns_ResourceRecordSet object without wrapping it in an array. Hopefully that is helpful. – josh.chavanne Aug 23 '15 at 22:47