Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Exporting a DNS Zone file from the TransIP API
require __DIR__ . '/vendor/autoload.php';
use Badcow\DNS\Zone;
use Badcow\DNS\Rdata\Factory;
use Badcow\DNS\ResourceRecord;
use Badcow\DNS\AlignedBuilder;
// Login details, fill those in with your TransIP username, the file containing
// your private key, and the domain you would like to export
Transip_ApiSettings::$login = "<username>";
Transip_ApiSettings::$privateKey = file_get_contents('<private_key_file>');
$domainName = '<>';
// Get the domain info
$domain = Transip_DomainService::getInfo($domainName);
// Construct the zone file
$zone = new Zone($domainName . '.');
$zone->setDefaultTtl(1); // 1 means automatic
foreach($domain->dnsEntries as $dnsEntry) {
$rr = new ResourceRecord;
switch($dnsEntry->type) {
case Transip_DnsEntry::TYPE_A:
case Transip_DnsEntry::TYPE_AAAA:
case Transip_DnsEntry::TYPE_CNAME:
case Transip_DnsEntry::TYPE_MX:
list($pref,$cont) = explode(' ', $dnsEntry->content);
$rr->setRdata(Factory::Mx($pref, $cont));
case Transip_DnsEntry::TYPE_TXT:
throw new \RuntimeException('Migrating ' . $dnsEntry->type . ' records is not implemented');
echo AlignedBuilder::build($zone);
"require" : {
"transip/transip-api-php" : "dev-master",
"Badcow/DNS": "^1.0"
"repositories": [
"type" : "vcs",
"url" : ""
Copy link

ramonfincken commented Mar 23, 2021

Deprecation warning: require.Badcow/DNS is invalid, it should not contain uppercase characters. Please use badcow/dns instead. Make sure you fix this as Composer 2.0 will error.

Copy link

ramonfincken commented Mar 23, 2021

Changed to make it work, thanks for the setup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment